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')" \
./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