diff --git a/.gitea/workflows/ci-deploy.yml b/.gitea/workflows/ci-deploy.yml index fc6ee79..73a2726 100644 --- a/.gitea/workflows/ci-deploy.yml +++ b/.gitea/workflows/ci-deploy.yml @@ -81,17 +81,32 @@ jobs: APP_BUILD_STAMP="$(date -u +'%Y-%m-%d %H:%M UTC')" \ ./deploy/deploy.sh docker compose ps - docker compose exec -T ai-service python - <<'PY' - import time - import urllib.request - - last = None - for _ in range(30): - try: - urllib.request.urlopen('http://127.0.0.1:8001/health', timeout=5).read() - raise SystemExit(0) - except Exception as exc: - last = exc - time.sleep(2) - raise last - PY + AI_CONTAINER_ID="$(docker compose ps -q ai-service)" + if [ -z "$AI_CONTAINER_ID" ]; then + echo "AI service container id could not be resolved after deploy." + docker compose ps + docker compose logs --tail=200 ai-service || true + exit 1 + fi + ATTEMPTS=90 + SLEEP_SECS=2 + i=1 + while [ "$i" -le "$ATTEMPTS" ]; do + HEALTH_STATUS="$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' "$AI_CONTAINER_ID" 2>/dev/null || echo unknown)" + if [ "$HEALTH_STATUS" = "healthy" ]; then + break + fi + if [ "$HEALTH_STATUS" = "unhealthy" ]; then + echo "AI service became unhealthy during deploy readiness wait." + docker compose logs --tail=200 ai-service || true + exit 1 + fi + sleep "$SLEEP_SECS" + i=$((i + 1)) + done + if [ "$HEALTH_STATUS" != "healthy" ]; then + echo "AI service did not become healthy within $((ATTEMPTS * SLEEP_SECS)) seconds. Final status: ${HEALTH_STATUS:-unknown}" + docker compose ps + docker compose logs --tail=200 ai-service || true + exit 1 + fi