From 7a538654080b0af96f89410f03cb7a3048d10912 Mon Sep 17 00:00:00 2001 From: MatheusAlves96 Date: Wed, 22 Apr 2026 23:57:20 -0300 Subject: [PATCH] fix(ci): add retry loop to health check, increase wait times - Replace single-shot curl with 12-attempt retry (15s between attempts) - Increase deploy sleep 15s -> 30s to give Swarm time to stabilize - Increase healthcheck initial wait 40s -> 60s - Fixes race condition where Traefik routes /api/health to frontend before backend registers --- .forgejo/workflows/deploy.yml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index ca57f7d..28aa256 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -135,7 +135,7 @@ jobs: --prune \ saas-imobiliaria - sleep 15 + sleep 30 docker stack services saas-imobiliaria" # ──────────────────────────────────────────────────────────────────────────── @@ -153,7 +153,7 @@ jobs: run: apk add --no-cache curl openssl - name: Wait for stack to stabilize - run: sleep 40 + run: sleep 60 - name: Frontend HTTPS run: | @@ -169,11 +169,17 @@ jobs: - name: Backend /api/health run: | - R=$(curl -s --max-time 15 --resolve "${{ vars.DOMAIN }}:443:${{ vars.SSH_HOST }}" "https://${{ vars.DOMAIN }}/api/health") - S=$(curl -s -o /dev/null -w "%{http_code}" --max-time 15 --resolve "${{ vars.DOMAIN }}:443:${{ vars.SSH_HOST }}" "https://${{ vars.DOMAIN }}/api/health") - echo "Health: $S → $R" - [ "$S" = "200" ] || (echo "❌ Health falhou ($S)" && exit 1) - echo "$R" | grep -q '"db": "ok"' || (echo "❌ DB não conectado" && exit 1) + for i in $(seq 1 12); do + R=$(curl -sk --max-time 15 --resolve "${{ vars.DOMAIN }}:443:${{ vars.SSH_HOST }}" "https://${{ vars.DOMAIN }}/api/health") + S=$(curl -sk -o /dev/null -w "%{http_code}" --max-time 15 --resolve "${{ vars.DOMAIN }}:443:${{ vars.SSH_HOST }}" "https://${{ vars.DOMAIN }}/api/health") + echo "Health attempt $i: $S → $R" + if [ "$S" = "200" ] && echo "$R" | grep -q '"db": "ok"'; then + echo "✅ Backend healthy" + break + fi + [ $i -eq 12 ] && echo "❌ Health falhou após 12 tentativas" && exit 1 + sleep 15 + done - name: TLS certificate validity run: |