Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,14 @@ jobs:
no-cache-filter = ["mcp-server"]
cache-from = ["type=registry,ref=ghcr.io/${REPOSITORY}/mcp-server:buildcache"]
}

target "uv-seed" {
context = "."
dockerfile = "Dockerfile"
target = "uv-seed"
tags = ["devops-cli-uv-seed:local"]
cache-from = ["type=registry,ref=ghcr.io/${REPOSITORY}/uv-seed:buildcache"]
}
EOF

- name: Build and Load Runner and MCP Server Images
Expand All @@ -635,6 +643,7 @@ jobs:
targets: |
runner
mcp-server
uv-seed
load: true
push: false

Expand Down Expand Up @@ -686,6 +695,42 @@ jobs:
# Resources and Sandboxes). The Service and MCP server scans keep the gate.
exit-code: "0"

- name: Run UV Seed Image Smoke Test
if: steps.image_changes.outputs.changed == 'true'
env:
SEED_IMAGE: devops-cli-uv-seed:local
RUNNER_IMAGE: devops-cli-runner:local
run: |
SEED_DIR="$RUNNER_TEMP/uv-seed-smoke"
rm -rf "$SEED_DIR"
mkdir -p "$SEED_DIR"
ID=$(docker create "$SEED_IMAGE" true)
docker cp "$ID:/seed.json" "$SEED_DIR/seed.json"
docker cp "$ID:/cache" "$SEED_DIR/cache"
docker rm "$ID" > /dev/null
test -f "$SEED_DIR/seed.json"
test -d "$SEED_DIR/cache"
jq -e '.uv and .python and .uv_lock_sha256' "$SEED_DIR/seed.json" > /dev/null
find "$SEED_DIR" ! -type l -exec chmod a+rX {} +
timeout 60 docker run --rm --network none --read-only --tmpfs /tmp --tmpfs /home/devops:mode=1777,exec,size=3g -v "$PWD:/checkout:ro" -v "$SEED_DIR:/opt/uv-seed:ro" --cap-drop ALL --security-opt no-new-privileges --entrypoint sh "$RUNNER_IMAGE" -ec '
mkdir /home/devops/project &&
tar -C /checkout --exclude=./.git --exclude=./.venv --exclude=./node_modules --exclude=./package-lock.json -cf - . | tar -C /home/devops/project -xf - &&
cd /home/devops/project &&
python -c "from pathlib import Path; from devops_cli.roadmap.runner_tools import _seed_fits, UV_SEED_DIR; assert _seed_fits(Path.cwd(), UV_SEED_DIR)" &&
python -m devops_cli.roadmap.runner_tools /home/devops/project &&
uv run --offline ruff --version &&
uv run --offline pytest --version &&
uv run --offline mypy --version
'

- name: Scan UV Seed Image for Vulnerabilities
if: steps.image_changes.outputs.changed == 'true'
timeout-minutes: 4
uses: ./.github/actions/image-scan
with:
image-ref: devops-cli-uv-seed:local
category: trivy-image-uv-seed

# Advisory only: reports newer upstream releases without gating any merge. Scheduled so
# the PyPI round-trip never sits on the pull request critical path.
dependency-freshness:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/release-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,28 @@ jobs:
size=$(docker image inspect "$IMAGE" --format '{{.Size}}')
if [ "$size" -gt 3000000000 ]; then echo "The mcp-server image is $size bytes, over the bound of 3000000000."; exit 1; fi

