fix: smoke-test henter fersk token per forsøk, robustere health-poll

This commit is contained in:
chrischristiansen-glitch 2026-06-10 11:22:56 +02:00
parent 2057152468
commit 733f26b971

View File

@ -68,14 +68,19 @@ steps:
echo "=== Smoke Test ===" echo "=== Smoke Test ==="
BASE_URL="https://${_CLOUD_RUN_URL}" BASE_URL="https://${_CLOUD_RUN_URL}"
TOKEN=$$(gcloud auth print-identity-token \ # Vent på at Cloud Run-instansen er klar (cold start kan ta opptil 90s)
--impersonate-service-account=${_AGENT_SA} \ # Henter fersk token per forsøk siden token kan utløpe under lang cold start
--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)
echo "Venter på /health ..." 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}" \ STATUS=$$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: Bearer $$TOKEN" \ -H "Authorization: Bearer $$TOKEN" \
"$$BASE_URL/health") "$$BASE_URL/health")
@ -85,11 +90,14 @@ steps:
done done
if [ "$$STATUS" != "200" ]; then if [ "$$STATUS" != "200" ]; then
echo "❌ /health svarte ikke 200 etter 120s (siste: $$STATUS)" echo "❌ /health svarte ikke 200 etter 180s (siste: $$STATUS)"
exit 1 exit 1
fi 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}" \ RESPONSE=$$(curl -s -w "\nHTTP_STATUS:%{http_code}" \
-H "Authorization: Bearer $$TOKEN" \ -H "Authorization: Bearer $$TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \