#!/usr/bin/env bash # Safe CTXD deploy: always ensures postgres is up before recreating ctxd. # Usage: ./scripts/deploy.sh [--build-only | --no-build] set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$ROOT" BUILD=1 if [[ "${1:-}" == "--no-build" ]]; then BUILD=0 elif [[ "${1:-}" == "--build-only" ]]; then docker compose build ctxd echo "Built ctxd image only." exit 0 fi if [[ "$BUILD" -eq 1 ]]; then echo "==> docker compose build ctxd" docker compose build ctxd fi echo "==> docker compose up -d postgres" docker compose up -d postgres echo "==> waiting for postgres healthy..." for i in $(seq 1 60); do if docker compose ps postgres 2>/dev/null | grep -q '(healthy)'; then break fi sleep 2 done if ! docker compose ps postgres 2>/dev/null | grep -q '(healthy)'; then echo "ERROR: ctxd-postgres did not become healthy. Check: docker compose logs postgres" >&2 exit 1 fi echo "==> docker compose up -d --force-recreate ctxd" docker compose up -d --force-recreate ctxd PORT="${CTXD_PORT:-9091}" echo "==> smoke: http://127.0.0.1:${PORT}/status" sleep 3 curl -sf "http://127.0.0.1:${PORT}/status" | head -c 200 echo "" docker compose ps postgres ctxd