Add HCL Examples & Docs (#852)

Fixes https://github.com/pulumi/pulumi-docker-build/issues/844
This commit is contained in:
Ian Wahbe
2026-05-18 12:11:41 +02:00
committed by GitHub
parent 55d6f8f216
commit a748e088ca
27 changed files with 661 additions and 78 deletions

View File

@@ -0,0 +1,2 @@
command-output
tmp

10
examples/hcl/Pulumi.yaml Normal file
View File

@@ -0,0 +1,10 @@
name: provider-docker-build
runtime: hcl
config:
dockerHubPassword:
type: string
secret: true
plugins:
providers:
- name: docker-build
path: ../../bin

View File

@@ -0,0 +1,2 @@
FROM alpine
RUN echo 👍

View File

@@ -0,0 +1,5 @@
FROM alpine
ARG SET_ME_TO_TRUE
RUN [ "$SET_ME_TO_TRUE" = "true" ]
RUN echo "That's the correct build arg, thanks! 👍"

View File

@@ -0,0 +1,2 @@
FROM alpine
RUN echo "This image doesn't use any local files, so it doesn't need a context parameter 👍"

View File

@@ -0,0 +1,3 @@
FROM bash AS base
RUN getent hosts metadata.google.internal

View File

@@ -0,0 +1,7 @@
FROM --platform=$BUILDPLATFORM alpine as build
RUN echo ${BUILDPLATFORM} > buildplatform
RUN echo ${TARGETPLATFORM} > targetplatform
FROM build
RUN cat buildplatform
RUN cat targetplatform

View File

@@ -0,0 +1,5 @@
# syntax=docker/dockerfile:1.4
FROM golang:latest
RUN version="$(go version)" && echo $version && [ "$version" = "go version go1.21.7 linux/amd64" ]
RUN echo "This image uses named contexts to pin golang:latest to a specific SHA 👍"

View File

@@ -0,0 +1,4 @@
FROM alpine
RUN --mount=type=secret,id=password [ "$(cat /run/secrets/password)" = "hunter2" ]

View File

@@ -0,0 +1,5 @@
FROM alpine
RUN apk add openssh-client
RUN --mount=type=ssh ssh-add -l

View File

@@ -0,0 +1,8 @@
FROM alpine as build-me
RUN echo 👍
FROM build-me as also-build-me
RUN echo 🤙
FROM build-me as dont-build-me
RUN [ "true" = "false" ]

171
examples/hcl/program.hcl Normal file
View File

@@ -0,0 +1,171 @@
pulumi {
required_providers {
docker-build = {
source = "pulumi/docker-build"
version = "0.1.0-alpha.0+dev"
}
}
}
resource "docker-build_image" "multiPlatform" {
push = false
dockerfile = {
location = "./app/Dockerfile.multiPlatform"
}
context = {
location = "./app"
}
platforms = ["plan9/amd64", "plan9/386"]
}
resource "docker-build_image" "registryPush" {
push = false
context = {
location = "./app"
}
tags = ["docker.io/pulumibot/buildkit-e2e:example"]
exports {
registry = {
oci_media_types = true
push = false
}
}
registries {
address = "docker.io"
username = "pulumibot"
password = var.dockerHubPassword
}
}
resource "docker-build_image" "cached" {
push = false
context = {
location = "./app"
}
cache_to {
local = {
dest = "tmp/cache"
mode = "max"
}
}
cache_from {
local = {
src = "tmp/cache"
}
}
}
resource "docker-build_image" "buildArgs" {
push = false
dockerfile = {
location = "./app/Dockerfile.buildArgs"
}
context = {
location = "./app"
}
build_args = {
"SET_ME_TO_TRUE" = "true"
}
}
resource "docker-build_image" "extraHosts" {
push = false
dockerfile = {
location = "./app/Dockerfile.extraHosts"
}
context = {
location = "./app"
}
add_hosts = ["metadata.google.internal:169.254.169.254"]
}
resource "docker-build_image" "sshMount" {
push = false
dockerfile = {
location = "./app/Dockerfile.sshMount"
}
context = {
location = "./app"
}
ssh {
id = "default"
}
}
resource "docker-build_image" "secrets" {
push = false
dockerfile = {
location = "./app/Dockerfile.secrets"
}
context = {
location = "./app"
}
secrets = {
"password" = "hunter2"
}
}
resource "docker-build_image" "labels" {
push = false
context = {
location = "./app"
}
labels = {
"description" = "This image will get a descriptive label 👍"
}
}
resource "docker-build_image" "target" {
push = false
dockerfile = {
location = "./app/Dockerfile.target"
}
context = {
location = "./app"
}
target = "build-me"
}
resource "docker-build_image" "namedContexts" {
push = false
dockerfile = {
location = "./app/Dockerfile.namedContexts"
}
context = {
location = "./app"
named = {
"golang:latest" = {
location = "docker-image://golang@sha256:b8e62cf593cdaff36efd90aa3a37de268e6781a2e68c6610940c48f7cdf36984"
}
}
}
}
resource "docker-build_image" "remoteContext" {
push = false
context = {
location = "https://raw.githubusercontent.com/pulumi/pulumi-docker/api-types/provider/testdata/Dockerfile"
}
}
resource "docker-build_image" "remoteContextWithInline" {
push = false
dockerfile = {
inline = "FROM busybox\nCOPY hello.c ./\n"
}
context = {
location = "https://github.com/docker-library/hello-world.git"
}
}
resource "docker-build_image" "inline" {
push = false
dockerfile = {
inline = "FROM alpine\nRUN echo \"This uses an inline Dockerfile! 👍\"\n"
}
}
resource "docker-build_image" "dockerLoad" {
push = false
context = {
location = "./app"
}
exports {
docker = {
tar = true
}
}
}
variable "dockerHubPassword" {
type = string
}
output "platforms" {
value = docker-build_image.multiPlatform.platforms
}

View File

@@ -35,6 +35,20 @@ func TestYAMLExample(t *testing.T) {
integration.ProgramTest(t, &test)
}
func TestHCLExample(t *testing.T) {
cwd, err := os.Getwd()
require.NoError(t, err)
test := integration.ProgramTestOptions{
Dir: path.Join(cwd, "hcl"),
Secrets: map[string]string{
"dockerHubPassword": os.Getenv("DOCKER_HUB_PASSWORD"),
},
}
integration.ProgramTest(t, &test)
}
func TestYAMLExampleUpgrade(t *testing.T) {
pt := pulumitest.NewPulumiTest(t, "upgrade",
opttest.AttachProviderServer("docker-build", providerServerFactory))