Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates templates to use the Docker Build provider #789

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.0.2" />
<PackageReference Include="Pulumi.Random" Version="4.*" />
</ItemGroup>
</Project>
32 changes: 19 additions & 13 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 All @@ -24,7 +24,8 @@
{
ResourceGroupName = resourceGroup.Name,
AdminUserEnabled = true,
Sku = new AzureNative.ContainerRegistry.Inputs.SkuArgs {
Sku = new AzureNative.ContainerRegistry.Inputs.SkuArgs
{
Name = AzureNative.ContainerRegistry.SkuName.Basic,
},
});
Expand All @@ -39,18 +40,21 @@
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",
Push = true,
Tags = new[] { Pulumi.Output.Format($"{registry.LoginServer}/{imageName}:{imageTag}") },
Context = new DockerBuild.Inputs.BuildContextArgs
{
Location = appPath
},
Registry = new Docker.Inputs.RegistryArgs {
Server = registry.LoginServer,
Platforms = new[] { DockerBuild.Platform.Linux_amd64 },
Registries = new[]{
new DockerBuild.Inputs.RegistryArgs{
Address = registry.LoginServer,
Username = registryUsername,
Password = registryPassword,
},
}},
});

// Use a random string to give the service a unique DNS name.
Expand All @@ -66,7 +70,8 @@
ResourceGroupName = resourceGroup.Name,
OsType = "linux",
RestartPolicy = "always",
ImageRegistryCredentials = new AzureNative.ContainerInstance.Inputs.ImageRegistryCredentialArgs {
ImageRegistryCredentials = new AzureNative.ContainerInstance.Inputs.ImageRegistryCredentialArgs
{
Server = registry.LoginServer,
Username = registryUsername,
Password = registryPassword,
Expand All @@ -75,7 +80,7 @@
{
new AzureNative.ContainerInstance.Inputs.ContainerArgs {
Name = imageName,
Image = image.ImageName,
Image = image.Ref,
Ports = new[]
{
new AzureNative.ContainerInstance.Inputs.ContainerPortArgs {
Expand All @@ -98,7 +103,8 @@
},
},
},
IpAddress = new AzureNative.ContainerInstance.Inputs.IpAddressArgs {
IpAddress = new AzureNative.ContainerInstance.Inputs.IpAddressArgs
{
Type = AzureNative.ContainerInstance.ContainerGroupIpAddressType.Public,
DnsNameLabel = dnsName,
Ports = new[]
Expand Down
2 changes: 2 additions & 0 deletions container-azure-go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go.work
go.work.sum
12 changes: 6 additions & 6 deletions container-azure-go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module ${PROJECT}
go 1.20

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-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-azure-native-sdk/containerinstance/v2 v2.40.0
github.com/pulumi/pulumi-azure-native-sdk/containerregistry/v2 v2.40.0
github.com/pulumi/pulumi-azure-native-sdk/resources/v2 v2.40.0
github.com/pulumi/pulumi-docker-build/sdk/go/dockerbuild v0.0.0-20240501144927-9b789f374285
github.com/pulumi/pulumi-random/sdk/v4 v4.16.1
github.com/pulumi/pulumi/sdk/v3 v3.115.2
)
28 changes: 17 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,17 +70,23 @@ 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{
Push: pulumi.Bool(true),
Tags: pulumi.StringArray{
pulumi.Sprintf("%s/%s:%s", registry.LoginServer, imageName, imageTag),
},
Registry: docker.RegistryArgs{
Server: registry.LoginServer,
Username: registryUsername,
Password: registryPassword,
Context: &dockerbuild.BuildContextArgs{
Location: pulumi.String(appPath),
},
Platforms: dockerbuild.PlatformArray{
dockerbuild.Platform_Linux_amd64,
},
Registries: dockerbuild.RegistryArray{
&dockerbuild.RegistryArgs{
Address: registry.LoginServer,
Username: registryUsername,
Password: registryPassword,
}},
})
if err != nil {
return err
Expand Down Expand Up @@ -113,7 +119,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
21 changes: 11 additions & 10 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,19 @@
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",
push=True,
tags=[pulumi.Output.concat(registry.login_server, f"/{image_name}:{image_tag}")],
platforms=[docker_build.Platform.LINUX_AMD64],
context=docker_build.BuildContextArgs(
location=app_path,
),
registry=docker.RegistryArgs(
server=registry.login_server,
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 Expand Up @@ -77,7 +78,7 @@
containers=[
containerinstance.ContainerArgs(
name=image_name,
image=image.image_name,
image=image.ref,
ports=[
containerinstance.ContainerPortArgs(
port=container_port,
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.1,<1.0.0
35 changes: 18 additions & 17 deletions container-azure-typescript/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as pulumi from "@pulumi/pulumi";
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 containerregistry from "@pulumi/azure-native/containerregistry";
import * as dockerBuild from "@pulumi/docker-build";
import * as pulumi from "@pulumi/pulumi";
import * as random from "@pulumi/random";
import * as docker from "@pulumi/docker";
import * as resources from "@pulumi/azure-native/resources";

// Import the program's configuration settings.
const config = new pulumi.Config();
Expand Down Expand Up @@ -38,24 +38,25 @@ 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", {
push: true,
tags: [pulumi.interpolate`${registry.loginServer}/${imageName}:${imageTag}`],
platforms: [dockerBuild.Platform.Linux_amd64],
context: {
location: appPath
},
registry: {
server: registry.loginServer,
registries: [{
address: registry.loginServer,
username: credentials.username,
password: credentials.password,
},
}],
});

// Use a random string to give the service a unique DNS name.
const dnsName = new random.RandomString("dns-name", {
length: 8,
special: false,
}).result.apply(result => `${imageName}-${result.toLowerCase()}`);
}).result.apply((result: string) => `${imageName}-${result.toLowerCase()}`);

// Create a container group for the service that makes it publicly accessible.
const containerGroup = new containerinstance.ContainerGroup("container-group", {
Expand All @@ -72,7 +73,7 @@ const containerGroup = new containerinstance.ContainerGroup("container-group", {
containers: [
{
name: imageName,
image: image.imageName,
image: image.ref,
ports: [
{
port: containerPort,
Expand Down Expand Up @@ -106,6 +107,6 @@ const containerGroup = new containerinstance.ContainerGroup("container-group", {
});

// Export the service's IP address, hostname, and fully-qualified URL.
export const hostname = containerGroup.ipAddress.apply(addr => addr!.fqdn!);
export const ip = containerGroup.ipAddress.apply(addr => addr!.ip!);
export const url = containerGroup.ipAddress.apply(addr => `http://${addr!.fqdn!}:${containerPort}`);
export const hostname = containerGroup.ipAddress.apply((addr: any) => addr!.fqdn!);
export const ip = containerGroup.ipAddress.apply((addr: any) => addr!.ip!);
export const url = containerGroup.ipAddress.apply((addr: any) => `http://${addr!.fqdn!}:${containerPort}`);
12 changes: 6 additions & 6 deletions container-azure-typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "${PROJECT}",
"devDependencies": {
"@types/node": "^18",
"typescript": "^5.0.0"
"@types/node": "^18.0.0",
"typescript": "^5.4.5"
},
"dependencies": {
"@pulumi/azure-native": "^2.0.0",
"@pulumi/docker": "^4.2.3",
"@pulumi/random": "^4.8.2",
"@pulumi/pulumi": "^3.113.0"
"@pulumi/azure-native": "^2.40.0",
"@pulumi/docker-build": "^0.0.2",
"@pulumi/pulumi": "^3.115.2",
"@pulumi/random": "^4.16.1"
}
}
2 changes: 1 addition & 1 deletion container-gcp-csharp/${PROJECT}.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Pulumi" Version="3.*" />
<PackageReference Include="Pulumi.DockerBuild" Version="0.0.2" />
<PackageReference Include="Pulumi.Gcp" Version="7.*" />
<PackageReference Include="Pulumi.Docker" Version="4.*" />
<PackageReference Include="Pulumi.Random" Version="4.*" />
</ItemGroup>
</Project>
22 changes: 13 additions & 9 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,15 +47,19 @@
// 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,
// Cloud Run currently requires x86_64 images
// https://cloud.google.com/run/docs/container-contract#languages
Platform = "linux/amd64",
Push = true,
Tags = new[]{
Output.Format($"{repoUrl}/{imageName}"),
},
Context = new DockerBuild.Inputs.BuildContextArgs
{
Location = appPath
},
// Cloud Run currently requires x86_64 images
// https://cloud.google.com/run/docs/container-contract#languages
Platforms = new[] { DockerBuild.Platform.Linux_amd64 }
});

// Create a Cloud Run service definition.
Expand All @@ -70,7 +74,7 @@
{
new Gcp.CloudRun.Inputs.ServiceTemplateSpecContainerArgs
{
Image = image.RepoDigest,
Image = image.Ref,
Resources = new Gcp.CloudRun.Inputs.ServiceTemplateSpecContainerResourcesArgs
{
Limits = {
Expand Down
2 changes: 2 additions & 0 deletions container-gcp-go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go.work
go.work.sum
3 changes: 2 additions & 1 deletion container-gcp-go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module ${PROJECT}
go 1.20

require (
github.com/pulumi/pulumi-docker-build/sdk/go/dockerbuild v0.0.0-20240501144927-9b789f374285
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.113.3
)
Loading
Loading