Skip to content

ci: publish the standalone image sooner - #175

Merged
kalaspuff merged 1 commit into
mainfrom
fctl/106-standalone-image-faster
Oct 21, 2026
Merged

kalaspuff merged 1 commit into
mainfrom
fctl/106-standalone-image-faster

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

A release waits for the standalone image: its Build and run a session job took 6.5 to 10 minutes in the last two releases, and its Publish job another 2.5. Most of that time went to work that didn't have to happen:

  • The Rust image moved under the cache. The Worker's stage built on rust:1-slim-bookworm, which Docker Hub rebuilds with every Rust and Debian release (it moved again this morning, after v0.14.1). Each move started every later layer over: cargo install worker-build ran again (2:03 in v0.14.1's run), and so did the download of the image's newer Rust, on top of which rustup toolchain install then put the pinned one. The stage now builds on rust:1.99.0-slim-bookworm, the Rust that rust-toolchain.toml pins, whose tag last changed on October 6. rustup toolchain install only adds the wasm32 target and the components. A test in xtask/src/serve.rs fails when the two versions differ, so a toolchain bump moves both.
  • The Worker's layer held a gigabyte. With the target directory and the fetched sources in it, every build exported it to the GitHub Actions cache: in v0.14.0's run, "preparing build cache for export" took 29 s and writing that layer 16 s, and Publish imported it again. The build's RUN now removes them and keeps only the Worker. worker-build's layer drops the sources cargo fetched for it, which every build that rebuilds the Worker imported too (18 s).
  • Publish built arm64 from scratch under QEMU. Its apt-get and npm ci took 90 s in v0.14.1's run, the same work in every release. Publish now writes its layers to a cache scope of its own (standalone-publish, the image's final layers only) and reads it back, so those steps run again only when the Node image or the lockfile changes.
  • The session through the image builds the CLI, host and agent without debug info (CARGO_PROFILE_DEV_DEBUG=0), as ci: run the checks in parallel jobs and deploy main sooner #170 does in ci.yml. In v0.14.0's run that build took 49 s.

The Worker itself still builds from scratch in every image build, dependencies included (about two minutes). Caching its dependencies in a layer of their own, as cargo-chef does, would need their build to copy worker-build's environment exactly: wasm-bindgen's macros read WASM_BINDGEN_USE_JS_SYS at expansion time, a variable cargo doesn't track, so a mismatch would give a wrong Worker, not a slow one.

How I verified it

This pull request's Standalone image run builds the image from the new Dockerfile, starts it, runs cargo xtask dev --smoke --server through it and checks that it stops cleanly. The xtask tests pass, the new one included. Publish runs only for a release, so its cache shows its effect from the second release after the merge on: the first one fills it.

Refs #170, which makes the checks on pull requests and the deploy from main faster.

Session: https://app.fctl.sh/s/ses_01M5FGG04ZQGCABWSN2Z0NDSJE

The Worker's stage built on rust:1-slim-bookworm, which moved with every
Rust and Debian release (it moved again this morning): each move started
the image's cached layers over, so building it ran cargo install
worker-build again (two minutes), downloaded a newer Rust and installed
the pinned one on top. It now builds on rust:1.99.0-slim-bookworm, the
Rust rust-toolchain.toml pins, which a test keeps the same.

The layer of the Worker's build kept the target directory and the fetched
sources, a gigabyte that every build exported to the cache (half a
minute) and the Publish job imported again; worker-build's kept the
sources it was built from. Both now drop them.

Publish ran the arm64 stage's apt-get and npm ci under QEMU for every
release (a minute and a half). Its layers now go to a cache of their own,
so they build again only when the base image or the lockfile changes.

The session through the image builds the CLI, host and agent without
debug info, as ci.yml does.
@fctl-sh
fctl-sh Bot requested a review from kalaspuff as a code owner October 21, 2026 16:33
kalaspuff pushed a commit that referenced this pull request Oct 21, 2026
CI took about 2 min 45 s to check a pull request: one job ran all of
`cargo xtask check` in sequence (formatting, generated types, Biome and
TypeScript, Clippy twice, the tests, Vitest, the web build), and the
smoke job built the host, then the web app, then the migrations, then
the Worker, one after another. A merge took 5 to 11 minutes to reach
app.fctl.sh, because the deploy only started its two-minute release
build of the Worker once both checks had passed. On top of that, every
run rebuilt work its caches should have saved.

## What changed

**The checks run in parallel.** `cargo xtask check` now takes parts:
`lint` (rustfmt, `web/src/gen`, Clippy for the host and the Worker),
`test` (`cargo test`) and `web` (Biome, TypeScript, Vitest, `node
--test`, the web build). With no part it runs everything, in the same
order as before. CI runs each part in a job of its own. A job named
`cargo xtask check` passes once all three have, so main's ruleset
requires the same checks as before. A test in `xtask/src/check.rs` fails
if `ci.yml` stops running one of the parts.

