From ae19faabacb6cf8cc0f673d81459b5be289d3a59 Mon Sep 17 00:00:00 2001 From: Christian Nunciato Date: Thu, 20 Oct 2022 12:53:34 -0700 Subject: [PATCH] Make image tag configurable, templatize package.json --- container-azure-csharp/Program.cs | 3 ++- container-azure-go/main.go | 6 +++++- container-azure-python/__main__.py | 3 ++- container-azure-typescript/index.ts | 3 ++- container-azure-typescript/package.json | 3 +-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/container-azure-csharp/Program.cs b/container-azure-csharp/Program.cs index 83d91786a..acb7c31fa 100644 --- a/container-azure-csharp/Program.cs +++ b/container-azure-csharp/Program.cs @@ -11,6 +11,7 @@ var config = new Config(); var appPath = config.Get("appPath") ?? "./app"; var imageName = config.Get("imageName") ?? "my-app"; + var imageTag = config.Get("imageTag") ?? "latest"; var containerPort = config.GetInt32("containerPort") ?? 80; var cpu = config.GetInt32("cpu") ?? 1; var memory = config.GetInt32("memory") ?? 2; @@ -40,7 +41,7 @@ // Create a container image for the service. var image = new Docker.Image("image", new() { - ImageName = Pulumi.Output.Format($"{registry.LoginServer}/{imageName}"), + ImageName = Pulumi.Output.Format($"{registry.LoginServer}/{imageName}:{imageTag}"), Build = new Docker.DockerBuild { Context = appPath, }, diff --git a/container-azure-go/main.go b/container-azure-go/main.go index 80c8de2d6..13d53f7af 100644 --- a/container-azure-go/main.go +++ b/container-azure-go/main.go @@ -26,6 +26,10 @@ func main() { if param := cfg.Get("imageName"); param != "" { imageName = param } + imageTag := "latest" + if param := cfg.Get("imageTag"); param != "" { + imageName = param + } containerPort := 80 if param := cfg.GetInt("containerPort"); param != 0 { containerPort = param @@ -67,7 +71,7 @@ func main() { // Create a container image for the service. image, err := docker.NewImage(ctx, "image", &docker.ImageArgs{ - ImageName: pulumi.Sprintf("%s/%s", registry.LoginServer, imageName), + ImageName: pulumi.Sprintf("%s/%s:%s", registry.LoginServer, imageName, imageTag), Build: docker.DockerBuildArgs{ Context: pulumi.String(appPath), }, diff --git a/container-azure-python/__main__.py b/container-azure-python/__main__.py index e8322917a..7547bfd3f 100644 --- a/container-azure-python/__main__.py +++ b/container-azure-python/__main__.py @@ -7,6 +7,7 @@ config = pulumi.Config() app_path = config.get("appPath", "./app") image_name = config.get("imageName", "my-app") +image_tag = config.get("imageTag", "latest") container_port = config.get_int("containerPort", 80) cpu = config.get_int("cpu", 1) memory = config.get_int("memory", 2) @@ -38,7 +39,7 @@ # Create a container image for the service. image = docker.Image( "image", - image_name=pulumi.Output.concat(registry.login_server, "/", image_name), + image_name=pulumi.Output.concat(registry.login_server, f"/{image_name}:{image_tag}"), build=docker.DockerBuild( context=app_path, ), diff --git a/container-azure-typescript/index.ts b/container-azure-typescript/index.ts index 044baa200..cc71fba1d 100644 --- a/container-azure-typescript/index.ts +++ b/container-azure-typescript/index.ts @@ -9,6 +9,7 @@ import * as docker from "@pulumi/docker"; const config = new pulumi.Config(); const appPath = config.get("appPath") || "./app"; const imageName = config.get("imageName") || "my-app"; +const imageTag = config.get("imageTag") || "latest"; const containerPort = config.getNumber("containerPort") || 80; const cpu = config.getNumber("cpu") || 1; const memory = config.getNumber("memory") || 2; @@ -38,7 +39,7 @@ const credentials = containerregistry.listRegistryCredentialsOutput({ // Create a container image for the service. const image = new docker.Image("image", { - imageName: pulumi.interpolate`${registry.loginServer}/${imageName}`, + imageName: pulumi.interpolate`${registry.loginServer}/${imageName}:${imageTag}`, build: { context: appPath, }, diff --git a/container-azure-typescript/package.json b/container-azure-typescript/package.json index 3ed6fe908..ec4ad0690 100644 --- a/container-azure-typescript/package.json +++ b/container-azure-typescript/package.json @@ -1,6 +1,5 @@ { - "name": "azure-container", - "main": "index.ts", + "name": "${PROJECT}", "devDependencies": { "@types/node": "^14" },