Repository navigation
build!: remove pip from the FOCA image - #592
Conversation
pip vendors copies of urllib3, msgpack and setuptools, which image scans report in every image built on FOCA, although only pip uses them, and only at build time. The final stage now uninstalls pip; the builder stage keeps it (upgraded) to install FOCA. The pip wheel bundled with ensurepip stays, as Trivy doesn't report it, so that python -m venv keeps working in build stages of derived images. Drop the ignore entries for the packages vendored by pip, and check in CI that the FOCA image has no pip (command, module or dist-info) and that the petstore image has neither uv nor pip. BREAKING CHANGE: images built on the FOCA image can no longer run pip install; they install their packages with uv instead. Refs #556 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
The FOCA image has no pip: the petstore image installs Gunicorn with uv from a stage pinned by digest, mounted into the install step only, from a requirements file with hashes (wheels only, no dependencies, compiled to bytecode). Dependabot updates the requirements file and the uv image, but not to Gunicorn 27, as FOCA's settings are tested with Gunicorn 26. Refs #556 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Show how images built on FOCA install Python packages without pip: with uv from a stage pinned by digest, without copying it into the image, for app dependencies, the app itself and plugins. Add the removal of pip to the migration guide of 0.20.0. Refs #556 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Move the image check into scripts/check-no-pip.sh, which fails if an image has pip (command, module or dist-info) or uv, and also when docker run itself fails; with --venv, it checks that python -m venv still works. The scan job runs it for every Python version, the integration job for the FOCA and petstore images, the latter also checking that Gunicorn was compiled to bytecode. Refs #556 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Check the installed packages with uv pip check after the --no-deps install, in the petstore image and the documented recipe; show how to install an app's own wheel (no hashes, no index); point the petstore README and the contributing guide to the uv pins; note that RECORD digests depend on the installer; clarify the migration guide's intro. Refs #556 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Show the app-wheel step as root and with uv pip check, link the migration guide to the recipe, move the petstore maintenance note in the contributing guide to its own paragraph, and rewrap comments. Refs #556 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Reviewer's GuideThe PR changes FOCA’s final image contract to exclude pip and uv, keeps installation tooling confined to build stages, and uses CI checks, a uv-based petstore example, documentation, dependency automation, and stricter scan configuration to enforce and explain the new workflow. Sequence diagram for uv-based derived image installationsequenceDiagram
participant UV as uv build stage
participant Docker as Docker build
participant FOCA as FOCA base image
participant App as Application image
Docker->>FOCA: FROM FOCA image
Docker->>UV: Mount /uv from pinned uv image
Docker->>App: uv pip install --system --require-hashes --only-binary :all: --no-deps --compile-bytecode
Docker->>App: uv pip check --system
Note over App: uv is mounted only during the build
Note over App: Final image contains neither uv nor pip
Flow diagram for the no-installer image checkflowchart TD
START[check-no-pip.sh image] --> RUN[docker run as root]
RUN --> INSPECT{pip, pip module, pip dist-info, or uv found?}
INSPECT -->|yes| FAIL[Fail image check]
INSPECT -->|no| DOCKER{docker run succeeded?}
DOCKER -->|no| FAIL
DOCKER -->|yes| VENV{--venv specified?}
VENV -->|yes| TEST[Run python -m venv and pip --version]
VENV -->|no| PASS[Pass]
TEST --> PASS
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #592 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 56 56
Lines 7090 7090
=========================================
Hits 7090 7090
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Linked issues
#556 build!: remove pip from the FOCA image · 5 of 5 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | The final FOCA image contains no pip, and an image test checks this. | ✅ Met | The final Docker stage uninstalls pip. CI runs scripts/check-no-pip.sh --venv on each Python-version image; the check looks for pip commands, the module, and pip dist-info, and verifies that python -m venv still works. |
| 2 | Trivy does not flag the pip wheel bundled with ensurepip. | ✅ Met | The CI scan job scans each Python-version image, and the PR verification reports the scans pass with no Python findings. |
| 3 | FOCA's .trivyignore.yaml has no entries for packages vendored by pip, and the image scan passes. |
✅ Met | The pip-vendored entries are removed and the file now has vulnerabilities: []; CI scans the built image. |
| 4 | Document installing packages on FOCA-based images with uv, including derived images that add plugins. | ✅ Met | The getting-started guide documents the digest-pinned uv stage, mounted only during installation, and covers dependencies, app wheels, and plugins; the deployment example also uses uv. |
| 5 | Document the pip removal as a breaking change in the 0.20.0 migration guide. | ✅ Met | The guide identifies the breaking change and provides migration steps and a uv installation example. |
Sourcery assessment
Approval pending. The security scan did not finish.
Summary
Removes pip from the final stage of the FOCA image, so that its vendored copies of urllib3, msgpack and setuptools (reported by image scans of every image built on FOCA) are gone. Images built on FOCA install their packages with uv from a stage pinned by digest, which is not copied into the image.
docker/Dockerfile: the final stage uninstalls pip. The builder stage keeps it, upgraded to>=26.2, to install FOCA. setuptools and wheel are removed inbaseas before. The pip wheel bundled withensurepipstays, so thatpython -m venvkeeps working, for example in build stages of derived images. Trivy 0.75.0 does not report it on any version, including pip 24.0 on 3.11 and 25.0.1 on 3.12..trivyignore.yaml: the pip-vendored entries are dropped (vulnerabilities: []).scripts/check-no-pip.sh: fails if an image has pip (the command, the module or apip-*.dist-info) or uv. It also fails ifdocker runitself fails. With--venv, it also checks thatpython -m venvworks. CI runs it:requirements.txt, which has hashes. The install uses wheels only,--no-depsand--compile-bytecode, followed byuv pip check. Dependabot now updates that file (no Gunicorn majors, as the settings are tested with 26) and the uv image (tag and digest).getting-started.mdgets a new section, "Installing Python packages": the uv recipe, the flags explained, the app's own wheel, and plugins.deployment.md: the Gunicorn example now uses uv.plugins.md(RECORDdigests depend on the installer), and the petstore README.Recommended recipe (final stage):
Closes #556
Verification
scripts/check-no-pip.sh --venv. An image built from thedevDockerfile fails it (/usr/local/bin/pip), and a nonexistent image fails it with exit code 125.--ignorefile .trivyignore.yaml --severity CRITICAL,HIGH --ignore-unfixed --exit-code 1: passes for all 5 images and for the petstore image. A full scan lists no pip, setuptools or wheel packages and no Python findings. Released0.19.0-py3.13with the new ignore file: 5 fixable HIGH findings (msgpack, setuptools, urllib3 vendored by pip), as expected.gunicorn --check-config --config python:foca.gunicorn_config "wsgi:create_app()"passes, anduv pip check --systempasses. The app-wheel recipe from the docs was built and run with a test wheel.pytestwith coverage, against a private MongoDB 7.0 container on port 12345 in its own network namespace: 3290 passed, 3 skipped, 100% coverage. One test (test_no_personal_email_addresses) failed in that container only, because it has no git; it passes locally.ruff check,ruff format --check,mypy,ast-grep scan,ast-grep test, semgrep scan and the semgrep rule tests, andmkdocs build --strict.check-no-pip.shpassing on all 5 scan images and on the FOCA and petstore images in both integration jobs.Declined review findings
scan.ymlscans the released 0.19.0 images with dev's.trivyignore.yaml. Once the ignore entries are dropped, that weekly scan reports the pip-vendored findings again, 5 of them fixable HIGH, until 0.20.0 is released. The entries are dropped anyway, as the agreed design of build!: remove pip from the FOCA image #556 asks (and its acceptance criteria). 0.20.0 images contain none of these packages, and releasing 0.20.0 ends the failures. If the weekly failures are unwanted until then, the alternative is to restore the entries in a one-line follow-up and drop them after the release.getting-started.md,deployment.mdandmigration-0.20.md(quality reviewer, medium): each page shows a complete Dockerfile for its own context, and the migration guide pins 0.20.0 on purpose. The explanation of the flags is only in getting-started.scripts/check-no-pip.sh(quality reviewer, low): the pass and failure paths were checked by hand (see Verification), and CI runs the script on every image..pycpath in the petstore check (quality reviewer, low): this matches the layout of the official Python images, which the example is built on.🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Summary by Sourcery
Remove pip from the FOCA runtime image and transition derived application images to verified, digest-pinned uv-based package installation.
New Features:
Bug Fixes:
Enhancements:
Build:
CI:
Documentation:
Tests:
Chores: