diff --git a/scripts/deploy-vps.sh b/scripts/deploy-vps.sh index 4af869d..cd0171d 100755 --- a/scripts/deploy-vps.sh +++ b/scripts/deploy-vps.sh @@ -42,7 +42,17 @@ if [[ -z "${PORT:-}" ]]; then fi fi PORT="${PORT:-9000}" -HEALTH_URL="http://localhost:${PORT}/health" +# Health verificato DENTRO la rete del container: in produzione la porta NON è +# pubblicata sull'host (Traefik la raggiunge via rete docker), quindi un curl da +# localhost darebbe un falso negativo (e rischierebbe un rollback inutile). +HEALTH_URL="http://127.0.0.1:${PORT}/health" + +# 0 se /health risponde 200 dall'interno del container. +app_health() { + docker compose exec -T "$SERVICE" python -c \ +"import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('${HEALTH_URL}').status==200 else 1)" \ + >/dev/null 2>&1 +} # ─── Pre-check ─────────────────────────────────────────────────────────── command -v git >/dev/null || { echo "FATAL: git non installato"; exit 1; } @@ -125,10 +135,11 @@ docker compose up -d echo "==> attendo /health (timeout ${HEALTH_TIMEOUT_SECONDS}s, retry ogni ${HEALTH_INTERVAL}s)" deadline=$(( $(date +%s) + HEALTH_TIMEOUT_SECONDS )) while [[ $(date +%s) -lt $deadline ]]; do - if curl -fsS "$HEALTH_URL" >/dev/null 2>&1; then + if app_health; then echo echo "==> health OK" - curl -s "$HEALTH_URL" + docker compose exec -T "$SERVICE" python -c \ +"import urllib.request; print(urllib.request.urlopen('${HEALTH_URL}').read().decode())" 2>/dev/null || true echo echo echo "==> deploy DONE (SHA $CURRENT_SHA → $NEW_SHA, branch $BRANCH)"