#!/usr/bin/env bash # Deploy Agent Market on this box from a git ref. # ./deploy.sh staging [ref] -> port 8795, data in ~/agent-market/staging-data (test data only) # ./deploy.sh demo -> port 8796, always origin/main (merged code only) set -euo pipefail ENVN=${1:?staging|demo} REPO=http://127.0.0.1:3000/leora/agent-market.git case "$ENVN" in staging) PORT=8795; REF=${2:-main} ;; demo) PORT=8796; REF=main ;; *) echo "unknown env"; exit 1 ;; esac ROOT=$HOME/agent-market/$ENVN mkdir -p "$ROOT" if [ ! -d "$ROOT/app/.git" ]; then git clone -q "$REPO" "$ROOT/app"; fi cd "$ROOT/app" && git fetch -q origin && git checkout -q --detach "origin/$REF" 2>/dev/null || git checkout -q --detach "$REF" echo "deploying $ENVN @ $(git rev-parse --short HEAD) on :$PORT" # Optional config outside the repo (never committed): shared LLM settings, then per-env overrides. # llm.env holds e.g. AGENT_MARKET_LLM_API_KEY_FILE / _BASE_URL / _MODELS (a path to the key, never the key itself). CONF=$HOME/.config/agent-market set -a [ -f "$CONF/llm.env" ] && . "$CONF/llm.env" [ -f "$CONF/$ENVN.env" ] && . "$CONF/$ENVN.env" set +a PID=$(ss -ltnp 2>/dev/null | grep ":$PORT " | grep -o 'pid=[0-9]*' | cut -d= -f2 || true) [ -n "$PID" ] && kill "$PID" && sleep 0.5 AGENT_MARKET_PORT=$PORT AGENT_MARKET_ENV=$ENVN AGENT_MARKET_DATA=$ROOT/data \ nohup python3 server.py >> "$ROOT/server.log" 2>&1 & sleep 1 curl -sf "http://127.0.0.1:$PORT/healthz" >/dev/null && echo "ok: http://127.0.0.1:$PORT"