fiddy/scripts/smoke-public-launch.sh

59 lines
1.7 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
BASE_URL="${1:-${BASE_URL:-}}"
if [[ -z "${BASE_URL}" ]]; then
echo "Usage: BASE_URL=https://your-domain ./scripts/smoke-public-launch.sh"
echo " or: ./scripts/smoke-public-launch.sh https://your-domain"
exit 1
fi
LIVE_URL="${BASE_URL%/}/api/health/live"
READY_URL="${BASE_URL%/}/api/health/ready"
tmp_headers_live="$(mktemp)"
tmp_headers_ready="$(mktemp)"
tmp_body_live="$(mktemp)"
tmp_body_ready="$(mktemp)"
trap 'rm -f "$tmp_headers_live" "$tmp_headers_ready" "$tmp_body_live" "$tmp_body_ready"' EXIT
status_live="$(curl -sS -D "$tmp_headers_live" -o "$tmp_body_live" -w "%{http_code}" "$LIVE_URL")"
status_ready="$(curl -sS -D "$tmp_headers_ready" -o "$tmp_body_ready" -w "%{http_code}" "$READY_URL")"
echo "LIVE status: $status_live"
echo "READY status: $status_ready"
if [[ "$status_live" != "200" ]]; then
echo "Live check failed:"
cat "$tmp_body_live"
exit 1
fi
if [[ "$status_ready" != "200" ]]; then
echo "Ready check failed:"
cat "$tmp_body_ready"
exit 1
fi
request_id_header_live="$(grep -i '^x-request-id:' "$tmp_headers_live" | tail -n 1 | cut -d':' -f2- | xargs || true)"
request_id_header_ready="$(grep -i '^x-request-id:' "$tmp_headers_ready" | tail -n 1 | cut -d':' -f2- | xargs || true)"
if [[ -z "$request_id_header_live" || -z "$request_id_header_ready" ]]; then
echo "Missing X-Request-Id header in one or more responses."
exit 1
fi
if ! grep -q '"request_id"' "$tmp_body_live"; then
echo "Live response missing request_id field."
exit 1
fi
if ! grep -q '"request_id"' "$tmp_body_ready"; then
echo "Ready response missing request_id field."
exit 1
fi
echo "Smoke checks passed."
echo "Live X-Request-Id: $request_id_header_live"
echo "Ready X-Request-Id: $request_id_header_ready"