Plan: CI compiles each thing once

Status

Done (2026-11-08) — U1–U6 delivered: every Rust job runs in one prebuilt craig-ci image, xtask is built once per pipeline, a car has one check job and one docs build, and main repeats nothing the train proved; plan ci-dev-loop (#3042) later replaced the car DAG, docker-promote and the registry hand-off with one car job and release-build

Issues: #2982 is the plan issue (retitled to this plan on approval; it carries the measurements). U1 closes #2980, U2 closes #2982 and #2940, U5 closes #2981; U1, U3, U4 and U6 each get a unit issue on approval, which the unit closes. Related: #2968 (the 4xlarge queue), #2969 (the runner cache’s S3 403), #2931, #2937, #2938, #2941 (the shape being changed), #2779 (the floating tags). Branches: chore/ci-image, chore/ci-xtask-once, chore/ci-car-dag, chore/ci-main-pipeline, chore/docs-link-check.

A Design + Scope plan: GitLab owns tracking; the plan freezes when U1 starts. The maintainer decided the three forks in § Decisions on 2026-11-07.

Context

Two pipelines of one tree were profiled (train pipeline 3038692446 for !2178; main pipeline 3038934337 after its merge), job traces read for Compiling lines, Finished … in times and queue durations.

Repeated work (4xlarge minutes) per car per merge

cargo install cargo-nextest cargo-machete --locked, compiled from source in every .rust-ci job (.gitlab-ci.yml:53)

7 × 2.2 ≈ 15

≈ 7

apt-get install build-essential … and the rustup toolchain download in every job (.gitlab-ci.yml:40-50)

≈ 7

≈ 3

xtask compiled in every job that runs it: 521 crates, 1-2.5 min on bookworm, 9-13 min on the Alpine RUST_IMAGE and in docker:27 (secrets-policy 9 m 03 s of 594 s; docker-promote 12 m 42 s)

≈ 15

≈ 27

lint, clippy and unit each compile the workspace on their own VM (#2941)

3 VMs, ≈ 25

clippy 5, writing a cache no job can read (#2969)

feature-matrix: every state bundle compiled in isolation, blocking, on every train

13

—

Antora built twice (docs-xref-check, review); docs-deadlinks compiles xtask to call lychee and repeats the Antora leg (skipped: no Antora in RUST_IMAGE)

≈ 8

≈ 13

pentest and perf-load: advisory, yet they run on every push to main and rebuild every devstack image from source (ci devstack-up without --from-digests)

—

55 + 38

docker-promote: release images and xtask built inside the dind image

—

40

build on main: 18 m 23 s in BuildKit against 3 m 34 s for the same tree on the train

—

18

Total

≈ 134, 11 VMs

≈ 190

Each VM also waits 24-60 minutes for a 4xlarge (#2968): the pool is shared with canopy, and fewer VMs per car is the lever CRAIG owns. The runner’s distributed cache answers 403 (#2969), so every design here is cache-independent: GitLab artifacts and the container registry carry state between jobs, nothing else.

Earlier plans: ci-integration-build-once-fanout.adoc (#1739, Not started) is superseded by merge-trains-gate’s build → battery ∥ e2e and by this plan; archiving it is a one-line follow-up, not a unit here.

Design

D1 — One CI image, keyed by its inputs

ci/Dockerfile.ci builds craig-ci: rust:1.97.0-bookworm with the pinned toolchain installed, cargo-nextest, cargo-machete, cargo-audit, cargo-deny and cargo-cyclonedx at pinned versions (the only pin site, #2980), the Docker CLI with the buildx and compose plugins from Docker’s signed apt repository (today’s .docker-host script), git-lfs, age, sops, openssl, and the cargo registry pre-fetched for the Cargo.lock at build time. Its tag is the SHA-256 of ci/Dockerfile.ci and rust-toolchain.toml (the craig-tools pattern, xtask/src/cmd/ci/buildx.rs:180-195), not of Cargo.lock: a lock drift costs a delta fetch at run time, never an image rebuild.

cargo xtask ci image --ensure computes the tag, asks the registry, and builds and pushes only when absent. The ci-image job runs first in every pipeline (needs: [], about 20 s when the image exists, 8-10 min when a toolchain bump rebuilds it). Every Rust job declares image: $CI_REGISTRY_IMAGE/ci/craig-ci:$CRAIG_CI_IMAGE_TAG, the tag a variable pinned in the YAML; a contract test recomputes the hash from the checkout and fails when the pin is stale, naming cargo xtask ci image --bump as the fix. RUST_IMAGE, RUST_CI_IMAGE, the docker:27 + dind pair, ci/Dockerfile.audit-tools and every apt-get, rustup and cargo install line leave the YAML. .cargo-cache goes with them: the image carries the registry, and the cache it fed is unreadable anyway.

Erratum (2026-11-07, U1): cargo-cyclonedx is pinned at 0.5.9, not the latest 0.5.10: 0.5.10 publishes no release binaries, and every tool in craig-ci is a checksummed release binary.

Erratum (2026-11-07, U1): until U5 retires docs-deadlinks, its viewer-emission leg skips: craig-ci carries no node, and installing it in the job would be the run-time install D1 removes.

D2 — xtask built once per pipeline

The xtask job (needs: [ci-image]) runs cargo build -p xtask --config profile.dev.debug=false, copies the binary to target/ci/bin/xtask and ships it as an artifact; it then runs the three content lints that docs-content-lints ran (lints mandatory-docs, plan-lint, lints doc-pointer-integrity: file scans, about 30 s), so that job goes. Every other job needs: [{job: xtask, artifacts: true}], puts target/ci/bin first on PATH through one .xtask-bin template, and its script lines read xtask …. The pipeline contract (pipeline_tests.rs) changes in three places: the verb prefix the script-line test accepts (xtask `), one allow-listed bootstrap line (the `xtask job’s cargo build -p xtask …, exempt from FORBIDDEN’s `cargo build rule by job name, the only exemption), and REQUIRED_OUTSIDE_DAG, where docs-content-lints becomes xtask (the lints now run there) and, with U3, docs-xref-check becomes docs.

Inside craig-tools the re-execution runs cargo xtask today, in two places: xtask/src/docker.rs (reexec_in_network, tools_exec) and xtask/src/cmd/ci/mod.rs:191-200 (StageCommand::argv, the cargo xtask ci <stage> argv run_stage hands to tools_exec); so the battery and e2e compile xtask a second time in the container. craig-tools is Playwright noble (glibc 2.39), the binary is bookworm (glibc 2.36) with rustls and no OpenSSL, and the checkout is mounted at its own path: both sites take their argv head from one new helper that returns current_exe() when it lies under the checkout and ["cargo", "xtask"] otherwise, so a developer’s cargo xtask dev exec keeps working. A unit test pins both branches of the helper.

Erratum (2026-11-07): the re-execution reuses current_exe() only under target/ci/bin/ (the bookworm-built artifact, glibc 2.36); a developer’s host-built binary can need a newer glibc than craig-tools' noble 2.39 (luchs builds against 2.44), so it falls back to cargo xtask.

Erratum (2026-11-07): ci-image keeps cargo xtask ci image --ensure, since it runs before the xtask job; the script-line test allows it in that job alone, as it allows the xtask job’s cargo build line.

#2940 (the per-job CARGO_ALIAS_XTASK and xtask-target cache) never reached main: it sits in car 6 (!2165). U2 closes it as superseded, and D6 rebases car 6 without that commit; nothing is removed from main.

Erratum (2026-11-07): car 6 merged before U1, so #2940’s alias and xtask-target cache did reach main; they leave with .cargo-cache in U1 (with their two contract tests), and U2 closes #2940 with nothing left to remove.

D3 — The car DAG: xtask → check ∥ build ∥ docs → battery ∥ e2e

  • check is one job again. A new cargo xtask ci check runs the lint, clippy and unit stages in sequence on one target directory, each to completion with its own step table and JSON report, and exits red if any was: #2941’s property (a red lint hides nothing) holds without three VMs. The three stage verbs stay for the hook and for validate.

  • build is unchanged in substance (xtask ci images --publish-digests), now without the tool installs and the xtask compile.

  • docs is one Antora build in the Antora image: --log-failure-level=warn (the xref gate, blocking), the review artifact and environment, and the source-level external-link check of D5 as a second script line that exits 42 on dead links, with allow_failure: {exit_codes: [42]} on the job, so the xref gate’s exit 2 still blocks and a dead external link never can. It replaces docs-xref-check, docs-deadlinks and review.

  • feature-matrix runs on main and on the schedule, never on a car: a bundle that stops building alone is a post-merge fix: (decision 2).

  • .car-rules, .stack-rules and D5 of ADR-086 keep their meaning; ADR-086 D2 is amended for the new job names.

Six VMs per car. The stack jobs keep $CI_BATTERY_RUNNER_TAG; everything stays on the 4xlarge (#2935).

Erratum (2026-11-07): CI_BATTERY_RUNNER_TAG is dropped (ADR-086 § D3, amended): every job runs on $CI_RUNNER_TAG.

D4 — main repeats nothing the train proved

The train pipeline ran on the merged result, so after the merge main holds a proven tree. On main: ci-image, xtask, build (it writes the BuildKit cache the cars read), docker-promote (needs: [build], reading that cache and the xtask artifact, no dind), secrets-policy (ADR-064’s keyed decrypt on protected refs), pages (an Antora build with --log-failure-level=warn), feature-matrix, the GitLab scan templates and sbom/release on tags. Not on main: clippy, docs-xref-check, docs-deadlinks, docs-content-lints, review. pentest, perf-load, perf-stress and cluster-tests run on the schedule and by hand (when: manual on main), and when a build artifact exists in their pipeline they take --from-digests instead of rebuilding (decision 1).

Erratum (2026-11-07): cargo-deny also stays on main when the dependency manifests change (#2658 put it there): a 33-second security scan of the merged lock, kept rather than dropped from the D4 set.

docker-promote reads and writes its own BuildKit cache group: ci images --push gains --write-cache, using cache_ref(image, "release") (buildx.rs:43) as --cache-from and, on main, --cache-to, so each promote rebuilds only the crates the merge changed. build and docker-promote keep separate groups because their CARGO_PROFILE differs.

The 18-minute build on main against 3 m 34 s for the same tree on the train is a cache miss, a slow export, or both. U4 compares the two traces' BuildKit step lines (#N CACHED against #N DONE <seconds>) stage by stage, then reproduces the miss on the 4xlarge-equivalent path with --progress=plain, testing the three candidate causes in order: the --write-cache run’s --cache-to export time itself (an export-only cost: fix by exporting once per distinct input hash, skipping when the registry already holds the cache for that hash), GIT_DEPTH: "0" changing a COPY . . input the train’s shallow clone lacked (fix: exclude .git in .dockerignore, or copy the same set), and a cache ref the train writes to but main reads from a different group. The fix is whichever the evidence names, with the evidence on the unit issue. Acceptance: build on main within 1.5× the train’s build for the same tree.

Erratum (2026-11-07): the evidence on #2985 named other causes than the three candidates: the cache writer, main’s interruptible `build, cancelled before it ran by the next merge’s pipeline; cargo’s crates.io fetch stalling inside the BuildKit cook (1053 s against 10 s); and images keyed by commit, so main could not find the train’s images for the same tree. The .git and cache-ref candidates were refuted, and the export is a secondary 100-240 s. U4 keys the images by HEAD^{tree} and reuses existing tags, tags the cache per cook recipe and exports it only when missing, makes build non-interruptible on main, and feeds craig-ci’s registry into the cook.

Erratum (2026-11-07): cluster-tests takes no --from-digests: its rig images take other build args and their own tag (docker-compose.cluster.yml), so build’s images are not its images. It keeps its rules (the `CLUSTER_TESTS schedule, manual on main, and the cluster-tests MR label) and builds its rig.

An Antora extension in docs/extensions/ (beside the mermaid one, registered in antora-playbook.yml) enables Asciidoctor’s catalog_assets, collects every external http(s) link per page with attributes substituted, checks them (HEAD then GET, bounded concurrency, retries, a timeout, the accept list and the exclusions ported from .lychee.toml) over Node’s core https module (the antora:3.1.14 image runs Node 16, which has no default fetch), writes build/link-check.json and prints one summary line per dead link naming page and URL. It never logs through Antora’s logger at warn or error, so it cannot trip --log-failure-level=warn; the docs job’s second script line reads the report and exits 42 when it holds a dead link (D3). Repo-root prose outside Antora goes through a small node script on the same Asciidoctor.js, writing into the same report. No new dependency. .lychee.toml, the lychee download, docs/extensions/lychee-preprocess.sh and cargo xtask docs deadlinks go (alternatives weighed on #2981: asciidoc-aware-link-check, linkspector, adoc-link-checker). A site’s outage is no car’s fault, so the leg stays advisory (ADR-086 D6).

D6 — Cutting over the pending cars

When U1-U4 are on main, every car still on the old shape is taken off the train, rebased onto main (or main merged in, where a stack of MRs shares history), pushed and re-added with auto_merge=true. Car 6 (!2165) loses #2940, which U2 supersedes, and keeps #2945. Each car’s issue gets the new pipeline id and its per-job timings beside the old ones.

Decisions

  1. pentest and perf-load leave the per-merge pipeline (schedule + manual). Advisory jobs that cost 93 runner-minutes per merge, on the pool the train queues for. Rejected: keeping them with --from-digests only (still about 40 minutes per merge of a 4xlarge for a detector that runs nightly anyway).

  2. feature-matrix runs on main and nightly, not per car. It proves each bundle builds in isolation; a break is a post-merge fix:, never a wrong merged behaviour. Rejected: folding it into check (+6 min on every car’s critical path).

  3. docker-promote stays per code merge, reading the BuildKit cache build just wrote and the xtask artifact; the latest images keep tracking main (#2779 keeps its own scope).

  4. The image tag is a pin in the YAML, held by a test, not a floating tag. A floating tag would let one MR’s toolchain bump change the image under every other running car; a pin makes the change travel with the commit that needs it.

  5. Keyed on the Dockerfile and toolchain, not on Cargo.lock: a lock changes weekly, a toolchain quarterly; a delta fetch costs seconds, an image build ten minutes.

  6. check is sequential on one VM. Wall time about 13-15 min against 11 for three parallel VMs; each VM waits 24-60 minutes for a runner, so one VM is faster end to end and two-thirds cheaper.

Risks

Risk Mode Mitigation and test

The pinned image tag drifts from its inputs and jobs run an old toolchain.

silent

The contract test recomputes the hash from the checkout and fails the check-stage tests on drift; ci image --bump rewrites the pin. Red proof: edit ci/Dockerfile.ci without bumping.

A job pulls craig-ci before ci-image has pushed it (first pipeline after a bump).

fail-closed

Every job needs: [ci-image] transitively through xtask; GitLab resolves image: at job start, after needs. Contract test: every job but ci-image depends on xtask or ci-image.

The xtask binary does not run in some job image.

fail-closed

All Rust jobs run in craig-ci (the binary’s own image); craig-tools is glibc 2.39 ≥ 2.36 and xtask links no C TLS. U2 proves the re-execution with the devstack battery (cargo xtask validate through craig-tools) before pushing.

check sequential hides nothing but takes longer than the slowest of three.

fail-open (throughput)

ci check runs all three to completion. U3 records wall and runner minutes for the first five cars on the plan issue; if wall exceeds 16 min, unit splits back out (one line in .gitlab-ci.yml), the others stay merged.

A dead external link, or the check’s own HTTP flake, blocks a car through the docs job.

fail-closed

The leg exits 42 and only 42 is allowed to fail; the extension never logs at warn or error. Contract test: docs has allow_failure.exit_codes == [42]; extension test: a dead link yields exit 42 and no Antora error log line. Retries and the accept list as lychee had; a weekly schedule run is the one that is read.

Removing .cargo-cache makes the registry fetch slower when Cargo.lock drifts from the image.

fail-open (throughput)

Measured in U1 on a car whose lock differs from the image’s: the delta fetch is seconds; the image rebuilds with the next toolchain bump regardless.

Scope

Unit Delivers Proves (tests)

U1

ci/Dockerfile.ci; cargo xtask ci image --ensure | --bump | --tag; the ci-image job; CRAIG_CI_IMAGE_TAG; every Rust job on craig-ci; .rust-ci, .docker-host, .cargo-cache, RUST_IMAGE, RUST_CI_IMAGE, the dind service, ci/Dockerfile.audit-tools and all apt-get/rustup/cargo install lines removed; git lfs pull in e2e only. The cyclonedx pin for #2980 lives here.

Contract: the pin equals the input hash (red: an unbumped Dockerfile edit); no script or before_script line installs anything; every job names craig-ci, the Antora image or a GitLab template. Unit: the hash covers exactly the two inputs. Live: one MR pipeline on the branch, every job green with no Compiling cargo-nextest and no apt-get in any trace (counted from the API). Docs: deployment-guide.adoc § CI/CD Pipeline, quality-gates.adoc § Battery stages (the image row). CHANGELOG. Closes #2980 and U1’s issue.

U2

The xtask job and artifact; .xtask-bin; every script line xtask …; the content lints in the xtask job (docs-content-lints removed); the in-checkout re-execution in craig-tools; #2940’s alias and cache entry removed.

Contract: every script line is an xtask verb or allow-listed (prefix changed; red: a cargo xtask line); the one cargo build line is the xtask job’s (red: the same line in another job); every job but ci-image needs xtask; REQUIRED_OUTSIDE_DAG names xtask. Unit: the argv helper picks current_exe() under the checkout and cargo xtask outside it, at both call sites. Live: cargo xtask validate through craig-tools from a checkout whose target/ci/bin/xtask exists shows no second xtask compile in the container. Docs: quality-gates.adoc § Battery stages, testing-reference.adoc § CI stages. CHANGELOG. Closes #2982, #2940.

U3

cargo xtask ci check; the check, docs jobs; lint, clippy, unit, docs-xref-check, docs-deadlinks, review removed; feature-matrix on main and schedule; ADR-086 D2 amended (dated); the DAG comment at the top of the YAML.

Contract: on a train exactly ci-image, xtask, check, build, docs, battery, e2e run and all block; on a plain MR check and docs advise and the stack jobs are manual (the existing rule evaluation, re-pinned); a red lint stage still runs clippy and unit (unit test over ci check with an injected failing stage). Live: the first five cars' wall and runner minutes recorded on the plan issue; docs has allow_failure.exit_codes == [42] and REQUIRED_OUTSIDE_DAG names it. Docs: quality-gates.adoc § Battery stages (check row), deployment-guide.adoc. CHANGELOG. Closes U3’s issue.

U4

main’s job set per D4; `docker-promote on craig-ci with needs: [build] and the cache; the scheduled stacks on schedule + manual with --from-digests when a build artifact exists; the main build cache miss found and fixed.

Contract: on main exactly the D4 set runs; pentest/perf-load are manual on main and automatic on the schedule. Live: the first main pipeline after merge ≤ 40 runner-minutes, build within 1.5× the train’s for the same tree, docker-promote ≤ 12 min; recorded on the plan issue with the traces' step timings. Docs: deployment-guide.adoc § CI/CD Pipeline (the schedule table). CHANGELOG with the ops note: pentest and perf-load results are nightly, not per merge. Closes U4’s issue.

U5

The link-check Antora extension and the root-prose script (D5) in the docs job; lychee, .lychee.toml, the preprocess script and cargo xtask docs deadlinks removed.

Extension tests with node against a throwaway local HTTP server: a dead URL fails, a live one passes, an attribute-derived URL is resolved, an excluded URL is skipped, a 429 is accepted. Contract: the docs job’s script lines. Docs: testing-reference.adoc (the docs checks), local-dev.adoc (running the check locally with node). CHANGELOG. Closes #2981.

U6

D6: the pending cars cut over.

Each car’s issue carries the new train pipeline id and per-job timings beside the old; no car lands on the old shape after U4 merges. Operational: no code, docs or CHANGELOG; the unit issue lists the cars and closes when the last has landed.

Order: U1 → U2 → U3 → U4, each a car stacked on the one before; U5 beside U3 (it changes only the docs job’s Antora inputs); U6 after U4 merges. .gitlab-ci.yml stays under 500 lines (it shrinks), needs: on every job, the CI lint API green on each unit.

Edit this page · latest