Skip to content

build: install locked, hash-checked dependencies - #278

Merged
uniqueg merged 6 commits into
devfrom
build/125-locked-deps
Oct 28, 2026
Merged

uniqueg merged 6 commits into
devfrom
build/125-locked-deps

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

The image now installs only locked, hash-checked Python packages (option A of the design: uv.lock plus Dependabot uv).

  • Lock: uv.lock locks all dependencies (runtime and the dev/docs extras) at exact versions with hashes. uv is added to the dev extra.
  • Image: a digest-pinned ghcr.io/astral-sh/uv stage is bind-mounted into the dependency step only (uv is not in the image). The step runs uv export --frozen --no-dev --no-emit-project, scripts/image_requirements.py drops a temporary FOCA commit reference (it has no hash; the script still checks that the base image has FOCA of that commit), and pip install --require-hashes --only-binary :all: --no-deps installs the rest. .dockerignore adds uv.lock and still excludes everything else, .env* included.
  • scripts/image_requirements.py now reads the uv export output (requirement entries with indented hash/comment lines) instead of pyproject.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).
  • CI: new step Check lock file (uv lock --check) in the existing lint job; no job IDs or names changed.
  • Dependabot: the root entry moves from pip to uv (same groups and versioning strategy), which updates pyproject.toml and uv.lock together; the docker entry now also updates the uv image. FOCA (foca and elixircloud/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: new "Dependencies" section in docs/development.md (how to update the lock), packaging guideline in docs/contributing.md.

Dependabot reads its configuration from the default branch, so the Dependabot part can only be verified after dev reaches main.

Closes #125

Verification

  • pytest -W ignore::DeprecationWarning: 1425 passed, 257 skipped (before merging dev); tests/test_image_requirements.py: 24 passed, 100% coverage of scripts/image_requirements.py
  • pre-commit run --all-files and --hook-stage manual gitleaks-all: passed
  • mkdocs build --strict: passed
  • uv lock --check: passed
  • docker build: passed; in the image, pip check finds no broken requirements, and neither the uv binary nor /tmp/src is left
  • Docker Compose (own project and port): app and MongoDB healthy, Swagger UI 200, /service-info answers
  • CI: all checks passed (Lint incl. uv 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.toml and uv.lock together is documented for the uv ecosystem; it can only be checked after dev reaches main (see above).

  • Build backend fetched without hashes (adversarial, low): pip install --no-deps /tmp/src still gets setuptools/setuptools-scm (build-system.requires) into an isolated build environment without hashes. This was already the case, uv.lock doesn'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.18 vs 0.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

uniqueg and others added 5 commits October 28, 2026 18:22
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]>
@uniqueg uniqueg added this to the v1.0.0-rc1 milestone Oct 28, 2026
@uniqueg uniqueg added type: security Related to security type: dependencies Related to managing upstream dependencies labels Oct 28, 2026
@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

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

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

Flow diagram for dependency lock verification

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

File-Level Changes

Change Details Files
Introduces a committed uv lockfile and updates dependency automation and validation to keep declared dependencies, exact versions, and hashes synchronized.
  • Adds uv.lock covering runtime, development, and documentation dependencies.
  • Adds uv to the dev extra and checks lock consistency with uv lock --check in CI.
  • Moves Dependabot dependency updates from pip to uv and coordinates Docker image updates.
  • Documents lock maintenance, image dependency behavior, and packaging guidance.
uv.lock
pyproject.toml
.github/workflows/ci.yml
.github/dependabot.yml
docs/development.md
docs/contributing.md
Changes the Docker build to install only frozen, hash-verified binary dependencies exported from the lockfile, using a digest-pinned uv tool stage that is mounted only during dependency installation.
  • Exports frozen runtime requirements with uv export --frozen --no-dev --no-emit-project.
  • Filters the temporary FOCA commit reference before installing with pip.
  • Uses --require-hashes, --only-binary :all:, and --no-deps for locked dependency installation.
  • Keeps uv, source files, and temporary build artifacts out of the final image and updates .dockerignore.
Dockerfile
.dockerignore
Reworks image requirement processing around uv's hashed requirements format and enforces that the base image's FOCA matches the lock or temporary commit pin.
  • Parses requirement entries together with indented hash and comment continuation lines.
  • Removes only validated FOCA commit references while preserving locked FOCA releases and their hashes.
  • Rejects unsupported FOCA requirement forms and mismatched base-image versions.
  • Expands unit and subprocess coverage for parsing, filtering, validation, and error cases.
scripts/image_requirements.py
tests/test_image_requirements.py

Assessment against linked issues

Issue Objective Addressed Explanation
#125 Install only exact, hash-checked runtime dependencies in the image, while keeping version ranges in the package dependency declarations. ✅
#125 Fail CI when the lock file is out of date with the dependency declarations. ✅
#125 Have Dependabot update the locked dependencies and document how to maintain the lock file. ✅

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 Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

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

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.
📢 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 October 28, 2026 19:52

@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 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


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

Comment thread scripts/image_requirements.py Resolved
Comment thread tests/test_image_requirements.py Resolved
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]>

@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.

Sourcery assessment

Approved.

@uniqueg
uniqueg merged commit d20fb6d into dev Oct 28, 2026
20 checks passed
@uniqueg
uniqueg deleted the build/125-locked-deps branch October 28, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: dependencies Related to managing upstream dependencies type: security Related to security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build: install locked, hash-checked dependencies

1 participant