Skip to main content

A Pulumi package for building Docker images with Buildkit.

Project description

Docker Buildkit Pulumi Provider

A Pulumi provider that builds and pushes a Docker image to a registry using Buildkit.

Motivation

Why use this provider over the official pulumi-docker provider? This provider fixes many of the bugs with the official Docker provider:

  • pulumi preview does not silently block while waiting for the Docker image to build.
  • Output from docker build streams to the terminal during pulumi up.
  • docker build is not invoked if nothing in the build context has changed.
  • Changes to the build context cause a diff to appear during pulumi preview.

It also provides several new features:

  • Support for cross-building images (e.g., building a linux/arm64 image on a linux/amd64 host.)
  • Automatic inline caching.

There are a few limitations though. The Image resource is much less configurable than the Image resource in the official Docker provider. And there is no support whatsoever for the other resource types, like Container or Secret.

Usage example

To build and push an image to an AWS ECR repository:

import base64

import pulumi
import pulumi_aws as aws
import pulumi_docker_buildkit as docker_buildkit

def get_registry_info(registry_id):
    credentials = aws.ecr.get_credentials(registry_id)
    username, password = base64.b64decode(credentials.authorization_token).decode().split(":")
    return docker_buildkit.RegistryArgs(
        server=credentials.proxy_endpoint,
        username=username,
        password=password,
    )


repo = aws.ecr.Repository("repo")
image = docker_buildkit.Image(
    "image",
    name=repo.repository_url,
    registry=repo.registry_id.apply(get_registry_info),
)

Warning: Be sure to aggressively exclude files in your .dockerignore. The Image resource hashes all files in the build context before determining whether to invoke docker build. This is fast, unless you have tens of thousands of files in your build context. The .git directory and node_modules are the usual culprits.

Future plans

I plan to make minor bugfixes as necessary for our use of this provider at @MaterializeInc. I do not currently plan to bring it to feature parity with the official Docker provider, nor do I have the time to entertain such contributions. Sorry! I encourage you to either fork this repository or to use the ideas here to improve the official Pulumi Docker provider.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pulumi_docker_buildkit-0.1.12.tar.gz (9.4 kB view details)

Uploaded Source

File details

Details for the file pulumi_docker_buildkit-0.1.12.tar.gz.

File metadata

  • Download URL: pulumi_docker_buildkit-0.1.12.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pulumi_docker_buildkit-0.1.12.tar.gz
Algorithm Hash digest
SHA256 6290874997f88b83052760c0c94ca5306d891b94681a387847e2a6d520649ac4
MD5 609857721dedc47348543bfb6a5f712e
BLAKE2b-256 916c1da6795911f640180b0be7664c3077b6b758dfedffd86ddac788ab06b8a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page