A Buildkite plugin for caching Docker images across builds using various registry providers (ECR and GAR currently supported).
This plugin speeds up your Docker builds by caching images between pipeline runs. Instead of rebuilding the same Docker image every time, it stores built images in ECR or Google Artifact Registry and reuses them when nothing has changed.
The plugin will check if a cached version of your image already exists. If it does, it pulls that instead of rebuilding. If not, it builds the image and saves it for next time. It automatically creates the necessary repositories in your registry if they don't exist.
Cache keys are generated based on your Dockerfile content and build context, so the cache automatically invalidates when you make changes to your code or build configuration.
Also see the Docker Buildkite Plugin for running pipeline steps in Docker containers.
The following pipeline will cache Docker builds in Amazon ECR.
steps:
- label: "π³ Build with ECR cache"
command: "echo 'Building with cache'"
plugins:
- docker-cache#v1.0.0:
provider: ecr
image: my-app
ecr:
region: us-east-1
account-id: "123456789012"
The following pipeline will cache Docker builds in Google Artifact Registry:
steps:
- label: "π³ Build with GAR cache"
command: "echo 'Building with cache'"
plugins:
- docker-cache#v1.0.0:
provider: gar
image: my-app
gar:
project: my-gcp-project
region: us
You can control how the cache is used with different strategies:
Pulls the complete cached image if available, builds from scratch if not:
steps:
- label: "π³ Artifact strategy"
plugins:
- docker-cache#v1.0.0:
provider: ecr
image: my-app
strategy: artifact
ecr:
region: us-east-1
account-id: "123456789012"
Uses layer caching during the build process:
steps:
- label: "π³ Build strategy"
plugins:
- docker-cache#v1.0.0:
provider: ecr
image: my-app
strategy: build
ecr:
region: us-east-1
account-id: "123456789012"
Tries artifact strategy first, falls back to build strategy if pull fails:
steps:
- label: "π³ Hybrid strategy"
plugins:
- docker-cache#v1.0.0:
provider: ecr
image: my-app
strategy: hybrid
ecr:
region: us-east-1
account-id: "123456789012"
For multi-stage Dockerfiles, you can specify the target stage:
steps:
- label: "π³ Multi-stage build"
plugins:
- docker-cache#v1.0.0:
provider: ecr
image: my-app
target: production
ecr:
region: us-east-1
account-id: "123456789012"
You can pass build arguments to Docker:
steps:
- label: "π³ Build with args"
plugins:
- docker-cache#v1.0.0:
provider: ecr
image: my-app
build-args:
- NODE_ENV=production
- API_URL=https://api.example.com
ecr:
region: us-east-1
account-id: "123456789012"
Which registry provider to use for caching: ecr
or gar
.
Name of your Docker image.
Example: my-app
How to use the cache:
artifact
: Pull complete cached image if available, build from scratch if notbuild
: Use layer caching during build processhybrid
: Try artifact strategy first, fall back to build strategy if pull fails
Default: hybrid
Path to your Dockerfile.
Default: Dockerfile
Inline Dockerfile content instead of reading from a file.
Docker build context path.
Default: .
Target stage for multi-stage builds.
Build arguments to pass to Docker.
Example: ["NODE_ENV=production", "VERSION=1.0.0"]
Additional docker build arguments as a single string.
Example: "--network=host --build-arg CUSTOM_ARG=value"
Build secrets to pass to Docker (requires BuildKit).
Example: ["id=mysecret,src=/local/secret", "id=mypassword"]
Additional cache sources for Docker build.
Example: ["my-base-image:latest"]
Skip pulling from cache (useful for testing).
Default: false
Whether to save cache after build.
Default: true
Whether to restore cache before build.
Default: true
Maximum age in days for cached images.
Default: 30
Custom cache key. If not provided, automatically generated from Dockerfile content and build context.
Example: ["my-key", "v1.0"]
or "custom-key"
Environment variable name for exporting the final image reference.
Default: BUILDKITE_PLUGIN_DOCKER_IMAGE
Enable verbose logging.
Default: false
Custom tag for the cached image.
Default: Generated from git commit or pipeline context
When using provider: ecr
, these options are available:
AWS region for ECR registry.
Example: us-east-1
AWS account ID (12 digits).
Example: 123456789012
Custom ECR registry URL. If not provided, will be constructed from account ID and region.
Example: 123456789012.dkr.ecr.us-east-1.amazonaws.com
When using provider: gar
, these options are available:
Google Cloud project ID.
Example: my-gcp-project
GAR region.
Valid values: us
, europe
, asia
, or specific regional endpoints like us-central1-docker.pkg.dev
Example: us
Artifact Registry repository name. If not provided, defaults to the image name.
Example: docker
(for repository name, results in full path like us-docker.pkg.dev/project/docker/image
)
The plugin handles ECR authentication automatically using your existing AWS credentials. Make sure your build environment has AWS credentials configured through:
- IAM roles (recommended for EC2/ECS)
- AWS credentials file
- Environment variables (
AWS_ACCESS_KEY_ID
,AWS_SECRET_ACCESS_KEY
)
Required permissions:
sts:GetCallerIdentity
ecr:GetAuthorizationToken
ecr:DescribeRepositories
ecr:CreateRepository
ecr:BatchGetImage
ecr:GetDownloadUrlForLayer
ecr:BatchCheckLayerAvailability
ecr:PutImage
ecr:InitiateLayerUpload
ecr:UploadLayerPart
ecr:CompleteLayerUpload
The plugin uses gcloud for GAR authentication with your existing Google Cloud credentials. Make sure your build environment has Google Cloud credentials configured through:
- Service account keys
- Workload Identity (recommended for GKE)
- Application Default Credentials
Required permissions:
artifactregistry.repositories.get
artifactregistry.repositories.create
artifactregistry.docker.images.get
artifactregistry.docker.images.push
artifactregistry.docker.images.pull
Cache keys are automatically generated from:
- Dockerfile content hash (primary)
- Build context hash (if different from Dockerfile location)
- Build arguments
- Target stage (for multi-stage builds)
This ensures the cache is invalidated whenever anything that affects the build changes.
To run testing, shellchecks and plugin linting use bk run
with the Buildkite CLI.
bk run
Or if you want to run just the tests, you can use the docker Plugin Tester:
docker run --rm -ti -v "${PWD}":/plugin buildkite/plugin-tester:latest
MIT (see LICENSE)