learning_ai_notes/scripts/compose-smoke.sh

66 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build and smoke-test the local Docker Compose stack.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
COMPOSE_CMD="${COMPOSE_CMD:-docker compose}"
BACKEND_URL="${BACKEND_URL:-http://localhost:4016}"
WEB_URL="${WEB_URL:-http://localhost:3000}"
JWT_SECRET="${JWT_SECRET:-dev-secret-change-me-at-least-32-characters}"
cd "$REPO_DIR"
if ! command -v docker >/dev/null 2>&1; then
echo "docker is required for compose smoke checks." >&2
exit 127
fi
cleanup() {
bash scripts/docker-prep.sh --restore >/dev/null 2>&1 || true
if [[ "${KEEP_COMPOSE:-0}" != "1" ]]; then
$COMPOSE_CMD down --remove-orphans >/dev/null 2>&1 || true
fi
}
trap cleanup EXIT
wait_for_url() {
local url="$1"
local label="$2"
local attempts="${3:-60}"
for attempt in $(seq 1 "$attempts"); do
if curl -fsS "$url" >/dev/null; then
echo "ok: $label"
return 0
fi
sleep 2
if [[ "$attempt" == "$attempts" ]]; then
echo "failed: $label did not respond at $url" >&2
return 1
fi
done
}
echo "Preparing Docker build dependencies..."
bash scripts/docker-prep.sh
echo "Building backend and web images..."
$COMPOSE_CMD build backend web
echo "Starting compose stack..."
NODE_ENV=development \
DB_PROVIDER=memory \
JWT_SECRET="$JWT_SECRET" \
FIELD_ENCRYPT_ENABLED=false \
FEATURE_FLAGS_ENABLED=false \
TELEMETRY_ENABLED=false \
$COMPOSE_CMD up -d backend web
wait_for_url "$BACKEND_URL/health" "backend health"
wait_for_url "$BACKEND_URL/api/bootstrap" "backend bootstrap"
wait_for_url "$WEB_URL" "web root"
echo "Compose smoke passed."