build(docker): downsize the Infrahub container image (~40%)
Why
The Infrahub container image built by invoke dev.build was ~1.37 GB. Most of that was overhead unrelated to running the server: the full C build toolchain shipped in the runtime layer, plus two heavy Python libraries that the server never imports.
Goal: shrink the image (faster pulls, smaller attack surface, lower registry/storage cost) with no change to runtime behavior.
Non-goals: no base-image swap (stays on python-slim), no change to the in-app docs/frontend bundles, no SDK code changes.
What changed
Image size: 1.37 GB -> 0.81 GB (-559 MB, ~41%), measured uniformly via docker history. Delivered as 3 independent commits:
build-essential+pkg-config+uvno longer ship in the image. Dependency resolution moves to a dedicatedbuilderstage; the finalbackendstage is a freshpython-slimcarrying onlytini/git/curl/ca-certificatesplus the prebuilt/.venvand/source. (-344 MB)numpyis no longer installed — it was an unused runtime dependency; moved to thedevgroup. (-58 MB)pyarrowis no longer installed by default — it's only used by the SDK'sinfrahubctl object loadimporter, never by the server/worker. Moved to a newobject-transferoptional extra. (-149 MB)
What stayed the same: editable installs, hatch-vcs git-based versioning (.git bind-mount preserved in the builder stage), the git credential helper, all env vars, and the tini entrypoint. No schema/API changes.
How to review
Start with development/Dockerfile (the stage split), then the two pyproject.toml/uv.lock dependency moves.
How to test
uv run invoke dev.build
# verify the slim runtime imports the heavy compiled extensions + app:
docker run --rm --entrypoint python <image> -c "import grpc, cryptography, neo4j, asyncpg, uvloop, hiredis, bcrypt, pydantic_core, infrahub.server; print('OK')"
# pyarrow/numpy absent; infrahubctl degrades gracefully:
docker run --rm --entrypoint infrahubctl <image> --help # -> "install the 'ctl' extra of infrahub-sdk"
Verified locally: both intermediate and final images build; all heavy extensions + infrahub.server/CLI/git.integrator import with pyarrow/numpy absent; infrahubctl prints the built-in ctl-extra hint.
Impact & rollout
- Backward compatibility: No runtime behavior change. Only caveat:
infrahubctl object loadinside the container now needsinfrahub-sdk[ctl](or theobject-transferextra) installed — it exits with that exact hint otherwise. - Deployment notes: Safe to deploy.
Checklist
- Changelog entries added (3
housekeepingfragments) - I have reviewed AI generated content
Summary by cubic
Shrink the Infrahub Docker image from 1.37 GB to 0.81 GB (~41%) by moving the build toolchain (build-essential, pkg-config, uv) into a dedicated builder stage and switching the runtime to a fresh python-slim that only ships tini, git, curl, ca-certificates, plus the prebuilt /.venv and /source. No runtime behavior changes.
-
Dependencies
numpyremoved from runtime; now dev-only.pyarrowmoved to theobject-transferextra; not installed by default.- Updated
python_sdkto lazy-loadpyarrowsoinfrahubctlworks without it; onlyobject loadneeds it.
-
Migration
- If you run
infrahubctl object loadin the container, installinfrahub-sdk[ctl]or enable theobject-transferextra.
- If you run