diff --git a/cloudbuild.yaml b/cloudbuild.yaml index b8ed39d..15fba5b 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -68,14 +68,19 @@ steps: echo "=== Smoke Test ===" BASE_URL="https://${_CLOUD_RUN_URL}" - TOKEN=$$(gcloud auth print-identity-token \ - --impersonate-service-account=${_AGENT_SA} \ - --audiences="$$BASE_URL") \ - || { echo "❌ Kunne ikke hente identity token"; exit 1; } - - # Vent på at Cloud Run-instansen er klar (cold start kan ta opptil 60s) + # Vent på at Cloud Run-instansen er klar (cold start kan ta opptil 90s) + # Henter fersk token per forsøk siden token kan utløpe under lang cold start echo "Venter på /health ..." - for i in $$(seq 1 12); do + STATUS="000" + for i in $$(seq 1 18); do + TOKEN=$$(gcloud auth print-identity-token \ + --impersonate-service-account=${_AGENT_SA} \ + --audiences="$$BASE_URL" 2>/dev/null) + if [ -z "$$TOKEN" ]; then + echo " /health forsøk $$i: kunne ikke hente token, venter..." + sleep 10 + continue + fi STATUS=$$(curl -s -o /dev/null -w "%{http_code}" \ -H "Authorization: Bearer $$TOKEN" \ "$$BASE_URL/health") @@ -85,11 +90,14 @@ steps: done if [ "$$STATUS" != "200" ]; then - echo "❌ /health svarte ikke 200 etter 120s (siste: $$STATUS)" + echo "❌ /health svarte ikke 200 etter 180s (siste: $$STATUS)" exit 1 fi - # Kjør /run + # Kjør /run med fersk token + TOKEN=$$(gcloud auth print-identity-token \ + --impersonate-service-account=${_AGENT_SA} \ + --audiences="$$BASE_URL") RESPONSE=$$(curl -s -w "\nHTTP_STATUS:%{http_code}" \ -H "Authorization: Bearer $$TOKEN" \ -H "Content-Type: application/json" \