- name: Run UV Seed Image Smoke Test
if: inputs.image == 'uv-seed'
env:
IMAGE: ghcr.io/${{ github.repository }}/${{ inputs.image }}@${{ needs.build.outputs.digest }}
run: |
SEED_DIR="$RUNNER_TEMP/uv-seed-smoke"
rm -rf "$SEED_DIR"
mkdir -p "$SEED_DIR"
ID=$(docker create "$IMAGE" true)
docker cp "$ID:/seed.json" "$SEED_DIR/seed.json"
docker cp "$ID:/cache" "$SEED_DIR/cache"
docker rm "$ID" > /dev/null
test -f "$SEED_DIR/seed.json"
test -d "$SEED_DIR/cache"
jq -e --arg lock "$(sha256sum uv.lock | cut -d' ' -f1)" '.uv and .python == "3.14" and .uv_lock_sha256 == $lock' "$SEED_DIR/seed.json" > /dev/null
DEVTOOLS_IMAGE=$(sed -n -E 's/^FROM ([^ ]+) AS devtools$/\1/p' Dockerfile)
test -n "$DEVTOOLS_IMAGE"
EXPECTED_UV=$(jq -r .uv "$SEED_DIR/seed.json")
docker pull --quiet "$DEVTOOLS_IMAGE" > /dev/null
find "$SEED_DIR" ! -type l -exec chmod a+rX {} +
timeout 60 docker run --rm --network none -e UV_PYTHON=/usr/bin/python3.14 -e UV_PYTHON_DOWNLOADS=never -e UV_COMPILE_BYTECODE=0 -e UV_MALWARE_CHECK=0 -e EXPECTED_UV="$EXPECTED_UV" -v "$PWD:/checkout:ro" -v "$SEED_DIR:/seed:ro" --entrypoint python3.14 "$DEVTOOLS_IMAGE" -c 'import os, pathlib, shutil, subprocess; assert subprocess.check_output(["uv", "--version"], text=True).split()[1] == os.environ["EXPECTED_UV"]; pathlib.Path("/tmp/project").mkdir(); shutil.copytree("/checkout", "/tmp/project", ignore=shutil.ignore_patterns(".git", ".venv", "node_modules", "package-lock.json"), dirs_exist_ok=True); shutil.copytree("/seed/cache", "/tmp/uv-cache", symlinks=True, dirs_exist_ok=True); env = {**os.environ, "UV_CACHE_DIR": "/tmp/uv-cache"}; subprocess.run(["uv", "sync", "--locked", "--group", "dev", "--offline"], cwd="/tmp/project", env=env, check=True); [subprocess.run(["uv", "run", "--offline", t, "--version"], cwd="/tmp/project", env=env, check=True) for t in ("ruff", "pytest", "mypy")]'

# The runner scan only reports (scan-exit-code 0): the runner builds FROM the devtools image,
# and the findings of its tool binaries go to code scanning and stop no build (SECURITY.md,
# Dedicated Development Resources and Sandboxes). The Service and MCP server scans keep the
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ jobs:
no-cache-filters: mcp-server
category: trivy-image-mcp-server
scan-exit-code: "1"
# Pre-populated uv cache seed for runner Job checkouts (#4814); FROM scratch holds no
# devtools binaries.
- image: uv-seed
title: UV Seed
description: Pre-populated uv cache seed for runner Job checkouts
no-cache-filters: ""
category: trivy-image-uv-seed
scan-exit-code: "1"
# A called workflow can only keep or lower these permissions; each of its jobs asks for less.
permissions:
contents: read
Expand Down
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,29 @@ USER 1000:1000

ENTRYPOINT ["devops"]

# The uv cache seed for runner Job checkouts (#4814). Built FROM `devtools` so it carries the
# exact uv and Python 3.14 of `runner`, populates `/cache` with `uv sync --locked --group dev`
# matching `bootstrap_checkout` in `src/devops_cli/roadmap/runner_tools.py`, and records
# `/seed.json` for `_seed_fits`. Placed before `service` so a default build still builds Service.
FROM devtools AS uv-seed-build

WORKDIR /app
# hadolint ignore=DL3064
ENV UV_CACHE_DIR=/cache \
UV_PYTHON=/usr/bin/python3.14 \
UV_PYTHON_DOWNLOADS=never \
UV_COMPILE_BYTECODE=0

COPY pyproject.toml uv.lock ./
COPY src/ ./src/
RUN uv sync --locked --group dev && \
/usr/bin/python3.14 -c 'import hashlib, json, pathlib, subprocess, sys; pathlib.Path("/seed.json").write_text(json.dumps({"uv": subprocess.check_output(["uv", "--version"], text=True).split()[1], "python": f"{sys.version_info.major}.{sys.version_info.minor}", "uv_lock_sha256": hashlib.sha256(pathlib.Path("uv.lock").read_bytes()).hexdigest()}) + "\n", encoding="utf-8")' && \
find /cache /seed.json ! -type l -exec chmod a+rX {} +

