#!/usr/bin/env bash # deploy.sh — Pull latest code and redeploy via Docker Compose # Run from /opt/cast-ghl-plugin after initial server setup. # Usage: bash deploy/deploy.sh set -euo pipefail APP_DIR="$(cd "$(dirname "$0")/.." && pwd)" cd "$APP_DIR" echo "==> Pulling latest code" git pull --ff-only echo "==> Building and restarting services" docker compose pull mongo # pull latest Mongo image if updated docker compose build --no-cache bridge docker compose up -d --remove-orphans echo "==> Waiting for health check" sleep 5 STATUS=$(docker compose ps --format json | python3 -c " import sys, json for line in sys.stdin: s = json.loads(line) if s.get('Service') == 'bridge': print(s.get('Health', s.get('State', 'unknown'))) " 2>/dev/null || echo "unknown") echo "Bridge container status: $STATUS" echo "==> Tailing last 20 log lines" docker compose logs --tail=20 bridge echo "" echo "=== Deploy complete ===" echo "Health endpoint: https://ghl.cast.ph/health"