ADR-040: Build-Once, Gate-Complete Artifact Promotion

Status

Accepted (2026-07-14)

Realized by #1007 (subsumes #1025). The two chronic gate failures that parked promotion at acceptance were fixed afterwards — #1067 (the per-shape CI cargo cache families) and #1068 (the dind service and toolchain image for integration-tests / validate-in-network); both are CHANGELOG.adoc entries under == Unreleased. #1073 (2026-07-15) extended build-once to test consumption — see Consequences and the ADR-015 amendment.

Context

The production promotion pipeline had accreted five structural defects (#1007, verified against the live pipeline + registry on 2026-07-14):

  1. Tag pipelines never existed. workflow.rules matched only MRs and branches, so the tag-only docker-promote and sbom rules were dead code — a pushed release tag created no pipeline at all.

  2. Promotion was gate-incomplete. docker-promote declared an explicit needs: list of six jobs and ignored every other blocking test-stage job — the ADR-011/ADR-031 policy audits, typed-id-path-audit (#1025), quality-budgets, cargo-doctest, integration-tests, the GitLab security scanners, cargo-deny, cargo-machete among them. Promotion could become runnable, and push latest, while a blocking gate was still running or failing.

  3. The artifact-input map was untested and incomplete. Promotion triggered only on /*.rs, /Cargo.toml, Cargo.lock, Dockerfile — but the images also consume rulesets/, migrations and static assets under services/, tools/, the portal Dockerfile, and .dockerignore. A ruleset-only or migration-only merge left the registry artifact silently stale.

  4. Promotion rebuilt from source. The promote job ran docker build and pushed the result — the published image was not necessarily the artifact any gate had seen, and latest moved in the same breath with no ordering guard.

  5. The applicant portal had no production artifact. The root Dockerfile excludes canopy-portal by design (the Dioxus dx pipeline builds the WASM client + server together, ADR-008), and no CI job built services/canopy-portal/Dockerfile at all.

The observable consequence: the registry’s latest dated to 2026-03-30 — three and a half months of merged main never reached the registry — and no ADR covered image promotion, registry tagging, or container supply-chain.

Decision

  1. Tag pipelines exist. workflow.rules gains - if: $CI_COMMIT_TAG; the gates whose rules were branch/MR-scoped (cargo-audit, cargo-machete, secrets-yaml-lint) run unconditionally on tags, so a tag pipeline is as gate-complete as main.

  2. Two deployable images, built once, under immutable staging refs. build-service-image (root Dockerfile) and build-portal-image (services/canopy-portal/Dockerfile) run in the test stage on every artifact-affecting main/tag commit and push content-addressed staging refs $CI_REGISTRY_IMAGE/build:$CI_COMMIT_SHA and $CI_REGISTRY_IMAGE/build/portal:$CI_COMMIT_SHA (plus mutable main-cache layer-cache pointers). A pipeline whose commit already has a staging ref reuses it (build-once across pipelines: a release tag on a main-built commit promotes the exact digest main tested). Staging refs are pipeline-internal; the production repositories are $CI_REGISTRY_IMAGE and $CI_REGISTRY_IMAGE/portal.

  3. Promotion is a complete barrier + a registry-side retag. docker-promote declares no needs: — a promote-stage job without needs waits for the entire test stage, so every blocking gate (including both image builds) gates every production-registry mutation; advisory (allow_failure) and manual jobs do not block, which is their documented contract. Promotion resolves the staging digests and retags them with docker buildx imagetools create — never docker build. Every promoted commit gets an immutable :<short-sha> production ref; tag pipelines additionally get :<tag>.

  4. latest is guarded and serialized. The promote job moves latest only when $CI_COMMIT_SHA equals the current refs/heads/main (checked via git ls-remote at promote time), so an older pipeline finishing late can never move latest backwards; resource_group: registry-promote serializes concurrent promotions.

  5. Every production digest has a retained SBOM. Each build job generates a CycloneDX SBOM from its pushed ref with a syft that is version-pinned (SYFT_VERSION) and checksum-verified (SYFT_SHA256, sha256sum -c before the binary runs in a job holding registry push credentials), retained as a never-expiring artifact; the tags-only sbom job keeps producing the source-level cargo SBOM for releases.

  6. The invariants are statically gated. cargo xtask ci-config-lint — a CI job and a pre-push validate static gate (#896 subsumption) — parses both Dockerfiles' COPY/ADD sources (any case) and fails if the YAML-anchored artifact-input map misses any build input, and asserts: the tag workflow rule exists; docker-promote sits in stage: promote with no needs:, never invokes docker build/docker buildx build, and carries a resource_group; every :latest reference in the file sits inside the promote job after the main-head guard line; build jobs and promote name the same immutable $CI_COMMIT_SHA staging-ref strings (a one-sided rename cannot land); the build-job base and promote both reference the *artifact-inputs anchor (trigger paths cannot drift); and the syft pin + checksum are present. Each assertion has a negative test, and the gate’s own test suite runs it against the real repo config.

Consequences

  • Promotion latency equals the slowest blocking gate (integration tests) — the price of gate-completeness. Force-merging past red CI still works for merges (the local battery is the merge gate, see Contributor Workflow Conventions); it no longer lets an untested image reach the registry.

  • A chronically red blocking gate now visibly parks promotion instead of being silently skipped past — as of acceptance, #1067 and #1068 do exactly that and must be fixed for the first promoted image under this ADR.

  • MR pipelines do not build images; a Dockerfile-breaking change surfaces on the main pipeline. Accepted: image builds are ~20–30 min each, and main breakage is visible + cheap to revert pre-1.0.

  • Build-once extends to test consumption (#1073, 2026-07-15): the CI integration stack pulls the staging refs instead of compiling the workspace in-daemon, so integration tests exercise the exact digests promotion retags — and integration-tests consequently runs only where the staging refs exist (tag pipelines, and main commits touching the artifact-input map), mirroring the build jobs' rules. See the ADR-015 amendment for the mechanism.

  • Image signing/attestation (cosign, SLSA provenance) is out of scope here and remains open; the immutable digest + retained SBOM chain is the foundation it would build on.

  • Deploy tooling can now rely on: :<short-sha> (immutable, every promoted main commit), :<tag> (releases), :latest (the newest gate-complete main head), for both the service image and …/portal.

References

  • #1007 (defect + acceptance criteria), #1025 (subsumed), #1066/#1067/#1068 (chronic CI failures found during delivery)

  • ADR-015 (the DinD integration job that now gates promotion)

  • ADR-017 (CI secrets)

  • ADR-033 §5 (the test-clock feature must never reach a production image — the build jobs pass no CARGO_FEATURES, keeping the Dockerfile’s empty default)

  • ADR-008 (why the portal is a separate image)

Amendment 1 (2026-10-03) — the portal builder’s downloaded tools (#1370, #2599, #2619)

Status unchanged (still Accepted). Decision 5’s SBOM is generated from each pushed image, so it lists what the runtime image ships and none of the tools the builder stage ran. The portal builder downloads build tools as well as crates. Each is a supply-chain input of the promoted portal image that no SBOM records, so services/canopy-portal/Dockerfile pins every tool it fetches with curl by version and URL and checks its sha256 before it first runs. The Alpine packages and the wasm32 rustup target it also installs are not version-pinned; apk checks packages against its signed index, and rustup checks components against the hashes in its channel manifest. dx’s rustup target add for a missing target is not covered by the NO_DOWNLOADS switch below; the builder installs the wasm32 target before dx runs, so dx never takes that path. The pinned tools:

  • wasm-opt (binaryen version_127) and wasm-bindgen 0.2.114, since #1180.

  • sccache 0.18.0, the release’s x86_64 musl static binary, since #1370. Its sha256 is the one the release publishes in its .sha256 asset. sccache wraps every rustc invocation of the portal build, so a substituted binary could change the compiled output; the pin and the checksum are the control.

  • esbuild 0.27.3, the npm registry’s @esbuild/linux-x64 tarball, since #2599. dioxus-cli 0.7.9 used to fetch it on every build, unverified, to minify the JavaScript the applicant portal serves. Its sha256 was computed from the tarball and cross-checked against the registry’s published sha512 dist.integrity.

The builder sets NO_DOWNLOADS, so dioxus-cli takes these provisioned copies or fails the build; it never downloads a tool (#2599).

The portal build sends no telemetry (#2619). A default dioxus-cli posts usage events from every invocation to its PostHog collector at dx-cli-stats.dioxus.dev, which would have carried data about every production build to a third party. dioxus-cli is installed with --features disable-telemetry, which makes its telemetry switch true at compile time, so no environment variable or settings file can turn it back on; portal_builder_installs_dioxus_cli_with_telemetry_compiled_off pins the feature.

sccache’s cache is the builder’s own BuildKit cache mount, so an entry carries the trust of the builder that wrote it, as the cargo registry mount already does. dioxus-cli itself is compiled from crates.io by cargo install --locked. portal_tool_layer_runs_no_download_it_has_not_verified (xtask/src/devstack_guard.rs) fails on any curl, wget or remote ADD in the portal Dockerfile that is not one of its pinned rows.

Amendment 2 (2026-10-03) — every tool download is pinned and verified (#2621)

Status unchanged (still Accepted). Amendment 1 pinned the portal builder’s tools; the CI jobs and the test images still fetched tools unverified. The cargo-test, coverage, cargo-audit, cargo-machete and sbom jobs piped cargo-binstall’s installer from its main branch into sh, and cargo-binstall then installed prebuilt binaries no digest pinned, all but the coverage tools at whatever version was newest. Dockerfile.integration and xtask/Dockerfile.validate-runner piped cargo-nextest’s tarball straight into tar. The cargo-audit job’s cargo-deny decides whether the advisory, license and ban gate passes, and the sbom job’s cargo-cyclonedx writes the release SBOM, so a substituted binary could change what is checked or what is shipped.

Each of those tools is now the x86_64 musl build of a pinned release, fetched as a file and checked with sha256sum -c against the digest committed beside its URL before it is unpacked: cargo-nextest 0.9.140, and for the coverage measurement cargo-nextest 0.9.133 with cargo-llvm-cov 0.8.7 (the versions coverage-baseline.toml records); cargo-deny 0.20.2; cargo-machete 0.9.2; cargo-cyclonedx 0.5.9. Each digest was computed from the downloaded tarball and matches the checksum file the release publishes; cargo-llvm-cov publishes none, and its digest matches the one GitHub records for the release asset. cargo-binstall is gone. The CI jobs unpack each tool into $CARGO_HOME/bin, where cargo looks for a subcommand before PATH, so a copy the job cache restores is replaced before it runs. cargo xtask perf runs k6 from grafana/k6 pinned to its image digest.

Decision 6 gains a rule. cargo xtask ci-config-lint scans .gitlab-ci.yml and every tracked Dockerfile (found with git ls-files, not listed by hand) and refuses: a curl or wget download unless the next command to name the file is sha256sum -c against a committed digest, whose failure stops the script; a download piped into a command or fetched inside a command substitution; any pipe into a shell; a remote ADD without --checksum=sha256:; and cargo binstall. The rules and their fixture tests are in xtask/src/cmd/ci_config_lint/downloads.rs.

Package-manager installs are outside the rule: apk checks a package against its signed index, rustup a component against its channel manifest’s hashes, cargo a crate against the registry index’s checksum, and npm a package against the integrity its lockfile records, or without a lockfile the integrity the registry reports.

Amendment 3 (2026-11-05) — the production image is promoted; the tests run its feature build (#3248)

Status unchanged (still Accepted). Maintainer decision, 2026-11-05: promote the production image built from the tested commit; the test jobs run that commit's feature image, which differs only by the test-feature flags, and the production image passes its own smoke stage.

The merge-train pipeline (plan merge-trains-are-the-gate) builds both images from the same commit in its build stage. images runs cargo xtask ci images --push: the production service, portal and Kanidm images under the staging refs of Decision 2, which the verb pushes and digest-pins in images.env, layer-cached from main as before. images-test runs cargo xtask ci images --push --test-features: the service image built with CARGO_FEATURES=canopy-api/test-clock,canopy-api/test-fault, the root Dockerfile's existing build argument, under $CI_REGISTRY_IMAGE/build/test:$CI_COMMIT_SHA, digest-pinned in images-test.env. The integration, e2e, identity and perf jobs bring their stack up from images.env with images-test.env laid over it. The smoke job boots the production images alone and runs the integration lane less every test source that needs /test/clock or /test/fault, which ADR-033 compiles out of the production build; the exclusion is derived from the sources, and a floor on the executed test count stops a broken filter from passing.

Decision 2 changes in one respect: the images are built on every pipeline, merge-request pipelines included, because every test job needs them; build-once across pipelines still reuses a staging ref the registry already holds. Decision 3 holds: docker-promote resolves and retags only the production staging refs, never build/test. Decision 5 moves: the per-image SBOMs are generated in docker-promote, from each production digest, before its first retag, so a failed SBOM stops the promotion and no production digest exists without one. Decision 6 follows: cargo xtask ci-config-lint asserts that images and images-test run those verbs, that docker-promote names both production staging refs and never the test repository, and that its SBOMs precede its first retag. The dind and prebuilt-variable rules are gone with the jobs they governed. ADR-033 stands.

Amendment 4 (2026-11-06) — the layer cache is a BuildKit registry cache (#3248)

Status unchanged (still Accepted). Decision 2's main-cache pointers were inline caches: an image carried its own layers as cache, so only the final stage's layers survived to the next pipeline, never a builder stage's. On fresh runner VMs every pipeline therefore recompiled the portal builder's dioxus-cli install and re-installed the service builder's toolchain packages, though neither changes between commits.

cargo xtask ci images now builds a registry image through a buildx docker-container builder that runs a digest-pinned BuildKit image. Each build reads the registry cache <path>:buildcache and pushes its ref directly (--provenance=false, so the ref stays a single manifest). Only a main pipeline writes the cache, with mode=max, which keeps every stage's layers. A pipeline on an older commit therefore cannot walk the cache backwards, as before. The content-addressed Kanidm image carries no cache. A local build is still a plain docker build.

Amendment 5 (2026-11-06) — three image jobs in parallel (#3248)

Status unchanged (still Accepted). Amendment 3 had images run after images-test so that it could reuse the portal and Kanidm images by ref. That put the production service build, and so smoke, behind the test build on every car. Three jobs now start together. images-shared (ci images --push --set shared) builds the portal and Kanidm images into images-shared.env. images-test (--set test) builds the test service image into images-test.env. images (--set release) builds the production service image into images.env. The stack jobs bring their stack up from the shared file with the test file laid over it; smoke uses the shared file with the production file. docker-promote still resolves the production staging refs from the registry. Decision 6's lint now asserts all three verbs.

Amendment 6 (2026-11-06) — the smoke stage is the k6 smoke profile (#3248)

Status unchanged (still Accepted). Maintainer decision, 2026-11-06: Amendment 3's smoke stage re-ran the integration lane against the production images, less every test source that needs /test/clock or /test/fault. That was 4,653 of the 4,971 tests infra had just run, compiled a second time: about 23 of a car's ~144 runner-VM minutes, on the car's critical path, on a 12-VM fleet two projects share.

smoke now brings the production images up and runs the k6 smoke profile (cargo xtask ci perf). That covers every service's /livez and authenticated reads through the identity plane, under the profile's latency and error thresholds, which now measure the release build. The test image still runs the whole integration lane in infra. docker-promote still ships only the production digests smoke booted. The filter derivation and the floor of Amendment 3 are gone with the ci smoke stage that held them.

Amendment 7 (2026-11-07) — the production image packages the car’s one build; promotion by tree (#3273)

Status unchanged (still Accepted). Maintainer direction, 2026-11-07: for a given merge, everything is compiled exactly once (plan compile-once-per-car).

Where the production image’s bytes come from. Not from a build stage in its Dockerfile. A merge-train car's build job runs cargo xtask ci build once, in the CI image (Dockerfile.ci: Alpine, musl, the pinned toolchain) and the car cargo profile, which leaves both binary sets (target/car/bin/release/, target/car/bin/devstack/) and the portal bundle (target/car/portal/). cargo xtask ci images then packages them by COPY into the runtime base: the root Dockerfile copies the release set (BINARY_SET=release, or devstack for the test image), services/canopy-portal/Dockerfile the portal's server and public/, tools/canopy-token-broker/Dockerfile the devstack broker. The binaries the stack jobs test, smoke boots and docker-promote ships are therefore the bytes one compile produced, never a second compile of the same tree. The same job packages and pushes the images, because each binary set (about 1.0 GB) is over GitLab's artifact size limit: the images move through the registry, as Decision 2's staging refs always did. Amendments 4 and 5 are superseded: there is no builder stage to layer-cache, and the three image jobs are gone into build.

A production image never carries a test surface. ci images --set release refuses a service binary that contains a test feature's route literal (/test/clock, /test/fault, which only test-clock and test-fault compile in, ADR-033 §5), naming the binary.

No image compiles. Decision 6 gains a rule: no tracked Dockerfile has a RUN that invokes cargo or dx (a --version probe aside), except devstack/kanidm/Dockerfile, which compiles Kanidm from its release tarball once per Kanidm version under its content-addressed tag, and Dockerfile.ci, the CI image itself, built once per content address.

Promotion by tree. A train merge writes a new merge commit whose tree is the car's (the erratum of plan compile-once-per-car), so Decision 2's commit-SHA staging refs never matched on main. ci images --push tags every packaged image by tree, $CI_REGISTRY_IMAGE/build:tree-<tree> (build/test, build/portal, build/token-broker likewise), <tree> being git rev-parse HEAD^{tree}, with the commit tag beside it for traceability; a tree ref the registry already holds is reused, not pushed again, so a promotion finds the digest the car tested. docker-promote drops GIT_STRATEGY: none for a depth-1 checkout, reads TREE=$(git rev-parse HEAD^{tree}), and resolves build:tree-$TREE and build/portal:tree-$TREE; a tree no car built fails the job, never rebuilds. Decision 3 holds: only the production refs are promoted, never build/test. Decision 6's lint asserts the tree line, the tree refs and that build runs the three ci images --push verbs.

Amendment 8 (2026-11-08) — promotion runs when its car built (#3275)

Status unchanged (still Accepted). Maintainer direction, 2026-11-07: a change that touches no product or scaffolding code does not run the battery (plan compile-once-per-car, the docs-only path). build and the stack jobs now run only when a code input changed (the .code-inputs list, the artifact-input map plus what the tests and the stack read), so a docs-only car pushes no build:tree-<tree> image. docker-promote therefore runs on main under that same anchor, changes: *code-inputs, and no longer under *artifact-inputs: it promotes exactly the trees a car built, and a docs-only merge promotes nothing rather than failing on a tree no car built. main's own pipeline runs no build or stack job; tags and schedules keep the full pipeline. Decision 6's lint now asserts that promote references *code-inputs, that the code-input map covers every artifact input, and that every job needing build carries build's anchor on each of its rules.

Amendment 9 (2026-11-09) — the release job builds, smokes and pushes; a car pushes nothing (#3355)

Status unchanged (still Accepted). Plan ci-runs-the-dev-loop: a merge-train car is one job that runs the developer's commands, and it pushes nothing (#3354). Amendment 7's promotion by tree retires with it: no car writes build:tree-<tree>, and docker-promote, the build/ staging repositories and the images.env files are gone. Amendment 8's code-input rule for promotion lapses with docker-promote: a tag always releases.

Build once, inside one job. The release job (stage: promote, resource_group: release) does the following, in order:

  1. It compiles the release binary set once: the car profile, every shipped binary, no feature.

  2. cargo xtask dev start packages that build, with the portal's dx bundle, into the images the stack runs. These are the root Dockerfile and the portal's, COPY only; Amendment 7's no-compile rule stands.

  3. It runs the k6 smoke against that stack (Amendment 6).

  4. Only then does it push those same images, tagging the images the smoke ran rather than rebuilding them. :<short-sha> is pushed first. Next, each image's SBOM is generated from the digest that push wrote (Decision 4: an SBOM before any further tag). Then come :<tag> on a tag pipeline and :latest only from main's current head.

Build-once now holds between the release build and its promotion.

It runs on a tag and on a schedule, after the car, which it names in needs (#3433: stage order alone did not hold it, because a job's needs replace stage order), so a release follows a green battery of the same commit and a failed car publishes nothing. On main it runs by hand, never on a merge request.

The release set carries no test surface. dev start packages a release build only when no binary a release image ships carries the /test/clock or /test/fault route. The devstack token broker is not shipped: it links canopy-test-lib and carries the routes in either set. That replaces Amendment 7's refusal in ci images --set release.

What pins it. Decision 6's lint asserts that the job exists and that its syft is pinned and checksum-verified. lanes.rs tests hold:

  • every push but the CI image's to the release job;

  • its rules off merge requests;

  • its build line to the release set's argv.

The devstack Kanidm is a cache, not a release. The release job also pushes $CI_REGISTRY_IMAGE/devstack/kanidm:<h> when the registry lacks it. It is built with BuildKit's inline cache, and <h> is the content address of its Dockerfile, which copies nothing from its context. A stack job builds Kanidm with --cache-from that ref before dev start, so the compile (about 11 minutes) is a cache hit. The image is never promoted, and a ref the registry lacks costs a build, never correctness.

docker-compose.prebuilt.yml stays as the deployment override (the Scaling & Deployment runbook).

Amendment 10 (2026-11-10) — a third deployable image: the configuration fetcher (#3260)

Status unchanged (still Accepted). A deployment that reads its configuration from git (ADR-051) runs canopy-config-fetch before its services, from an image of its own, $CI_REGISTRY_IMAGE/config-fetch, so the service image carries neither git nor a signature verifier.

The release job treats it as it treats the service and portal images (Amendment 9): the one release build compiles its binary, cargo xtask dev start packages it (tools/canopy-config-fetch/Dockerfile, COPY only), and after the smoke the job pushes :<short-sha>, records the digest in release-digests.txt, writes its SBOM from that digest (Decision 4), and gives it the release tags. docker-compose.prebuilt.yml requires CANOPY_PREBUILT_CONFIG_FETCH_IMAGE beside the other two refs. A lanes.rs test holds every image the job publishes to all four steps.

Edit this page · default