1+ #! /usr/bin/env bash
2+ # =============================================================================
3+ # scripts/setup.sh — One-command local dev setup for Fluid
4+ #
5+ # Usage:
6+ # chmod +x scripts/setup.sh && ./scripts/setup.sh
7+ #
8+ # What it does:
9+ # 1. Checks required tools (Node, npm, Rust, Docker, docker compose)
10+ # 2. Copies .env.example → .env if .env does not exist
11+ # 3. Starts Postgres, Redis, and stellar-quickstart via docker compose
12+ # 4. Installs npm dependencies
13+ # 5. Runs Prisma migrations
14+ # 6. Starts all dev servers in parallel
15+ # =============================================================================
16+
17+ set -euo pipefail
18+
19+ # ── Colours ──────────────────────────────────────────────────────────────────
20+ RED=' \033[0;31m'
21+ GREEN=' \033[0;32m'
22+ YELLOW=' \033[1;33m'
23+ CYAN=' \033[0;36m'
24+ BOLD=' \033[1m'
25+ RESET=' \033[0m'
26+
27+ info () { echo -e " ${CYAN} [setup]${RESET} $* " ; }
28+ success () { echo -e " ${GREEN} [setup]${RESET} $* " ; }
29+ warn () { echo -e " ${YELLOW} [setup]${RESET} $* " ; }
30+ error () { echo -e " ${RED} [setup] ERROR:${RESET} $* " >&2 ; }
31+ die () { error " $* " ; exit 1; }
32+
33+ # ── 1. Prerequisite checks ────────────────────────────────────────────────────
34+ info " ${BOLD} Checking required tools...${RESET} "
35+
36+ check_tool () {
37+ local cmd=" $1 " label=" $2 " hint=" $3 "
38+ if ! command -v " $cmd " & > /dev/null; then
39+ die " '$label ' not found. $hint "
40+ fi
41+ success " $label found: $( command -v " $cmd " ) "
42+ }
43+
44+ check_tool node " Node.js" " Install from https://nodejs.org"
45+ check_tool npm " npm" " Comes with Node.js"
46+ check_tool cargo " Rust" " Install from https://rustup.rs"
47+ check_tool docker " Docker" " Install from https://docs.docker.com/get-docker/"
48+
49+ # docker compose (v2 plugin) or docker-compose (v1 standalone)
50+ if docker compose version & > /dev/null 2>&1 ; then
51+ COMPOSE=" docker compose"
52+ elif command -v docker-compose & > /dev/null; then
53+ COMPOSE=" docker-compose"
54+ else
55+ die " docker compose not found. Install Docker Desktop or the Compose plugin."
56+ fi
57+ success " Docker Compose found: $COMPOSE "
58+
59+ # ── 2. Environment file ───────────────────────────────────────────────────────
60+ info " ${BOLD} Setting up environment...${RESET} "
61+
62+ if [ ! -f .env ]; then
63+ cp .env.example .env
64+ success " Copied .env.example → .env"
65+ warn " Review .env and fill in any required secrets before continuing."
66+ else
67+ info " .env already exists — skipping copy."
68+ fi
69+
70+ # ── 3. Start infrastructure services ─────────────────────────────────────────
71+ info " ${BOLD} Starting infrastructure (Postgres, Redis, Stellar quickstart)...${RESET} "
72+
73+ $COMPOSE up -d postgres redis stellar-quickstart
74+
75+ info " Waiting for Postgres to be healthy..."
76+ until $COMPOSE exec -T postgres pg_isready -U " ${POSTGRES_USER:- fluid} " -d " ${POSTGRES_DB:- fluid_db} " & > /dev/null; do
77+ sleep 2
78+ done
79+ success " Postgres is ready."
80+
81+ info " Waiting for Horizon (stellar-quickstart) to be healthy..."
82+ until curl -sf http://localhost:8000/health & > /dev/null; do
83+ sleep 3
84+ done
85+ success " Horizon is ready at http://localhost:8000"
86+
87+ # ── 4. Install Node dependencies ──────────────────────────────────────────────
88+ info " ${BOLD} Installing Node dependencies...${RESET} "
89+ npm install
90+ success " npm install complete."
91+
92+ # ── 5. Prisma migrations ──────────────────────────────────────────────────────
93+ info " ${BOLD} Running Prisma migrations...${RESET} "
94+ if [ -f server/package.json ] && grep -q ' "prisma"' server/package.json 2> /dev/null; then
95+ (cd server && npx prisma migrate deploy)
96+ success " Prisma migrations applied."
97+ else
98+ warn " No Prisma config found in server/ — skipping migrations."
99+ fi
100+
101+ # ── 6. Start dev servers in parallel ─────────────────────────────────────────
102+ info " ${BOLD} Starting all dev servers in parallel...${RESET} "
103+ echo " "
104+ echo -e " ${BOLD} Servers starting:${RESET} "
105+ echo -e " • Node API → http://localhost:3001"
106+ echo -e " • Rust engine → http://localhost:3000"
107+ echo -e " • Admin dashboard → http://localhost:3002"
108+ echo -e " • Horizon → http://localhost:8000"
109+ echo " "
110+ warn " Press Ctrl+C to stop all servers."
111+ echo " "
112+
113+ # Run each dev server in the background, tee output with a prefix
114+ run_server () {
115+ local label=" $1 " ; shift
116+ " $@ " 2>&1 | sed " s/^/[${label} ] /" &
117+ }
118+
119+ run_server " rust" cargo run --manifest-path fluid-server/Cargo.toml
120+ run_server " node-api" npm run --prefix server dev
121+ run_server " dashboard" npm run --prefix admin-dashboard dev
122+
123+ # Wait for all background jobs; exit cleanly on Ctrl+C
124+ trap ' echo ""; info "Shutting down dev servers..."; kill 0' INT TERM
125+ wait
0 commit comments