Validate In-Network Runner
For a contributor whose host-side battery fails on infrastructure reachability
rather than on code: cargo xtask validate-in-network runs the same
cargo xtask validate inside a container attached to the devstack’s compose
network.
Why
cargo xtask validate runs its nextest arms on the host, where the infra lane
reaches the devstack Postgres on the host-mapped port recorded in .ports.env
(CANOPY_PORT_POSTGRES_5432, resolved by
crates/canopy-test-lib/src/infrastructure.rs). A host that cannot serve that
shape — a fresh box, a loopback or DNS oddity, macOS Docker networking —
produces failures that look like missing services.
Inside the compose network the same suite resolves postgres:5432,
rabbitmq:5672 and clamav:3310 by service name — the
containerised model
ADR-015 mandates for
integration tests, extended to the whole validate path.
This is opt-in. Neither runner is something git push runs
(What git push runs); reach for the in-network
runner when the host path fails on reachability, not on code.
Prerequisites
-
Docker daemon running.
-
The devstack up (
cargo xtask dev start), or pass--with-devstack. The runner attaches to the<project>_defaultcompose network, where<project>is the lower-cased workspace directory name (xtask/src/docker.rs::project_name). -
The workspace is bind-mounted into the container at
/app; the run uses your checkout.
Usage
cargo xtask validate-in-network # devstack already up
cargo xtask validate-in-network --with-devstack # boot the devstack first
cargo xtask validate-in-network --no-build # skip the runner-image rebuild
cargo xtask validate-in-network -- --timing # extra args for the inner validate
Flags (xtask/src/cmd/validate_in_network.rs): --with-devstack boots the
devstack when it is not up (without the flag the command fails fast when the
stack is down); --no-build skips rebuilding the runner image from
xtask/Dockerfile.validate-runner (the default rebuild is cheap through the
layer cache unless the Dockerfile changed); everything after -- is appended
to the inner cargo xtask validate.
Before its docker run, the command readies the devstack on the host, as the
inner validate cannot (#2776): the shared bootstrap (crate::bootstrap)
reconciles .ports.env, sources the dev secrets, boots the stack or syncs it
to your tree through devstack_guard::ensure_ready (the bring-up test, e2e
and coverage share), re-reads the live port bindings, and brings the
observability profile up, so the eligibility metric smoke test finds
Prometheus.
The runner always adds --skip-docker to the inner validate — a Docker build
inside the container would need DinD, and the host battery owns image builds —
and sets CANOPY_VALIDATE_RUNNER=in-network, which the validate report records
as runner: in-network.
Artifact ownership (#1253)
The container runs validate as root: the image’s cargo registry and target/
are root-owned, so running as the host uid would break the build. The runner
passes the host id -u / id -g in as HOST_UID / HOST_GID and wraps the
inner command in a shell that chown -Rs test-results/ back to the host
after validate exits (|| true, so validate’s exit code is preserved). The
report itself is written 0644, so test-results/validate-report.json stays
host-readable even if the chown fails. The build goes to the named volume
<project>_validate_target, mounted over /app/target (#2773), so the root
container never writes the checkout’s own target/, whose files the host
user could not remove afterwards. The volume keeps the runner’s build warm
between runs; docker volume rm <project>_validate_target reclaims it. See
The validate report.
The runner image and secrets (#2773)
xtask/Dockerfile.validate-runner installs every cargo tool validate’s
preflight probes (PREFLIGHT_CARGO_TOOLS in xtask/src/cmd/doctor.rs):
cargo-nextest, cargo-deny and cargo-machete, at the releases and digests
CI’s own jobs pin. A unit test holds the image to the preflight’s list. The
runner has no docker daemon, so validate records its secrets-decrypt
stage as skipped: the tests use their literal fallbacks, as the compose
in-network lane’s do, and no secret floor is written into the mounted
workspace. The container runs as root over a checkout the host user owns,
which git refuses as "dubious ownership", so the wrapper first marks /app
a safe directory for the container’s git; the signing check then reads the
checkout’s own commit.gpgsign and user.signingkey.
Validate inside the runner (#2776)
Under CANOPY_VALIDATE_RUNNER=in-network (runner_from in
xtask/src/cmd/validate.rs), validate takes the devstack as ready: the host
readied it, the runner has no docker daemon, and compose’s relative bind mounts
would resolve against the container’s /app. It records these stages as
skipped, each with its reason in the report:
-
reconcile-ports-env: the host owns.ports.env, whoselocalhostports the container cannot reach; -
secrets-decrypt, as above; -
devstack-project-name: the compose project is the host’s, and/appnames none; -
devstack-warm: the runner builds no image; -
devstack-readyanddevstack-observability: the host did both before thedocker run; -
ports-refresh-post-devstack: the tests take the compose-network addresses; -
docker-build: the wrapper passes--skip-docker, and without it there is no daemon to build with.
secret-floor-write does not run, as there are no decrypted secrets to write.
The lane env is the runner’s own CANOPY_TEST__* environment, the
service_mesh_env table the host passes in, so both nextest arms, the schema
sweep and the doctests reach postgres:5432, canopy-rules:8001 and the rest
by compose name. api-docs fetches each service’s OpenAPI document at its
compose name and container port (api_docs::Reach::InNetwork), the address the
same table gives the tests. Every other stage runs as it does on the host.
The token broker (#2768)
The runner’s environment names canopy-test-lib’s canopy-identity token broker
(Testing › the token broker) the way the
host renderer does, at the bind-mounted workspace’s paths:
CANOPY_TESTUPSTREAM_CREDENTIALS=/app/.devstack/idp/kanidm.json,
CANOPY_TESTUPSTREAM_CA=/app/.devstack/idp/kanidm-ca.pem and
CANOPY_TESTIDENTITY_KEYS=/app/.devstack/identity/keys, with
CANOPY_TESTUPSTREAM_ADDR=kanidm:<port> from .ports.env (Kanidm listens on
its reserved port in the network too). Its session cache,
CANOPY_TEST__IDENTITY_BROKER_CACHE, is /tmp/canopy-identity-broker inside
the container: the runner is root, and a root-owned entry under the workspace
would lock the host lanes out of it. Each in-network run therefore signs its
persons in afresh.
Trade-offs vs host validate
| Aspect | Host (cargo xtask validate) |
In-network |
|---|---|---|
Speed |
Uses the host cargo cache directly; fastest warm |
Image build (unless |
Network model |
|
Compose service names ( |
Failure shape |
Surfaces host differences (toolchain, a local postgres) |
Reproducible across hosts; a failure is a product bug |
Default |
Yes — |
No — opt-in |
CI
No pipeline job runs it: the merge train's car runs the lanes itself
(CI vs local). Run
cargo xtask validate-in-network --with-devstack by hand when a host-validate
failure looks environment-specific.