Offline builds
This page is published from the rig repository. Edit on GitHub View source
python3 rig.py build <machine> --offline builds the agent in a Linux guest that never
reaches crates.io or the ONNX Runtime CDN. It suits slow or metered connections: the host
downloads once, packs a bundle, and every later build in every VM reuses it. The host side is
tools/offline_bundle.py; the guest side is the --offline
path of provisioning/agent-build.sh.
The bundle
A gzip tarball, .offline/synthaea-offline-<KEY>-<target>.tar.gz in the rig checkout
(ignored by git), about 100 MB:
| Entry | Content |
|---|---|
KEY | The bundle key (below) |
vendor/ | cargo vendor --locked --versioned-dirs of the agent checkout, merged with the vendored crates of the eBPF toolchain's sysroot |
vendor-config.toml | The source replacement cargo vendor printed, with the guest path left as @VENDOR@ |
ort-cache/dfbin/<target>/<digest>/ | pyke's prebuilt ONNX Runtime for the guest's target, when the host's ort cache has it |
Why the sysroot crates
The eBPF crate builds core with nightly -Z build-std, which resolves the standard
library's own Cargo.lock and needs its dependencies (compiler_builtins and others).
Vendoring only the agent's own dependencies is not enough: an offline probe build then fails with
no matching package named core. The bundle therefore installs the eBPF nightly on the host
(with rust-src, about 70 MB on first use), vendors the crates of
<sysroot>/lib/rustlib/src/rust/library/Cargo.toml, and merges any crate not already present
into vendor/.
The key
KEY = first 16 hex digits of sha256( agent/Cargo.lock + "\0" + agent/packaging/toolchain/ebpf-toolchain.txt )
Those two files decide every crate the build needs, so they decide whether a bundle fits.
bundle_key computes it in Python on the host and
expected_bundle_key computes it in bash in the guest;
tests/test_offline_bundle.py checks that the two agree
byte for byte.
On the host
rig.py build --offline syncs the sources, then runs tools/offline_bundle.py --push <machine> before the guest build. By hand:
python3 tools/offline_bundle.py # build the bundle for x86_64-unknown-linux-gnu
python3 tools/offline_bundle.py --push debian12 # build it for the guest's architecture and upload it
python3 tools/offline_bundle.py --push debian12 --target aarch64-unknown-linux-gnu
push works in this order:
- Asks the guest, over
vagrant ssh, foruname -mand the key of the bundle it already has. The target defaults to<arch>-unknown-linux-gnu. - Vendors into
.offline/<KEY>/, unlessvendor/.completeis already there: vendoring is cached per key, and the marker is written last so an interrupted run starts over. - Looks up the ONNX Runtime digest for the target in the vendored
ort-sys'sbuild/download/dist.tsv, then the runtime itself in the host's ort cache (ORT_CACHE_DIR,XDG_CACHE_HOME,~/.cache/ort.pyke.io,~/Library/Caches/ort.pyke.io,%LOCALAPPDATA%\ort.pyke.io). The cache holds it after any host build of the agent on the same OS and architecture. Without it the bundle is made anyway, with a warning. - Packs the tarball, unless it is already cached, writing to a
.partialfile first. - Skips the upload when the guest already has that key; otherwise uploads the tarball to
/tmp/in the guest withvagrant upload.
The host needs rustup and cargo, which any agent work needs anyway.
In the guest
agent-build.sh --offline (prepare_offline_build):
- Unpacks the newest
/tmp/synthaea-offline-*.tar.gzinto~/synthaea-offline.new, swaps it in place of~/synthaea-offline, and deletes the pushed tarballs. With no tarball in/tmp(the host skipped the upload), the bundle already in place is used. - Refuses, with exit 2, a bundle whose
KEYdoes not match the syncedCargo.lockand toolchain file, or no bundle at all. - Points a private
CARGO_HOMEat~/synthaea-offline/cargo-home, whoseconfig.tomlis the source replacement (with the real vendor path) plus[net] offline = true. Nested cargo invocations, such as the eBPF build the agent's build script starts, inherit it; online builds, which use~/.cargo, are not affected. - Copies the bundled ONNX Runtime into
~/.cache/ort.pyke.io/dfbin/, whereort-syslooks before downloading.
Switching a guest between online and offline builds recompiles the dependencies once, because their source paths changed: about 10 minutes at 4 vCPUs.
Limits
- Provisioning a new machine (its first
up) needs the network: packages, rustup, bpf-linker and thecargo installof bindgen and aya-tool. --ort-compatinstalls packages from the guest's mirror, even with--offline; the build says so.--ort staticclones and builds ONNX Runtime, so it is refused with--offline. Alpine, which has no prebuilt runtime, therefore cannot build offline.- A Windows or Intel macOS host has no cached Linux ONNX Runtime to bundle. The guest then downloads it once (about 25 MB), unless an earlier online build left it in its cache.
- Windows guests have no offline mode;
rig.pyignores--offlinefor them.