Skip to content

build: pin image dependencies by hash - #389

Merged
uniqueg merged 5 commits into
devfrom
build/365-hash-pins
Nov 2, 2026
Merged

uniqueg merged 5 commits into
devfrom
build/365-hash-pins

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

The image build installed the runtime dependencies from the version ranges of pyproject.toml (scripts/image_requirements.py), so rebuilds of the same commit or tag could get other versions than the image that was scanned and smoke-tested. Now it installs what uv.lock locks, hash-checked:

  • Runtime dependencies: exported from the lock (uv export --frozen --no-dev --no-emit-project) with the uv of the existing digest-pinned uv stage, mounted into the steps that use it (the image contains no uv), and installed with uv pip install --system --require-hashes --only-binary :all: --no-deps.
  • App: built as a wheel in a separate build stage, with the hash-checked build-system group in a uv venv, offline, without build isolation and without network (uv build --wheel --offline --no-build-isolation, RUN --network=none), then installed offline without dependencies; uv pip check --system then checks the result.
  • scripts/image_requirements.py: ported from cloud-registry (byte-identical): filters the uv export, drops a temporary FOCA commit pin (no hash), and fails unless the base image has the locked FOCA release. Its tests are ported too.
  • tests/test_image_build.py (new): every uv command is hash-checked or offline, no pip runs, uv is mounted and never copied, the offline steps have no network, the lock satisfies build-system.requires and locks the base image's FOCA. The unpinned PLUGINS step (local builds only, empty for published images) is the single, conditional exception.
  • Dependabot: new FOCA versions are ignored in both the uv and docker entries, because the build fails unless base image and lock agree, so separate PRs would each fail. They are bumped by hand together, as in cloud-registry. Digest updates of the base image's tag still come.
  • Docs: development.md (the image build, trust of base-image packages via the digest, BuildKit, FOCA pins), plugin-images.md, and an image note in the upgrade guide's section for the next release.
  • Stale lock: "CI fails if the lock is out of date" is already met by uv lock --check in the lint job.

Closes #365

Consistency with cloud-registry and trs-filer

Same structure as cloud-registry's Dockerfile: export from the lock, image_requirements.py, a build stage with the build-system group, an offline wheel build. There is one deliberate difference: proTES installs with uv instead of pip (uv venv, uv pip install, uv build), because the FOCA image is dropping pip (foca#556, merged on FOCA's dev; FOCA 0.20.0 isn't released). trs-filer's #216 hash-checks build requirements in CI only, as proTES already did.

Overlap with #336

pip removal follows in #336 (adopt the FOCA image without pip). This PR stays on FOCA 0.19 and leaves pip, the PLUGINS build argument, the derived-image recipe (examples/plugin-image/) and .trivyignore.yaml unchanged. Apart from the PLUGINS step, the image build no longer runs pip.

Note

py-tes 1.1.4 declares pytest and sphinx as runtime dependencies, so they are in the image, now at locked versions. This predates the change.

Verification

  • docker build (BuildKit): passes. The image has no uv and nothing left in /tmp, and an earlier build's package versions equal the lock's runtime export, with pip check clean.
  • Smoke tests on own ports (Compose project of its own): tests/smoke/check.sh and tests/smoke/plugins.sh pass.
  • Trivy 0.69.3 on the local image (CRITICAL/HIGH, --ignore-unfixed, .trivyignore.yaml): 0 findings.
  • pytest with coverage, without Helm: 1154 passed, 1 skipped, plus tests/test_config_examples.py with 30 passed and 2 failed (those 2 need Helm); total coverage 100%.
  • Image build tests mutation-checked: dropping --require-hashes, --no-build-isolation, --network=none or uv pip check, or a non-empty PLUGINS default, each fails a test.
  • ruff check and format, mypy, ast-grep, uv lock --check, mkdocs build --strict: pass.

