Files
loki/scripts/deploy-status.sh
T
xandClaude Opus 4.8 7bd4fd22ec chore(devops): kill three recurring deploy footguns
Tier-1 DevX fixes for pains hit repeatedly in practice:

1. ci-gate: cancelled != failed. CI runs with cancel-in-progress, so a
   follow-up push cancels the earlier commit's run; the gate counted that
   as a failure and printed "CI FAILED", blocking a deploy that never
   should have run. Now a cancelled run on a SUPERSEDED (non-tip) commit
   exits 3 → the hook skips it quietly (the newer commit deploys); only
   genuine failure/timeout/action_required block.

2. Per-SHA deploy logs. Every deploy wrote to one shared
   /tmp/push-deploy-fleetcrown.log, so completion-greps matched stale
   lines from prior deploys (false PROBLEM/DEPLOYED). Each deploy now
   writes /tmp/push-deploy-fleetcrown-<sha>.log (+ a -latest symlink),
   and `npm run deploy:status` shows live SHA vs origin/main, health,
   in-flight deploy, and the last log's verdict — no more curl|grep.

3. `npm run db:apply-box <file.sql>` applies box DDL AS THE APP ROLE, so
   objects are owned by `fleetcrown` and visible to the app. Applying as
   `postgres` (the reflex) left tables invisible to the app role — the
   drift-check false-failed and rolled back twice. Verified: a table it
   creates is owned by the app role.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 12:41:27 +02:00

57 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# deploy-status.sh — what's live, what's pending, is it healthy? One glance.
#
# WHY: the only way to answer "what SHA is on the box / did my deploy land / is
# one still running" used to be `curl … | grep sentry-release` plus grepping a
# shared log full of stale lines. This reads the per-SHA deploy logs the hook
# now writes and shows the whole picture at once.
#
# Usage: bash scripts/deploy-status.sh (or: npm run deploy:status)
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
PROD_URL="${FLEETCROWN_WEB_URL:-https://fleetcrown.orangecat.ch}"
cd "$PROJECT_DIR"
LOCAL=$(git rev-parse --short HEAD 2>/dev/null || echo "?")
git fetch origin main -q 2>/dev/null || true
ORIGIN=$(git rev-parse --short origin/main 2>/dev/null || echo "?")
LIVE=$(curl -s --max-time 6 "$PROD_URL/sign-in" 2>/dev/null | grep -oiE 'sentry-release=[a-f0-9]{7}' | head -1 | cut -d= -f2)
LIVE="${LIVE:-unknown}"
# curl's -w prints the code even on failure (000 = unreachable); no fallback needed.
HEALTH=$(curl -s -o /dev/null -w '%{http_code}' --max-time 6 "$PROD_URL/api/health" 2>/dev/null)
HEALTH="${HEALTH:-000}"
# In-flight deploy (the flock'd deploy-hetzner.sh carries --ref <sha>)
INFLIGHT=$(pgrep -af 'deploy-hetzner\.sh' 2>/dev/null | grep -v pgrep \
| grep -oE -- '--ref [a-f0-9]+' | awk '{print substr($2,1,7)}' | head -1)
echo "── FleetCrown deploy status ──────────────────────────────"
printf " %-14s %s\n" "local HEAD" "$LOCAL"
printf " %-14s %s\n" "origin/main" "$ORIGIN"
printf " %-14s %s (health %s)\n" "live on box" "$LIVE" "$HEALTH"
if [ "$LIVE" = "unknown" ]; then
echo " ⚠ could not read live SHA (box unreachable from here — the box itself may be fine)"
elif [ "${LIVE:0:7}" = "${ORIGIN:0:7}" ]; then
echo " ✓ box is up to date with origin/main"
else
echo " ● box is BEHIND origin/main — a deploy is needed or in flight"
fi
if [ -n "$INFLIGHT" ]; then
echo " ⟳ deploy IN FLIGHT for $INFLIGHT"
else
echo " · no deploy currently running"
fi
# Most recent per-SHA deploy log — show its verdict line.
LASTLOG=$(ls -t /tmp/push-deploy-fleetcrown-*.log 2>/dev/null | grep -v latest | head -1)
if [ -n "$LASTLOG" ]; then
echo "── last deploy log: $LASTLOG"
grep -aiE 'deploy OK:|deployed .* verified|deploy FAILED|rolling box back|BLOCKED by CI|superseded' "$LASTLOG" 2>/dev/null | tail -3 | sed 's/^/ /'
fi
echo "──────────────────────────────────────────────────────────"