FROM scratch AS uv-seed
COPY --from=uv-seed-build /cache /cache
COPY --from=uv-seed-build /seed.json /seed.json

# The layers of the Service and MCP server images that a change of `src/` keeps: git, the Node
# runtime, gh and OpenSpec, and the venv of the runtime requirements. gh comes from the devtools
# image, and OpenSpec from the `openspec` stage. The image holds no uv, curl or pip.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-25
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Design

## Decisions

- **Build `uv-seed-build` from `devtools` and copy into `FROM scratch AS uv-seed` before `service`.**
- `_seed_fits` in `src/devops_cli/roadmap/runner_tools.py` compares `uv --version`, `<major>.<minor>` of Python, and the sha256 of `uv.lock`. Building `uv-seed-build` from `devtools` with `UV_PYTHON=/usr/bin/python3.14`, `UV_PYTHON_DOWNLOADS=never`, `UV_CACHE_DIR=/cache`, and `UV_COMPILE_BYTECODE=0` guarantees the cached wheels and `uv` layout match the `runner` stage. Placing both stages before `service` ensures a default `docker build .` still builds `service`. Making `/cache` and `/seed.json` world-readable (`chmod -R a+rX`) lets non-root uid `1000` copy them in smoke tests and runner pods.
- **Write `/seed.json` inline with `/usr/bin/python3.14` in the `uv-seed-build` `RUN` step.**
- Computing the `uv` version token, Python `<major>.<minor>`, and `uv.lock` sha256 with `/usr/bin/python3.14` uses the exact field names and derivation logic of `_seed_fits` with no extra helper script.
- **Extract and verify the `uv-seed` image with `docker create <image> true` and `docker cp`.**
- A `FROM scratch` image holds no shell binary, so `docker create ... true` + `docker cp` extracts `/seed.json` and `/cache` reliably across Docker and Podman. In `ci.yml`, `Run UV Seed Image Smoke Test` mounts the extracted seed at `/opt/uv-seed:ro` in `devops-cli-runner:local` with `--network none` and runs `_seed_fits`, `python -m devops_cli.roadmap.runner_tools`, and `uv run --offline` within 60 s. In `release-image.yml`, `Verify` pulls the `devtools` image pinned in `Dockerfile` first, then verifies `/seed.json` and runs offline `uv sync --locked --group dev --offline` with `--network none` within 60 s.
- **Keep registry cache and Trivy scan parity.**
- `ci.yml` reads `ghcr.io/${REPOSITORY}/uv-seed:buildcache` and writes none; `release-image.yml` reads and writes `uv-seed:buildcache`. Both scan `uv-seed` under category `trivy-image-uv-seed` with exit code `1` because `uv-seed` holds no `devtools` Go binaries.
- **Exempt Docker's reserved `scratch` base in `_unpinned_dockerfile_images`.**
- `scratch` has no registry manifest or `@sha256:` digest, so `tests/invariants/test_service_image.py` skips `scratch` while continuing to require `@sha256:` or an earlier stage name on every other `FROM`.

## Rejected alternatives

- **Embedding `/opt/uv-cache` in `runner`**: Adds ~852 MB to the runner image and couples runner image updates to lockfile wheel cache bloat.
- **Using `FROM ghcr.io/astral-sh/uv` in `uv-seed-build`**: Can diverge from the `uv` version installed in `devtools`, causing `_seed_fits` to fall back online.
- **Running `docker run` directly on `uv-seed`**: Impossible on `FROM scratch` without bundled binaries; extraction via `docker create` and `docker cp` tests the exact OCI payload.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Proposal: #4814

## Why

