Skip to content

perf(k8s): put the dependencies in their own image layers - #4872

Merged
dan-petty merged 3 commits into
mainfrom
perf/4550-dependency-image-layers
Nov 12, 2026
Merged

dan-petty merged 3 commits into
mainfrom
perf/4550-dependency-image-layers

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Each release changed 1.2 GB of the Service image layers and 1.7 GB of the runner image layers, so each node pulled them again. Now a release changes only the project layer, about 32 MB.

A new lock stage exports the requirements of uv.lock without the project, so a version bump keeps the cache of the dependency stages. runner-deps and service-deps hold every dependency layer. The final stages, which CI and the release never cache, add only the apt upgrade and the project, in one COPY --parents. Each uv install mounts the uv cache, so no layer holds it.

The wheel directory with UV_FIND_LINKS is left out: uv sync --locked --offline does not read it for a locked package. #4814 takes the offline venv.

Closes #4550
Change: openspec/changes/archive/2026-11-11-4550-put-the-dependencies-in-their-own/

@dan-petty dan-petty added type/infra Type infra: the build, CI, images or cluster scope/k8s Kubernetes commands, Helm charts, pods, services, and policies labels Nov 12, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Measurements (local BuildKit v0.34.2, 2026-11-11)

Each build used --no-cache-filter service or --no-cache-filter runner, as CI and the release do. Build A is main. Build B adds a one-line change of src/. Build C adds the same change and sets version 9.9.9 in pyproject.toml and uv.lock, as a release does. The sizes are the uncompressed sizes of docker history for the layer digests (docker image inspect) that A lacks.

Image Change Before (main) After
Service src/ only (B) 1,218.7 MB of 1,361.6 MB 31.8 MB
Service src/ and version (C) not measured 31.8 MB
Runner src/ only (B) 1,746.9 MB of 1,933.0 MB 31.9 MB
Runner src/ and version (C) not measured 31.9 MB

On main, the re-run COPY of the unchanged node binary in the service stage also gave a new 126.9 MB layer, so the dependency layers must sit in cached stages.

Image sizes (docker image inspect): runner 2,427,882,016 bytes (2,498,283,337 on main, bound 3,000,000,000), Service 1.74 GB (no change).

Checks run on the images

  • Service: /healthz answers ok in the container, id -u is 1000, gh, git, openspec and devops --version run, the read-only probe of the smoke test passes, devops_cli loads from /app/.venv/, lizard imports, and the image holds no uv, gcc, curl, pip or pytest.
  • Runner: python -m devops_cli.roadmap.runner_tools gives "All 28 runner tools run at their pins", the read-only probe passes, the image holds no gcc, npm or pip, and uv run --locked ruff --version in a copy of the checkout on a read-only root prints ruff 0.16.8.
  • mcp-server (builds on runner): kubectl v1.37.2, helm v4.3.1 and devops --version run as user 1000.
  • The old image build ran no uv malware check either: uv sync -vv next to pyproject.toml and uv pip sync -vv sent no request to OSV.

Tests

devops ci fail-to-pass --base origin/main: 15 of the changed tests fail on the base (the new stages do not exist there) and pass on the branch. The 11 test files that read the Dockerfile pass (297 tests).

Steps after the merge

No manifest, ConfigMap or Secret changes. After the first release with this change rolls out:

  1. On a node that holds the previous release, check the pull time of the next runner Job: kubectl -n devops get events --field-selector reason=Pulled -o custom-columns=TIME:.lastTimestamp,MSG:.message | grep runner. The target is a container start in 10 s or less.
  2. After 7 days, take the median from Job create to container start of the runner Jobs. The target is 10 s or less.

The first uv child of a Job and the offline venv stay with #4814.

The lock stage exports the runtime and dev requirements of uv.lock without
the project, so a release keeps the dependency layers. The runner and
Service images build on cached stages that hold every dependency, and their
final stages add only the apt upgrade and the project.
@dan-petty

Copy link
Copy Markdown
Owner Author

Checks after the second push

31 of 32 checks pass, the three required checks included. The fixes of the second push: the lock files now go to /lock/ (bandit B108 flagged the /tmp/ literals of the tests), tests/invariants/test_image_layers.py is listed in docs/TESTING.md, and the tiktoken test names the deps stage.

Service Image Tests (shard 5 of 6) fails on tests/invariants/test_hermetic_floor.py::test_a_support_helper_called_outside_pytest_writes_nothing, a test that #4857 added. Its child runs python -I, which ignores the PYTHONPATH that gives pytest to the Service image test run, so the child stops with ModuleNotFoundError: No module named 'pytest'. The Service image held no pytest before this change either. #4857 changed no image content, so its pull request did not run this job. #4891 holds the fix. This pull request stays a draft until that check passes.

@dan-petty
dan-petty marked this pull request as ready for review November 12, 2026 04:04
@dan-petty
dan-petty merged commit 48dc866 into main Nov 12, 2026
32 checks passed
@dan-petty
dan-petty deleted the perf/4550-dependency-image-layers branch November 12, 2026 04:04
@dan-petty

Copy link
Copy Markdown
Owner Author

Review findings after the merge

This pull request merged before the fix of its review finding was pushed, so the finding is now issue #4928.

Finding Severity Result
All image builds share the GitHub Actions cache scope buildkit, and each cache-to replaces the cache index of the build before it. So a release does not find the dependency stages of every image, and the statement of k8s/README.md that a release keeps those layers is not sure. major Confirmed. Filed as #4928.

Evidence of the check:

  • git grep -n "type=gha" .github/workflows on main gives 19 entries, and none names scope=.
  • The Docker documentation of the cache backend (section Scope) gives the default scope buildkit and says that each build of an image replaces the cache of the build before it.
  • The cache list of main holds one index for all image builds, index-buildkit-1-f921bd05#907. The repository cache holds 12,577,035,846 bytes, against a limit of 10 GB.
  • A test that each type=gha entry names scope= with the target of its build fails on main with 19 entries (devops ci fail-to-pass --base origin/main: "failed on base: tests.invariants.test_image_layers::test_each_image_build_keeps_its_cache_in_the_scope_of_its_image") and passes with the scopes set. fix(ci): give each image build its own cache scope #4928 holds the fix as written.

Live step that stays with a person: the 10 s container start check of #4550 needs the release after the #4928 fix, because until then a release can build the dependency stages again.

dan-petty pushed a commit that referenced this pull request Nov 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.116.0](v0.115.0...v0.116.0)
(2026-11-12)


### Features

* **gh:** name the gh groups issue, run, label and secret
([#4923](#4923))
([2dd4c97](2dd4c97))


### Bug Fixes

* **ci:** set job timeouts from the measured run times
([#4892](#4892))
([e26dde5](e26dde5))
* **design:** check the design test bound and source hex values
([#4922](#4922))
([e2c1a5a](e2c1a5a))
* **k8s:** check the credential sync context as a kubeconfig name
([#4916](#4916))
([8797c88](8797c88))
* **roadmap:** bound the stage gate returns and start no return in a
drain ([#4925](#4925))
([77eed38](77eed38))
* **roadmap:** count each implement outcome once with its repo
([#4903](#4903))
([c17f71f](c17f71f))
* **roadmap:** refine looks again at a wait that older rules set
([#4919](#4919))
([e6f7cb9](e6f7cb9))


### Performance Improvements

* **k8s:** put the dependencies in their own image layers
([#4872](#4872))
([48dc866](48dc866))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/k8s Kubernetes commands, Helm charts, pods, services, and policies type/infra Type infra: the build, CI, images or cluster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(k8s): put the dependencies in their own image layers

1 participant