Skip to content

ci: publish multi-arch (amd64/arm64) Docker images - #267

Closed
quanuanc wants to merge 1 commit into
rustledger:mainfrom
quanuanc:docker-multi-arch
Closed

quanuanc wants to merge 1 commit into
rustledger:mainfrom
quanuanc:docker-multi-arch

Conversation

@quanuanc

Copy link
Copy Markdown

Why

The published ghcr.io/rustledger/rustfava image is amd64-only, and the Dockerfile hardcodes an x86_64-linux wasmtime CLI download, so it can't even be built on an arm64 host (Apple Silicon, Graviton, Raspberry Pi). This PR makes the image build and publish for both linux/amd64 and linux/arm64.

Dockerfile

  • Drop the wasmtime CLI download entirely. The runtime uses wasmtime-py (a core dependency with prebuilt wheels for both arches) since the JSON-RPC engine was replaced by the component engine — the CLI binary was dead weight, and it was the only arch-specific piece of the image.
  • Build the frontend in a separate stage pinned to $BUILDPLATFORM. bun is unreliable under QEMU user emulation, and its JS/CSS output is architecture-independent, so cross-builds never run it emulated. The build backend then skips its bun step in the final stage because the prebuilt static assets are fresher than the frontend sources (bun isn't installed there at all).
  • Pre-fetch the (arch-independent) rustledger component wasm into the installed package, so containers work offline and the first request doesn't stall on a download. Without this, every fresh container re-downloads the component on first page load.
  • Bind dual-stack ([::]) by default. Docker publishes ports on IPv6 too, and browsers resolve localhost to ::1 first, so the previous IPv4-only (0.0.0.0) bind made http://localhost:<port> fail (connection reset) on common setups even though the container was healthy. An explicit --host still overrides this.

The final image is also slimmer: no apt packages, no bun, no wasmtime CLI, and the source tree is removed after pip install.

publish.yml (docker job)

  • Build and push linux/amd64,linux/arm64 via buildx/QEMU on tags. Only the Python install runs emulated (pure Python + prebuilt wheels); the frontend builds natively.
  • Run the build + smoke (no push) on PRs and main too, so multi-arch regressions surface before a release. Pushing and registry login stay tag-gated.
  • Fix the smoke step, which had never actually executed (it was added after v1.31.0 and the job was tag-gated, and it fails as written):
    • curl | grep -q under pipefail is flaky (early grep exit SIGPIPEs curl) — capture the body instead.
    • grep -qi rustfava can't pass here: the page HTML doesn't contain the string "rustfava". The wheel smoke only matches because the runner's checkout path (/home/runner/work/rustfava/...) leaks into the ledger-data JSON; in the container the path is /data/example.beancount. Assert on rendered ledger data and a query API round trip instead.
    • Keep the container (no --rm) so docker logs still works after a startup crash, and dump logs/body on every failure path.

Verification

Full workflow run on my fork (workflow_dispatch, same code): quanuanc/rustfava run 30208362401 — wheel build ✅, wheel smoke ✅, docker job ✅ (amd64 image built + container smoke passed, multi-arch amd64+arm64 buildx build completed; push correctly skipped on non-tag).

Also built and ran the image natively on an arm64 Mac: server starts, ledger loads, pages render, and the query API responds.

🤖 Generated with Claude Code

The Dockerfile hardcoded an x86_64 wasmtime CLI download, so the
published image only ran on amd64 (arm64 hosts like Apple Silicon had
to emulate or build from source, and the build failed there anyway).

Dockerfile:
- Drop the wasmtime CLI download entirely: the runtime uses wasmtime-py
  (a core dependency with prebuilt wheels for both arches) since the
  JSON-RPC engine was replaced by the component engine.
- Build the frontend in a separate stage pinned to $BUILDPLATFORM: bun
  is unreliable under QEMU user emulation, and the JS/CSS output is
  architecture-independent, so cross-builds never run it emulated. The
  build backend then skips its bun step because the prebuilt static
  assets are fresher than the frontend sources.
- Pre-fetch the (arch-independent) rustledger component wasm into the
  image so containers work offline and the first request does not
  stall on a download.
- Bind dual-stack ([::]) by default: Docker publishes ports on IPv6
  too, and browsers resolve localhost to ::1 first, so an IPv4-only
  bind made http://localhost:<port> fail on many hosts.

publish.yml docker job:
- Build and push linux/amd64 + linux/arm64 via buildx/QEMU on tags.
- Run the build + smoke (no push) on PRs and main too, so multi-arch
  regressions surface before a release.
- Fix the (previously never-executed) smoke step: keep the container
  for docker logs, avoid the grep -q SIGPIPE/pipefail flake, and
  assert on rendered ledger data + a query API round trip instead of
  the string "rustfava" (the page only contains it by accident when
  the ledger's file path does).

Co-Authored-By: Claude Fable 5 <[email protected]>
@CLAassistant

CLAassistant commented Aug 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@robcohen robcohen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — the reasoning in the description is unusually careful, and I checked the load-bearing claims rather than taking them on trust. They all hold. Two things block merging, neither of them about the substance.

Claims verified

The wasmtime CLI really is dead weight. src/rustfava/rustledger/backend.py documents that the CLI JSON-RPC engine was removed and that the component backend needs the wasmtime Python package; there's no subprocess/which use of a wasmtime binary anywhere in src/rustfava. Dropping it is what makes the image arch-independent, so this is the right thread to have pulled.

The touch trick genuinely skips the bun step. _build_backend.py:53-55 takes max(st_mtime_ns) over the frontend sources and skips when app_js is newer, so overlaying the prebuilt assets and touching them does short-circuit the rebuild. Good — that's load-bearing for the cross-build, since bun isn't installed in the final stage.

The old smoke assertion could not have passed. I ran the server against a ledger whose path contains no "rustfava" and fetched /:

assertion result
grep -qi rustfava (current) no match — would fail
grep -q 'id="ledger-data"' (yours) matches

So your diagnosis is exactly right: the wheel smoke passes only because the runner's checkout path leaks rustfava into the ledger-data JSON, and in the container the path is /data/example.beancount. id="ledger-data" is emitted by _layout.html:21, so it's a real invariant rather than an accident.

The dual-stack bind works. With RUSTFAVA_HOST=:: on Linux, [::1], 127.0.0.1 and localhost all served (302 each).

The workflow changes are safe to run on PRs. Registry login is gated to push + tag, push: is gated the same way, both new actions are SHA-pinned, and persist-credentials: false is preserved. Running build+smoke unpushed on PRs is a real improvement given the job was previously tag-only — which is precisely why the broken smoke went unnoticed.

Blocking: this now conflicts

.github/workflows/publish.yml conflicts with main. The cause is the github-actions dependency bumps that landed since you opened this (#275, and #288 earlier today), which moved the same SHA pins you're editing.

On rebase, note that #288 bumped docker/setup-buildx-action to v4.3.0 (37fe631027851001ddb9b187196cc803df7f5f0e); this branch still pins v4.2.0, so take main's value. Your new docker/setup-qemu-action pin is fine as-is.

Blocking: CI has never run

This PR shows a single check (license/cla, signed — thank you). The rest are gated behind outside-contributor workflow approval, so none of it has executed here. Your fork run is good evidence, but a maintainer will need to approve the runs so it's verified against this repo. Worth flagging that the check list gives no visual hint that anything is waiting — the same trap that left #282 parked for six days.

Non-blocking notes

  1. grep -qi rustfava survives at publish.yml:105 and :225 (the wheel smokes). By your own analysis those pass only because the runner's path happens to contain the string — they'd break if the checkout path changed. Out of scope here, but worth a follow-up.
  2. With RUSTFAVA_HOST=:: the startup banner prints Starting Fava on http://:::5198, which is a bit unfortunate. Pre-existing formatting, but this PR makes it the default users see.
  3. FYI, #292 landed today and put the pinned version into the component wasm filename. Your prefetch step is unaffected — _default_wasm_path and _download_component_wasm are unchanged, and I confirmed the one-liner still resolves and downloads. Nice side effect: the baked-in component is now version-tagged.

Rebase and I'll get the runs approved.

@robcohen

Copy link
Copy Markdown
Member

Superseded by #298, which is your commit rebased onto current main with authorship intact — opened there rather than force-pushing to your fork, so your branch stays yours.

Thank you for this. The description did the hard part: it correctly identified that the wasmtime CLI download was the only arch-specific piece and had become dead weight, that bun can't be trusted under QEMU, and — the find I most appreciated — that the docker smoke test could never have passed, because the page only contains the string "rustfava" when the ledger's file path happens to. I reproduced that: serving a ledger from a path without "rustfava" in it, grep -qi rustfava finds nothing while your id="ledger-data" assertion matches. That test was added after v1.31.0 and never ran, exactly as you said.

The only change I made to your work was quoting $GITHUB_OUTPUT in the new version step (SC2086), kept as a separate commit. It happens to clear a pre-existing finding too, since the step it replaces had the same unquoted write.

Worth reporting back: on #298 the docker job ran on a PR for the first time — 3m26s, green, multi-arch build and container smoke both passing. Your change is what made that possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants