-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·397 lines (342 loc) · 13 KB
/
install.sh
File metadata and controls
executable file
·397 lines (342 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#!/usr/bin/env bash
set -euo pipefail
# =============================================================================
# install.sh — Local development setup for Retail Agentic Commerce
#
# Starts Docker infrastructure (Milvus, Phoenix, MinIO), installs dependencies,
# seeds the vector database, starts all 8 services in background, verifies health.
# Usage: ./install.sh
# Stop: ./stop.sh
# =============================================================================
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
PID_FILE="$ROOT_DIR/.local-dev.pids"
LOG_DIR="$ROOT_DIR/logs"
ENV_FILE="$ROOT_DIR/.env"
ROOT_VENV="$ROOT_DIR/.venv"
AGENTS_DIR="$ROOT_DIR/src/agents"
AGENTS_VENV="$AGENTS_DIR/.venv"
UI_DIR="$ROOT_DIR/src/ui"
WIDGET_DIR="$ROOT_DIR/src/apps_sdk/web"
# --- Colors ----------------------------------------------------------------
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m' # No Color
info() { printf "${CYAN}[INFO]${NC} %s\n" "$1"; }
ok() { printf "${GREEN}[OK]${NC} %s\n" "$1"; }
warn() { printf "${YELLOW}[WARN]${NC} %s\n" "$1"; }
err() { printf "${RED}[ERROR]${NC} %s\n" "$1"; }
# =============================================================================
# 1. Idempotency — stop existing services if running
# =============================================================================
if [ -f "$PID_FILE" ]; then
warn "Existing services detected (.local-dev.pids found). Stopping them first..."
if [ -x "$ROOT_DIR/stop.sh" ]; then
"$ROOT_DIR/stop.sh"
else
# Inline fallback if stop.sh isn't executable yet
while IFS=: read -r pid name; do
kill "$pid" 2>/dev/null || true
done < "$PID_FILE"
sleep 2
while IFS=: read -r pid name; do
kill -9 "$pid" 2>/dev/null || true
done < "$PID_FILE"
rm -f "$PID_FILE"
fi
fi
# =============================================================================
# 2. Validate prerequisites
# =============================================================================
info "Checking prerequisites..."
PREREQ_FAIL=0
check_cmd() {
if ! command -v "$1" &>/dev/null; then
err "$1 is not installed. $2"
PREREQ_FAIL=1
fi
}
check_cmd "python3" "Install Python 3.12+: https://www.python.org/downloads/"
check_cmd "uv" "Install uv: curl -LsSf https://astral.sh/uv/install.sh | sh"
check_cmd "node" "Install Node.js 18+: https://nodejs.org/"
check_cmd "pnpm" "Install pnpm: npm install -g pnpm"
check_cmd "docker" "Install Docker Desktop: https://www.docker.com/products/docker-desktop/"
# Check Python version (need 3.12+)
if command -v python3 &>/dev/null; then
PY_VER=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
PY_MAJOR=$(echo "$PY_VER" | cut -d. -f1)
PY_MINOR=$(echo "$PY_VER" | cut -d. -f2)
if [ "$PY_MAJOR" -lt 3 ] || { [ "$PY_MAJOR" -eq 3 ] && [ "$PY_MINOR" -lt 12 ]; }; then
err "Python 3.12+ required, found $PY_VER"
PREREQ_FAIL=1
else
ok "Python $PY_VER"
fi
fi
# Check Node version (need 18+)
if command -v node &>/dev/null; then
NODE_VER=$(node -v | sed 's/^v//')
NODE_MAJOR=$(echo "$NODE_VER" | cut -d. -f1)
if [ "$NODE_MAJOR" -lt 18 ]; then
err "Node.js 18+ required, found $NODE_VER"
PREREQ_FAIL=1
else
ok "Node.js $NODE_VER"
fi
fi
if [ "$PREREQ_FAIL" -ne 0 ]; then
err "Prerequisites not met. Install the missing tools above and re-run."
exit 1
fi
ok "All prerequisites met"
# =============================================================================
# 3. Environment setup
# =============================================================================
info "Configuring environment..."
if [ ! -f "$ENV_FILE" ]; then
cp "$ROOT_DIR/env.example" "$ENV_FILE"
ok "Created .env from env.example"
else
ok ".env already exists"
fi
# Source env vars we need
set -a
# shellcheck disable=SC1090
source "$ENV_FILE"
set +a
# Validate NVIDIA_API_KEY
if [ -z "${NVIDIA_API_KEY:-}" ] || [ "$NVIDIA_API_KEY" = "nvapi-xxx" ]; then
err "NVIDIA_API_KEY is not configured."
echo ""
echo " Get a free API key at: https://build.nvidia.com/settings/api-keys"
echo " Then set it in your .env file: NVIDIA_API_KEY=nvapi-..."
echo ""
exit 1
fi
ok "NVIDIA_API_KEY is set"
# Warn on non-default NIM endpoints
if [ "${NIM_LLM_BASE_URL:-}" != "https://integrate.api.nvidia.com/v1" ] || \
[ "${NIM_EMBED_BASE_URL:-}" != "https://integrate.api.nvidia.com/v1" ]; then
warn "NIM endpoints are not using public defaults — using custom endpoints"
fi
# =============================================================================
# 4. Start Docker infrastructure (Milvus, Phoenix, MinIO)
# =============================================================================
info "Starting Docker infrastructure..."
# Ensure Docker daemon is running
if ! docker info &>/dev/null; then
err "Docker daemon is not running. Start Docker Desktop and re-run."
exit 1
fi
ok "Docker daemon is running"
# Create the shared Docker network if it doesn't exist
if ! docker network inspect acp-infra-network &>/dev/null; then
docker network create acp-infra-network >/dev/null
ok "Created Docker network: acp-infra-network"
else
ok "Docker network acp-infra-network already exists"
fi
# Start infrastructure services
docker compose -f "$ROOT_DIR/docker-compose.infra.yml" up -d
ok "Docker infrastructure containers started"
# Wait for Milvus to be healthy
info "Waiting for Milvus to be healthy..."
MILVUS_READY=false
for attempt in $(seq 1 30); do
if curl -sf "http://localhost:9091/healthz" -o /dev/null --max-time 5 2>/dev/null; then
MILVUS_READY=true
break
fi
printf " Attempt %d/30: Milvus not ready yet...\r" "$attempt"
sleep 5
done
printf "\n"
if $MILVUS_READY; then
ok "Milvus is healthy (localhost:19530)"
else
warn "Milvus did not become healthy within timeout — agents may fail to connect"
fi
# =============================================================================
# 5. Install dependencies
# =============================================================================
info "Installing dependencies..."
# Root venv
info "Setting up root Python environment..."
cd "$ROOT_DIR"
uv venv --quiet 2>/dev/null || uv venv
uv sync --quiet 2>/dev/null || uv sync
ok "Root venv ready ($ROOT_VENV)"
# Agents venv
info "Setting up agents Python environment..."
cd "$AGENTS_DIR"
uv venv --quiet 2>/dev/null || uv venv
"$AGENTS_VENV/bin/pip" install -q -e ".[dev]" 2>/dev/null || uv pip install -e ".[dev]" --python "$AGENTS_VENV/bin/python"
ok "Agents venv ready ($AGENTS_VENV)"
# UI
info "Installing UI dependencies..."
cd "$UI_DIR"
if [ ! -f ".env.local" ]; then
cp env.example .env.local
ok "Created src/ui/.env.local from env.example"
fi
pnpm install --frozen-lockfile 2>/dev/null || pnpm install
ok "UI dependencies installed"
# Apps SDK Widget (non-blocking)
info "Installing Apps SDK widget dependencies..."
cd "$WIDGET_DIR"
if pnpm install --frozen-lockfile 2>/dev/null || pnpm install 2>/dev/null; then
ok "Apps SDK widget dependencies installed"
else
warn "Apps SDK widget install failed (non-blocking, widget dev server may not work)"
fi
cd "$ROOT_DIR"
# =============================================================================
# 6. Build environment prefix for agents and seeder
# =============================================================================
# Env vars are already exported from the source above (set -a / set +a block)
NAT_ENV_VARS=(
NVIDIA_API_KEY
NIM_LLM_BASE_URL
NIM_LLM_MODEL_NAME
NIM_EMBED_BASE_URL
NIM_EMBED_MODEL_NAME
MILVUS_URI
PHOENIX_ENDPOINT
)
AGENT_ENV=""
for var in "${NAT_ENV_VARS[@]}"; do
val="${!var:-}"
if [ -n "$val" ]; then
AGENT_ENV="$AGENT_ENV $var=$val"
fi
done
mkdir -p "$LOG_DIR"
# =============================================================================
# 7. Seed Milvus vector database with product embeddings
# =============================================================================
if $MILVUS_READY; then
info "Seeding Milvus with product catalog embeddings..."
if env $AGENT_ENV "$AGENTS_VENV/bin/python" "$AGENTS_DIR/scripts/seed_milvus.py" > "$LOG_DIR/milvus-seeder.log" 2>&1; then
ok "Milvus seeded with product embeddings (see logs/milvus-seeder.log)"
else
warn "Milvus seeding failed — check logs/milvus-seeder.log for details"
warn "Search and recommendation agents may not return results"
fi
else
warn "Skipping Milvus seeding (Milvus not healthy)"
fi
# =============================================================================
# 8. Start services
# =============================================================================
info "Starting services..."
# Parallel arrays for Bash 3.2 compatibility (no declare -A)
SVC_NAMES=()
SVC_PORTS=()
SVC_PIDS=()
start_service() {
local name="$1" port="$2" logfile="$LOG_DIR/$1.log"
shift 2
# Run the command in background, redirect output to log
"$@" > "$logfile" 2>&1 &
local pid=$!
echo "$pid:$name" >> "$PID_FILE"
SVC_NAMES+=("$name")
SVC_PORTS+=("$port")
SVC_PIDS+=("$pid")
info " Started $name (PID $pid, port $port) → logs/$name.log"
}
# --- Backend services (using root venv uvicorn) ---
start_service "merchant" 8000 \
"$ROOT_VENV/bin/uvicorn" src.merchant.main:app --host 0.0.0.0 --port 8000
start_service "psp" 8001 \
"$ROOT_VENV/bin/uvicorn" src.payment.main:app --host 0.0.0.0 --port 8001
start_service "apps-sdk" 2091 \
"$ROOT_VENV/bin/uvicorn" src.apps_sdk.main:app --host 0.0.0.0 --port 2091
# --- NAT Agents (using agents venv, need env vars) ---
start_agent() {
local name="$1"
local port="$2"
local config="$3"
local logfile="$LOG_DIR/$name.log"
cd "$AGENTS_DIR"
env $AGENT_ENV "$AGENTS_VENV/bin/nat" serve --config_file "configs/$config" --port "$port" > "$logfile" 2>&1 &
local pid=$!
echo "$pid:$name" >> "$PID_FILE"
SVC_NAMES+=("$name")
SVC_PORTS+=("$port")
SVC_PIDS+=("$pid")
info " Started $name (PID $pid, port $port) → logs/$name.log"
cd "$ROOT_DIR"
}
start_agent "promotion-agent" 8002 "promotion.yml"
start_agent "post-purchase-agent" 8003 "post-purchase.yml"
start_agent "recommendation-agent" 8004 "recommendation.yml"
start_agent "search-agent" 8005 "search.yml"
# --- UI (Next.js dev server) ---
cd "$UI_DIR"
pnpm dev > "$LOG_DIR/ui.log" 2>&1 &
UI_PID=$!
echo "$UI_PID:ui" >> "$PID_FILE"
SVC_NAMES+=("ui")
SVC_PORTS+=("3000")
SVC_PIDS+=("$UI_PID")
info " Started ui (PID $UI_PID, port 3000) → logs/ui.log"
cd "$ROOT_DIR"
ok "All services launched"
# =============================================================================
# 9. Health checks
# =============================================================================
info "Waiting for services to start (15s)..."
sleep 15
printf "\n${BOLD}%-25s %-6s %-8s %s${NC}\n" "SERVICE" "PORT" "STATUS" "PID"
printf "%-25s %-6s %-8s %s\n" "-------" "----" "------" "---"
HEALTH_ENDPOINTS_NAMES=( "merchant" "psp" "apps-sdk" "promotion-agent" "post-purchase-agent" "recommendation-agent" "search-agent" "ui" )
HEALTH_ENDPOINTS_PORTS=( 8000 8001 2091 8002 8003 8004 8005 3000 )
HEALTH_ENDPOINTS_PATHS=( "/health" "/health" "/health" "/health" "/health" "/health" "/health" "/" )
ALL_HEALTHY=true
for i in "${!HEALTH_ENDPOINTS_NAMES[@]}"; do
name="${HEALTH_ENDPOINTS_NAMES[$i]}"
port="${HEALTH_ENDPOINTS_PORTS[$i]}"
path="${HEALTH_ENDPOINTS_PATHS[$i]}"
# Find the PID for this service
pid="?"
for j in "${!SVC_NAMES[@]}"; do
if [ "${SVC_NAMES[$j]}" = "$name" ]; then
pid="${SVC_PIDS[$j]}"
break
fi
done
# Check health with retries (up to ~25s per service for slow agent startups)
status="${RED}FAIL${NC}"
for attempt in 1 2 3 4 5; do
if curl -sf "http://localhost:$port$path" -o /dev/null --max-time 5 2>/dev/null; then
status="${GREEN}OK${NC}"
break
fi
sleep 5
done
if [[ "$status" == *"FAIL"* ]]; then
ALL_HEALTHY=false
fi
printf "%-25s %-6s %-8b %s\n" "$name" "$port" "$status" "$pid"
done
# =============================================================================
# 10. Summary
# =============================================================================
printf "\n"
if $ALL_HEALTHY; then
printf "${GREEN}${BOLD}All services are running!${NC}\n"
else
printf "${YELLOW}${BOLD}Some services failed health checks. Check logs for details.${NC}\n"
fi
printf "\n${BOLD}Access URLs:${NC}\n"
echo " Demo UI: http://localhost:3000"
echo " Merchant API: http://localhost:8000/docs"
echo " PSP: http://localhost:8001/docs"
echo " Apps SDK MCP: http://localhost:2091/docs"
echo " Phoenix Traces: http://localhost:6006"
echo " MinIO Console: http://localhost:9001"
printf "\n${BOLD}Logs:${NC} $LOG_DIR/<service>.log\n"
printf "${BOLD}Stop services:${NC} ./stop.sh\n\n"