Plan: Compile once per car — one build job feeds every image and every test; docs-only changes skip the battery (#3271)
Status: Done (2026-11-08) — U1 to U4 implemented; U4's acceptance comes from cars (a docs-only car, a code car and the main pipeline after it), whose pipeline ids go on #3275
Epic: none
Issues: #3271 (parent) · #3272 U1 (w3) · #3273 U2 (w5) · #3274 U3 (w3) · #3275 U4 (w2); each unit’s MR Closes its issue, U4 closes the parent. Out of scope, filed: #3276 warm cross-car cache, #3277 distributed build
Branches: refactor/ci-one-build, feat/ci-image-from-binaries, feat/ci-test-archive, chore/ci-docs-only-path
A Design + Scope plan: GitLab owns tracking, the child issues carry the implementer brief, and the plan freezes when U1 starts.
Erratum (2026-11-07): main re-ran check, the three image builds and the stack for every merge (about 63 VM-minutes for !1999’s), a second compile of a tree the car had built. A train merge writes a new merge commit: !1999’s car tested 949cbf3f, main got febb6965: same tree 3d56a044, different commit (the parents can differ too: on a car behind another, the first parent is the car ahead’s train commit; craig confirmed the tree match on six train/main pairs). So build:$CI_COMMIT_SHA never matched on main. U2 addresses the staging images by tree (git rev-parse HEAD^{tree}) and changes docker-promote to resolve its tree and retag from it (see Images from binaries). U4 restricts main’s pipeline to docker-promote, pages and sbom.
Erratum (2026-11-07): U1 measured each binary set at 1.0 GB and the nextest archive at 1.7 GB, both over GitLab's artifact size limit, so they cannot travel between jobs as artifacts. U2's build job therefore packages and pushes the images itself (ci images runs inside build, from target/car/). The three image jobs retire, build writes their dotenv files, and the archive ships inside the integration runner image (build/integration:tree-<tree>): the registry route the Risks table names. One fewer VM per image set, which the measured queue time (38.6 min for a car's first job) favours.
Erratum (2026-11-07): U2's host build with --target x86_64-unknown-linux-musl fails on a glibc host without a musl C toolchain (aws-lc-sys and ring call x86_64-linux-musl-gcc; tried on luchs), so dev start|refresh|reload build in the CI image instead (docker run of Dockerfile.ci, checkout mounted, ci build --binaries <set>) and rust-toolchain.toml gains no musl target; the no-cargo Dockerfile rule also exempts Dockerfile.ci, which installs dioxus-cli once per content address.
Erratum (2026-11-07): U2 left build/integration:tree-<tree> unbuilt: nothing packaged the archive. U3 adds it to ci images --set test; Dockerfile.integration is Alpine with the pinned nextest, the tree and the archive, and links the archive's build root (target/car/tests.root) to /app so the paths cargo compiled into the test binaries resolve.
Erratum (2026-11-07): U3 runs ci unit as its own line in build after ci build, not as a step of it, and retires ci clippy, whose fmt and feature-builds become ci build steps (graph-clippy is renamed clippy). Over the archive the partition is three-way: the archive carries the three conformance suites, which ci infra's filter (ARCHIVE_INTEG_FILTER) excludes and ci identity runs. Each job still compiles xtask to run cargo xtask (45 to 90 s a job, #3251), so after U3 the workspace and its tests compile in build alone, not everything: a car's other jobs each print xtask's Compiling lines.
Erratum (2026-11-08): U4 lists *code-inputs in full, repeating *artifact-inputs (YAML cannot splice one alias into another list), and ci-config-lint checks that it covers every artifact input. docker-promote keeps a changes: condition, *code-inputs (ADR-040 Amendment 8), rather than losing it: a docs-only car builds no image, so promoting its merge would fail on a tree no car built.
Erratum (2026-11-08): U3 kept the MR pipeline's docs job; U4 runs it only when a code input changed. lint runs on a car only when build is skipped, since build runs ci lint itself. Every job that needs build (fixture-smoke among them) carries the same condition, and ci-image skips main's push pipeline. main's pipeline also runs GitLab's security template jobs (semgrep-sast, secret_detection, gemnasium-dependency_scanning), which U4 leaves as they are, so U4's main acceptance is docker-promote, pages and those scans.
Context
Direction (maintainer, 2026-11-07). "For a given merge, everything should be compiled exactly once." And: a docs-only path that does not run the battery for changes that are not product or scaffolding code. craig found the same waste (its plan ci-compile-once, approved the same day, stops short of this plan’s shape and names it as its own next step); the two projects compare findings on the cicd channel and implement separately.
What a car compiles today (car 3038548869, the first on the nine-job shape, 151 VM-minutes; every job on a fresh 4xlarge VM with an empty target/):
| Job | What it compiles | Compile time |
|---|---|---|
every job |
xtask, 714 crates (#3251) |
45–90 s each, 8 jobs |
check |
clippy |
about 20 min |
images |
the 19 service binaries, |
11.5 min |
images-test |
the same 19 binaries, |
2.5 min |
images-shared |
the portal ( |
16–32 min |
infra |
the integration tests, |
5.4 min |
e2e / identity |
the three conformance suites, |
1.2 min |
the MR’s own pipeline |
lint and docs: xtask, rustdoc, the lints' own cargo calls |
8–15 min, on a tree the car recompiles |
So the workspace’s dependency graph is compiled from scratch in six different jobs, in three cargo profiles (test, release, devstack), on two toolchain images, twice inside Docker where no cache survives the VM. Cargo’s own caching cannot help: GitLab’s cache was measured as the critical path’s largest cost (#1067 bounds it at 16 GB and wipes it), and a BuildKit cache mount never leaves the VM.
What exists to build on. cargo xtask ci <stage> verbs are the pipeline’s leaves (plan merge-trains-are-the-gate; xtask/src/cmd/ci/mod.rs registers them). ci images --set builds three sets in parallel; docker-compose.prebuilt.yml composes from registry refs; nextest 0.9.140 is in Dockerfile.ci; lanes::TEST_FEATURES, CLIPPY_FEATURES and FEATURE_BUILDS name the feature sets, and lanes::test_feature_args_for(packages) narrows a feature list to the packages a -p selection names, since cargo refuses a pkg/feature of an unselected member. .gitlab-ci.yml is under ci-config-lint (xtask/src/cmd/ci_config_lint.rs and its gating.rs): every script line is a cargo xtask verb or on gating::ALLOWED; gating::TRAIN_JOBS lists the jobs whose first rule is the merge-train one; gating::NEEDS maps each stack job to its image jobs and the exact ci devstack --images bring-up line; the CI_IMAGE_TAG is the digest of Dockerfile.ci and rust-toolchain.toml.
Names that collide. nextest already has a ci profile (.config/nextest.toml [profile.ci], unit.rs CI_PROFILE), selected with --profile; a cargo profile is selected with --cargo-profile on nextest and --profile on cargo. The new cargo profile is therefore named car, never ci.
Scope
In scope:
-
One
buildjob per car that compiles the workspace once and publishes: the service binaries (production and devstack sets), the portal bundle, xtask, the nextest archive, and the clippy and rustdoc verdicts from that same compile. -
Image jobs that package prebuilt binaries:
Dockerfile,services/canopy-portal/Dockerfile,tools/canopy-token-broker/DockerfileandDockerfile.integrationlose theircargo/dxstages. -
Stack jobs that run the archive and compile nothing.
-
A docs-only path: a change outside the code inputs runs the docs checks alone, on the MR pipeline and on its car.
-
The lints the MR pipeline runs without a workspace compile.
-
ADR-040 Amendment 7 (where the production image’s bytes come from) and the plan
merge-trains-are-the-gate's erratum.
Out of scope (issues filed at approval):
-
A warm cross-car cache (sccache to the registry or S3; a persistent builder). This plan removes the redundant compiles; a warm cache would shorten the one that remains, and is a separate measurement.
-
Splitting the one build across VMs by crate. One VM compiles the whole graph in about 12 minutes; splitting it would recompile shared dependencies.
-
xtask as a prebuilt artifact for the MR pipeline’s
lintjob (#3251 stays open for that one job; the car’s jobs get xtask frombuild). -
craig’s implementation.
Design
One build, one graph
The build job, on one VM in the CI image, runs cargo xtask ci build, which issues these invocations in order, all against one target/ and one cargo profile, car:
-
cargo build --profile car -p <the 22 binary packages> --features <test_feature_args_for(those packages) + canopy-api/test-clock,canopy-api/test-fault>: the devstack set. The packages are the 19 services, canopy-seed, canopy-cli and canopy-token-broker (lanes::BINARY_PACKAGES, new); the portal is not among them (it isdx's, step 6). The feature list is narrowed bytest_feature_args_for, as every-pinvocation in xtask is. -
The same without the two test features: the production set. Cargo’s feature unification rebuilds only
canopy-apiand the crates that depend on it; the dependency crates' artifacts are reused, and the invocation’s--timingsreport (kept as an artifact) shows what it recompiled. -
cargo nextest archive --cargo-profile car --profile ci --workspace --all-targets --features <CLIPPY_FEATURES> --archive-file target/car/tests.tar.zst: every test binary (unit, integration, the conformance suites, thetests/targets), on the same dependency artifacts. The archive carries the binaries and the metadata a laternextest run --archive-fileneeds, with no source and no cargo. -
ci clippy'sfmtstep (no compile), thencargo clippy --profile car --workspace --all-targets --features <CLIPPY_FEATURES> — -D warnings: clippy drives rustc for the workspace crates and reuses the dependency artifacts of step 3 (clippy-driveris a rustc wrapper; cargo passes the dependencies'.rlibfiles unchanged). Whether the reuse is complete is the first measurement U1 makes (Risks). -
ci docs's two steps on the same graph:rustdoc-private(cargo doc --profile car --document-private-itemswith its denied lints) and the doctests (cargo test --doc --profile car, whose examples are their own binaries, [what-cannot-be-once]). -
dx build --platform web --fullstack --releasefor the portal, once: the wasm32 client is its own target ([what-cannot-be-once]); its native server half sharestarget/with step 1 under thecarprofile (Dioxus.tomlnames the server profile). -
The
feature-buildsgate (lanes::FEATURE_BUILDS): sixcargo checkinvocations on the sametarget/, each a package in isolation. They check, not codegen, and reuse the graph’s metadata; today they run inci clippy. -
ci unit:nextest run --archive-file target/car/tests.tar.zstwith the unit selection, on this VM, right after the archive exists. -
ci lint's 42 gates (itsdocsgate holds the AsciiDoc, plan and stray-backtick checks): xtask only.
Steps 4, 5, 7, 8 and 9 are today’s check job (su-exec tester cargo xtask ci lint|clippy|docs|unit); check therefore folds into build, which runs the same four verbs' steps unprivileged as check does today (the chown -R tester prelude and su-exec move with them; gating::ALLOWED's ("check", "su-exec tester cargo xtask ", …) entry becomes build's).
The job’s artifacts, under target/car/: bin/release/, bin/devstack/ (the two sets, by binary name), portal/ (the server and public/), tests.tar.zst, xtask, and timings/ (cargo’s HTML reports). GitLab artifacts carry them to the later jobs; expire_in: 1 day.
The car profile (new in Cargo.toml): inherits = "release", debug = false, strip = "debuginfo", codegen-units = 16, lto = false, incremental = false. One profile for everything a car produces: the production image’s binaries are optimised exactly as the tests ran them, which a determination’s reproducibility also wants. The devstack profile is retired. test and test-debug stay for developers' hosts, where cargo xtask test keeps its lanes.
The CI image (Dockerfile.ci) gains what the portal’s Dockerfile provisions today for dx build: dioxus-cli 0.7.9 (--features disable-telemetry), wasm-bindgen-cli 0.2.114, wasm-opt and esbuild, each pinned by URL and sha256 as that Dockerfile pins them, and the wasm32-unknown-unknown target. The CI_IMAGE_TAG changes with it, as the lint requires. The portal’s own Dockerfile keeps none of it.
The one split that stays
canopy-api/test-clock and test-fault (ADR-033 §5, #1325) must never reach the production image, so the production and devstack binary sets differ in those two features. With feature unification they are two invocations over one graph: cargo recompiles canopy-api and the crates that depend on it (the service crates, seconds each after the first); everything beneath compiles once. This is the one place "exactly once" holds for the dependency graph but not for the leaf crates. The maintainer chose to keep it (2026-11-07): the alternative, one binary set with the test surfaces gated at runtime, is what ADR-033 rejected on audit-integrity grounds.
What cannot be once
Three things compile twice by their nature; the plan names them so no one looks for a fix:
-
A crate’s unit-test harness (
cfg(test)) is a different artifact from its library. Every crate with inline tests is compiled as a lib (for its dependents) and as a test binary. This is rustc, not the pipeline. -
rustdoc re-type-checks every crate it documents; it reuses the dependency metadata, not the codegen. Each doctest example is compiled as its own small binary against the library.
-
The portal’s wasm32 client is another target triple: the crates common to the client and the server (serde, the contracts) compile once per target.
Images from binaries
Dockerfile becomes one runtime stage with no cargo: Alpine 3.24, the same user and WORKDIR, COPY target/car/bin/${BINARY_SET}/ /app/ and the policy layers (rulesets/, fixtures/config/) as today; ARG BINARY_SET=release|devstack picks the set. services/canopy-portal/Dockerfile copies target/car/portal/; tools/canopy-token-broker/Dockerfile its binary. Dockerfile.integration becomes the archive’s runtime: Alpine plus the pinned static cargo-nextest and COPY target/car/tests.tar.zst /app/tests.tar.zst; its ENTRYPOINT is cargo-nextest nextest run --archive-file /app/tests.tar.zst --workspace-remap /app followed by today’s -E filter. The image’s app user, the test-results volume and the CANOPY_TEST__* environment stay.
cargo xtask ci images --set release|test|shared keeps its interface, and images.env its contract, so ci devstack does not change. Its staging refs gain the tree form (the erratum): ci images --push tags build:tree-<tree>, build/test:tree-<tree> and build/portal:tree-<tree>, <tree> being git rev-parse HEAD^{tree}, and keeps the commit tag beside it for traceability. docker-promote drops GIT_STRATEGY: none for a depth-1 fetch (GIT_DEPTH: 1), reads the tree the same way, and retags build@<digest of build:tree-<tree>>; a tree it cannot find fails the job, never rebuilds. The three image jobs now need: build (the YAML and gating::NEEDS) and each takes about two minutes: a docker buildx build of a COPY-only Dockerfile, plus the push. images and images-test stay two jobs so smoke and the stack jobs keep their needs: and the lint’s map stands.
The portal’s dx build moving to the build job retires #3258’s cargo-metadata race for good: the fetch happens once, on the host.
The developer’s dev start. Compose builds images from source today. After U2 it builds them from target/car/, so cargo xtask dev start|refresh runs ci build's binary steps (1, 2 and 6) on the host first, then the same COPY-only Dockerfiles. The devstack’s test-clock/test-fault opt-in (CANOPY_CARGO_FEATURES) becomes the devstack set, which is what it always built; the staleness marker (devstack_guard.rs) hashes the binaries' inputs as it hashes sources today. A developer builds the workspace once per refresh, on the host, in the car profile; the portal-build pins in devstack_guard.rs move to ci build's tests.
Tests from the archive
ci infra runs canopy-integration as today; the container runs the archive. ci identity runs the three conformance binaries from the archive (-E 'binary(idp_conformance_kanidm)' and its siblings, under nextest’s idp-conformance profile) instead of identity conformance's own cargo nextest run; identity/conformance.rs gains the archive as an input and keeps the provisioning it does today. The stack jobs need: the image jobs, which need: build, so the archive artifact reaches them through the chain (needs: artifacts are transitive only when listed; the stack jobs list build explicitly). The test-lanes-lint --verify-partition invariant holds: the partition is a filter over one archive.
The lints without a compile
ci lint's 42 gates read source and the policy layers; they run xtask only. The MR pipeline’s lint job compiles xtask (48 s warm) and nothing else. ci docs (rustdoc-private and the doctests) runs only in build on a car; the MR pipeline’s docs job is removed, since lint's docs gate already carries the AsciiDoc checks.
The docs-only path
.gitlab-ci.yml gains one changes: anchor, code-inputs: *artifact-inputs plus tests//, docker-compose*.yml, .config//, compliance//, devstack//, Dockerfile. build, the image jobs and the stack jobs carry rules: changes: *code-inputs on their merge-train and merge-request rules. A change outside that set (under docs/, CHANGELOG.adoc, AGENTS.md, .gitlab/) runs lint (all 42 gates, among them the plan, SPDX and docs gates) and antora (the site builds; today pages does it only on main) and nothing else, on its MR pipeline and on its car. The train still gates the merge: a docs-only car is a two-job car, about four minutes, instead of a nine-job one. A change touching both docs and code runs everything.
main promotes, nothing more (the erratum). After a train merge, main’s tree is one a car built and tested. main’s pipeline therefore runs docker-promote, pages and, on a tag, sbom: build, the image jobs and the stack jobs lose their $CI_COMMIT_BRANCH == "main" rule (.stack-rules, .car-rules), and docker-promote loses its changes: condition, since the car built every tree that merges. Tags and schedules keep the full pipeline.
On a merge-train pipeline rules:changes compares the car’s diff against the train’s target, which is exactly the change the car carries; on an MR pipeline it compares the MR’s diff against its target. ci-config-lint gains the rule that build and every job that transitively needs: it carry the same changes: anchor, so a stack job cannot be scheduled on a car whose build was skipped.
What ci-config-lint changes
gating::ALLOWED gains docker-promote's tree line (TREE=$(git rev-parse HEAD^{tree})) and its build:tree- lookups in place of the $CI_COMMIT_SHA ones; every other new script line is a cargo xtask ci verb (the check entry’s su-exec prefix moves to build). gating::TRAIN_JOBS lists the new job set; gating::NEEDS maps the image jobs to build and the stack jobs to the image jobs and build. Two new rules: no Dockerfile under the lint’s list contains a RUN line that invokes cargo ` or `dx ` (the build stages are gone and must not come back), and the `changes: anchor rule above.
Risks
| Risk | Class | Mitigation and the test that pins it |
|---|---|---|
The two binary sets share |
silent |
Cargo fingerprints artifacts by feature set; the sets are distinct files under |
The archive is large and its upload or download becomes the critical path, or exceeds the artifact size limit. |
fail-closed |
The |
|
fail-open |
The lint ties every stack job to |
Clippy does not reuse the archive’s dependency artifacts and compiles the graph a second time; or lints change fingerprints so the archive’s artifacts are rebuilt after it. |
silent |
U1 measures on |
|
fail-closed |
The binary steps build |
Units (weights by complexity) — U1 → U2 → U3 → U4
Weights: 1 trivial · 2 small · 3 medium · 5 large · 8 very large. One unit = one independently shippable MR = one child issue.
U1 (w3) — cargo xtask ci build, the car profile and the CI image; measure
Files: xtask/src/cmd/ci/build.rs (new), xtask/src/cmd/ci/mod.rs, xtask/src/lanes.rs (BINARY_PACKAGES), Cargo.toml ([profile.car]), Dockerfile.ci (the dx toolchain), .gitlab-ci.yml (CI_IMAGE_TAG; the build job beside the jobs that exist, on every car), xtask/src/cmd/ci_config_lint/gating.rs (TRAIN_JOBS gains build), docs/modules/ROOT/pages/tooling/xtask-catalog.adoc.
The verb, the profile, the image; the job runs on every car beside today’s jobs, publishing its artifacts and --timings. Nothing consumes the artifacts yet. Tests: the verb’s argv per step (contract); the devstack set’s features equal test_feature_args_for(BINARY_PACKAGES) plus the two test features, the production set’s exclude them (contract); the car profile has no debuginfo (contract, read from the manifest). Acceptance, on the issue: three cars' timings per step, the archive’s size, and whether clippy rebuilt the graph.
U2 (w5) — Images from binaries
Files: Dockerfile, services/canopy-portal/Dockerfile, tools/canopy-token-broker/Dockerfile, rust-toolchain.toml (the musl target), xtask/src/cmd/ci/images.rs, xtask/src/cmd/ci_config_lint.rs and gating.rs (the no-cargo-in-Dockerfiles rule; NEEDS), xtask/src/devstack_guard.rs (the portal-build pins move to ci build; the staleness inputs), xtask/src/cmd/dev.rs (dev start|refresh builds first), docker-compose.yml (the build: blocks' args), .gitlab-ci.yml (the image jobs need: build; docker-promote by tree), ADR-040 Amendment 7, deployment-guide.adoc, local-dev.adoc.
Tests: the Dockerfile rule (regression: a planted RUN cargo fails the lint); the production set refuses a test-feature binary (contract); the staging refs carry the tree form and docker-promote's lookup matches it (contract, on the YAML and the verb); the devstack’s staleness marker changes when a binary input changes (regression). Acceptance: a car whose three image jobs each take under two minutes, smoke green on the production images, and dev start on luchs from host-built binaries.
U3 (w3) — Tests from the archive; check folds into build
Files: Dockerfile.integration, xtask/src/cmd/ci/{infra,unit,identity,clippy,docs}.rs, xtask/src/cmd/test.rs (run_integration_tests_container passes no features: the archive has them), xtask/src/cmd/identity/conformance.rs, .gitlab-ci.yml (check removed; the stack jobs need: build), gating.rs (ALLOWED, NEEDS), testing.adoc.
Tests: the partition invariant over the archive (test-lanes-lint --verify-partition, as today); ci unit's selection unchanged (contract); ci identity runs each suite from the archive under the idp-conformance profile (contract). Acceptance: a car with no Compiling line in any job but build (the traces grepped, recorded on the issue), and the car’s VM-minutes against car 3038548869’s 151.
U4 (w2) — The docs-only path
Files: .gitlab-ci.yml (*code-inputs, the antora job, main’s rules), xtask/src/cmd/ci_config_lint/gating.rs (the anchor rule), contributor-workflow.adoc, merge-trains-are-the-gate.adoc (erratum).
Tests: the anchor rule (regression: a stack job without build's anchor fails the lint). Acceptance: two cars on the issue, a docs-only MR that ran lint and antora only, and a code MR that ran every job; and the main pipeline after that code MR’s merge, which ran docker-promote and pages only and promoted the car’s digests. Closes the parent with the plan’s Status set to Done.
Verification
-
cargo xtask testpasses. -
After U3: a car’s traces show
Compilinglines inbuildalone; the car’s VM-minutes and wall time are recorded against today’s 151 and 108. -
After U4: a docs-only car runs
lintandantoraonly. -
The merge train’s pipeline is green (CI is the gate).
Documentation Updates
-
tooling/xtask-catalog.adoc(ci build),testing.adoc(the archive),deployment-guide.adoc(where the image’s binaries come from),contributor-workflow.adoc(the docs-only path),local-dev.adoc(dev startbuilds once on the host) -
CHANGELOG.adoc— one entry per unit -
ADR-040 Amendment 7 (and Amendment 8, U4);
plans/merge-trains-are-the-gate.adocerratum
Review log
| round | vendor | resolved model | verdict |
|---|---|---|---|
1 |
Anthropic |
claude-fable-5-1 |
FLAGS: |
2 |
gemini-4-argon |
FLAGS: the same, plus |