Repository navigation
feat(oci): add pull-through cache for OCI registries - #441
Conversation
Image pulls from CI and workstations repeatedly fetch the same layers from Docker Hub and other registries, which is slow and runs into pull rate limits. The oci strategy serves the Distribution API from cachew so those pulls hit the local and tiered caches instead. Blobs and digest-addressed manifests are immutable, so they are checked against their digest before caching and never revalidated. Tag manifests are mutable and vary on Accept, so they are keyed on a normalised Accept header and revalidated with a HEAD request on Docker-Content-Digest after tag-ttl. Docker Hub does not count HEADs against rate limits. A stale tag is served when the upstream is unavailable or rate limiting. Clients reach a registry either at /oci/<registry>/v2/ (containerd with override_path) or on a dedicated hostname at /v2/, because Docker and Podman cannot use a path prefix. Upstream auth uses go-containerregistry's token transport with the strategy's own credentials, one per repository scope. Client credentials are stripped and never forwarded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The unit tests use a hand-written fake registry, which only proves cachew agrees with our own reading of the Distribution spec. This test runs the reference registry in Docker and pulls through cachew with go-containerregistry's client, checking every blob digest. It covers anonymous and htpasswd upstreams, tag updates, and serving from cache after the registry is gone. It requires Docker and fails without it, so CI cannot pass it silently. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 653763df1d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
passThrough now returns a failed response copy, and ServeHTTP logs it. Remove the field comments on ociRequest. Co-authored-by: Chain <492cad42391b4a5c84d831885f468e6f1699c0a8c39241f1c002235ece37ee69@buzz> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Elizabeth Worstell <worstell@squareup.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f5f0fad1a8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Co-authored-by: Chain <492cad42391b4a5c84d831885f468e6f1699c0a8c39241f1c002235ece37ee69@buzz> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Elizabeth Worstell <worstell@squareup.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 716ae885b1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| CacheKey(o.blobKey). | ||
| Transform(o.transform). | ||
| Verify(o.verifier). | ||
| ParallelFetch(int64(config.BlobChunkSizeMB)<<20, int(config.BlobConcurrency)) |
There was a problem hiding this comment.
Handle zero-length blobs before parallel range fetching
When a valid OCI blob has size zero, enabling ParallelFetch makes the cold miss request Range: bytes=0-...; a compliant registry answers that unsatisfiable range with 416 and Content-Range: bytes */0. The handler only invokes the parallel reader for a 206 response, so it forwards the 416 instead of returning and caching the valid empty blob, making images or artifacts containing zero-length descriptors impossible to pull through this strategy.
Useful? React with 👍 / 👎.
Image pulls from CI and workstations fetch the same layers from Docker Hub and other registries over and over. That is slow, and it runs into pull rate limits. This adds an
ocistrategy that serves the OCI Distribution API from cachew, so those pulls hit the local and tiered caches instead. It builds on the handler groundwork from #438 and the request coalescing from #440.The changes, one commit each:
ocistrategy, configured with one block per registry./oci/<registry>/v2/, which suits containerd withoverride_path, or on a dedicated hostname at/v2/, which Docker and Podman need because they cannot use a path prefix./v2/is answered locally. Pushes and any other write method get a 405.library/namespace, are applied before the name and reference are validated.ParallelFetch, with configurable chunk size and concurrency (32 MB × 4 by default). Registry redirects to a CDN are followed on the server side.Acceptheader. Aftertag-ttl(default 5m) they are revalidated with a HEAD request onDocker-Content-Digest, since the cache replaces upstream ETags. Docker Hub does not count HEADs against rate limits. A stale tag is served when the upstream is unavailable or rate limiting.username/password, or anonymous access when they are unset. One transport is kept per repository scope. ClientAuthorizationandCookieheaders are removed and never forwarded.ocisection with a Docker Hub example and setup notes for containerd and Docker.registry:3, Distribution 3.1.2) running in Docker. It pulls through cachew with go-containerregistry's client and checks every blob digest. It covers anonymous and htpasswd upstreams, tag updates, and serving from cache after the registry container is removed. It runs under theintegrationtag in CI and fails rather than skips when Docker is missing.New dependencies:
golang.org/x/cryptowas already an indirect dependency and is now direct, because the integration test uses bcrypt to create the htpasswd file.Known limitations:
tags/listresponses, theLinkheader for the next page still uses the upstream path. A path-prefixed client that follows it will go around cachew.🤖 Generated with Claude Code