Wait for AI service health in deploy workflow

This commit is contained in:
2026-03-27 11:01:14 +01:00
parent 8d1ab8ae17
commit dccbd11224
+29 -14
View File
@@ -81,17 +81,32 @@ jobs:
APP_BUILD_STAMP="$(date -u +'%Y-%m-%d %H:%M UTC')" \ APP_BUILD_STAMP="$(date -u +'%Y-%m-%d %H:%M UTC')" \
./deploy/deploy.sh ./deploy/deploy.sh
docker compose ps docker compose ps
docker compose exec -T ai-service python - <<'PY' AI_CONTAINER_ID="$(docker compose ps -q ai-service)"
import time if [ -z "$AI_CONTAINER_ID" ]; then
import urllib.request echo "AI service container id could not be resolved after deploy."
docker compose ps
last = None docker compose logs --tail=200 ai-service || true
for _ in range(30): exit 1
try: fi
urllib.request.urlopen('http://127.0.0.1:8001/health', timeout=5).read() ATTEMPTS=90
raise SystemExit(0) SLEEP_SECS=2
except Exception as exc: i=1
last = exc while [ "$i" -le "$ATTEMPTS" ]; do
time.sleep(2) HEALTH_STATUS="$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' "$AI_CONTAINER_ID" 2>/dev/null || echo unknown)"
raise last if [ "$HEALTH_STATUS" = "healthy" ]; then
PY 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