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>
This commit is contained in:
Fredrik Johansson
2026-11-07 17:24:18 +01:00
co-authored by Claude Opus 5.5
parent 0af576d8a8
commit 54e90908ca
+9 -4
View File
@@ -54,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"
@@ -70,8 +75,8 @@ if [ -f "$dir/.trace-meta" ]; then
trace_events_url="" trace_events_url=""
trace_token="" trace_token=""
if [ -f "$dir/.env" ]; then if [ -f "$dir/.env" ]; then
trace_events_url="$(grep -m1 '^TRACE_EVENTS_URL=' "$dir/.env" | cut -d= -f2-)" 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-)" trace_token="$(grep -m1 '^TRACE_RECEIPT_TOKEN=' "$dir/.env" | cut -d= -f2- || true)"
fi fi
if [ -z "$trace_events_url" ] || [ -z "$trace_token" ]; then if [ -z "$trace_events_url" ] || [ -z "$trace_token" ]; then
@@ -92,12 +97,12 @@ if [ -f "$dir/.trace-meta" ]; then
if [ -z "$body" ]; then if [ -z "$body" ]; then
echo " ⚠ $meta_url never responded — submitting a failed deployment receipt" echo " ⚠ $meta_url never responded — submitting a failed deployment receipt"
payload="{\"schemaVersion\":1,\"eventType\":\"deployment\",\"eventId\":\"${project}-${env}-unknown-${ts}\",\"project\":\"${project}\",\"environment\":\"${env}\",\"occurredAt\":\"${occurred_at}\",\"result\":\"failed\",\"verification\":{\"health\":\"unreachable\"}}" 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 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")" 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")" 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}" short_commit="${commit:0:7}"
payload="{\"schemaVersion\":1,\"eventType\":\"deployment\",\"eventId\":\"${project}-${env}-${short_commit}-${ts}\",\"project\":\"${project}\",\"environment\":\"${env}\",\"occurredAt\":\"${occurred_at}\",\"result\":\"success\",\"source\":{\"commit\":\"${commit}\"},\"artifacts\":${artifacts},\"verification\":{\"health\":\"healthy\"}}" 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}" echo " ✓ deploy verified healthy at commit ${short_commit}"
fi fi