Not run locally: tests/test_chart.py and the 2 chart examples (Helm isn't installed here), and the tests against a real MongoDB (no app code changed). CI runs them. semgrep couldn't run directly; the push hook and CI's pre-commit run it.

CI: all checks pass, including CI passed, Chart, Smoke test, Scan image and Test (MongoDB 7.0). The image pushes are skipped on pull requests; the dev push run after the merge is the first test of the push job with the new build.

  • CI on the head commit d938be5: CI passed is green (17 passed, 3 skipped as intended). That commit changes only tests/test_image_build.py and came after the two reviewer rounds on 5f512a7.

Review

Full lane: adversarial-reviewer and quality-reviewer, two rounds. Round 2 found no high or medium findings.

Declined review findings

  • Packages that the base image already has at the locked version (e.g., FOCA) aren't re-checked against the lock's hashes by uv pip install. --reinstall would check them, at the cost of a larger layer. They are trusted through the base image's digest pin, as documented in development.md and the Dockerfile.
  • The tests don't detect exec-form RUN [...] or downloaders such as curl or wget. None are used, and a parser for them isn't worth it now.
  • Aligning cloud-registry's build with uv is out of scope here.
  • test_build_requirements_satisfied looks up names as written in pyproject.toml. Another spelling (setuptools_scm) would raise a KeyError, which still fails the test.

🤖 Generated with Claude Code

https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG

Summary by Sourcery

Make image builds reproducible by installing the application and its dependencies from the hash-verified uv lock while building the application offline.

New Features:

  • Install runtime and application build dependencies from the frozen uv lock with hash verification and offline wheel-based builds.
  • Build the application in a dedicated stage and install the resulting wheel without bundling uv or build requirements in the final image.

Bug Fixes:

  • Ensure rebuilds of the same commit use the exact dependency versions that were reviewed and scanned.
  • Fail image builds when the base image's FOCA version does not match the locked dependency or required temporary commit pin.

Enhancements:

  • Add image-build validation covering hash-checked installs, offline operation, uv mounting, locked build requirements, and the conditional unpinned plugin exception.
  • Update the dependency filtering utility to process uv-exported requirements while preserving hashes and validating FOCA compatibility.

Build:

  • Update the Docker image build to use BuildKit mounts, locked uv exports, a separate wheel-build stage, and offline installation checks.

Documentation:

  • Document locked image dependencies, BuildKit requirements, base-image trust, FOCA coordination, and the unchanged local plugin-build exception.
  • Explain the image dependency pinning change in the upgrade guide and plugin-image documentation.

Tests:

  • Add comprehensive Dockerfile policy tests and expand image-requirement tests for hashed exports and FOCA version validation.

Chores:

  • Configure Dependabot to defer FOCA version updates until the base image and lock can be updated together while retaining digest updates.

uniqueg and others added 4 commits November 2, 2026 13:10
The image build installed the runtime dependencies from the version
ranges of pyproject.toml, so rebuilds of the same commit could get
other versions. It now exports them from uv.lock with the digest-pinned
uv image (mounted, not copied) and installs them with
uv pip install --system --require-hashes --only-binary :all: --no-deps.
The app is built as a wheel in a build stage, with the hash-checked
build-system group, offline and without build isolation, then
installed offline. scripts/image_requirements.py now filters the uv
export (as in cloud-registry) and fails unless the base image has the
locked FOCA. tests/test_image_build.py checks that every install is
hash-checked or offline; only the PLUGINS argument for local builds
stays unpinned.

Refs #365

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
The image build now fails unless the base image has the locked FOCA,
so separate Dependabot pull requests for the foca package and the
base image would each fail, also for patch releases. FOCA is updated
by hand, in both places together, as in cloud-registry.

Refs #365

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Review findings: as nothing is resolved (--no-deps), uv pip check now
checks the installed packages; tests require it, refuse uv venv --seed
and anything after the PLUGINS conditional, and check that the lock
satisfies build-system.requires and has the base image's FOCA.
Dependabot still proposes digest updates of the base image tag. The
docs say that packages of the base image are trusted through its
digest and that the build needs BuildKit; the FOCA pin paragraph keeps
its wrapping.

Refs #365

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
@uniqueg uniqueg added this to the v1.0.0-rc1 milestone Nov 2, 2026
@uniqueg uniqueg added type: delivery Related to packaging, deployment etc. type: security Related to security labels Nov 2, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The image build now derives runtime and build dependencies from uv.lock, installs them with hash verification or offline-only paths, builds and installs the application wheel without network access, and validates lock/base-image FOCA consistency. Supporting script logic, structural image-build tests, dependency automation, and documentation were updated to enforce and explain the reproducibility guarantees.

Sequence diagram for hash-checked and offline image installation

sequenceDiagram
    participant BuildKit
    participant UV as uv stage
    participant Lock as uv.lock
    participant Base as FOCA base image
    participant Image as Final image

    BuildKit->>UV: Mount digest-pinned uv
    BuildKit->>Lock: uv export --frozen --no-dev --no-emit-project
    Lock-->>BuildKit: Locked runtime requirements with hashes
    BuildKit->>Base: Run image_requirements.py
    Base-->>BuildKit: Validate installed FOCA
    BuildKit->>Base: uv pip install --system --require-hashes
    BuildKit->>Image: Install application wheel --offline --no-index
    BuildKit->>Image: uv pip check --system
Loading

Flow diagram for offline application wheel construction

flowchart TD
    Source[Application source]
    Lock[uv.lock build-system group]
    Env[Build virtual environment]
    Wheel[Application wheel]
    Image[Final image]

    Lock -->|hash-checked install| Env
    Source -->|uv build --wheel --offline --no-build-isolation| Wheel
    Env --> Wheel
    Wheel -->|offline install without dependencies| Image
Loading

File-Level Changes

Change Details Files
Reworked the Docker image build to install and build exclusively from hash-verified, locked dependencies while keeping uv out of the final image.
  • Added a digest-pinned uv tool stage mounted only into consuming build steps.
  • Exported runtime and build-system requirements from uv.lock with frozen, hash-checked, wheel-only installs.
  • Built the application wheel in an isolated stage using locked build requirements, offline and without build isolation or network access.
  • Installed the wheel offline and added uv pip check validation.
  • Preserved the conditional, intentionally unpinned PLUGINS installation as the sole exception.
Dockerfile
tests/test_image_build.py
tests/test_build.py
.dockerignore
Updated requirement filtering to process uv export output and enforce consistency between the lock and the FOCA base image.
  • Removed the pyproject.toml parser and added parsing of multiline uv-export entries, including hashes and comments.
  • Dropped temporary FOCA commit references while retaining their locked dependency entries.
  • Rejected mismatched or non-plain locked FOCA release requirements and verified the installed base-image version.
  • Expanded unit coverage for commit pins, release mismatches, malformed forms, continuation lines, and empty input.
scripts/image_requirements.py
tests/test_image_requirements.py
Adjusted dependency automation and documentation to describe reproducible image builds and coordinated FOCA updates.
  • Made Dependabot ignore FOCA version updates in both uv and Docker while retaining digest updates.
  • Documented BuildKit requirements, lock/hash behavior, digest trust for base-image packages, plugin exceptions, and coordinated FOCA bumps.
  • Added upgrade guidance describing the image dependency pinning behavior.
.github/dependabot.yml
docs/development.md
docs/plugin-images.md
docs/upgrading.md

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

@read-the-docs-community

read-the-docs-community Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 proTES | 🛠️ Build #35587663 | 📁 Comparing d938be5 against latest (105c6f5)

  🔍 Preview build  

3 files changed
± development/index.html
± plugin-images/index.html
± upgrading/index.html

@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 (105c6f5) to head (d938be5).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #389   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         2217      2233   +16     
=========================================
+ Hits          2217      2233   +16     

☔ 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 17:01

@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 found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="Dockerfile" line_range="108" />
<code_context>
+  && uv pip check --system \
+  && rm -rf /tmp/src /tmp/uv-*.lock

 ## Plugins for local builds (e.g., `--build-arg PLUGINS="<distribution>==<version>"`,
 ## pip requirement specifiers without spaces, separated by spaces; recorded
</code_context>
<issue_to_address>
**Unpinned local plugins**

The issue asks for the image build to install only pinned, hash-checked distributions. The runtime and build dependencies meet this, but local builds with `PLUGINS` set still install packages from the index without hash checks.
</issue_to_address>

### Comment 2
<location path="tests/test_image_build.py" line_range="210-213" />
<code_context>
+
+def test_runtime_requirements_without_build_requirements() -> None:
+    """The runtime requirements of the image leave out the build group."""
+    packages = _pinned(_export("--no-dev"))
+    assert "connexion" in packages
+    assert "setuptools" not in packages
+    assert "setuptools-scm" not in packages
+
+
</code_context>
<issue_to_address>
**Build dependencies enter runtime image**

When the Dockerfile’s runtime export starts including dependency groups, `test_runtime_requirements_without_build_requirements` calls `_export("--no-dev")` directly at line 210, so its assertions check that helper’s fixed selection rather than the Dockerfile’s export command. Changing the Dockerfile to export `--all-groups` still passes this test while adding build and development dependencies to the image.

Check the export arguments used by the Dockerfile, or otherwise verify its actual runtime export excludes those groups.
</issue_to_address>

### Comment 3
<location path="tests/test_image_build.py" line_range="319-321" />
<code_context>
+        if "PLUGINS" in run
+    ]
+    assert len(runs) == 1, runs
+    assert re.match(r'if \[ -n "\$\{PLUGINS\}" \]; then\s', runs[0]), runs[0]
+    # Nothing runs after the conditional
+    assert runs[0].rstrip().endswith("fi"), runs[0]
</code_context>
<issue_to_address>
**Local plugin installs silently stop**

