Repository navigation
build: pin image deps and base by digest - #685
Conversation
The builder stage installs dependencies and build tools with hashes, from files compiled from `pyproject.toml`, and base images are given by digest. CI fails if the pins don't fit, Dependabot updates them, and releases have the files as assets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`packaging` is a build tool too, so it counted as installed and didn't reach `/install`. Test the check of the script, and name the job after what it checks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThis PR makes FOCA image builds reproducible by selecting digest-pinned Python base stages and installing version-specific, hash-verified dependencies generated from pyproject.toml. A uv compilation/check workflow, CI gate, tests, Dependabot configuration, release assets, and documentation keep the Dockerfile, requirement files, supported Python versions, and build matrices synchronized. Sequence diagram for compiling and validating image requirementssequenceDiagram
participant Developer
participant Script as compile-image-requirements.sh
participant UV as uv
participant Project as pyproject.toml
participant Files as docker/requirements
participant CI
Developer->>Script: --upgrade
Script->>Project: Read dependencies and build-system requirements
loop Python versions 3.11 through 3.15
Script->>UV: pip compile --generate-hashes
UV-->>Files: Write py<version>.txt
end
Script->>UV: Compile build.txt with pip and build requirements
UV-->>Files: Write build.txt
CI->>Script: --check
Script->>UV: Recompile requirements without changing hashes
UV-->>Script: Candidate pins
Script-->>CI: Pass if pins fit pyproject.toml
Flow diagram for digest-pinned FOCA image constructionflowchart TD
Select[PY_IMAGE selects one pinned Python stage] --> Builder[Builder stage]
Builder --> Tools[Install hashed build requirements]
Tools --> Deps[Install hashed Python-version requirements]
Deps --> Source[Install FOCA with --no-deps and --no-build-isolation]
Source --> Final[Copy installed files into final 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 #685 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 61 61
Lines 8071 8071
=========================================
Hits 8071 8071
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 found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="docker/Dockerfile" line_range="49" />
<code_context>
+# image), then FOCA alone; files copied here must be in the allowlist of
+# `.dockerignore`; dependencies that are also build tools (`packaging`) must be
+# installed again, for the final image
+COPY docker/requirements/ ./requirements/
+ARG PY_IMAGE
+RUN pip install --no-cache-dir --require-hashes -r requirements/build.txt
</code_context>
<issue_to_address>
**Image builds cannot copy requirements**
Docker excludes the parent `docker/` directory, so the negated requirements-directory pattern does not re-include its files and this `COPY` fails with a missing source; every image build stops.
Re-include `docker/` before `docker/requirements/` in `.dockerignore`.
</issue_to_address>
### Comment 2
<location path="scripts/compile-image-requirements.sh" line_range="52" />
<code_context>
+ }
+ fi
+ # shellcheck disable=SC2086 # `upgrade` is empty or one option
+ uv pip compile --quiet --generate-hashes --no-header ${upgrade} \
+ --output-file "${output}" "$@"
+ if [ "${mode}" = "--check" ]; then
</code_context>
<issue_to_address>
**Failed upgrades leave mixed pins**
When `uv` fails on a later requirements file after earlier files have compiled, each successful loop iteration writes directly to its requirements file; a later `uv pip compile` failure leaves earlier versions upgraded and later versions unchanged, so the failed run leaves a partially updated set in the working tree.
Compile every output into a staging directory and replace the target files only after all compilations succeed.
</issue_to_address>
### Comment 3
<location path="tests/test_image_requirements.py" line_range="85" />
<code_context>
+ for path in REQUIREMENTS.glob("py*.txt")
+ for pin in re.findall(r"^([a-z0-9._-]+)==", path.read_text(), re.M)
+ } & set(pins)
+ assert not shared or "--ignore-installed" in text
+
+
</code_context>
<issue_to_address>
**Shared package misses final image**
When `--ignore-installed` remains somewhere in the Dockerfile but is removed from the runtime requirements install command, pip skips the globally installed shared package when installing runtime requirements to `/install`, so the final image lacks it.
Assert the flag is on the specific runtime requirements install command, or verify that shared packages reach `/install`.
</issue_to_address>Linked issues
#629 build: pin image deps and base by digest · 4 of 6 met · 2 to check by hand
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Use hashed constraints for each supported Python version in the image build, and fail CI when pins no longer fit pyproject.toml. | ✅ Met | The builder installs hashed requirements with --require-hashes, and the Image constraints job runs the check script in the merge gate. |
| 2 | Pin base images by digest. | ✅ Met | Each supported Python base image in docker/Dockerfile is referenced by a SHA-256 digest. |
| 3 | Have Dependabot keep dependency pins and base image digests current without changing the deliberately chosen Python versions. | 👀 Check by hand (external system) | Check Dependabot's first runs to confirm it updates the digests across the Dockerfile stages and the hashed requirement files while leaving the Python tags unchanged. |
| 4 | Publish the constraints as release assets, leaving them in the repository if this needs new workflow permissions. | ✅ Met | The publish job copies each Python-version requirements file into dist with the requested asset name and already has contents: write permission. |
| 5 | Verify that SBOMs are already published; do not add new SBOM work. | 👀 Check by hand (runtime) | The CI and release image build steps retain sbom: true; verify that the resulting published images actually include SBOMs. |
| 6 | Document updating constraints in contributing docs and reusing them in deployment docs. | ✅ Met | The contributing guide documents compiling and updating image requirements, and the deployment guide describes using the release assets. |
Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: docker/Dockerfile:49, scripts/compile-image-requirements.sh:52, tests/test_image_requirements.py:85
A failure on a later file left earlier files upgraded. Also checks that the flag --ignore-installed is on the command installing for the image. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Closes #629.
docker/Dockerfile: oneFROM python:<version>-slim-trixie@sha256:... AS python-<version>-slim-trixiestage per Python version, selected withPY_IMAGE. The builder installs pip and the build tools, then FOCA's dependencies, with--require-hashesfromdocker/requirements/, and FOCA itself without dependencies or build isolation.scripts/compile-image-requirements.sh [--check | --upgrade]: compilesdocker/requirements/py<version>.txtandbuild.txtfrompyproject.tomlwith uv.Image constraints(in the gate): fails if the pins don't fitpyproject.toml. Hashes aren't compared, as pinned versions can gain wheels at any time./docker/requirements, docker digests of the Python images, grouped, with Python versions left alone.foca-image-requirements-py<version>.txt: no new workflow permissions, asPublish releasealready hascontents: write.sbom: truestays on the image builds; verified only, as the issue says..dockerignore: allowlist, with onlydocker/requirements/added; no secrets in the context.Verification
ruff,mypy, strict docs build, fullpytestwith MongoDB, 100% coverage.tests/test_image_requirements.pycovers stages, digests, workflow matrices, hashes and the--checkscript with a stand-in foruv.scripts/compile-image-requirements.sh --checkpasses on the files, and failed by hand after making apyproject.tomlrequirement impossible.pipsequence in a Python 3.13 venv; compiled files for arm64 equal those for x86_64.Integration,Scan image) do that.Not verified until they run: Dependabot on several
FROM python:<tag>@sha256lines and theignorerule for tags like3.13-slim-trixie, and on hashed files without a header. The release step runs only on a tag: per the release rules, this needs a dry run before the next tag, as the release workflow changed. Please watch the first runs.Declined review findings
--only-binarywould avoid that, and it would stop the build for that version. Documented.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Make FOCA image builds reproducible by pinning base images and dependencies, and automate validation and maintenance of those constraints.
New Features:
Bug Fixes:
Enhancements:
CI:
Documentation:
Tests:
Chores: