Files
20260512-skg-tk/scripts/verify-local-docker.sh

65 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"
if [ ! -f deploy/.env.local ]; then
echo "deploy/.env.local is missing. Run ./scripts/start-local-docker.sh first." >&2
exit 1
fi
WEB_PORT="$(grep -E '^LOCAL_WEB_PORT=' deploy/.env.local | tail -1 | cut -d= -f2-)"
WEB_PORT="${WEB_PORT:-4390}"
WEB_URL="http://127.0.0.1:${WEB_PORT}"
AUTH_USERNAME="$(grep -E '^WEB_AUTH_USERNAME=' deploy/.env.local | tail -1 | cut -d= -f2-)"
AUTH_USERNAME="${AUTH_USERNAME:-skg}"
AUTH_PASSWORD="$(grep -E '^WEB_AUTH_PASSWORD=' deploy/.env.local | tail -1 | cut -d= -f2-)"
AUTH_PASSWORD="${AUTH_PASSWORD:-local-skg}"
COMPOSE=(docker compose -f docker-compose.local.yml --env-file deploy/.env.local)
"${COMPOSE[@]}" ps
login_status="$(curl --noproxy '*' -sS -o /tmp/skg-local-login.html -w '%{http_code}' "${WEB_URL}/login/")"
if [ "$login_status" != "200" ]; then
echo "ERROR: unexpected /login/ status ${login_status}" >&2
head -40 /tmp/skg-local-login.html >&2 || true
exit 1
fi
echo "web:/login/ 200"
root_status="$(curl --noproxy '*' -sS -o /tmp/skg-local-root.html -w '%{http_code}' "${WEB_URL}/")"
if [ "$root_status" != "302" ] && [ "$root_status" != "200" ]; then
echo "ERROR: unexpected / status ${root_status}" >&2
head -40 /tmp/skg-local-root.html >&2 || true
exit 1
fi
echo "web:/ ${root_status}"
api_status="$(curl --noproxy '*' -sS -o /tmp/skg-local-api-health.json -w '%{http_code}' "${WEB_URL}/api/health")"
if [ "$api_status" != "401" ]; then
echo "ERROR: unexpected unauthenticated /api/health status ${api_status}" >&2
cat /tmp/skg-local-api-health.json >&2 || true
exit 1
fi
echo "web:/api/health 401"
login_api_status="$(curl --noproxy '*' -sS -o /tmp/skg-local-login-api.json -w '%{http_code}' -c /tmp/skg-local-cookie.jar -X POST "${WEB_URL}/api/auth/login" -H 'content-type: application/json' --data "{\"username\":\"${AUTH_USERNAME}\",\"password\":\"${AUTH_PASSWORD}\"}")"
if [ "$login_api_status" != "200" ]; then
echo "ERROR: unexpected /api/auth/login status ${login_api_status}" >&2
cat /tmp/skg-local-login-api.json >&2 || true
exit 1
fi
echo "web:/api/auth/login 200"
"${COMPOSE[@]}" exec -T api python - <<'PY'
import json
import main
data = main.health()
database = data.get("database") or {}
if not data.get("ok") or not database.get("connected"):
raise SystemExit(json.dumps(data, ensure_ascii=False)[:1000])
print("api:health ok db connected")
PY