Repository navigation
fix(docker): prune the gateway's dev packages from the all-in-one image - #433
Merged
Merged
Conversation
The upstream saic-python-mqtt-gateway image runs a plain `poetry install`, so the venv the all-in-one image copies also carries the dev group: pytest, mypy, pylint, pre-commit and 28 more packages that never run. virtualenv, via pre-commit, raised code scanning alerts #592-#595. prune-venv.py keeps only what the gateway's six runtime dependencies resolve to and uninstalls the rest. Importing main.py afterwards loads every gateway module, so a runtime package pruned by mistake fails the build instead of the gateway at startup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes code scanning alerts #592, #593, #594 and #595:
virtualenv21.3.1 in/opt/saic/app/.venv(CVE-2026-102925, CVE-2026-102930, CVE-2026-102937 high, CVE-2026-102938 medium).Cause
The upstream
saicismartapi/saic-python-mqtt-gatewayimage runs a plainpoetry install, so the venv we copy into the all-in-one image also carries the gateway's dev group: pytest, mypy, pylint, ruff, pre-commit and their dependencies, 31 packages at 0.12.0 that never run.virtualenvcomes in through pre-commit. 0.12.0 is still the newest stable gateway, so a tag bump doesn't help.Fix
Bumping
virtualenvwould only move the alerts to the next dev package, so the image now drops the whole dev group:docker/all-in-one/prune-venv.pywalks the installed packages' dependency metadata from the gateway's six runtime dependencies and uninstalls everything they don't need. It fails the build if one of those six isn't installed, which flags an upstream dependency change.import mainfrom the gateway source. That loads 71 of its 72 modules (the 72nd,log_config, only uses the standard library), so a runtime package pruned by mistake fails the build instead of the gateway at startup.The six names mirror
[project].dependenciesin the gateway'spyproject.tomland need comparing on every gateway bump. Upstreamdevelop(0.13.0) already swapsgmqttforaiomqtt; on that bump the prune step fails the build until the list is updated.Testing
Local Docker was down, so CI built the image first. Before that I checked in a Python 3.14 venv holding every package from the gateway's 0.12.0
poetry.lockat its exact version, running the same steps as the Dockerfile:coloramais never installed) and the runtime packages and pip stayimport mainpasses on the pruned venvgmqttremoved, the import check exits 1import mainsucceedsNo .NET or frontend code changed, so the unit test suites aren't affected.
Upstream
SAIC-iSmart-API/saic-python-mqtt-gateway#469 fixes this at the source with
poetry install --only main. Once a gateway release ships it, the prune step has nothing left to remove and can go.🤖 Generated with Claude Code