Skip to content

feat: add --cache-ref flag for registry-based BuildKit layer cache#518

Open
ccc-uglydawg wants to merge 3 commits intorailwayapp:mainfrom
ccc-uglydawg:feat/cache-ref
Open

feat: add --cache-ref flag for registry-based BuildKit layer cache#518
ccc-uglydawg wants to merge 3 commits intorailwayapp:mainfrom
ccc-uglydawg:feat/cache-ref

Conversation

@ccc-uglydawg
Copy link
Copy Markdown

Summary

Adds a --cache-ref CLI flag that configures BuildKit to use a remote container registry for layer cache import/export (type=registry).

This enables stateless CI/CD workers to share build cache across deploys by storing layers in a container registry, rather than relying on local disk cache that is lost on pod restart.

Usage

railpack build . --cache-ref registry.example.com/cache:latest

Changes

  • cli/build.go: Add --cache-ref string flag, pass to BuildWithBuildkitClientOptions
  • buildkit/build.go: Add CacheRef field, configure CacheImports/CacheExports with type=registry and mode=max

Context

BuildKit natively supports registry-based cache via CacheImports/CacheExports with type=registry. Railpack already supports GHA cache (ImportCache/ExportCache fields with type=gha) but doesn't expose registry cache. This is a small addition that unlocks stateless build workers for multi-tenant platforms where each customer has their own registry.

Adds a --cache-ref CLI flag that configures BuildKit to use a remote
container registry for layer cache import/export (type=registry).

This enables stateless CI/CD workers to share build cache across deploys
by storing layers in the customer's own container registry, rather than
relying on local disk cache that is lost on pod restart.

Usage: railpack build . --cache-ref registry.example.com/cache:latest
@iloveitaly
Copy link
Copy Markdown
Collaborator

@ccc-uglydawg seems like a great improvement! Do you know if builtkit will throw an error if a bad cache registry is provided or should we do some sort of validation there?

cccnv added 2 commits March 16, 2026 13:13
BuildKit needs Docker credentials to push/pull cache from private
registries when using --cache-ref. Attach authprovider to the session
so it reads ~/.docker/config.json (populated by crane auth login or
docker login) for registry authentication.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants