Skip to content

build!: remove pip from the FOCA image - #592

Merged
uniqueg merged 6 commits into
devfrom
build/556-no-pip
Nov 2, 2026
Merged

uniqueg merged 6 commits into
devfrom
build/556-no-pip

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

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 in base as before. The pip wheel bundled with ensurepip stays, so that python -m venv keeps 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: []).
  • New scripts/check-no-pip.sh: fails if an image has pip (the command, the module or a pip-*.dist-info) or uv. It also fails if docker run itself fails. With --venv, it also checks that python -m venv works. CI runs it:
    • in the integration job, on the FOCA image and on the petstore app image (which is also checked for Gunicorn bytecode);
    • in the scan job, on every Python version (3.11 to 3.15).
  • Petstore example: installs Gunicorn with uv from requirements.txt, which has hashes. The install uses wheels only, --no-deps and --compile-bytecode, followed by uv pip check. Dependabot now updates that file (no Gunicorn majors, as the settings are tested with 26) and the uv image (tag and digest).
  • Docs:
    • getting-started.md gets 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.
    • The 0.20.0 migration guide gets a breaking change, "No pip in the FOCA image", with steps for apps.
    • Smaller updates: the contributing guide (scan steps, petstore pins), plugins.md (RECORD digests depend on the installer), and the petstore README.

Recommended recipe (final stage):

FROM ghcr.io/astral-sh/uv:<version>@sha256:<digest> AS uv

FROM elixircloud/foca:<version>-py3.13@sha256:<digest>
USER root
RUN --mount=from=uv,source=/uv,target=/usr/local/bin/uv \
    --mount=type=bind,source=requirements.txt,target=/tmp/requirements.txt \
    UV_NO_CACHE=1 uv pip install --system --require-hashes --only-binary :all: \
        --no-deps --compile-bytecode -r /tmp/requirements.txt \
    && uv pip check --system
USER 1000

Closes #556

Verification

  • Image built for Python 3.11, 3.12, 3.13, 3.14 and 3.15. Every image passes scripts/check-no-pip.sh --venv. An image built from the dev Dockerfile fails it (/usr/local/bin/pip), and a nonexistent image fails it with exit code 125.
  • Trivy 0.75.0 (the shared action's version), run with --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. Released 0.19.0-py3.13 with the new ignore file: 5 fixable HIGH findings (msgpack, setuptools, urllib3 vendored by pip), as expected.
  • Petstore image (uv) builds. gunicorn --check-config --config python:foca.gunicorn_config "wsgi:create_app()" passes, and uv pip check --system passes. The app-wheel recipe from the docs was built and run with a test wheel.
  • pytest with 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.
  • Also passing: ruff check, ruff format --check, mypy, ast-grep scan, ast-grep test, semgrep scan and the semgrep rule tests, and mkdocs build --strict.
  • CI (run 41453672252, a30a79c): all 28 checks pass (push, publish and the Trivy code-scanning check skip on PRs, as intended); the logs show check-no-pip.sh passing on all 5 scan images and on the FOCA and petstore images in both integration jobs.

Declined review findings

  • Scheduled scan of 0.19.0 (adversarial reviewer, medium): scan.yml scans 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.
  • Deduplicating the uv snippet across getting-started.md, deployment.md and migration-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.
  • No unit tests for 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.
  • Hard-coded .pyc path 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:

  • Add a documented uv-based workflow for installing Python packages in applications derived from the FOCA image.
  • Add an image validation script that detects pip and uv while optionally verifying virtual-environment support.

Bug Fixes:

  • Remove pip and its vendored packages from the final FOCA image to eliminate associated image-scan findings.

Enhancements:

  • Update the petstore image to install hashed, wheel-only dependencies with uv and validate them.
  • Remove obsolete Trivy exceptions for packages previously vendored by pip.

Build:

  • Adjust the Docker build stages to retain pip only while building FOCA and remove it from the runtime image.

CI:

  • Check all FOCA Python-version images and the petstore image for forbidden installers in CI.

Documentation:

  • Document the no-pip breaking change, uv installation recipes, migration steps, and installer-dependent plugin record hashes.

Tests:

  • Add CI coverage for installer absence, virtual-environment creation, and compiled Gunicorn bytecode in the petstore image.

Chores:

  • Configure Dependabot to update petstore Python requirements and its pinned uv image.

uniqueg and others added 6 commits November 2, 2026 13:27
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
@uniqueg uniqueg added this to the v0.20.0 milestone Nov 2, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The 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 installation

sequenceDiagram
    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
Loading

Flow diagram for the no-installer image check

flowchart 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
Loading

File-Level Changes

Change Details Files
Removes pip from the runtime FOCA image while preserving pip only in build contexts and retaining ensurepip’s bundled wheel for virtual-environment creation.
  • Uninstalls setuptools and wheel in the shared base, upgrades pip only in the builder, and uninstalls pip in the final stage.
  • Adds comments documenting the installer boundary and its impact on derived images and vulnerability scans.
docker/Dockerfile
Adds automated enforcement that FOCA-derived images contain neither pip nor uv and that virtual environments remain usable.
  • Introduces a Docker-based checker for pip commands, the pip module, pip dist-info, uv, and Docker execution failures.
  • Runs the checker with venv validation across Python versions and against the FOCA and petstore images; separately verifies Gunicorn bytecode.
scripts/check-no-pip.sh
.github/workflows/ci.yml
Replaces final-stage pip installation with pinned, ephemeral uv installation for the petstore example and documents the derived-image installation contract.
  • Installs hashed, wheel-only requirements with --system, --no-deps, --compile-bytecode, and validates them with uv pip check.
  • Adds a hashed Gunicorn requirements file and Dependabot coverage for petstore Python and uv image dependencies.
  • Documents uv recipes, migration steps, plugin implications, and installer-dependent RECORD digests.
examples/petstore/Dockerfile
examples/petstore/requirements.txt
examples/petstore/.dockerignore
examples/petstore/README.md
.github/dependabot.yml
docs/getting-started.md
docs/deployment.md
docs/migration-0.20.md
docs/contributing/index.md
docs/plugins.md
Removes Trivy exceptions for vulnerabilities found only in pip’s vendored packages.
  • Drops the vendored setuptools, urllib3, and msgpack vulnerability entries while retaining an explicitly empty vulnerability list.
.trivyignore.yaml

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6022851) to head (a30a79c).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #592   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           56        56           
  Lines         7090      7090           
=========================================
  Hits          7090      7090           
Flag Coverage Δ
test_unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 2, 2026 13:40

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@uniqueg
uniqueg merged commit db2c9b5 into dev Nov 2, 2026
90 of 104 checks passed
@uniqueg
uniqueg deleted the build/556-no-pip branch November 2, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build!: remove pip from the FOCA image

1 participant