Pulumi Docker Provider 4.0: Build Images Up To 50x Faster
Posted on
The Pulumi Docker Provider has been a top Pulumi provider since it launched in 2018. It can be used to provision any of the resources available in Docker, including containers, images, networks, volumes and more.
One of the most heavily used features of this provider is the docker.Image
resource, which enables Pulumi users to build and (optionally) push a local Docker context (like an application folder) to a registry as part of a Pulumi deployment. Today we are excited to announce a set of improvements to the docker.Image
resource driven by the feedback we have received from our community. This set of improvements includes:
- Significantly improved performance (including reduced need for rebuilds)
- BuildKit support (including cross-platform builds)
- Rich Docker build logs inside Pulumi IaC program output
- Pulumi YAML and Pulumi Java support
Our friends Nikhil Benesch and the Materialize team created a Docker image provider that demonstrated better workflows with Docker BuildKit and we’re excited to finally make these improvements part of our official Pulumi Docker Provider.
Below is a video walkthrough of using the v4 Docker provider:
Significantly improved performance
To improve the efficiency of the Pulumi Docker Provider, we have changed the default behavior to rebuild only on context change. In addition, the cacheFrom
option now offers the ability to use a registry as the image cache. By leveraging BuildKit and caching improvements, subsequent rebuilds may be up to 50x faster. This functionality and other improvements of the Pulumi Docker Provider we are announcing today are highly requested from our community.
BuildKit support
The enhanced functionality and performance provided by the Docker BuildKit can now be fully leveraged in your Pulumi programs. BuildKit is now the default builder version mode. The V1 builder can still be accessed by specifying Build.BuilderVersion=BuilderV1
. BuildKit comes with functionality to improve your builds’ performance and the reusability of your Dockerfiles. Cross-platform builds are now supported, enabling image building for a target container runtime that is different from the build environment.
import * as docker from "@pulumi/docker";
const img = new docker.Image("my-image", {
imageName: "docker.io/pulumibot/demo-image:latest",
build: {
context: "app",
dockerfile: "Dockerfile",
args: {
"BUILDKIT_INLINE_CACHE": "1"
},
builderVersion: "BuilderBuildKit", // can also be set to `BuilderV1`
cacheFrom: {
images: ["docker.io/pulumibot/demo-image:cache-base"]
},
platform: "linux/amd64",
}
});
Rich Docker build logs inside Pulumi IaC program output
Filtered docker logs during build and push will now be displayed in the Info box on pulumi up.
Pulumi YAML and Pulumi Java support
We announced Pulumi YAML and Pulumi Java last year and are excited to have extended support to the Pulumi Docker Provider. This release schematizes all Docker resources, which enables auto-support of all Pulumi languages. In addition, this means the docker.Image
resource can now participate in the CRUD (create, replace, update, delete) lifecycle.
Migrating to 4.0
The 4.0 version of the Pulumi Docker Provider consists of a significant overhaul of the docker.Image
resource. As a result there are some breaking changes to the behavior of the docker.Image
resource and supporting types, as well as some minor name changes.
As the docker.Image
resource does not manage any backend state, updating to the 4.0 version does not require any resource imports or stack updates.
For most use cases, migrating should be as simple as updating the pulumi-docker
version to 4.0.0 and adjusting the Pulumi program code to reflect updated types.
Please find the detailed migration guide in the release notes for v4.0.0.
Getting started
The Pulumi Docker Provider has everything you need to build, run, and push Docker images for any container registry. Visit the Pulumi Docker Provider installation and configuration page to start building your next image now!