The first `uv` child of an implement Job starts with an empty cache and takes 30 to 101 s (#4814). A read-only cache inside the image fails because `uv` acquires a lock on the cache directory even with `--offline`, and a wheelhouse with `UV_FIND_LINKS` or `--no-index --find-links` does not serve locked URLs or fails platform resolution. #6517 added `bootstrap_checkout` and `_seed_fits` in `src/devops_cli/roadmap/runner_tools.py` to copy `/opt/uv-seed/cache` when `/opt/uv-seed/seed.json` matches the Job's `uv`, Python minor version, and `uv.lock` hash, then run `uv sync --locked --group dev --offline` with `UV_MALWARE_CHECK=0`. No image target, CI check, or release publish exists yet for `uv-seed`.

## What Changes

- Add stages `uv-seed-build` (`FROM devtools`) and `uv-seed` (`FROM scratch`) to `Dockerfile` before `service`, running `uv sync --locked --group dev` with `UV_CACHE_DIR=/cache` and `UV_PYTHON=/usr/bin/python3.14`, writing `/seed.json` (`uv`, `python`, `uv_lock_sha256`), and copying `/cache` and `/seed.json` into `uv-seed`.
- Extend the `Runner Image` (`mcp-server-image`) job of `.github/workflows/ci.yml` to build `uv-seed` alongside `runner` and `mcp-server` in one `docker/bake-action` call without pushing, run a seed smoke test verifying `seed.json` and an offline `--network none` sync against `devops-cli-runner:local`, and scan `devops-cli-uv-seed:local` with `.github/actions/image-scan`.
- Add `uv-seed` to the `image` matrix of `.github/workflows/release.yml` and add a seed smoke step to `.github/workflows/release-image.yml` so releases push, verify, attest, and tag `ghcr.io/dan-petty/devops-cli/uv-seed`.
- Update image invariants in `tests/invariants/test_service_image.py`, `tests/invariants/test_runner_image.py`, and the run-step allowlist in `tests/commands/test_ci.py`.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `container-image-layers`: Add the `uv-seed` OCI image build target, CI bake smoke/scan validation, and release publish/verify requirements.

## Impact

- Build & CI: `Dockerfile`, `.github/workflows/ci.yml`, `.github/workflows/release.yml`, `.github/workflows/release-image.yml`
- Tests: `tests/invariants/test_service_image.py`, `tests/invariants/test_runner_image.py`, `tests/commands/test_ci.py`
- Cluster runner mount in `k8s/devops/` remains deferred to #7072.

## Feasibility

Confirmed against `Dockerfile`, `.github/workflows/ci.yml`, `.github/workflows/release.yml`, `.github/workflows/release-image.yml`, and `src/devops_cli/roadmap/runner_tools.py`. Both `_seed_fits` and `bootstrap_checkout` are already merged (#6517), `Dockerfile` pins `devtools` (`uv` and `/usr/bin/python3.14`), and `mcp-server-image` uses `docker/bake-action`. `tests/invariants/test_service_image.py` must allow `FROM scratch` for `uv-seed`, and `tests/invariants/test_runner_image.py` + `tests/commands/test_ci.py` must include the new `uv-seed` bake target and smoke step.

## Existing Tool Considered

Adopted `uv` cache and `--offline` mode (`https://docs.astral.sh/uv/concepts/cache/`) together with the existing `docker/bake-action` and `.github/actions/image-scan` composite action. Alternatives (`UV_FIND_LINKS` wheelhouse, `--no-index --find-links`, direct read-only cache mount, in-runner cache copy, separate Dockerfile/job) were rejected in #4814 because they either fail `uv` resolution/locking or bloat `runner` by 852 MB.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## ADDED Requirements

### Requirement: The uv-seed image pre-populates the dev dependency cache
The `Dockerfile` SHALL define a `uv-seed-build` stage `FROM devtools` before `service` that runs `uv sync --locked --group dev` with `UV_CACHE_DIR=/cache` and `UV_PYTHON=/usr/bin/python3.14` and writes `/seed.json` matching `_seed_fits`, plus a `uv-seed` stage `FROM scratch` holding `/cache` and `/seed.json`.

#### Scenario: The seed target builds and a default build still builds service
- **WHEN** `uv run devops ci --check --only hadolint` runs after adding `uv-seed-build` and `uv-seed` before `service` in `Dockerfile`
- **THEN** `hadolint` exits 0 and reports no warning or error for `Dockerfile`, and `test_service_dockerfile_base_images_pinned_by_digest` passes with `FROM scratch AS uv-seed`

### Requirement: CI validates the uv-seed target
The `mcp-server-image` job of `.github/workflows/ci.yml` SHALL bake `uv-seed` with `cache-from` pointing at `uv-seed:buildcache` and `push: false`, verify `seed.json` and an offline `--network none` sync against `devops-cli-runner:local`, and scan `devops-cli-uv-seed:local` under `trivy-image-uv-seed`.

#### Scenario: CI workflow checks accept the uv-seed bake and smoke steps
- **WHEN** `uv run devops ci --check --only actionlint,zizmor` runs after editing `.github/workflows/ci.yml`
- **THEN** the command exits 0 and reports no finding in `.github/workflows/ci.yml`

### Requirement: Release publishes and verifies the uv-seed image
`.github/workflows/release.yml` SHALL include `uv-seed` in its `image` matrix (`category: trivy-image-uv-seed`, `scan-exit-code: "1"`), and `.github/workflows/release-image.yml` SHALL smoke-test `seed.json` and offline `--network none` sync in `verify` when `inputs.image == 'uv-seed'`.

#### Scenario: Release workflow checks accept the uv-seed matrix entry and smoke test
- **WHEN** `uv run devops ci --check --only actionlint,zizmor` runs after editing `.github/workflows/release.yml` and `.github/workflows/release-image.yml`
- **THEN** the command exits 0 and reports no finding in `.github/workflows/release.yml` or `.github/workflows/release-image.yml`
26 changes: 26 additions & 0 deletions openspec/changes/archive/2026-11-25-4814-uv-seed-image/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Tasks

## 1. Update image and CI invariants first

Kind: other. Reads: `tests/invariants/test_runner_image.py`, `tests/invariants/test_service_image.py`, `tests/commands/test_ci.py`, `Dockerfile`, `.github/workflows/ci.yml`. Changes: `tests/invariants/test_runner_image.py`, `tests/invariants/test_service_image.py`, `tests/commands/test_ci.py`.

- [x] 1.1 Update `tests/invariants/test_runner_image.py` so `test_the_pull_request_check_builds_the_runner_image_and_pushes_nothing` requires `uv-seed` in `docker/bake-action` targets, `target "uv-seed"` and its `cache-from` ref in `Write Docker Bake Definition`, and `Run UV Seed Image Smoke Test` plus `Scan UV Seed Image for Vulnerabilities` in `mcp-server-image`; verify it fails against `origin/main` before workflow edits
- Verification: `$ uv run pytest tests/invariants/test_runner_image.py`
- [x] 1.2 Update `_unpinned_dockerfile_images` in `tests/invariants/test_service_image.py` to permit Docker's reserved `scratch` base while keeping digest pinning enforced for all other images, and add `("mcp-server-image", "Run UV Seed Image Smoke Test")` to the run-step allowlist in `tests/commands/test_ci.py`
- Verification: `$ uv run pytest tests/invariants/test_service_image.py tests/commands/test_ci.py`

## 2. Add uv-seed target and CI/release wiring

Kind: other. Reads: `Dockerfile`, `.github/workflows/ci.yml`, `.github/workflows/release.yml`, `.github/workflows/release-image.yml`. Changes: `Dockerfile`, `.github/workflows/ci.yml`, `.github/workflows/release.yml`, `.github/workflows/release-image.yml`.

- [x] 2.1 Add `uv-seed-build` (`FROM devtools`) and `uv-seed` (`FROM scratch`) stages before `service` in `Dockerfile` running `uv sync --locked --group dev` into `/cache` and writing `/seed.json` matching `_seed_fits`
- Verification: `$ uv run devops ci --check --only hadolint`
- [x] 2.2 Update `.github/workflows/ci.yml`, `.github/workflows/release.yml`, and `.github/workflows/release-image.yml` to bake, smoke-test offline (`--network none`), scan (`trivy-image-uv-seed`), attest, and tag `uv-seed`
- Verification: `$ uv run devops ci --check --only actionlint,zizmor`

## 3. Full local validation

Kind: other. Reads: `Dockerfile`, `.github/workflows/ci.yml`, `.github/workflows/release.yml`, `.github/workflows/release-image.yml`, `tests/invariants/test_runner_image.py`, `tests/invariants/test_service_image.py`, `tests/commands/test_ci.py`. Changes: none.

- [x] 3.1 Run the affected pytest suites and non-test CI gates (`hadolint`, `actionlint`, `zizmor`, `test-tree`, `openspec`, etc.) after archiving the change
- Verification: `$ uv run devops ci --check --skip test --force`
Loading