Overview
Now that you have a Blacksmith runner, you can take advantage of our NVMe-backed cache to persist your Docker layers across CI runs. To enable Docker layer caching, you’ll use two Blacksmith actions in your GitHub Actions workflow file. This allows your Docker builds to reuse cached docker layers from previous runs, and only rebuild the layers that have changed. Our customers have reported 2x to 40x improvements in build times due to this change.Diff Example
When using
useblacksmith/build-push-action
without useblacksmith/setup-docker-builder
, the runner will use the default builder configured in your environment. However, this builder will not leverage Blacksmith’s Docker layer caching nor will it report Docker analytics to the Blacksmith control plane.Basics
Not using the docker/build-push-action
?
If you’re not using the docker/build-push-action
in your workflow, but are instead calling Docker commands directly or are using the docker/bake-action
, you can still cache your Docker layers by setting up a Blacksmith builder before interacting with Docker.
This builder will be hydrated with the layer cache from previous runs and will commit the updated layer cache at the end of the job.
Diff Example
How it works
Under the hood, your Docker layer caches are stored on sticky disks.How caching works in Docker builds
When you do a Docker build, each step in your Dockerfile creates a new layer in your Docker image. Without caching, when you make a change to your Dockerfile, Docker will rebuild all the layers in the image, even if only one layer has changed. This can be slow, especially for large Docker images. However, with caching, Docker can reuse layers from previous builds instead of rebuilding them from scratch. Docker will only rebuild from the layer that has changed and use the cached layers for the rest of the image.How Blacksmith runners cache your Docker layers
When a GitHub Action job uses the Blacksmith Docker actions, the process works as follows:- The
setup-docker-builder
action configures a buildx builder with access to cached layers from previous runs - The
build-push-action
then uses this builder to run your Docker build, leveraging the cached layers instead of rebuilding everything from scratch - At the end of the job, the runner commits its changes to the layer cache for future runs. This commit only runs if no other steps in the job have failed or been canceled.
Multi-platform builds
Current approach: Using a matrix strategy
You can build multi-platform Docker images on Blacksmith by using GitHub Actions matrix strategy. This approach leverages Blacksmith’s native runners for each architecture to avoid the performance penalties of emulation.Diff Example
blacksmith-8vcpu-ubuntu-2204
and the arm64 build runs on blacksmith-8vcpu-ubuntu-2204-arm
. Each image is pushed with its own tag that includes the architecture.
For ARM builds, this avoids needing to use QEMU to emulate ARM on an amd64 runner, which can be extremely slow.
Merging images into a multi-arch manifest
After building separate images for each architecture, you can merge them into a single multi-arch manifest using Docker’s manifest commands:Diff Example
Diff Example
Coming soon: Native multi-platform support
In the future, theuseblacksmith/build-push-action
action will support multi-platform builds natively. You’ll simply need to specify the platforms you want to build for in the platforms
input, and Blacksmith will automatically spawn native builders for each platform, eliminating the need for the matrix strategy shown above.
Diff Example
blacksmith-8vcpu-ubuntu-2204
and the arm64 build on a blacksmith-8vcpu-ubuntu-2204-arm
runner) and automatically merged into a single multi-arch manifest.
Security
Docker layer caching executes within the same runners that process your GitHub Actions workflows. This means they automatically inherit all security protections and isolations that are detailed in our security documentation. The BuildKit daemon in each runner (buildkitd
) that powers Docker builds, runs exclusively on a local Unix socket and is not exposed to the public internet.
The Docker layer cache for each repository is stored in a secure Ceph cluster. Every runner gets an ephemeral authentication token that allows it to request and commit artifacts.
The runners do not have persistent credentials to the Ceph cluster or direct access to artifacts in the cluster. The Ceph cluster is configured with object-level access controls.
Pricing
For pricing, please visit our pricing page.FAQ
How can I monitor my usage?
How can I monitor my usage?
Users can login to the Blacksmith dashboard and navigate to the
Usage & Billing
page to get a breakdown of their current usage.