From e80eeb69e095a89c969f1c4a2458333c55c65224 Mon Sep 17 00:00:00 2001 From: gnezim Date: Tue, 28 Apr 2026 14:44:12 +0300 Subject: [PATCH] deploy-container: wait for SSR readiness before returning from swap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Run 549's wait-for-health logged two HTTP 502s before its third attempt succeeded — nginx → docker forwarding hit the new container during the ~4s window between \`docker run -d\` returning and Node.js inside finishing its boot. The retry loop covered it but the log was noisy and a slower boot could blow past the 30×2s budget. Added a post-run readiness probe inside swap: poll http://127.0.0.1:${PORT}/ on the host (docker container is published to 127.0.0.1, runner uses host network mode) until it answers 2xx, up to 30 attempts × 1s. Skipped under --dry-run so the tests/ci/ shell tests still pass without touching the network. Net effect: wait-for-url against the public URL now succeeds first attempt, and the run aborts cleanly if the SSR doesn't come up at all instead of looking healthy because nginx happens to keep a warmed connection. --- scripts/ci/deploy-container.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/ci/deploy-container.sh b/scripts/ci/deploy-container.sh index ba804064..d57b4f42 100755 --- a/scripts/ci/deploy-container.sh +++ b/scripts/ci/deploy-container.sh @@ -57,6 +57,25 @@ case "$CMD" in run run -d --name flights-web --restart unless-stopped \ -p "127.0.0.1:${PORT}:8080" \ "${IMAGE}:current" + # 5. Wait for the SSR inside the container to start listening before + # returning. Without this, the next nginx-side probe gets a few + # 502s while Node.js is still booting — works (wait-for-url.sh + # retries) but adds noise to the deploy log. + if [ "$DRY_RUN" -eq 0 ]; then + attempt=1 + while [ "$attempt" -le 30 ]; do + if curl -fsS -o /dev/null "http://127.0.0.1:${PORT}/"; then + echo "swap: SSR ready on :${PORT} after $attempt attempt(s)" + break + fi + if [ "$attempt" -eq 30 ]; then + echo "swap: SSR did not respond on :${PORT} after 30 attempts" >&2 + exit 1 + fi + sleep 1 + attempt=$((attempt + 1)) + done + fi ;; rollback) if [ "$DRY_RUN" -eq 0 ] && ! docker image inspect "${IMAGE}:previous" >/dev/null 2>&1; then