thermograph/infra/deploy/secrets/dry-run-render.sh
emi de8e847f9f
All checks were successful
Build + push backend image (Forgejo registry) / build-push (push) Successful in 1m23s
Build + push frontend image (Forgejo registry) / build-push (push) Successful in 1m22s
Sync infra to hosts / sync-beta (push) Successful in 9s
Sync infra to hosts / sync-prod (push) Successful in 8s
secrets-guard / encrypted (push) Successful in 6s
shell-lint / shellcheck (push) Successful in 9s
Deploy backend to beta VPS / deploy (push) Successful in 2m4s
Deploy frontend to beta VPS / deploy (push) Successful in 1m8s
shell: add shellcheck CI guard and drive the tree to zero findings (#19)
Adds .forgejo/workflows/shell-lint.yml (pinned shellcheck v0.11.0 + sha256, -x,
default severity, fail on any finding, not path-filtered) and drives all 26
scripts to zero findings.

Two defects shellcheck cannot see:

render-secrets.sh left DECRYPTED vault contents in /tmp whenever a sops decrypt
failed -- the caller's set -e aborted the function before either cleanup ran.
Now removed on every exit path, with `|| return 1` on both sops calls so a
decrypt failure can never write a partial /etc/thermograph.env regardless of the
caller's shell options. Explicitly not a `trap ... RETURN`: such a trap set in a
sourced function persists into the caller's shell and re-fires when the caller's
next `.`/source completes, where the function-local tmp is unset -- fatal and
silent under deploy.sh's set -u. The file now records that reasoning.

autoscale.sh ran `set -eu` without pipefail while piping docker stats into awk,
so a failed left side was swallowed and the loop autoscaled on empty input.
Promoted to pipefail with a missed sample treated as a skip; verified busybox ash
in docker:27-cli supports it.

Also: capture-fixtures.sh's `jq . || cat` ran cat after jq had consumed stdin,
silently writing truncated fixtures; deploy.sh/deploy-stack.sh `# shellcheck
source=` paths corrected for the monorepo layout.
2026-07-23 22:26:05 +00:00

46 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Run ON a prod/beta box (via `ssh <box> 'bash -s' < this`), after the encrypted vault
# file has been scp'd to /tmp/tg-<env>.yaml. NON-DESTRUCTIVE go/no-go for the cutover:
# renders the vault and diffs the KEY=VALUE set against the live /etc/thermograph.env.
# Prints only PASS/FAIL and any differing key NAMES — never secret values. No git, no
# writes; touches nothing. (The encrypted file is safe to ship; only ciphertext.)
set -euo pipefail
key=/etc/thermograph/age.key
env_name="$(sudo cat /etc/thermograph/secrets-env)"
host="/tmp/tg-${env_name}.yaml"
common="/tmp/tg-common.yaml"
command -v sops >/dev/null || { echo "FAIL: sops not installed"; exit 1; }
[ -f "$host" ] || { echo "FAIL: $host not found — scp the encrypted vault file first"; exit 1; }
keymat="$(sudo grep '^AGE-SECRET-KEY-' "$key")"
tmp="$(mktemp)"; live="$(mktemp)"; trap 'rm -f "$tmp" "$live"' EXIT
: > "$tmp"
[ -f "$common" ] && SOPS_AGE_KEY="$keymat" sops -d --input-type yaml --output-type dotenv "$common" >> "$tmp"
SOPS_AGE_KEY="$keymat" sops -d --input-type yaml --output-type dotenv "$host" >> "$tmp"
# sudo is only for the READ of the root-owned live env; the redirect target is our
# own mktemp file, so the redirect correctly runs as the invoking user (sudo tee
# would wrongly write it as root).
# shellcheck disable=SC2024
sudo cat /etc/thermograph.env > "$live"
python3 - "$live" "$tmp" <<'PY'
import sys
def load(p):
out={}
for line in open(p, encoding="utf-8"):
s=line.rstrip("\n").strip()
if not s or s.startswith("#") or "=" not in s: continue
k,_,v=s.partition("="); out[k.strip()]=v
return out
live,rend=load(sys.argv[1]),load(sys.argv[2])
lost=sorted(set(live)-set(rend)); added=sorted(set(rend)-set(live))
changed=sorted(k for k in live if k in rend and live[k]!=rend[k])
if lost or added or changed:
print("FAIL — the render would NOT match the live env")
if lost: print(" lost keys:", lost)
if added: print(" extra keys:", added)
if changed: print(" value-changed keys:", changed)
sys.exit(1)
print(f"PASS — all {len(live)} keys render byte-identical to the live /etc/thermograph.env")
PY