#!/bin/zsh # Author: Simon-Pierre Boucher # Contact: contact@spboucher.ai # Project: chat.spboucher.ai # # Single-command deploy, run ON m4m64a: # ~/apps/chat.spboucher.ai/ops/deploy.sh # Pulls latest (if a git remote exists), installs deps, builds, restarts agents. set -euo pipefail APP_DIR="$HOME/apps/chat.spboucher.ai" cd "$APP_DIR" echo "==> chat.spboucher.ai deploy ($(date))" if git rev-parse --is-inside-work-tree >/dev/null 2>&1 && git remote get-url origin >/dev/null 2>&1; then echo "==> git pull" git pull --ff-only fi echo "==> npm ci" npm ci echo "==> build" npm run build mkdir -p "$APP_DIR/logs" "$APP_DIR/data" echo "==> restart launchd agents" for AGENT in ai.spboucher.chat.app ai.spboucher.chat.ngrok; do PLIST="$HOME/Library/LaunchAgents/$AGENT.plist" if [ ! -f "$PLIST" ]; then cp "$APP_DIR/ops/$AGENT.plist" "$PLIST" echo " installed $AGENT.plist" fi launchctl unload "$PLIST" 2>/dev/null || true launchctl load "$PLIST" echo " restarted $AGENT" done echo "==> waiting for health" for i in {1..30}; do if curl -sf -o /dev/null http://127.0.0.1:3000/login; then echo "==> app is up: http://127.0.0.1:3000 → https://chat.spboucher.ai" exit 0 fi sleep 1 done echo "!! app did not come up within 30s — check $APP_DIR/logs/app.log" >&2 exit 1