Skip to content

Commit

Permalink
Merge pull request #820 from pulumi/blampe/docker-build
Browse files Browse the repository at this point in the history
Update container templates to use docker-build provider
  • Loading branch information
blampe authored Aug 21, 2024
2 parents d1c1ed3 + b7d5636 commit e12d3bb
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 87 deletions.
2 changes: 1 addition & 1 deletion container-azure-csharp/${PROJECT}.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Pulumi" Version="3.*" />
<PackageReference Include="Pulumi.AzureNative" Version="2.*" />
<PackageReference Include="Pulumi.Docker" Version="4.*" />
<PackageReference Include="Pulumi.DockerBuild" Version="0.*" />
<PackageReference Include="Pulumi.Random" Version="4.*" />
</ItemGroup>
</Project>
34 changes: 23 additions & 11 deletions container-azure-csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using Pulumi;
using AzureNative = Pulumi.AzureNative;
using Docker = Pulumi.Docker;
using DockerBuild = Pulumi.DockerBuild;
using Random = Pulumi.Random;

return await Pulumi.Deployment.RunAsync(() =>
Expand Down Expand Up @@ -39,17 +39,29 @@
var registryPassword = credentials.Apply(result => result.Passwords[0]!.Value!);

// Create a container image for the service.
var image = new Docker.Image("image", new()
var image = new DockerBuild.Image("image", new()
{
ImageName = Pulumi.Output.Format($"{registry.LoginServer}/{imageName}:{imageTag}"),
Build = new Docker.Inputs.DockerBuildArgs {
Context = appPath,
Platform = "linux/amd64",
Tags = new[]
{
Pulumi.Output.Format($"{registry.LoginServer}/{imageName}:{imageTag}"),
},
Registry = new Docker.Inputs.RegistryArgs {
Server = registry.LoginServer,
Username = registryUsername,
Password = registryPassword,
Context = new DockerBuild.Inputs.BuildContextArgs
{
Location = appPath,
},
Platforms = new[]
{
DockerBuild.Platform.Linux_amd64,

},
Registries = new[]
{
new DockerBuild.Inputs.RegistryArgs
{
Address = registry.LoginServer,
Password = registryPassword,
Username = registryUsername,
},
},
});

Expand All @@ -75,7 +87,7 @@
{
new AzureNative.ContainerInstance.Inputs.ContainerArgs {
Name = imageName,
Image = image.ImageName,
Image = image.Ref,
Ports = new[]
{
new AzureNative.ContainerInstance.Inputs.ContainerPortArgs {
Expand Down
8 changes: 5 additions & 3 deletions container-azure-go/go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module ${PROJECT}

go 1.20
go 1.21.7

toolchain go1.22.1

require (
github.com/pulumi/pulumi-azure-native-sdk/containerinstance/v2 v2.1.1
github.com/pulumi/pulumi-azure-native-sdk/containerregistry/v2 v2.1.1
github.com/pulumi/pulumi-azure-native-sdk/resources/v2 v2.0.0
github.com/pulumi/pulumi-docker-build/sdk/go/dockerbuild v0.0.6
github.com/pulumi/pulumi-random/sdk/v4 v4.8.2
github.com/pulumi/pulumi-docker/sdk/v4 v4.2.3
github.com/pulumi/pulumi/sdk/v3 v3.96.1
github.com/pulumi/pulumi/sdk/v3 v3.128.0
)
24 changes: 13 additions & 11 deletions container-azure-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/pulumi/pulumi-azure-native-sdk/containerinstance/v2"
"github.com/pulumi/pulumi-azure-native-sdk/containerregistry/v2"
"github.com/pulumi/pulumi-azure-native-sdk/resources/v2"
"github.com/pulumi/pulumi-docker/sdk/v4/go/docker"
"github.com/pulumi/pulumi-docker-build/sdk/go/dockerbuild"
"github.com/pulumi/pulumi-random/sdk/v4/go/random"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
Expand Down Expand Up @@ -70,16 +70,18 @@ func main() {
registryPassword := credentials.Passwords().Index(pulumi.Int(0)).Value().Elem()

// Create a container image for the service.
image, err := docker.NewImage(ctx, "image", &docker.ImageArgs{
ImageName: pulumi.Sprintf("%s/%s:%s", registry.LoginServer, imageName, imageTag),
Build: docker.DockerBuildArgs{
Context: pulumi.String(appPath),
Platform: pulumi.String("linux/amd64"),
image, err := dockerbuild.NewImage(ctx, "image", &dockerbuild.ImageArgs{
Tags: pulumi.StringArray{pulumi.Sprintf("%s/%s:%s", registry.LoginServer, imageName, imageTag)},
Context: &dockerbuild.BuildContextArgs{
Location: pulumi.String(appPath),
},
Registry: docker.RegistryArgs{
Server: registry.LoginServer,
Username: registryUsername,
Password: registryPassword,
Platforms: dockerbuild.PlatformArray{dockerbuild.Platform_Linux_amd64},
Registries: dockerbuild.RegistryArray{
&dockerbuild.RegistryArgs{
Address: registry.LoginServer,
Username: registryUsername,
Password: registryPassword,
},
},
})
if err != nil {
Expand Down Expand Up @@ -113,7 +115,7 @@ func main() {
Containers: containerinstance.ContainerArray{
containerinstance.ContainerArgs{
Name: pulumi.String(imageName),
Image: image.ImageName,
Image: image.Ref,
Ports: containerinstance.ContainerPortArray{
containerinstance.ContainerPortArgs{
Port: pulumi.Int(containerPort),
Expand Down
18 changes: 9 additions & 9 deletions container-azure-python/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pulumi
import pulumi_docker as docker
import pulumi_docker_build as docker_build
import pulumi_random as random
from pulumi_azure_native import resources, containerregistry, containerinstance

Expand Down Expand Up @@ -37,18 +37,18 @@
registry_password = credentials.apply(lambda creds: creds.passwords[0].value)

# Create a container image for the service.
image = docker.Image(
image = docker_build.Image(
"image",
image_name=pulumi.Output.concat(registry.login_server, f"/{image_name}:{image_tag}"),
build=docker.DockerBuildArgs(
context=app_path,
platform="linux/amd64",
tags=[pulumi.Output.concat(registry.login_server, f"/{image_name}:{image_tag}")],
context=docker_build.BuildContextArgs(
location=app_path,
),
registry=docker.RegistryArgs(
server=registry.login_server,
platforms=[docker_build.Platform.LINUX_AMD64],
registries=[docker_build.RegistryArgs(
address=registry.login_server,
username=registry_username,
password=registry_password,
),
)],
)

# Use a random string to give the service a unique DNS name.
Expand Down
2 changes: 1 addition & 1 deletion container-azure-python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pulumi>=3.0.0,<4.0.0
pulumi-azure-native>=2.0.0,<3.0.0
pulumi-random>=4.0.0,<5.0.0
pulumi-docker>=4.0.0,<5.0.0
pulumi-docker-build>=0.0.0,<1.0.0
18 changes: 9 additions & 9 deletions container-azure-typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as resources from "@pulumi/azure-native/resources";
import * as containerregistry from "@pulumi/azure-native/containerregistry";
import * as containerinstance from "@pulumi/azure-native/containerinstance";
import * as random from "@pulumi/random";
import * as docker from "@pulumi/docker";
import * as dockerbuild from "@pulumi/docker-build";

// Import the program's configuration settings.
const config = new pulumi.Config();
Expand Down Expand Up @@ -38,17 +38,17 @@ const credentials = containerregistry.listRegistryCredentialsOutput({
});

// Create a container image for the service.
const image = new docker.Image("image", {
imageName: pulumi.interpolate`${registry.loginServer}/${imageName}:${imageTag}`,
build: {
context: appPath,
platform: "linux/amd64",
const image = new dockerbuild.Image("image", {
tags: [pulumi.interpolate`${registry.loginServer}/${imageName}:${imageTag}`],
context: {
location: appPath,
},
registry: {
server: registry.loginServer,
platforms: ["linux/amd64"],
registries: [{
address: registry.loginServer,
username: credentials.username,
password: credentials.password,
},
}],
});

// Use a random string to give the service a unique DNS name.
Expand Down
2 changes: 1 addition & 1 deletion container-azure-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"dependencies": {
"@pulumi/azure-native": "^2.0.0",
"@pulumi/docker": "^4.2.3",
"@pulumi/docker-build": "^0.0.6",
"@pulumi/random": "^4.8.2",
"@pulumi/pulumi": "^3.113.0"
}
Expand Down
2 changes: 1 addition & 1 deletion container-gcp-csharp/${PROJECT}.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Pulumi" Version="3.*" />
<PackageReference Include="Pulumi.Gcp" Version="7.*" />
<PackageReference Include="Pulumi.Docker" Version="4.*" />
<PackageReference Include="Pulumi.DockerBuild" Version="0.*" />
<PackageReference Include="Pulumi.Random" Version="4.*" />
</ItemGroup>
</Project>
21 changes: 14 additions & 7 deletions container-gcp-csharp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Pulumi;
using Gcp = Pulumi.Gcp;
using Docker = Pulumi.Docker;
using DockerBuild = Pulumi.DockerBuild;
using System.Collections.Generic;
using Random = Pulumi.Random;
using Output = Pulumi.Output;
Expand Down Expand Up @@ -47,14 +47,21 @@
// Create a container image for the service.
// Before running `pulumi up`, configure Docker for Artifact Registry authentication
// as described here: https://cloud.google.com/artifact-registry/docs/docker/authentication
var image = new Docker.Image("image", new()
var image = new DockerBuild.Image("image", new()
{
ImageName = Output.Format($"{repoUrl}/{imageName}"),
Build = new Docker.Inputs.DockerBuildArgs {
Context = appPath,
Tags = new[]
{
Output.Format($"{repoUrl}/{imageName}"),
},
Context = new DockerBuild.Inputs.BuildContextArgs
{
Location = appPath,
},
Platforms = new[]
{
// Cloud Run currently requires x86_64 images
// https://cloud.google.com/run/docs/container-contract#languages
Platform = "linux/amd64",
DockerBuild.Platform.Linux_amd64,
},
});

Expand All @@ -70,7 +77,7 @@
{
new Gcp.CloudRun.Inputs.ServiceTemplateSpecContainerArgs
{
Image = image.RepoDigest,
Image = image.Ref,
Resources = new Gcp.CloudRun.Inputs.ServiceTemplateSpecContainerResourcesArgs
{
Limits = {
Expand Down
7 changes: 5 additions & 2 deletions container-gcp-go/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
module ${PROJECT}

go 1.20
go 1.21.7

toolchain go1.22.1

require (
github.com/pulumi/pulumi-docker-build/sdk/go/dockerbuild v0.0.6
github.com/pulumi/pulumi-gcp/sdk/v7 v7.0.0
github.com/pulumi/pulumi-random/sdk/v4 v4.13.2
github.com/pulumi/pulumi/sdk/v3 v3.91.1
github.com/pulumi/pulumi/sdk/v3 v3.128.0
)
19 changes: 9 additions & 10 deletions container-gcp-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"strconv"

"github.com/pulumi/pulumi-docker/sdk/v4/go/docker"
"github.com/pulumi/pulumi-docker-build/sdk/go/dockerbuild"
"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/artifactregistry"
"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/cloudrun"
"github.com/pulumi/pulumi-random/sdk/v4/go/random"
Expand Down Expand Up @@ -76,15 +76,14 @@ func main() {
// Create a container image for the service.
// Before running `pulumi up`, configure Docker for authentication to Artifact Registry as
// described here: https://cloud.google.com/artifact-registry/docs/docker/authentication
image, err := docker.NewImage(ctx, "image", &docker.ImageArgs{
Registry: docker.RegistryArgs{},
ImageName: pulumi.Sprintf("%s/%s", repoUrl, imageName),
Build: docker.DockerBuildArgs{
Context: pulumi.String(appPath),
// Cloud Run currently requires x86_64 images
// https://cloud.google.com/run/docs/container-contract#languages
Platform: pulumi.String("linux/amd64"),
image, err := dockerbuild.NewImage(ctx, "image", &dockerbuild.ImageArgs{
Tags: pulumi.StringArray{pulumi.Sprintf("%s/%s", repoUrl, imageName)},
Context: &dockerbuild.BuildContextArgs{
Location: pulumi.String(appPath),
},
// Cloud Run currently requires x86_64 images
// https://cloud.google.com/run/docs/container-contract#languages
Platforms: dockerbuild.PlatformArray{"linux/amd64"},
})
if err != nil {
return err
Expand All @@ -97,7 +96,7 @@ func main() {
Spec: cloudrun.ServiceTemplateSpecArgs{
Containers: cloudrun.ServiceTemplateSpecContainerArray{
cloudrun.ServiceTemplateSpecContainerArgs{
Image: image.RepoDigest.Elem(),
Image: image.Ref.Elem(),
Resources: cloudrun.ServiceTemplateSpecContainerResourcesArgs{
Limits: pulumi.ToStringMap(map[string]string{
"memory": memory,
Expand Down
16 changes: 8 additions & 8 deletions container-gcp-python/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pulumi
import pulumi_docker as docker
import pulumi_docker_build as docker_build
from pulumi_gcp import cloudrun, config as gcp_config
from pulumi_gcp import artifactregistry
import pulumi_random as random
Expand Down Expand Up @@ -53,15 +53,15 @@
# Create a container image for the service.
# Before running `pulumi up`, configure Docker for Artifact Registry authentication
# as described here: https://cloud.google.com/artifact-registry/docs/docker/authentication
image = docker.Image(
image = docker_build.Image(
"image",
image_name=pulumi.Output.concat(repo_url, "/", image_name),
build=docker.DockerBuildArgs(
context=app_path,
# Cloud Run currently requires x86_64 images
# https://cloud.google.com/run/docs/container-contract#languages
platform="linux/amd64"
tags=[pulumi.Output.concat(repo_url, "/", image_name)],
context=docker_build.BuildContextArgs(
location=app_path,
),
# Cloud Run currently requires x86_64 images
# https://cloud.google.com/run/docs/container-contract#languages
platforms=[docker_build.Platform.LINUX_AMD64],
)

# Create a Cloud Run service definition.
Expand Down
2 changes: 1 addition & 1 deletion container-gcp-python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pulumi>=3.0.0,<4.0.0
pulumi-gcp>=7.0.0,<8.0.0
pulumi-docker>=4.0.0,<5.0.0
pulumi-docker-build>=0.0.0,<1.0.0
pulumi-random >=4.0.0,<5.0.0
19 changes: 8 additions & 11 deletions container-gcp-typescript/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
import * as docker from "@pulumi/docker";
import * as dockerbuild from "@pulumi/docker-build";
import * as random from "@pulumi/random";

// Import the program's configuration settings.
Expand Down Expand Up @@ -41,17 +41,14 @@ let repoUrl = pulumi.concat(location, "-docker.pkg.dev/", project, "/", reposito
// Create a container image for the service.
// Before running `pulumi up`, configure Docker for authentication to Artifact Registry
// as described here: https://cloud.google.com/artifact-registry/docs/docker/authentication
const image = new docker.Image("image", {
imageName: pulumi.concat(repoUrl, "/", imageName),
build: {
context: appPath,
platform: "linux/amd64",
args: {
// Cloud Run currently requires x86_64 images
// https://cloud.google.com/run/docs/container-contract#languages
DOCKER_DEFAULT_PLATFORM: "linux/amd64",
},
const image = new dockerbuild.Image("image", {
tags: [pulumi.concat(repoUrl, "/", imageName)],
context: {
location: appPath,
},
// Cloud Run currently requires x86_64 images
// https://cloud.google.com/run/docs/container-contract#languages
platforms: ["linux/amd64"],
});

// Create a Cloud Run service definition.
Expand Down
Loading

0 comments on commit e12d3bb

Please sign in to comment.