Compare commits
2
Commits
a640bc1faf
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54e90908ca | ||
|
|
0af576d8a8 |
@@ -8,6 +8,18 @@
|
||||
# Expects a directory at $DEPLOY_ROOT/<project>/ containing a
|
||||
# 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
|
||||
# names, deploy directory names, and vault keys are three independent
|
||||
# strings in practice (a repo can be named one thing, its deploy
|
||||
@@ -42,6 +54,11 @@ else
|
||||
vault="$project/$env"
|
||||
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
|
||||
mv "$dir/.env.new" "$dir/.env"
|
||||
echo " ✓ pulled $vault"
|
||||
@@ -51,3 +68,48 @@ else
|
||||
fi
|
||||
|
||||
(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
|
||||
|
||||
Reference in New Issue
Block a user