diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26eb1030..1afa5eb9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -588,33 +588,58 @@ jobs: - name: Trigger deployment if: steps.deploy_guard.outputs.should_deploy == 'true' run: | - max_attempts=5 + # The Coolify box rebuilds the image from git on deploy, so its API + # (port 8000) can be unreachable for several minutes while a prior + # build runs. We just need the webhook to land once: retry on + # connection-level failures with a capped backoff over a wide window. + max_attempts=10 + max_delay=60 attempt=1 + # Separator we control, so curl's --write-out fields can never be + # confused with the response body. + marker="===CURL_META===" + while [ $attempt -le $max_attempts ]; do echo "Attempt $attempt of $max_attempts..." - response=$(curl -s -w "\n%{http_code}" \ + curl_exit=0 + response=$(curl -sS \ + -w "${marker}\nhttp_code=%{http_code}\ncurl_exit=%{exitcode}\nerrormsg=%{errormsg}\ntiming=DNS:%{time_namelookup}s Connect:%{time_connect}s Total:%{time_total}s Remote:%{remote_ip}:%{remote_port}" \ --connect-timeout 30 \ - --max-time 120 \ + --max-time 300 \ -H "Authorization: Bearer ${{ secrets.DEPLOYMENT_TOKEN }}" \ - "http://147.93.126.54:8000/api/v1/deploy?uuid=ww00sswosco8w80k08c0occ8&force=false") || true + "http://147.93.126.54:8000/api/v1/deploy?uuid=ww00sswosco8w80k08c0occ8&force=false") || curl_exit=$? - http_code=$(echo "$response" | tail -n1) - body=$(echo "$response" | sed '$d') + body="${response%%${marker}*}" + meta="${response#*${marker}}" + http_code=$(echo "$meta" | sed -n 's/^http_code=//p') + curl_code=$(echo "$meta" | sed -n 's/^curl_exit=//p') + errormsg=$(echo "$meta" | sed -n 's/^errormsg=//p') + timing=$(echo "$meta" | sed -n 's/^timing=//p') - echo "Response: $body" - echo "HTTP Status: ${http_code:-timeout}" + echo "Response body: $body" + echo "HTTP Status: ${http_code:-none}" + echo "curl exit: ${curl_code:-$curl_exit}" + echo "curl error: ${errormsg:-none}" + echo "Timing: $timing" - if [ -n "$http_code" ] && [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then + if [ "${http_code:-0}" -ge 200 ] && [ "${http_code:-0}" -lt 300 ]; then echo "Deployment triggered successfully!" exit 0 fi - echo "Deployment request failed with status $http_code" + # 4xx are caller errors (bad token / uuid) — retrying won't help. + if [ "${http_code:-0}" -ge 400 ] && [ "${http_code:-0}" -lt 500 ]; then + echo "Got client error $http_code — not retryable. Failing fast." + exit 1 + fi + + echo "Deployment request failed (http=${http_code:-none} curl_exit=${curl_code:-$curl_exit}: ${errormsg:-none})" if [ $attempt -lt $max_attempts ]; then - delay=$((30 * (2 ** (attempt - 1)))) + delay=$((15 * attempt)) + [ $delay -gt $max_delay ] && delay=$max_delay echo "Retrying in ${delay}s..." sleep $delay fi