ci(linux): cache cargo home and target dir (#27) #534
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "ci/27-linux-cache"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What changed
Workflow files only (plus one sentence in
crates/fluxer-voice/README.md); no Rust code.ci.yaml, joblinux:container.volumesmountsfluxer-native-cargo:/cache/cargoandfluxer-native-target:/cache/target.CARGO_HOME=/cache/cargo/home,RUSTUP_HOME=/cache/cargo/rustup,CARGO_TARGET_DIR=/cache/target/ci,FLUXER_LIVEKIT_CACHE_DIR=/cache/cargo/downloads/livekit-server(tools/livekit-test-server.shhonours it). The pinned FFmpeg already lands in the target dir (xtask ffmpeg fetch→<target>/ffmpeg), so it's cached along with it.$CARGO_HOME/bintoGITHUB_PATH, and logs whether each path is a mounted volume or a plain dir.cargo-deny --versionis the pinned version. Otherwise it's unpacked to.partialand renamed into place.--versionis dropped and fetched again.dfand the target dir's size, then deletes/cache/target/cionly (never the registry, the toolchain or the release dir) when free space is belowMIN_FREE_GB=30or the dir is aboveMAX_TARGET_GB=40. It recordscold/warm.always()): logs the sizes of target/debug/release/ffmpeg, CARGO_HOME, registry, git and RUSTUP_HOME, plusdf. Log only, no release asset.CARGO_INCREMENTAL=0and the rest of the env are unchanged. The checkout is still a freshgit fetch.release.yaml, joblinux: same volumes, same CARGO_HOME/RUSTUP_HOME, its ownCARGO_TARGET_DIR=/cache/target/release-build, the same idempotent Install Rust, a disk guard (MIN_FREE_GB=30,MAX_TARGET_GB=15) and Report disk use. AddsCARGO_INCREMENTAL=0, because the dir now persists and xtask's own dev build would otherwise keep incremental artifacts. The volume names are written as"fluxer\x2Dnative-…", which YAML reads as-. The literal would failno_old_product_name_in_shipped_files(xtask/tests/package.rs), which bans the old name in release.yaml. The alternative is adding the two names to that test'sALLOWED_OLD, a Rust change this PR was not allowed to make.Locking (why nothing can wedge)
/cache/cargo/.install.lock(flock) serialises toolchain, cargo-deny and livekit installs between concurrent jobs, because rustup doesn't lock./cache/target/ci.lock(orrelease-build.lock) is held around prune, the FFmpeg fetch and the build. A second CI job waits instead of having its dir pruned under it. Cargo would serialise the two builds on its own target lock anyway.ci.lockis held, no other job can be runningcargo deny, so any*.lockleft in$CARGO_HOME/advisory-dbsmust come from a killed run and is deleted..cargo-ok.What release and CI can share
The release build is the same
cargo build --release --locked -p fluxer --no-default-featuresthat CI's packaging test runs, so therelease/artifacts could in principle be shared (all but the app crate, which bakes in the version and channel). They are kept in separate dirs so that a concurrent CI job and release job don't wait on each other for the whole build. CI's debug/test artifacts are of no use to the release build. Shared: toolchain, registry, git checkouts.Runner-side requirement
The runner ignores the mounts until both names are listed. Add them to the runner config and restart forgejo-runner:
(Keep any existing entries.) Docker creates the volumes on first use.
Without it
The jobs work exactly as before, uncached:
/cache/*are plain container directories, every step creates what it needs, and the log showscache: /cache/cargo NOT mounted (not in the runner's valid_volumes): cold build. Tested locally inubuntu:22.04both without volumes and with two throwaway named volumes: the second run printedrust: 1.98.1 from the cache,cargo-deny: 0.20.2 from the cache,disk: warm build.How to measure
ci.yaml(workflow_dispatch) on this branch. The first run is cold: expect ~50 min, anddisk: cold buildin the log.rust: … from the cache,disk: warm build, with only the workspace's own crates recompiled where needed (fingerprints match), and no toolchain, crate, livekit or FFmpeg download.Report disk uselines (/cache/target/cisize → retuneMIN_FREE_GB/MAX_TARGET_GB).release.yaml(/cache/target/release-build).Verified locally
run:block passesbash -n.no_old_product_name_in_shipped_files,release_workflow_never_names_a_package_file_in_the_feed_steps,no_ci_workflow_writes_the_stable_feed,promote_stable(14) andpackage::libs::tests::declared_everywhere(3) all pass.Refs #27
🤖 Generated with Claude Code
After pruning, the Linux jobs of ci.yaml and release.yaml now fail the "Prune the build cache" step at once when /cache/target still has less than DISK_FLOOR_GB (25) free ("runner low on disk: N GB free, need 25"), instead of starting a build that runs out of disk halfway. release.yaml writes its volume names plainly (no more `\x2D` trick); the two names are in xtask/tests/package.rs's ALLOWED_OLD as Docker volume names on the CI runner, not product text. The runner's docker storage is now a 193 GB disk, so the target dir caps go up: MAX_TARGET_GB 40 -> 60 for CI, 15 -> 25 for release. Refs #27 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>