build(docker): exclude dev dependency-group from runtime image#1012
Conversation
The env-builder stage ran `uv sync --active --no-install-project`, which by default installs the PEP 735 `dev` dependency-group from pyproject.toml (`hypothesis`, `pre-commit`). That venv is copied wholesale into the runtime image, so dev-only tooling shipped in production. Add `--no-default-groups` so only the core runtime dependencies are installed. This is safe: - CI unit/integration tests install `.[dev]` on the runner via `make install`, independently of the container, so they are unaffected. - The Dockerfile `test` stage is never built in CI (only `wheel-artifact`, `runtime`, and `licenses-artifact` targets are used), and it lacks pytest regardless, so nothing relied on the dev group being present. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Harrison King Saturley-Hall <hsaturleyhal@nvidia.com>
Try out this PRQuick install: pip install --upgrade --force-reinstall git+https://github.com/ai-dynamo/aiperf.git@e8b3d590825b043dddfc12cc28116de077463410Recommended with virtual environment (using uv): uv venv --python 3.12 && source .venv/bin/activate
uv pip install --upgrade --force-reinstall git+https://github.com/ai-dynamo/aiperf.git@e8b3d590825b043dddfc12cc28116de077463410Last updated for commit: |
WalkthroughDockerfile: env-builder now runs ChangesDockerfile build & test stages
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
With env-builder no longer pulling the dev group, the test stage (FROM env-builder) had no test tooling at all -- and it never had pytest even before, since pytest lives in the [test] extra, not the dev group. Reinstall aiperf with the [test] extra (pytest, pytest-asyncio, pytest-cov, pytest-xdist, hypothesis, httpx, jsonschema, looptime, trustme) from the already-built wheel so the stage can actually run the suite. Uses the wheel from wheel-builder via a PEP 508 direct reference with extras. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Harrison King Saturley-Hall <hsaturleyhal@nvidia.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
Dockerfile (1)
244-247: ⚡ Quick win
aiperf[test]uses thetestextra (not a dependency-group); tighten wheel glob
testis defined under the rootpyproject.toml’s[project.optional-dependencies], souv pip install "aiperf[test] @ file://${WHEEL}"should resolve correctly as an extra (not a PEP 735 dependency-group).Minor robustness:
WHEEL=$(ls /tmp/dist/aiperf-*.whl)can break if the glob matches more than one wheel (newline(s) -> malformedfile://URL). The Dockerfile assumes a single wheel; consider enforcing “exactly one match”.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Dockerfile` around lines 244 - 247, The Dockerfile should keep installing the extra as an extra (use "aiperf[test] @ file://${WHEEL}") but make the WHEEL selection robust: ensure the glob for /tmp/dist/aiperf-*.whl yields exactly one wheel (or deterministically pick one) before constructing WHEEL and running the uv pip install step; update the WHEEL assignment and add a short guard that fails the build or chooses a single wheel if multiple matches are present so the resulting file:// URL is always valid (referencing the WHEEL variable and the uv pip install "aiperf[test] @ file://${WHEEL}" invocation).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@Dockerfile`:
- Around line 244-247: The Dockerfile should keep installing the extra as an
extra (use "aiperf[test] @ file://${WHEEL}") but make the WHEEL selection
robust: ensure the glob for /tmp/dist/aiperf-*.whl yields exactly one wheel (or
deterministically pick one) before constructing WHEEL and running the uv pip
install step; update the WHEEL assignment and add a short guard that fails the
build or chooses a single wheel if multiple matches are present so the resulting
file:// URL is always valid (referencing the WHEEL variable and the uv pip
install "aiperf[test] @ file://${WHEEL}" invocation).
Summary
Two related fixes to dependency installation in the
Dockerfile.1. Exclude the dev dependency-group from the runtime image
The
env-builderstage ran:RUN uv sync --active --no-install-projectBy default
uv syncinstalls the PEP 735devdependency-group declared inpyproject.toml's[dependency-groups](hypothesis,pre-commit). That venv (/opt/aiperf/venv) is copied wholesale into theruntimeimage, so dev-only tooling was shipping in the production container. (Confirmed by the installed versions matching the[dependency-groups]pins, not the looser[project.optional-dependencies]extras.)This adds
--no-default-groupsso only the core runtime dependencies are installed:2. Make the
teststage actually able to run testsWith the dev group no longer installed, the
teststage (FROM env-builder) had no test tooling — and it never hadpytesteven before, sincepytestlives in the[test]extra, not the dev group. The stage now reinstalls aiperf with the[test]extra from the already-built wheel:This pulls
pytest,pytest-asyncio,pytest-cov,pytest-xdist,hypothesis,httpx,jsonschema,looptime, andtrustmeinto the test image.Why change #1 is safe
make ci-install/make first-time-setup→make install→uv pip install -e ".[dev]"(the[dev]extra), an entirely separate path from the Dockerfile'suv syncdependency-group. The container is never used to run those tests.testDocker stage is not built in CI. The only targets built (innightly.yml) arewheel-artifact,runtime, andlicenses-artifact; there is no--target testanywhere in.github/,Makefile, or docs. Change Add the license file and pre commit hooks #2 nonetheless makes that stage correct for anyone who does build it locally.Impact
runtime(production) image: dropshypothesis,pre-commit, and their unique transitive deps — pure bloat removal.[dependency-groups]defines only thedevgroup, so no other group is affected.testimage: now has a working test toolchain instead of a half-populated venv.tqdm,pydantic,transformers, etc.) are unchanged — they live in[project.dependencies]and are always installed.Testing
git grep-verified there is no--target testconsumer in CI/Makefile/docs.Dockerfile(env-buildersync flag +teststage); no application code touched. Theaiperf[test] @ file://…form is standard PEP 508 direct-reference-with-extras syntax supported by uv.🤖 Generated with Claude Code