When the body of the conditional `PLUGINS` step is replaced with a no-op, `test_plugins_only_on_request` checks at lines 318-321 only that the `RUN` starts with the conditional and ends with `fi`; replacing its body with a no-op still passes, leaving local `PLUGINS` builds without their requested plugins.

Assert that the conditional body contains the expected plugin installation and dependency check.
</issue_to_address>

Linked issues

#365 build: pin image dependencies by hash · 1 of 2 met

# Requirement Status Notes
1 The image build installs only pinned, hash-checked distributions. 🟡 Partly met The runtime and build dependencies use hash-checked lock exports, and the app wheel is installed offline, but local builds with PLUGINS set still run an unpinned pip install.
2 CI fails if the lock is out of date with pyproject.toml. ✅ Met The CI workflow runs uv lock --check.

Sourcery assessment

Approval pending. 3 findings to address first.

Blocking findings: Dockerfile:108, tests/test_image_build.py:213, tests/test_image_build.py:321


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

Comment thread Dockerfile Resolved
Comment thread tests/test_image_build.py Resolved
Comment thread tests/test_image_build.py Resolved
Automated review findings: the tests of the exports now rest on what
the Dockerfile selects, and the PLUGINS step must really install the
plugins and check the result.

Refs #365

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
@uniqueg
uniqueg merged commit 6781d7f into dev Nov 2, 2026
32 checks passed
@uniqueg
uniqueg deleted the build/365-hash-pins branch November 2, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: delivery Related to packaging, deployment etc. type: security Related to security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build: pin image dependencies by hash

1 participant