ADR-047: Devstack Image Build Strategy — Cache Mounts vs cargo-chef vs Host musl Cross-Compile

Status: Accepted (2026-09-08)
Issue: #1369
Ruling: © accepted — revisit (A) when #1370 lands (#1794)
Relates to: ADR-040 (build-once), ADR-015 amendment (CI prebuilt path), ADR-008 / ADR-026 (portal dx pipeline), #1365, #1370, #732, #1180, #1189 (closed wontfix); follow-ups #1792, #1793, #1794; #2593 (Amendment 3); #2605 (Amendment 4); #2606 (Amendment 5); #1370 (Amendment 6); #2600 (Amendment 7); #2618 (Amendment 8); #2614 (Amendment 9)

Context

The devstack builds every service binary inside the docker daemon: the root Dockerfile copies the workspace and runs one cargo build --profile devstack --workspace --exclude canopy-portal under two sharing=locked BuildKit cache mounts (registry + /app/target; Dockerfile:86-90, #1365) with CARGO_INCREMENTAL=0 (:88); xtask hashes sources, manifests, Dockerfiles and features (xtask/src/devstack_guard.rs:35-50, :431-476) to pick Cached (compose up -d --build) or NoCache (compose build --no-cache; :906-946). #1365’s closing note (2026-08-08) recorded its box’s floor — a one-line canopy-api change recompiles 4 units, wall unchanged because the portal’s deliberately cold dx build (193.5 s there; #732, services/canopy-portal/Dockerfile:104-115) is the floor — and CHANGELOG.adoc:650 / local-dev.adoc:165-170 carry that record. Builder-cache pruning is closed wontfix by maintainer ruling (#1189, 2026-08-27: "BuildKit cache pruning is system administration — the developer/operator’s domain, not the project’s … no project mechanism ships").

#1369 asked whether extending ADR-040 build-once to local dev — cross-compile on the host to x86_64-unknown-linux-musl, COPY the binaries into thin Alpine images — would move the floor to host incremental compilation ("~1 min for a one-crate change"), weighed against cargo-chef dependency layers and against the cache-mount build as the terminal state.

Measured on this box (2026-09-08)

AMD Ryzen AI MAX+ PRO 395 (16c/32t), 94 GiB, btrfs, Docker 29.7.2 / Compose 5.5.1, one builder (default, docker driver; buildx-ls.txt), rust:1.96-alpine = rustc 1.96.1. Every row: docker buildx build --progress=plain --build-arg CARGO_PROFILE=devstack -f <Dockerfile> -t <tag> . from the workspace root, sequentially, the devstack’s containers up and idle (docker-ps.txt: 19 canopy app containers). One-line change = a comment at crates/canopy-api/src/lib.rs:2, reverted with git checkout — <that file>. n = 1; export = the whole exporting to image step; downloads = Downloaded lines. B1 = cargo install cargo-chef 27.3 s (87 units) + cook 63.9 s (740) + cargo build 69.0 s (59). C2’s 21 units = canopy-api + the 18 service binaries + canopy-test-lib + xtask.

Scenario Wall cargo RUN Units Export Downloads

C1 — #1365 Dockerfile, both mounts on fresh id=s, --no-cache (from-zero)

138.8 s

122.1 s

740

11.4 s

734

C2 — same, warm mounts, one-line canopy-api change

78.5 s

61.3 s

21

11.9 s

0

C3 — real Dockerfile, --no-cache, the devstack’s shared mounts, pristine tree

140.6 s

122.6 s

740

11.4 s

734

B1 — cargo-chef 0.1.78 variant, --no-cache (from-zero)

204.7 s

63.9 + 69.0 s

886

37.9 s

779

B2 — cargo-chef, warm layers, one-line change (cook CACHED; all workspace crates rebuilt)

113.3 s

68.7 s

59

38.9 s

0

Footprints (capture buildx-du-verbose.txt, 2026-09-08 14:27 UTC): the shared //app/target record reads 6.30 GB today, grown by later reloads (the fresh-id namespace’s size at measurement time was observed live, not preserved); the shared registry record 617 MB. cargo-chef’s records survive in the capture: a 2.90 GB cook layer plus a 3.43 GB final-RUN snapshot per build (B1 and B2 each) and a 1.86 GB runtime COPY layer, against one 1.43 GB /out snapshot per cache-mount build. Images (docker-images.txt): live canopy-canopy-* 2.09 GB each (the scratch images shared that runtime stage), alpine:3.23 14 MB, rust:1.96-alpine 1.41 GB. Host gnu target/: 165 GB (du -sh).

Observation, cause not determined. Neither of the root Dockerfile's shared mounts existed when C3 started at 12:47:44: C3 fetched 734 crates and compiled 740 units, identical to fresh-id C1 (140.6 s vs 138.8 s), and the capture shows both shared records — //app/target, //usr/local/cargo/registry — created at 12:47:48, by C3 — which left both populated for the devstack’s next refresh — while /out snapshots from nine devstack builds earlier that day (02:29–07:23 UTC) survive beside them. Candidates: BuildKit GC eviction (the #1189 / #1180 forensics class), an operator prune, or a builder / cache-namespace mismatch between compose’s builds and a direct docker buildx build. Either way the live devstack’s next "cached" refresh would have paid the from-zero path, and pruning is the operator’s by ruling — the recorded floor is best-effort on any box. Gap: xtask’s NoCache class on warm mounts was never measured; C3 was meant to be that row. (A) was not measured: this host has the gnu and wasm32 targets only and no musl-gcc, zig, cross, cmake or cargo-zigbuild; installing system packages was out of scope.

Decision

© — the #1365 cache-mount in-image build is the devstack’s terminal state, hardened rather than replaced: on this box it already delivers the floor #1369 set out to buy with (A) — a one-crate change costs 78.5 s wall / 61.3 s of cargo (C2) — and the decisive mechanism is the portal: every option keeps its cold dx build (193.5 s per #1365; not re-measured here), and (A)'s host build would run sequentially ahead of compose up --build, so wall cannot improve while the portal stays cold. Declining the issue’s proposal is ©; #1369 closes as evaluated-and-declined. Hardening set, filed: #1792 — explicit id=
aligned sharing on both mounts, a cold-cache announcement in dev refresh / dev status, an operator GC recipe in local-dev.adoc; #1793 — correct the record (CHANGELOG.adoc:650 "4 units" → the 21-unit closure; local-dev.adoc:166-171 "owned by the #1189 policy" → the operator ruling); #1794 — re-evaluate (A) once #1370 lands, with the incremental question (below) settled before measuring.

On ruling. Acceptance flipped: Status, :description:, Ruling, the recommendation into this Decision, the nav row and the architecture cheat-sheet bullet (both status-neutral). Rollback: (A) = delete the thin Dockerfile, the xtask artefact-hash dimension and the toolchain target; (B) = restore the mounts (cook snapshots linger until an operator prune); © = N/A, nothing changed. A post-acceptance reversal is a superseding ADR. Terminal states not chosen, kept as the record:

  • (A) — x86_64-unknown-linux-musl joins rust-toolchain.toml targets (:20, a recorded sync divergence); a musl-targeting C toolchain becomes a per-developer prerequisite; a thin Dockerfile.devstack (FROM alpine:3.23, COPY of the 19 host binaries from a staging dir — .dockerignore:2 excludes target/) sits beside the production Dockerfile; devstack_guard gains an artefact-hash staleness dimension and runs the host cargo build --target x86_64-unknown-linux-musl --profile devstack first; ci-config-lint's COPY-map parser learns the second Dockerfile.

  • (B) — the root Dockerfile gains planner / cook stages and drops the mounts; cook has no --exclude, so either an explicit member list every new crate must join (or the recipe silently under-cooks) or cook --workspace.

Alternatives Considered

Option Adoption Security

(A)

Per-box musl C toolchain + rustup target; xtask, thin Dockerfile, docs

Binaries enter dev images from an unaudited host toolchain; production Dockerfile untouched

(B)

One root-Dockerfile edit; a member list (or --workspace) to keep

cargo install cargo-chef inside the production build — a new build-time dependency in the ADR-040 §5 surface

©

None

Unchanged — a fresh builder sees an empty cache and produces the prior image

(A) Host musl cross-compile + thin COPY images (the #1369 proposal)

C-compiled crate (cargo tree -i cc -e normal,build --target x86_64-unknown-linux-musl) Reached via Workspace consumers

aws-lc-sys 0.39.0

aws-lc-rs ← rustls 0.23, rustls-webpki, jsonwebtoken 10.3

canopy-auth, xtask (canopy-web as a dev-dependency), every rustls user

ring 0.17.14

rustls; object_store 0.13; jsonwebtoken 9.3 ← reqsign ← zen-engine

canopy-store, canopy-rules

rquickjs-sys 0.10.0

zen-engine 0.55 (QuickJS)

canopy-rules, xtask

psm 0.1.30 + stacker 0.1.23

typst-eval 0.14; zen-expression

canopy-typst, canopy-rules

cmake 0.1.58 is a build-dependency of aws-lc-sys; the musl target ships pre-generated aws-lc bindings (no bindgen / libclang). A host build needs the rustup target plus a musl-targeting C compiler exported as CC_x86_64_unknown_linux_musl / AR_… with a [target.…musl] linker entry — the distro musl / musl-tools package (musl-gcc) or cargo-zigbuild 0.23.4 + zig, which sets CC / CXX / AR for build scripts itself — and a per-box proof that all five C crates build on it. One more full workspace target per profile lands on the host (the shared devstack-profile record is 6.30 GB today).

Incremental dichotomy — (A) is not bounded by C2. © runs with CARGO_INCREMENTAL=0 (Dockerfile:88); devstack inherits dev (Cargo.toml:279-280), so a host build under it has rustc incremental on. (A) either inherits CARGO_INCREMENTAL=0 — then its cargo time approximates C2’s 61 s (same units, profile, toolchain; host CPU) — or keeps incremental and must carry a #732-class staleness argument (a within-crate-incremental artefact behind a fresh image id is the hazard #1365 closed out). Its floor is unmeasured. Its one unique property: a host target/ is immune to BuildKit GC and operator prunes — the C3 observation cannot happen to it.

Staleness and what it bends. The image becomes a function of 19 binaries, so devstack_guard hashes host artefacts instead of inputs (Cached / NoCache collapse to "host build, then image iff the binaries changed"; the content-addressed COPY keeps stale_app_containers, :773, sound; CARGO_PROFILE / CANOPY_CARGO_FEATURES become host flags). The devstack stops exercising the production Dockerfile, so ADR-040’s test-what-you-promote property (extended to CI by docker-compose.prebuilt.yml
CANOPY_PREBUILT_IMAGES, :711-741) no longer holds locally — CI, Alpine and the portal’s dx build (ADR-008 / ADR-026) are unchanged.

(B) cargo-chef dependency-layer caching — measured

Planner / cook / build stages, no cache mounts, cargo-chef 0.1.78 installed inside the image. It works as designed — the cook layer survives a source change (B2: CACHED, zero registry recompiles) — and its floor is structural: every workspace crate rebuilds on every change (59 units, 68.7 s of cargo, 113.3 s wall, 1.4× C2) and grows with the workspace. Storage is worse (a 3.43 GB snapshot per rebuild vs 1.43 GB), the cold path slower (204.7 s vs 138.8 s), and the layers are as evictable as mounts. Rejected on the warm-path number alone. Production / CI path: (B) edits the root Dockerfile, which is also the ADR-040 production / CI build; cargo install cargo-chef@0.1.78 --locked inside it compiles a new build-time dependency from crates.io — a supply-chain delta against ADR-040 §5 (the per-image SBOM is generated from the pushed image, so the tool never appears in it). Upside: the cook layer is an ordinary image layer, so CI’s main-cache layer-cache pointers (ADR-040 §2) could carry it across pipelines, which a cache mount cannot. cargo chef cook --workspace is the no-member-list variant (it also cooks the portal’s tree; not measured).

© the #1365 cache-mount build as the terminal state — measured

C1 / C2 above. C2’s 21 units (not the 4 at CHANGELOG.adoc:650) are canopy-api plus everything depending on it — the correct closure (#1793). Weaknesses: mount survival is the operator’s concern by ruling (#1189), so the floor is best-effort on any box — #1792 announces a cold cache instead of pretending; the wall is portal-floored (#1370). Maintenance is zero-delta; staleness stays the input-hash model with cargo’s fingerprinting beneath it and rustc incremental off; fit (musl, Alpine, xtask-only) is exact.

Consequences

  • The build does not change; #1792 / #1793 / #1794 carry the findings. #1369’s premise — an in-daemon floor materially above host incremental compilation — is not borne out here: 61 s of cargo for a 21-unit closure.

  • The C3 observation’s consequence depends on its cause: GC eviction or an operator prune → the floor is best-effort and dev status must say so (#1792’s announcement + operator recipe); a builder / namespace mismatch → #1792’s explicit id= + aligned sharing makes compose and direct builds share one cache. Either way the from-zero path is 140 s on this box.

References

  • #1369, #1365 (closing note, 2026-08-08), #1370, #732, #1180, #1189 (closed wontfix 2026-08-27); #1792, #1793, #1794; ADR-040, ADR-015, ADR-008.

  • Evidence attached to #1369 (note 3803397315): times.tsv, run.sh, Dockerfile.cm, Dockerfile.chef, cook-packages.txt, the five build logs; captures of 2026-09-08 14:27 UTC: buildx-du-verbose.txt, docker-images.txt, buildx-ls.txt, docker-ps.txt.

Amendment 1 (2026-09-17) — as built

Status unchanged (still Accepted). Two things the frozen sections could not carry.

Line references, re-located by construct. The Context, Decision and Alternatives cite line numbers that drifted within days of acceptance — partly because this ADR’s own follow-ups edited the files it cites. Read each as the construct it names:

  • Dockerfile:86-90 / :88 — the builder stage’s single RUN --mount=type=cache in the root Dockerfile: two mounts, /usr/local/cargo/registry and /app/target, each with an explicit id= and sharing=locked (#1792), and CARGO_INCREMENTAL=0 set on that same RUN ahead of cargo build --profile "${CARGO_PROFILE}" --workspace --exclude canopy-portal.

  • services/canopy-portal/Dockerfile:104-115 — the portal’s dx bundle --platform web --fullstack --release step, which mounts only the cargo registry and git caches (no target mount — the #732 hazard) and is therefore the cold floor the Decision describes.

  • xtask/src/devstack_guard.rs:35-50 — SOURCE_DIRS / DEPS_FILES; :431-476 — check_staleness, which hashes sources, manifests, Dockerfiles and features into a RebuildType (Cached = compose up -d --build; NoCache = compose build --no-cache, assembled by no_cache_build_args); :906-946 — auto_refresh; :773 — stale_app_containers; :711-741 — prebuilt_images / prebuilt_pull_args / cold_up_args, the CANOPY_PREBUILT_IMAGES + docker-compose.prebuilt.yml path.

  • rust-toolchain.toml:20 — the targets key (wasm32-unknown-unknown only); Cargo.toml:279-280 — [profile.devstack] inherits = "dev"; .dockerignore:2 — the target/ entry.

  • CHANGELOG.adoc:650 — the #1365 entry (Closes #1365) under == Unreleased; local-dev.adoc:165-170 / :166-171 — the cache-mount bullet under "Devstack lifecycle" in Local Development.

Follow-ups. #1792 shipped (CHANGELOG.adoc, Closes #1792): explicit id= + sharing=locked on all four cache mounts across both Dockerfiles, pinned by a devstack_guard.rs test; cold_cache_notice / live_cold_cache_notice name a missing shared mount, with the C1/C2 cost, in dev status and before a dev refresh rebuild. #1793’s record corrections are in the tree: the #1365 CHANGELOG entry carries the 2026-09-08 correction (21 units; #1189 closed wontfix — cache pruning is the operator’s), and local-dev.adoc’s cache-mount bullet states the operator-domain ruling. #1794 (re-evaluate (A) once #1370 lands) has no CHANGELOG entry of its own as of this amendment.

Amendment 2 (2026-09-23) — freshness is keyed on content (#2237)

Status unchanged (still Accepted). Option © assumed "cargo’s fingerprinting beneath" the input-hash model was sound. It was not. Cargo’s freshness for workspace sources is mtime-based, and BuildKit caches a COPY layer by content. A source directory identical to an earlier build’s is a cache hit carrying that earlier build’s mtimes, while the /app/target mount may hold artifacts compiled since from another branch. Cargo then keeps those artifacts, and a fresh-id image links another branch’s crate. On 2026-09-23 a battery’s canopy-tanf served the previous branch’s canopy-contracts-tanf doc comments behind a cached COPY crates/. Only the OpenAPI drift stage caught it.

The build RUN therefore hashes every copied source before cargo build and diffs the hashes against a per-profile manifest kept beside the artifacts in the target mount. It touches each changed or new file, or every file when no manifest exists, and rewrites the manifest only after the build succeeds. Crate-level reuse is otherwise unchanged. devstack_guard.rs pins the order of the steps (root_builder_rebuilds_on_content_not_copy_mtimes). Stable cargo has no checksum freshness (-Zchecksum-freshness is nightly-only), so the content step stays until the pinned toolchain gains one.

Amendment 3 (2026-10-03) — every rebuild is cached (#2593)

Status unchanged (still Accepted). Decision © and the #1189 and #1792 rulings stand. What changed is xtask’s escalation: the NoCache class the Context and Amendment 1 describe (compose build --no-cache, assembled by no_cache_build_args) is gone. RebuildType is None or Cached, and a change to the dependency manifests, a Dockerfile or the feature set takes the same cached path as a source change. Read the Context’s and Amendment 1’s NoCache, no_cache_build_args and cold_up_args references as superseded by this amendment.

Why --no-cache was never needed. Every input is already part of a BuildKit cache key. The manifests and sources key on COPY content, a Dockerfile edit changes its instruction’s key, and the feature set keys the build step through ARG CARGO_FEATURES. Stale crate mtimes are handled by Amendment 2’s content step, and cargo identifies a registry crate by version and checksum. Base images are re-pulled only by --pull, which --no-cache never implied. The escalation arrived with the original guard (92c6217b4), before the Dockerfiles had cache mounts, with no stated reason.

What it cost. --no-cache re-ran layers that depend on no workspace file: the portal builder’s cargo install dioxus-cli@0.7.9 --locked (557 s of release compile), apk add and rustup target add. In the 2026-10-03 session logs every no-cache build also found the shared cache mounts empty, so the root build compiled from zero (356 s, 726 downloads). A lockfile-only push spent 15–17 min in devstack-ready, against about 4.5 min for a cached rebuild. 36 of 193 refreshes took the path, 33 of them for a Cargo.lock change.

The C3 observation. C3 was itself a --no-cache build, and it too began over empty mounts. The cause is still not determined; this amendment records the correlation, not a cause. With no --no-cache path left, a from-zero build follows only a missing cache record, which cold_cache_notice announces, and the Context’s "Gap" (the NoCache class on warm mounts) no longer has a subject.

As built.

  • devstack_build_args (xtask/src/devstack_guard.rs) is the one constructor of every devstack image build: the refresh’s rebuild, dev start / reload / restart and the from-source cold start (cold_start_args). It yields --profile <p> build, profile first (#697) and never --no-cache.

  • The build is its own teed compose call ahead of the up, not up --build. The refresh’s and dev start's up runs through docker::up_healthy_with_recovery on inherited stdio, and until #2596 it did not fail on a non-zero compose up, so a failed build behind up --build could leave the old containers serving and the markers stamped. Since #2596 a non-zero up fails the bring-up unless it left the host-port casualty the recovery rounds exist for.

  • Every up comes from devstack_up_args: profile first, no --build, and --no-build on the prebuilt path (#1073). A plain up builds only an image the daemon has lost, with the same profile and cache.

  • dev restart no longer runs a profile-less compose build --no-cache. That build skipped every profile-gated app service (the #697 class), and only the up after it rebuilt the images --rmi local had removed.

  • every_devstack_build_argv_is_cached_and_carries_the_active_profile pins both properties over every argv the guard and dev start construct. The stale-container check (stale_app_containers) still runs after every refresh up. Since #2598 it picks app containers by compose label and compares image content, not image ids: under an image store that writes provenance attestations, a cached rebuild moves every tag to a new manifest-list digest, and the old name filter and id comparison would have hidden a stale container or flagged a current one.

Operator remedy. The #1189 ruling is unchanged: no project mechanism prunes the builder cache. To clear a corrupted cache mount, run docker builder prune --filter type=exec.cachemount, then cargo xtask dev refresh. The next image rebuild starts from empty mounts and pays the from-zero path (C1) once.

Amendment 4 (2026-10-03) — the portal builds its client and server at once (#2605)

Status unchanged (still Accepted). Read Amendment 1’s "dx bundle --platform web --fullstack --release step" as dx build --platform web --fullstack --release --debug-symbols false --force-sequential false. Its cache mounts are unchanged, so it is still the cold floor the Decision describes, and #732’s no-persistent-target rule stands.

Why. For a web app, dioxus-cli 0.7.9’s dx bundle builds the wasm client, then the native server, and adds only a copy of the two outputs (cli/bundle.rs). dx build --fullstack runs the two builds at once with tokio::join! (cli/build.rs), so the floor becomes the longer build, not the sum of both. Left unset, --force-sequential follows the CI variable. The flag takes a value (num_args = 0..=1), so --force-sequential false keeps the build parallel in any environment.

As built.

  • dx build has no --out-dir. The RUN sets CARGO_TARGET_DIR=/app/target and copies server and public/ from /app/target/dx/canopy-portal/release/web/, where a release web build leaves them, to /build/out. The runtime stage’s COPY lines are unchanged.

  • The image ships only what the release layout actually holds. A release build moves the wasm and its JavaScript glue into public/assets/ and deletes its temporary wasm/ dir. index.html loads the glue, and the glue loads the wasm. The RUN fails unless the server is executable, index.html is non-empty, every /assets/… path index.html references is a non-empty regular file, and those scripts load at least one non-empty regular .wasm file.

  • portal_build_runs_client_and_server_in_parallel_and_checks_what_it_ships (xtask/src/devstack_guard.rs) pins the command, the two copies, the check and its order.

Amendment 5 (2026-10-03) — the portal build’s own registry record (#2606)

Status unchanged (still Accepted). Amendment 1’s follow-up note records #1792’s explicit ids, equal to their targets, on all four cache mounts. Read it as amended here for the portal: its registry and git mounts now take the ids /canopy-portal/usr/local/cargo/registry and /canopy-portal/usr/local/cargo/git, with targets unchanged and sharing=locked. The root build’s mounts keep their ids.

Why. A sharing=locked record admits one build at a time. While both builds mounted /usr/local/cargo/registry, the portal build waited for the root build’s whole cargo RUN, and the reverse. sharing=shared is not the fix: two builds would write one registry at once, and cargo’s .package-cache lock lives outside the mount.

The cold-cache notice keys on record ids. docker buildx du --verbose describes a record as cached mount <target> from exec <cmd> with id "<id>", and the Dockerfile frontend makes <id> the mount’s id= behind a / prefix (BuildKit frontend/dockerfile/dockerfile2llb/convert_runmount.go, solver/llbsolver/mounts/mount.go). The notice matched records by target, which the two registry records now share, so the portal’s record would have satisfied the root’s entry. parse_cachemount_ids (xtask/src/docker.rs) reads the with id value. SHARED_CACHE_MOUNTS (xtask/src/devstack_guard.rs) lists Dockerfile ids, each with what its absence costs, and the portal’s registry record has its own entry. That entry is watched only when the stack’s stored profile builds the portal (PORTAL_PROFILES, pinned to the canopy-portal service’s compose profiles:), since a stack on any other profile never creates the record. The portal’s git record is not watched: it holds at most a clone of the workspace’s one git dependency (xtask’s checkdocs), so its absence costs one clone, not compile work.

First build after the change. The portal’s new records start empty, so its next build downloads every crate once. The portal’s old //usr/local/cargo/git record, which no Dockerfile mounts any more, stays until BuildKit GC or an operator prune removes it (#1189).

Erratum (2026-10-25, as-built): the workspace has no git dependency since #2990 retired xtask’s checkdocs, so the portal’s git record holds nothing a build needs.

Amendment 6 (2026-10-03) — sccache caches the portal’s registry-crate compiles (#1370)

Status unchanged (still Accepted). The Decision names the portal’s cold dx build as the floor and #1370 as the issue that would lift it. #1370 lands as sccache in the portal builder, which also meets #1794’s trigger for re-evaluating (A).

The #732 constraint. #732 deleted the portal’s /app/target cache mount, because dx’s incremental compilation in a persistent target could emit a stale wasm bundle behind a fresh image id. Whatever speeds the portal up must still start every build from an empty target.

Alternative Warm path #732

A persistent portal target again

Fastest: cargo and dx reuse everything that is fresh

Reverses #732; a stale bundle behind a fresh id is possible again. Rejected.

A cargo-chef dependency layer for the portal, like (B) for the root

Dependencies come from an image layer; the workspace crates and dx’s pipeline rebuild

Compatible, but the layer is reused only if cook reproduces dx’s cargo invocations exactly: two targets, and the profiles dx defines through --config and selects with --profile (dioxus-cli 0.7.9 build/request.rs, cargo_build_arguments and profile_args). It also adds a build-time tool to the ADR-040 §5 surface, as (B) would. Not taken.

sccache in the portal builder

Every registry crate’s library compile with unchanged inputs is a cache hit, for the wasm client and the native server alike. The workspace crates, binaries, build scripts, proc-macros and dx’s pipeline rebuild: dx wraps the workspace crates' rustc itself, and sccache 0.18.0 cannot cache a compile behind that second wrapper (below)

Compatible. The target still starts empty, and a hit requires the same compiler, arguments, sources, dependency rlibs, CARGO_* environment and working directory (sccache 0.18.0 src/compiler/rust.rs, generate_hash_key), so a changed input is a miss. Taken: unlike cargo-chef it needs no reproduction of dx’s cargo invocations, and the ~450 registry packages of the client and server dependency trees it caches are the bulk of the build, against 14 workspace crates.

As built.

  • The tool layer downloads sccache 0.18.0’s x86_64 musl static binary, checks it against the sha256 the release publishes beside it, and runs sccache --version before the image uses it, as #1180 does for wasm-opt and wasm-bindgen. portal_tool_layer_runs_no_download_it_has_not_verified pins the URL and checksum of every curl download.

  • Only the build RUN sets RUSTC_WRAPPER=sccache and SCCACHE_DIR=/sccache, over a --mount=type=cache,target=/sccache,id=/sccache,sharing=locked record capped at sccache’s default 10 GiB. dx keeps an inherited RUSTC_WRAPPER in its base builds but adds itself as RUSTC_WORKSPACE_WRAPPER (dioxus-cli 0.7.9 build/request.rs), so cargo runs each workspace compile as sccache dx <rustc> … with rustc’s absolute toolchain path (cargo util/context, get_tool). sccache finds rustc behind dx (src/compiler/compiler.rs, detect_compiler), but its argument parser skips a leading argument only when it is literally rustc (src/compiler/rust.rs, parse_arguments), so it counts the path as a second input, refuses with "multiple input files", and lets the compile run uncached. The registry crates, which cargo compiles without the workspace wrapper, are cached.

  • dx build's status decides the RUN. It is captured, sccache --show-stats prints the hit counts and sccache --stop-server stops the server whatever the build did, and a failed build then exits with its own status. portal_build_caches_dependency_compiles_and_keeps_dx_builds_verdict pins the order; the cache-mount test pins the new mount; #732’s portal_dockerfile_has_no_app_target_cache_mount is unchanged.

  • The cold-cache notice watches the /sccache record on the profiles that build the portal: without it, the next portal build redoes every dependency compile.

Amendment 7 (2026-10-03) — the root build compiles only the binaries it ships (#2600)

Status unchanged (still Accepted). Read the Context’s and Amendment 1’s cargo build --profile "${CARGO_PROFILE}" --workspace --exclude canopy-portal as that command plus one --bin per shipped binary. The build RUN names the 20 binaries once, in a bins variable: the build compiles those targets, the staging copies those into /out, and root_image_compiles_exactly_the_binaries_it_ships (xtask/src/devstack_guard.rs) ties the list to the runtime stage’s COPY lines. xtask, the workspace’s largest crate, and canopy-test-lib ship nothing and are no longer compiled. C2’s 21-unit closure for a one-line canopy-api change, which counted both, loses those two units.

Why --bin and not -p. Cargo resolves features from the selected packages, not from the targets a --bin filter picks (cargo 1.96 ops/cargo_compile/mod.rs, create_bcx; a bins-only filter needs no dev-dependencies, compile_filter.rs, need_dev_deps). Keeping --workspace --exclude canopy-portal keeps every shipped binary’s feature set exactly as it was. cargo build --unit-graph for both commands, in the devstack and release profiles, with and without canopy-api/test-clock,canopy-api/test-fault, gives the same units with the same features, minus the 11 (devstack) or 14 (release) units only xtask and canopy-test-lib need. Selecting the 20 packages with -p instead changes six units of the shipped closure: tokio loses test-util, rustix loses alloc, default, fs and std, bitflags loses std, and toml_edit loses default.

Amendment 8 (2026-10-03) — the root build selects only the shipped packages (#2618)

Status unchanged (still Accepted). Read Amendment 7’s --workspace --exclude canopy-portal as superseded by this amendment: the build selects the 20 packages that own a shipped binary, one -p each from a pkgs variable, and keeps Amendment 7’s --bin list.

Why. Amendment 7 kept the workspace selection so that no shipped binary’s feature set would change. That feature set was wrong. Cargo resolves features across every selected package, so the workspace selection compiled into every production binary the features of members that ship nothing: tokio’s test-util from canopy-test-lib’s dependencies, and features of rustix, bitflags and toml_edit that only xtask needs. cargo build --unit-graph for the new selection and the old --workspace build, in the devstack and release profiles, with and without canopy-api/test-clock,canopy-api/test-fault, differs by exactly six units: tokio loses test-util, rustix (three units) loses alloc, default, fs and std, bitflags loses std, and toml_edit loses default. No unit is added, and Amendment 7’s 11 (devstack) or 14 (release) units still drop out. Every shipped binary builds under the new selection in both profiles, with and without those features, with no manifest change. root_image_selects_only_the_packages_that_own_its_binaries (xtask/src/devstack_guard.rs) checks against cargo metadata that every selected package owns a binary in bins and that every binary’s owner is selected.

Figures, as of this amendment. By the same unit graph on the 2026-10-03 tree, the root build’s selection compiles 730 crates from zero, against 736 for the old selection, on the build host (C1’s 740 was measured in the musl builder). A one-line canopy-api change rebuilds 20 crates, the reverse dependencies of canopy-api: canopy-api, canopy-overpayments (which joined the closure after C2) and the 18 services, against 22 for the old selection. The cold-cache notice quotes these.

Amendment 9 (2026-10-04) — validate builds the images in the background (#2614)

Status unchanged (still Accepted). On a source change the cached build the Decision and Amendment 3 describe now usually runs twice per validate, and the second run reuses every layer the first one built.

  • cargo xtask validate's advisory devstack-warm stage runs docker compose -p <project>-validate-warm --profile <P> build from the repo root as a background job, spawned after the repository stages and joined just before devstack-ready (under CANOPY_VALIDATE_BACKGROUND=off it runs inline there). P is the devstack’s stored profile, and the arguments after the project are devstack_build_args(P), the ones devstack-ready's build passes.

  • Its environment carries the build’s image inputs as devstack-ready's build does: the resolved feature set (feature_env_pair(), the CARGO_FEATURES build arg) and CANOPY_CARGO_PROFILE (the CARGO_PROFILE build arg), the latter inherited from validate’s environment by both. The same build args over the same context give the same BuildKit cache keys, so devstack-ready's build, which still runs and still owns the verdict, finds every step cached.

  • Compose names the image of a service with no image: <project>-<service>, and no service built under a devstack profile or e2e sets one (no_service_built_under_a_devstack_profile_sets_an_image, xtask/src/cmd/validate/warm.rs). The warm build therefore tags only <project>-validate-warm-<service> images, which neither the running stack nor the anti-latch check reads.

  • It runs only when the markers call the images stale, never on a prebuilt or in-network run. A failure is recorded with its log’s tail and never fails the battery.

Amendment 10 (2026-11-07) — thin COPY images from the car’s build; the cache mounts are gone (#3273)

Status: the ruling is superseded. Plan compile-once-per-car compiles every binary once per merge-train car (cargo xtask ci build, in the CI image) and packages it by COPY (ADR-040 Amendment 7), which is option (A)'s thin images. The devstack follows: cargo xtask dev start|refresh|reload builds one binary set and the portal first, then the same COPY-only Dockerfiles. Not by a host musl cross-compile, as (A) proposed: on a glibc host aws-lc-sys and ring need x86_64-linux-musl-gcc, which the distribution does not ship (tried on luchs, 2026-11-07). The build runs in the CI image instead (docker run of Dockerfile.ci with the checkout mounted, ci build --binaries <set>; xtask/src/devstack_binaries.rs), which is CI's environment exactly. The images' cache mounts, the content-hash touch of Amendments 2–8 and the cold-builder-cache notice are gone with the build stages that needed them; cargo's own target/ carries the warm state. Amendment 9's background job now runs that binary build.

Edit this page · default