Skip to content

perf(k8s): seed the uv cache of a runner pod from the image #4814

Description

@dan-petty

Problem or Motivation

#4550 asked for the wheels of uv.lock in the runner image, named by UV_FIND_LINKS, so that uv sync --locked --offline builds the venv of a checkout with no network. The cluster gate (#4691) needs that venv. This does not work. Measured with uv 0.13.6 in python:3.14-slim-trixie on 2026-11-11, with RUN --network=none:

  • UV_FIND_LINKS=<wheel dir> uv sync --locked --offline stops: "Failed to download ast-grep-cli==0.51.0 ... Network connectivity is disabled, but the requested data wasn't found in the cache: https://files.pythonhosted.org/...". uv installs a locked package from the URL in uv.lock and reads only its cache. It does not search the find-links for that package.
  • uv sync --locked --offline --no-index --find-links <wheel dir> resolves again for every platform and fails: "only pywin32{sys_platform == 'win32'}<304 is available".
  • A uv cache in the image, read-only, fails: "Could not acquire lock ... Read-only file system (os error 30)". The root filesystem of a runner pod is read-only.

So the first uv child of an implement Job still starts with an empty cache (30 to 101 s, measured in #4550).

Proposed Solution & Architectural Design

  • The runner image holds a uv cache that uv sync --locked filled at build time, for example at /opt/uv-cache. Measured: 852 MB for the runtime and dev groups.
  • Before the first uv child, the pod copies that cache into its writable cache (UV_CACHE_DIR on the home volume), for example in an init container. Measured: the copy takes 9 s, and then uv sync --locked --offline of a checkout takes 2 s, with no network.
  • The pull request states the growth of the runner image against the bound of 3000000000 bytes in the CI smoke test.

Acceptance:

  • In the runner image, uv sync --locked --offline of a main checkout into an empty venv ends in at most 60 s with no network.
  • The first uv child of an implement Job ends in under 30 s.
  • The runner image stays under its size bound.

Target Subsystem

Kubernetes: the runner image (Dockerfile) and the runner Job template.

Existing Tool Considered

uv's own cache and --offline (https://docs.astral.sh/uv/concepts/cache/). uv has no read-only cache and no second cache. Rejected with the evidence above: UV_FIND_LINKS, and --no-index --find-links. Cost to build: about 30,000 tokens and 2 hours; about 1,000 tokens a month to keep; about 5,000 tokens to fix.

Dependencies

#4550 puts the dependencies in their own image layers first. #4691 needs this item.

Alternatives check of 2026-11-14: not-applicable.
Class: perf, no search.
Tool: none found.

Proposed design

Problem statement

The first uv child of an implement Job starts with an empty cache and takes 30 to 101 s. The root file system of a runner pod is read-only, and uv needs a writable cache. A read-only cache in the image fails with a lock error. UV_FIND_LINKS does not serve the locked URLs, and --no-index --find-links resolves for every platform. This change builds and publishes a uv-seed OCI image with a filled cache and a seed record for a later runner Job. The runner Job mount is deferred to a new issue.

Acceptance criteria

Requirement: Seed image target

The Dockerfile SHALL define a uv-seed target that fills /cache with the cache of uv sync --locked --group dev and writes /seed.json with the uv, Python and uv.lock values.

Scenario: The seed target builds

  • WHEN A person runs docker buildx build --target uv-seed --output type=local,dest=seed-out . at the repository root.
  • THEN The command exits 0, seed-out/seed.json holds the uv, python and uv_lock_sha256 keys, and seed-out/cache holds the uv cache.

Requirement: Offline sync from the seed

The seed cache SHALL let uv sync --locked --group dev --offline build the venv of a checkout with no network.

Scenario: The offline sync from the seed cache

  • WHEN A person copies cache/ from the seed image and runs uv sync --locked --group dev --offline in the runner image with UV_CACHE_DIR set to that copy and --network none.
  • THEN The command exits 0 within 60 seconds and creates the .venv of the checkout.

Requirement: Seed record contract

The seed build SHALL write /seed.json so that _seed_fits accepts it against the runner's uv, Python and uv.lock.

Scenario: The seed record matches the runner

  • WHEN A test calls _seed_fits in src/devops_cli/roadmap/runner_tools.py with a record whose uv and python match the runner and whose uv_lock_sha256 matches the checkout.
  • THEN The function returns true, and it returns false for a record with a different uv, python or uv_lock_sha256.

Requirement: CI seed build

The Runner Image job of ci.yml SHALL build the uv-seed target with the runner and mcp-server targets in one bake call and push nothing.

Scenario: The image job runs on the pull request

  • WHEN The Runner Image job of ci.yml runs on a pull request that changes Dockerfile.
  • THEN The job exits 0, loads devops-cli-uv-seed:local, and its seed smoke step exits 0.

Requirement: Release publishes the seed

The release workflow SHALL publish ghcr.io/dan-petty/devops-cli/uv-seed by digest, smoke-test the digest, attest it and tag it with the release tag and latest.

Scenario: The workflow validators run

  • WHEN CI runs uv run devops ci --check --only actionlint,zizmor.
  • THEN The command exits 0, so release.yml and release-image.yml are valid with the uv-seed matrix entry and the seed smoke step.

Existing Tool Considered

The alternatives check of 2026-11-14 in the issue body gives the verdict not-applicable for class perf and names no tool. The block holds the result. uv is the open tool that covers the need. It fills the cache with uv sync --locked --group dev and reads it with --offline (src/devops_cli/roadmap/runner_tools.py:363). uv lacks a read-only cache and a command that exports its cache as an image. This change adds a uv-seed target to the existing Dockerfile. It builds the target with the docker/bake-action that ci.yml already uses. The change writes no library code; the body records about 30,000 tokens and 2 hours for the rejected --find-links wheelhouse.

Key questions

  • Where does the uv cache seed live?: A separate OCI image, ghcr.io/dan-petty/devops-cli/uv-seed, holds /cache and /seed.json. This item builds and publishes the image. The runner Job mount is deferred to a new issue. (best practice) [sources: src/devops_cli/roadmap/runner_tools.py]
    • Chosen: Separate OCI image. It keeps the runner image unchanged and gives the seed its own release tag.
    • Rejected: Cache in the runner image. It grows the runner image by 852 MB and ties each seed to a runner image build.
    • Rejected: Read-only cache used directly. uv needs a writable cache even with --offline; the body measured the lock failure on a read-only file system.
    • Rejected: Shared PVC or NFS cache. The cluster has no RWX storage, and shared writable state causes flock problems.
  • Which base image, uv and Python versions must the seed match?: _seed_fits compares the uv version, the <major>.<minor> Python and the sha256 of uv.lock. The runner image builds FROM devtools and sets UV_PYTHON=/usr/bin/python3.14, so the seed builds FROM devtools with the same UV_PYTHON. It must not use the uv image of Dockerfile, whose uv can differ from the devtools uv that a Job runs. (best practice) [sources: src/devops_cli/roadmap/runner_tools.py:363]
    • Chosen: Build FROM devtools. It gives the seed the uv and Python 3.14 of the runner image, so _seed_fits matches and Renovate moves both images together.
    • Rejected: Build FROM the uv image. The runner takes its uv from devtools, which can differ, so the seed would not match and the Job would fall back online.
    • Rejected: Build FROM python:3.14-slim-trixie with uv copied in. It adds a second Python and uv pin that must track the devtools image, with no gain.
  • How should the seed image be built and validated?: Add a uv-seed target to the existing Dockerfile before the service stage, so a build with no --target still builds the Service. The build stage is FROM devtools, sets UV_CACHE_DIR=/cache, UV_PYTHON=/usr/bin/python3.14 and UV_COMPILE_BYTECODE=0, copies pyproject.toml, uv.lock and src/, runs uv sync --locked --group dev, and writes /seed.json. The final FROM scratch stage copies /cache and /seed.json. The Runner Image job of ci.yml adds the target to its bake call with push false, and a smoke step copies the seed out and syncs offline. release.yml adds uv-seed to the image matrix and release-image.yml gets a seed smoke step. (best practice) [sources: .github/workflows/ci.yml, .github/workflows/release.yml, .github/workflows/release-image.yml]
    • Chosen: One Dockerfile target and the existing bake call. It reuses the devtools pin, the registry build cache and the one hosted image job.
    • Rejected: A separate Dockerfile and a new CI job. It duplicates the devtools pin and adds a hosted job.
    • Rejected: A Python builder command that writes the seed. It adds code for a build-time file that a shell line writes; the live check proves the record.
  • What runner image size bound applies?: The runner image bound is 7000000000 bytes in .github/workflows/ci.yml and .github/workflows/release-image.yml. The 3000000000-byte bound in the body is stale. This item does not change the runner image, so the bound does not move. [sources: .github/workflows/ci.yml, .github/workflows/release-image.yml]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Moved to new items

#7072

Activity

  1. added
    source/agent
    type/infra
    scope/k8s
    status/new
    value/medium
    effort/medium
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/infra. The perf prefix of the title gives the type.
    • Scope: scope/k8s. The (k8s) scope of the title gives the scope.
    • Priority: P2-Medium. It unblocks #4691 and cuts 30 to 101 s from every implement Job, but it is a CI optimisation, not a production defect.
    • Value: Medium. Each implement Job saves 30 to 101 s of wait time, which compounds across many Jobs per day.
    • Effort: Medium. It needs a Dockerfile change, an init container or copy step, and an image-size check; the author estimates about 2 hours.
    • Related: perf(k8s): put the dependencies in their own image layers #4550, which asks for a different change. Both work on the runner image and uv cache, but #4550 reorders image layers while this candidate adds a pre-built uv cache and a copy step.
  3. added
    priority/p2-medium
    on Nov 11, 2026
  4. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    One more measured fact for this item (2026-11-11, runner image of the #4550 change, a host under build load, empty uv cache): uv run --locked ruff --version in a copy of the checkout took 110 s, and uv printed "Bytecode compiled 19212 files in 1m 11s". The runner image sets UV_COMPILE_BYTECODE=1 for its own build, and every uv child of a Job inherits it (the image had the same variable before #4550). A plan for the first uv child should measure the cost of that compilation against its gain in a Job.

  5. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Class: perf. The check makes no search and no model call for an item of this class.

    Tool: none found

    Checked on 2026-11-14. A person decides what this means for the item. The check changes no label and closes no issue.

  6. added
    status/ready
    and removed
    status/new
    on Nov 15, 2026
  7. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at e5dfddb (see proposed design in issue body).

  8. 6 remaining items

  9. added
    status/new
    and removed
    status/ready
    on Nov 25, 2026
  10. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Owner question: See the first point of Open questions in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  11. added
    status/ready
    and removed
    status/new
    on Nov 25, 2026
  12. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See Moved to new items in the section Proposed design of the body.

  13. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 25, 2026
  14. removed
    status/in-review
    on Nov 25, 2026
  15. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor
  16. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-25 17:09 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/k8ssource/agenttype/infravalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions