Compare commits

..
2 Commits
Author SHA1 Message Date
Fredrik JohanssonandClaude Opus 5.5 54e90908ca deploy.sh: name the Trace project from the vault key, not the directory
Docker / build-and-push (push) Successful in 1m30s
Trace authenticates receipts per project. Receipts used the deploy
directory name, so a project deployed from a differently named
directory (goonk from goonk-cv/) was rejected on every deploy. Use the
vault key's project part instead, which is what Trace knows.

Also stop exiting silently when .env lacks TRACE_EVENTS_URL or
TRACE_RECEIPT_TOKEN: under pipefail the failed grep ended the script
right after compose up, instead of reaching the "receipt skipped" note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 17:24:18 +01:00
Fredrik JohanssonandClaude Sonnet 5 0af576d8a8 deploy.sh: submit a Trace deployment receipt after compose up
Trace keeps build and deployment receipts separate on purpose, but
nothing was ever wired up to emit the second one from a plain
docker-compose deploy host — so Trace kept reporting the last commit
someone had told it about, not what's actually running. Opt-in per
project via a .trace-meta marker pointing at a site-meta-shaped health
endpoint; missing marker, missing TRACE_* config, or Trace being
unreachable are all non-fatal, matching the existing keep-pull
best-effort style.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-21 03:24:59 +02:00
+62
View File
@@ -8,6 +8,18 @@
# Expects a directory at $DEPLOY_ROOT/<project>/ containing a # Expects a directory at $DEPLOY_ROOT/<project>/ containing a
# docker-compose.yml. # docker-compose.yml.
# #
# After the stack is up, optionally submits a Trace deployment receipt
# (see trace/docs/INTEGRATING_PROJECTS.md) — opt-in per project via a
# $dir/.trace-meta marker file containing one URL to a site-meta-shaped
# health endpoint (a JSON body with an embedded build identity is enough:
# {"build":{"commit":...,"artifacts":[...]}}). No marker file, no
# TRACE_EVENTS_URL/TRACE_RECEIPT_TOKEN in the pulled .env, or Trace being
# unreachable are all non-fatal — the compose deploy has already
# happened by the time this runs, same "best effort" philosophy as the
# keep pull below. A health check that never responds still submits a
# receipt, honestly reporting result:"failed" — absence of a receipt
# means "unknown" to Trace, never "success".
#
# The vault key is NOT assumed to match the deploy-directory name — repo # The vault key is NOT assumed to match the deploy-directory name — repo
# names, deploy directory names, and vault keys are three independent # names, deploy directory names, and vault keys are three independent
# strings in practice (a repo can be named one thing, its deploy # strings in practice (a repo can be named one thing, its deploy
@@ -42,6 +54,11 @@ else
vault="$project/$env" vault="$project/$env"
fi fi
# Trace authenticates receipts per project, so the receipt has to name the
# project the way Trace knows it — the vault key's project part, not the
# deploy directory (goonk deploys from goonk-cv/ but is "goonk" to Trace).
trace_project="${vault%%/*}"
if command -v keep >/dev/null 2>&1 && keep pull "$vault" --out "$dir/.env.new" 2>/dev/null; then if command -v keep >/dev/null 2>&1 && keep pull "$vault" --out "$dir/.env.new" 2>/dev/null; then
mv "$dir/.env.new" "$dir/.env" mv "$dir/.env.new" "$dir/.env"
echo " ✓ pulled $vault" echo " ✓ pulled $vault"
@@ -51,3 +68,48 @@ else
fi fi
(cd "$dir" && docker compose up -d) (cd "$dir" && docker compose up -d)
# --- Trace deployment receipt (best effort — never fails the deploy) ---
if [ -f "$dir/.trace-meta" ]; then
meta_url="$(cat "$dir/.trace-meta")"
trace_events_url=""
trace_token=""
if [ -f "$dir/.env" ]; then
trace_events_url="$(grep -m1 '^TRACE_EVENTS_URL=' "$dir/.env" | cut -d= -f2- || true)"
trace_token="$(grep -m1 '^TRACE_RECEIPT_TOKEN=' "$dir/.env" | cut -d= -f2- || true)"
fi
if [ -z "$trace_events_url" ] || [ -z "$trace_token" ]; then
echo " · trace receipt skipped: TRACE_EVENTS_URL/TRACE_RECEIPT_TOKEN not set in $dir/.env"
else
echo " · waiting for $meta_url to report healthy…"
body=""
for _ in $(seq 1 15); do
if body="$(curl -fsS --max-time 5 "$meta_url" 2>/dev/null)"; then
break
fi
body=""
sleep 2
done
ts="$(date -u +%Y%m%dT%H%M%SZ)"
occurred_at="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
if [ -z "$body" ]; then
echo " ⚠ $meta_url never responded — submitting a failed deployment receipt"
payload="{\"schemaVersion\":1,\"eventType\":\"deployment\",\"eventId\":\"${trace_project}-${env}-unknown-${ts}\",\"project\":\"${trace_project}\",\"environment\":\"${env}\",\"occurredAt\":\"${occurred_at}\",\"result\":\"failed\",\"verification\":{\"health\":\"unreachable\"}}"
else
commit="$(node -e 'let b="";process.stdin.on("data",d=>b+=d);process.stdin.on("end",()=>{try{const d=JSON.parse(b);process.stdout.write((d.build&&d.build.commit)||"unknown")}catch{process.stdout.write("unknown")}})' <<<"$body")"
artifacts="$(node -e 'let b="";process.stdin.on("data",d=>b+=d);process.stdin.on("end",()=>{try{const d=JSON.parse(b);process.stdout.write(JSON.stringify((d.build&&d.build.artifacts)||[]))}catch{process.stdout.write("[]")}})' <<<"$body")"
short_commit="${commit:0:7}"
payload="{\"schemaVersion\":1,\"eventType\":\"deployment\",\"eventId\":\"${trace_project}-${env}-${short_commit}-${ts}\",\"project\":\"${trace_project}\",\"environment\":\"${env}\",\"occurredAt\":\"${occurred_at}\",\"result\":\"success\",\"source\":{\"commit\":\"${commit}\"},\"artifacts\":${artifacts},\"verification\":{\"health\":\"healthy\"}}"
echo " ✓ deploy verified healthy at commit ${short_commit}"
fi
if curl -fsS --max-time 5 -H "Authorization: Bearer ${trace_token}" -H "Content-Type: application/json" --data-binary "$payload" "$trace_events_url" >/dev/null 2>&1; then
echo " ✓ submitted deployment receipt to trace"
else
echo " · trace receipt submission failed (deploy already happened; not fatal)"
fi
fi
fi