Repository navigation
build: pin image dependencies by hash - #389
Conversation
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
Closes #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
Reviewer's GuideThe 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 installationsequenceDiagram
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
Flow diagram for offline application wheel constructionflowchart 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
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 #389 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 23 23
Lines 2217 2233 +16
=========================================
+ Hits 2217 2233 +16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
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
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 whatuv.locklocks, hash-checked:uv export --frozen --no-dev --no-emit-project) with the uv of the existing digest-pinneduvstage, mounted into the steps that use it (the image contains no uv), and installed withuv pip install --system --require-hashes --only-binary :all: --no-deps.buildstage, with the hash-checkedbuild-systemgroup 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 --systemthen 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 satisfiesbuild-system.requiresand locks the base image's FOCA. The unpinnedPLUGINSstep (local builds only, empty for published images) is the single, conditional exception.uvanddockerentries, 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.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.uv lock --checkin 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, abuildstage with thebuild-systemgroup, 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'sdev; 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
PLUGINSbuild argument, the derived-image recipe (examples/plugin-image/) and.trivyignore.yamlunchanged. Apart from thePLUGINSstep, the image build no longer runs pip.Note
py-tes1.1.4 declarespytestandsphinxas 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, withpip checkclean.tests/smoke/check.shandtests/smoke/plugins.shpass.--ignore-unfixed,.trivyignore.yaml): 0 findings.pytestwith coverage, without Helm: 1154 passed, 1 skipped, plustests/test_config_examples.pywith 30 passed and 2 failed (those 2 need Helm); total coverage 100%.--require-hashes,--no-build-isolation,--network=noneoruv pip check, or a non-emptyPLUGINSdefault, each fails a test.uv lock --check,mkdocs build --strict: pass.Not run locally:
tests/test_chart.pyand 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; thedevpush run after the merge is the first test of the push job with the new build.CI passedis green (17 passed, 3 skipped as intended). That commit changes onlytests/test_image_build.pyand came after the two reviewer rounds on 5f512a7.Review
Full lane:
adversarial-reviewerandquality-reviewer, two rounds. Round 2 found no high or medium findings.Declined review findings
uv pip install.--reinstallwould check them, at the cost of a larger layer. They are trusted through the base image's digest pin, as documented indevelopment.mdand theDockerfile.RUN [...]or downloaders such as curl or wget. None are used, and a parser for them isn't worth it now.test_build_requirements_satisfiedlooks up names as written inpyproject.toml. Another spelling (setuptools_scm) would raise aKeyError, 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:
Bug Fixes:
Enhancements:
Build:
Documentation:
Tests:
Chores: