feat: detect CUDA image bloat in dockerfile validator - #140
Conversation
Adds size-awareness to `env-doctor dockerfile`, which previously validated
CUDA correctness but said nothing about image size.
Fixes a pre-existing false positive first. `_validate_runtime_devel_mismatch`
scanned every line for compilation keywords while `_validate_base_image` only
recorded the final stage's flavor, so a correct multi-stage build (compile in
-devel, ship in -runtime) was reported as a hard ERROR. Lines are now
partitioned by build stage and compilation detection is scoped to the final
stage. Without this, the new multi-stage suggestion would have recommended a
layout the tool then condemned.
New checks, all conservative:
- devel image with no compilation detected -> suggest a slimmer variant.
Inverting the runtime/devel heuristic is riskier than it reads: a missed
keyword would tell the user to change base images and break their build, so
this is INFO only and stays quiet when dependencies are opaque
(requirements.txt, local project installs, git URLs).
- single-stage devel that must compile -> suggest a multi-stage split
- apt/conda CUDA installs on a CUDA base image -> flag as redundant. Folded
into the existing _validate_cuda_toolkit_installation rather than added as a
separate method, which would have double-reported on the same line.
Size data is keyed on variant, not tag. The nvidia/cuda tag space (CUDA patch
x variant x cuDNN x distro) is combinatorial and grows monthly, so an
exact-tag map would go stale silently. Recommendations quote the delta
("roughly 3.3 GB smaller") rather than absolute sizes, since the ratio between
variants is stable across releases while the megabytes are not.
Also dedupes the compilation keyword list that was copy-pasted in two places.
No CLI changes: _print_validation_result renders issue text generically, and
the MCP dockerfile_validate path picks the new findings up unchanged.
Tests: 39 pass in the dockerfile validator (24 existing + 15 new), including a
regression test asserting the multi-stage pattern produces no error.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UFJDqdhBShSdESfPBKpubz
SummaryAdds image size and bloat detection to Along the way this fixes a pre-existing false positive on The bug this fixes first
That is exactly the layout this PR's new multi-stage suggestion recommends. Without the fix, the tool would emit a fix it then condemns. Lines are now partitioned by build stage, and compilation detection is scoped to the final stage. Verified by round-tripping the tool's own suggested output back through the validator: 0 errors, 0 warnings. New checks
Example output: Design decisions worth reviewingSize data is keyed on variant, not tag. The Recommendations quote the delta, never absolute sizes. "roughly 3.3 GB smaller" rather than "4500 MB → 1200 MB". The ratio between variants has been stable for years; the absolute megabytes drift every release and would make the tool look unmaintained. The Redundancy detection was folded into the existing Dropped from the original proposal: generic Dockerfile lint ( Test plan
Files
|
Adds size-awareness to
env-doctor dockerfile, which previously validated CUDA correctness but said nothing about image size.Fixes a pre-existing false positive first.
_validate_runtime_devel_mismatchscanned every line for compilation keywords while_validate_base_imageonly recorded the final stage's flavor, so a correct multi-stage build (compile in -devel, ship in -runtime) was reported as a hard ERROR. Lines are now partitioned by build stage and compilation detection is scoped to the final stage. Without this, the new multi-stage suggestion would have recommended a layout the tool then condemned.New checks, all conservative:
Size data is keyed on variant, not tag. The nvidia/cuda tag space (CUDA patch x variant x cuDNN x distro) is combinatorial and grows monthly, so an exact-tag map would go stale silently. Recommendations quote the delta ("roughly 3.3 GB smaller") rather than absolute sizes, since the ratio between variants is stable across releases while the megabytes are not.
Also dedupes the compilation keyword list that was copy-pasted in two places.
No CLI changes: _print_validation_result renders issue text generically, and the MCP dockerfile_validate path picks the new findings up unchanged.
Tests: 39 pass in the dockerfile validator (24 existing + 15 new), including a regression test asserting the multi-stage pattern produces no error.