Repository navigation
build: install locked, hash-checked dependencies - #278
Conversation
Lock all dependencies in uv.lock (exact versions and hashes). The image build exports the locked runtime dependencies with uv (mounted from a digest-pinned uv image, not kept in the image), leaves out a temporary FOCA commit reference (scripts/image_requirements.py now reads the export), and installs them with pip --require-hashes --only-binary :all: --no-deps. CI checks that the lock matches pyproject.toml (uv lock --check in the lint job; uv comes with the dev extra). Dependabot's root entry moves from pip to uv, which updates pyproject.toml and uv.lock together, and the docker entry now also updates the uv image. Document the lock workflow in the development and contributing docs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop handling of a continued FOCA pin line, which uv export never writes (git requirements have no hashes); test empty input. Say in the Dockerfile and docs that the export leaves out the extras. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The lock pins FOCA itself, so a base image with another FOCA release (e.g., a Dependabot patch update of the base image alone) would get the locked FOCA installed on top, silently reverting it. Fail the build instead, and document that the base image and the lock are updated together. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fail closed when the export locks FOCA in another form than foca==<version> (e.g., with a marker or extras), instead of skipping the check of the base image version. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR makes Docker dependency installation reproducible and supply-chain-checked by committing a uv lockfile, exporting frozen hashed runtime requirements, installing only verified wheels, and validating FOCA compatibility with the base image. CI, Dependabot, documentation, and focused script tests are updated to maintain and verify the new workflow. Sequence diagram for locked Docker dependency installationsequenceDiagram
participant DockerBuild
participant UVImage
participant UV
participant RequirementsScript
participant BaseImage
participant Pip
DockerBuild->>UVImage: Mount /uv as /usr/local/bin/uv
DockerBuild->>UV: export --frozen --no-dev --no-emit-project
UV-->>DockerBuild: Hashed locked requirements
DockerBuild->>RequirementsScript: image_requirements.py locked.txt
RequirementsScript->>BaseImage: Read installed FOCA version
alt FOCA matches locked release or commit
RequirementsScript-->>DockerBuild: Filtered requirements
DockerBuild->>Pip: install --require-hashes --only-binary :all: --no-deps
Pip-->>DockerBuild: Verified runtime dependencies installed
else FOCA mismatch
RequirementsScript-->>DockerBuild: Build failure
end
Flow diagram for dependency lock verificationflowchart TD
Change[Change dependency declaration]
Lock[Run uv lock]
Check[CI: uv lock --check]
Build[Docker build]
Install[Hash-checked wheel installation]
Change --> Lock
Lock --> Check
Check -->|pass| Build
Check -->|fail| Stop[Reject build]
Build --> Install
File-Level Changes
Assessment against linked issues
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 #278 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 21 21
Lines 2179 2195 +16
=========================================
+ Hits 2179 2195 +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 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="scripts/image_requirements.py" line_range="98" />
<code_context>
+ raise ValueError(
+ f"FOCA must be locked as 'foca==<version>': '{requirement.strip()}'"
+ )
+ if locked["version"] != installed:
+ raise ValueError(
+ f"The base image has FOCA {installed}, but "
</code_context>
<issue_to_address>
**FOCA updates cannot merge independently**
When dependabot opens separate FOCA patch-update PRs for the lock file and base image, `image_requirements.py` rejects each PR because the locked and installed FOCA versions differ, so the required image build and CI check fail and neither PR can pass the normal merge gate.
Allow the lock-file and base-image updates to pass their required checks when submitted as separate PRs, or otherwise coordinate the updates so each PR can pass.
Also at `.github/dependabot.yml:21`.
</issue_to_address>
### Comment 2
<location path="tests/test_image_requirements.py" line_range="151" />
<code_context>
- assert capsys.readouterr().out == "foca>=0.1\ngunicorn\n"
- pyproject.write_text(f'[project]\ndependencies = ["{PIN}"]\n')
- assert image_requirements.main([str(pyproject)]) == 1
+ monkeypatch.setattr(importlib.metadata, "version", lambda name: "0.18.0")
+ requirements = tmp_path / "requirements.txt"
+ requirements.write_text(FOCA_RELEASE + GUNICORN)
</code_context>
<issue_to_address>
**Wrong FOCA lookup passes**
When `main()` queries a distribution other than `foca`, or no longer uses the metadata lookup, `test_main` accepts any lookup name because its `lambda name: "0.18.0"` returns the same value for every distribution; even if `main()` queried the wrong package or stopped consulting metadata, the assertions would pass, and the image build could check against a version unrelated to installed FOCA.
Make the mock assert that `name == "foca"` (or assert that the mock was called with `"foca"`).
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: scripts/image_requirements.py:98, tests/test_image_requirements.py:151
The image build fails unless the base image has the locked FOCA, so separate Dependabot pull requests for the base image and the lock would each fail; FOCA is bumped by hand in both together. Check that main() looks up the version of FOCA. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
The image now installs only locked, hash-checked Python packages (option A of the design:
uv.lockplus Dependabotuv).uv.locklocks all dependencies (runtime and thedev/docsextras) at exact versions with hashes.uvis added to thedevextra.ghcr.io/astral-sh/uvstage is bind-mounted into the dependency step only (uv is not in the image). The step runsuv export --frozen --no-dev --no-emit-project,scripts/image_requirements.pydrops a temporary FOCA commit reference (it has no hash; the script still checks that the base image has FOCA of that commit), andpip install --require-hashes --only-binary :all: --no-depsinstalls the rest..dockerignoreaddsuv.lockand still excludes everything else,.env*included.scripts/image_requirements.pynow reads theuv exportoutput (requirement entries with indented hash/comment lines) instead ofpyproject.toml. As the lock pins FOCA itself, the build also fails unless the base image has exactly the locked FOCA release (otherwise a base image update alone would be silently reverted by the lock).Check lock file(uv lock --check) in the existinglintjob; no job IDs or names changed.piptouv(same groups and versioning strategy), which updatespyproject.tomlanduv.locktogether; thedockerentry now also updates the uv image. FOCA (focaandelixircloud/foca) is now ignored entirely, not just majors and minors: patch PRs of the two entries would each fail the FOCA check, so FOCA is bumped by hand in both together (Sourcery finding). This also stops digest-only updates of the FOCA base image tag.docs/development.md(how to update the lock), packaging guideline indocs/contributing.md.Dependabot reads its configuration from the default branch, so the Dependabot part can only be verified after
devreachesmain.Closes #125
Verification
pytest -W ignore::DeprecationWarning: 1425 passed, 257 skipped (before mergingdev);tests/test_image_requirements.py: 24 passed, 100% coverage ofscripts/image_requirements.pypre-commit run --all-filesand--hook-stage manual gitleaks-all: passedmkdocs build --strict: passeduv lock --check: passeddocker build: passed; in the image,pip checkfinds no broken requirements, and neither the uv binary nor/tmp/srcis left/service-infoanswersuv lock --check, Test, Chart, Docs, Release readiness, Smoke test, Scan image; CodeQL)Declined review findings
Pin uv in the dev extra to the Dockerfile's uv version (quality, medium): declined. Every PR builds the image (smoke test, scan), which runs the export with the pinned uv, so an incompatible lock fails CI. Exact pins in two Dependabot ecosystems would make their separate PRs fail each other.
Drop
--no-dev(quality, low): kept, as decided for this issue; the Dockerfile and docs now say that the export leaves out the extras by default.Dependabot claim unverified (quality, low): updating
pyproject.tomlanduv.locktogether is documented for theuvecosystem; it can only be checked afterdevreachesmain(see above).Build backend fetched without hashes (adversarial, low):
pip install --no-deps /tmp/srcstill getssetuptools/setuptools-scm(build-system.requires) into an isolated build environment without hashes. This was already the case,uv.lockdoesn't lock build requirements, and they aren't installed into the image; out of scope here (possible follow-up: build the wheel in a builder stage from hashed build requirements).FOCA versions compared as strings, not per PEP 440 (adversarial round 2, low): only false failures are possible (e.g.
0.18vs0.18.0), never a silent mismatch; FOCA versions are always three-part, and the script must stay stdlib-only. Documented in the docstring.Open questions
None.
🤖 Generated with Claude Code