#!/usr/bin/env bash # Post-deploy HTTP smoke checks for Amare. # Required env: # SMOKE_BASE_URL e.g. https://staging.example.com # Optional env: # SMOKE_RETRIES attempts per path (default: 30) # SMOKE_SLEEP_SEC sleep between attempts (default: 5) # SMOKE_PATHS space-separated paths (default: /up / /admin/login) set -euo pipefail : "${SMOKE_BASE_URL:?SMOKE_BASE_URL is required}" SMOKE_BASE_URL="${SMOKE_BASE_URL%/}" SMOKE_RETRIES="${SMOKE_RETRIES:-30}" SMOKE_SLEEP_SEC="${SMOKE_SLEEP_SEC:-5}" SMOKE_PATHS="${SMOKE_PATHS:-/up / /admin/login}" check_path() { local path="$1" local url="${SMOKE_BASE_URL}${path}" local attempt local code for ((attempt = 1; attempt <= SMOKE_RETRIES; attempt++)); do code="$(curl -sS -o /tmp/amare-smoke-body -w '%{http_code}' --max-time 20 "$url" 2>/dev/null || true)" if [[ "$code" == "200" ]]; then echo "OK ${path} (HTTP ${code}) attempt=${attempt}" return 0 fi echo "WAIT ${path} (HTTP ${code:-000}) attempt=${attempt}/${SMOKE_RETRIES}" sleep "$SMOKE_SLEEP_SEC" done echo "FAIL ${path} after ${SMOKE_RETRIES} attempts" >&2 if [[ -f /tmp/amare-smoke-body ]]; then head -c 500 /tmp/amare-smoke-body >&2 || true echo >&2 fi return 1 } echo "Smoke against ${SMOKE_BASE_URL}" failed=0 for path in $SMOKE_PATHS; do if ! check_path "$path"; then failed=1 fi done if (( failed != 0 )); then echo "Smoke checks failed." >&2 exit 1 fi echo "Smoke checks passed."