From 30a418c583a56a1287e3622601f3a2a84d29816a Mon Sep 17 00:00:00 2001 From: chrischristiansen-glitch Date: Wed, 10 Jun 2026 10:06:45 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20smoke-test=20med=20retry,=20verbose=20cu?= =?UTF-8?q?rl=20og=20health-check=20f=C3=B8rst?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloudbuild.yaml | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index ef03cb0..b8ed39d 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -66,19 +66,46 @@ steps: - '-c' - | echo "=== Smoke Test ===" + BASE_URL="https://${_CLOUD_RUN_URL}" + TOKEN=$$(gcloud auth print-identity-token \ --impersonate-service-account=${_AGENT_SA} \ - --audiences="https://${_CLOUD_RUN_URL}") \ + --audiences="$$BASE_URL") \ || { echo "❌ Kunne ikke hente identity token"; exit 1; } - RESPONSE=$$(curl -sf \ + # Vent på at Cloud Run-instansen er klar (cold start kan ta opptil 60s) + echo "Venter på /health ..." + for i in $$(seq 1 12); do + STATUS=$$(curl -s -o /dev/null -w "%{http_code}" \ + -H "Authorization: Bearer $$TOKEN" \ + "$$BASE_URL/health") + echo " /health forsøk $$i: HTTP $$STATUS" + [ "$$STATUS" = "200" ] && break + sleep 10 + done + + if [ "$$STATUS" != "200" ]; then + echo "❌ /health svarte ikke 200 etter 120s (siste: $$STATUS)" + exit 1 + fi + + # Kjør /run + RESPONSE=$$(curl -s -w "\nHTTP_STATUS:%{http_code}" \ -H "Authorization: Bearer $$TOKEN" \ -H "Content-Type: application/json" \ -d '{"user_id": "ci", "session_id": "smoke-$BUILD_ID", "message": "ping"}' \ - "https://${_CLOUD_RUN_URL}/run") \ - || { echo "❌ Smoke test feilet — /run svarte ikke"; exit 1; } + "$$BASE_URL/run") + HTTP_STATUS=$$(echo "$$RESPONSE" | grep "HTTP_STATUS:" | cut -d: -f2) + BODY=$$(echo "$$RESPONSE" | grep -v "HTTP_STATUS:") - echo "✅ Smoke test OK: $$RESPONSE" + echo " /run HTTP $$HTTP_STATUS" + if [ "$$HTTP_STATUS" != "200" ]; then + echo "❌ Smoke test feilet — /run svarte HTTP $$HTTP_STATUS" + echo "Body: $$BODY" + exit 1 + fi + + echo "✅ Smoke test OK: $$BODY" echo "=== Smoke Test ferdig ===" # Steg 6: Deploy-notifikasjon til webhook/chat-app