**`cargo xtask dev` builds in parallel.** The CLI, host and agent build
on one thread; the Worker (`worker-build --dev`) builds on a second, in
`target/worker` so the two cargo builds don't wait for each other's
lock; npm ci, the web build and the D1 migrations run on a third. The
last two prefix their lines with `worker │` and `web │`. `wrangler dev`
builds in `target/worker` too, so as it starts it only binds the Worker
again. This speeds up local `cargo xtask dev` as well as CI's smoke job.

**ring and the TLS stack stopped rebuilding on every run.** `cargo run`
gives xtask `CARGO_MANIFEST_DIR` and `CARGO_PKG_VERSION_*`, and every
cargo that xtask started inherited them. ring's build script tracks
those variables, and rust-cache's keys leave out the workspace version.
So after each release, every job on every run rebuilt ring, rustls,
tungstenite and everything that depends on them, twice in the check job.
Locally, alternating `cargo build` and `cargo xtask` rebuilt them each
time too. xtask now strips those variables from the commands it runs.

**Caches that hit, and stay within the quota.** `.github/actions/rust`
sets up Rust the same way in every job:
- The toolchain comes from a cache: 3 s instead of rustup's 10 s.
- The runner image's preinstalled toolchains are removed (0.3 s).
rust-cache hashes every installed toolchain into its keys, so each
runner image update started the caches over, and during a rollout every
cache existed twice (keys `7543b454` and `b771e0df` on main today).
- rust-cache saves from main only. The repository's caches were at 11.6
GB, over GitHub's 10 GB limit, so main's caches were being evicted.
- Dev and test builds leave out debug info
(`CARGO_PROFILE_DEV_DEBUG=0`). Locally that took the test build from 50
s to 15 s with warm dependencies, and the caches shrank: the smoke's
from 405 to 263 MB, lint and test 188 and 216 MB against the old check
job's 552 MB.

**xtask comes from a cache.** Every job spent 9 s building xtask.
`.github/actions/xtask` puts the binary on PATH from a cache keyed by
what it is built from (its crate, fctl-proto, the manifests, the
lockfile, the toolchain), and builds it only when one of those changed.
The jobs run `xtask check lint` and the like, and the web and Commits
jobs need no Rust at all when the cache hits.

**main deploys sooner.** The Worker's release build runs in its own job,
beside the checks, and the deploy waits for the checks and that build.
The build is cached by the files it is built from (its three crates, the
manifests, the lockfile, the toolchain, `ci.yml`, worker-build's
version). A push that leaves those as they were, such as web, docs, host
or agent changes, skips it (9 s). The deploy takes xtask from its cache,
builds the web app itself (2 s), downloads the Worker and runs `xtask
deploy fctl-sh --skip-build`.

## Measured on this pull request

| | before (main today) | after, warm caches |
|---|---|---|
| `cargo xtask check` check | 2:40 | 0:50 |
| `cargo xtask dev --smoke` check | 2:00 | 1:10 to 1:16 |
| pull request, both checks green | about 2:45 | about 1:15 |
| main, push to deployed, Worker unchanged | 5:00 to 11:00 | about 2:00
(estimate: checks plus the 28 s deploy dry run) |
| main, push to deployed, Worker changed | 5:00 to 11:00 | about 2:45
(estimate: the Worker's job, 2:00 to 2:30 with warm caches, plus the
deploy) |

The smoke job is now the critical path: its builds run side by side for
about 25 s, and the session itself takes 17 s (12 s of watched checks
and a 3 s background task, which are what it tests). With every cache
cold, the first run on this pull request still had `cargo xtask check`
green after 2:18.

## How I verified it

- `cargo xtask check` (all parts) and each part on its own pass locally,
as does `cargo xtask dev --smoke`. Under the same conditions (warm
dependencies, workspace crates rebuilt, fresh state), the smoke took 57
s before this change and 47 s after.
- Four CI runs on this pull request. The main-only parts (caches saved,
the Worker build, and a deploy dry run that took xtask from its cache,
built the web app, downloaded the Worker artifact and ran `xtask deploy
fctl-sh --skip-build --dry-run` and `wrangler deploy --dry-run`) were
exercised through temporary commits, removed in the last one. The dry
run caught a real bug: the first version unpacked xtask's binary into
the checkout, where `xtask/` is the crate.
- A temporary commit that misformatted xtask made the lint part fail
and, with it, the required `cargo xtask check` check, while the other
jobs passed; a revert followed it.

## After the merge

The first run on main starts every cache over (the keys changed), so it
takes about five minutes, building worker-build too. The ones after it
are warm. The old caches (`v0-rust-check-*`, `v0-rust-deploy-*`,
`v0-rust-dev-*-7543b454-*` and `-b771e0df-*`) are no longer used and
expire within a week; deleting them frees about 2 GB sooner.

The Release workflow and the standalone image are unchanged here: #175
makes the image's build and publish faster.

Session: https://app.fctl.sh/s/ses_01M5FGG04ZQGCABWSN2Z0NDSJE

---------

Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
@kalaspuff
kalaspuff merged commit 42e56f8 into main Oct 21, 2026
7 checks passed
@kalaspuff
kalaspuff deleted the fctl/106-standalone-image-faster branch October 21, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant