ADR-021: Immutable Artifact Promotion — Build Once, Verify, Promote by Digest
Context
Each production release rebuilt everything at tag time: a fresh frontend bundle and a fresh container image were produced from a commit that had already been built, tested, and deployed to staging. The artifact reaching production was therefore a sibling of the one verified on staging — near-identical, but never provably the same bytes.
The only technical justification for the per-environment rebuild was a single build-time input: the Google Analytics measurement ID, injected exclusively into tag builds so staging traffic never reached production analytics. One public string was forcing a duplicate build, a slower release, and a tested-vs-shipped gap.
Decision
Build exactly one environment-agnostic artifact per merge to `main` and promote it to production by content digest — never rebuild.
The merge build produces a container tagged `app:sha-<commit>`, signs it with cosign keyless (Fulcio certificate bound to the pipeline's OIDC identity, recorded in the Rekor transparency log), and deploys staging by digest. A `v*` tag triggers a promotion, not a build: the pipeline resolves the digest built for the tagged commit, hard-fails unless the cosign signature proves the image came from this repository's pipeline, re-tags it `prod-<version>`, and applies the production Terraform with the immutable digest reference. Firebase Hosting assets are extracted from inside the verified image itself, so the static bundle served at the edge is provably the one baked into the running container.
The artifact became environment-agnostic by moving the one differing value to runtime: the GA measurement ID is baked into every build, and a strict hostname guard in the telemetry module activates analytics only on the production domain. Since ADR-031 the bundle carries no analytics ID at all.
Amended 2026-10-16: promotion is roll-forward only. After each release only the newest `prod-v*` tag is kept, and the registry cleanup keeps `dev-latest`/`prod-latest`, the 8 newest versions and `:buildcache`, deleting everything else once it is older than 2 hours. An old release is rebuilt from its commit rather than rolled back to, and an unreleased staging build can age out and become unpromotable (recovery: a `workflow_dispatch` of the pipeline on `main`). Builds use `--provenance=false`, so the keyless cosign signature and its identity check are the only attestation. The `v*` tag comes from the "Prepare release draft" workflow (`release.yml`, `workflow_dispatch` only): it creates a draft release, and a person clicking Publish creates the tag.
Consequences
Benefits:
* What was tested on staging is byte-for-byte what production runs — the tested-vs-shipped gap is closed structurally, not by convention.
* Supply-chain gate: nothing reaches production without a verifiable keyless cosign signature from this pipeline, checked against the repository's identity at promotion time.
* Releases run roughly twice as fast — no compile, no docker build at tag time. (The original instant-rollback path via retained `prod-<version>` tags was dropped; see the 2026-10-16 amendment.)
Trade-offs:
* A tag must point at a commit that produced a staging build. Tagging, say, a tests-only merge fails fast with explicit guidance; a manual workflow dispatch on `main` rebuilds the missing image.
Alternatives considered
1. Rebuild at tag time (status quo): Rejected — duplicate work on every release, a cold build cache on the production path, and a production artifact that was never the one verified on staging.
2. A runtime configuration service for the analytics ID: Rejected as overkill — the measurement ID is public by nature (visible in any page source), and a hostname guard achieves the same isolation with zero moving parts.
3. Promotion via a separate artifact store: Rejected — the container registry already holds the canonical artifact; re-tagging a digest is atomic, auditable, and adds no new infrastructure.