Skip to content

Commit 69acb41

Browse files
committed
Updating to fix DockerBuild Settings, Fixes #1869
1 parent d53fcce commit 69acb41

File tree

4 files changed

+65
-46
lines changed

4 files changed

+65
-46
lines changed

aws-py-voting-app/__main__.py

+29-20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pulumi
77
import pulumi_aws as aws
88
import pulumi_docker as docker
9+
import pulumi_docker_build as docker_build
910

1011
# Get the password to use for Redis from the pulumi config
1112
config = pulumi.Config()
@@ -18,7 +19,9 @@
1819
# Creating a VPC and a public subnet
1920
app_vpc = aws.ec2.Vpc("app-vpc", cidr_block="172.31.0.0/16", enable_dns_hostnames=True)
2021

21-
app_vpc_subnet = aws.ec2.Subnet("app-vpc-subnet", cidr_block="172.31.32.0/20", vpc_id=app_vpc.id)
22+
app_vpc_subnet = aws.ec2.Subnet(
23+
"app-vpc-subnet", cidr_block="172.31.32.0/20", vpc_id=app_vpc.id
24+
)
2225

2326
# Creating a gateway to the web for the VPC
2427
app_gateway = aws.ec2.InternetGateway("app-gateway", vpc_id=app_vpc.id)
@@ -143,10 +146,6 @@
143146
port=redis_port,
144147
protocol="TCP",
145148
target_type="ip",
146-
stickiness=aws.lb.TargetGroupStickinessArgs(
147-
enabled=False,
148-
type="lb_cookie",
149-
),
150149
vpc_id=app_vpc.id,
151150
)
152151

@@ -166,7 +165,9 @@
166165
port=redis_port,
167166
protocol="TCP",
168167
default_actions=[
169-
aws.lb.ListenerDefaultActionArgs(type="forward", target_group_arn=redis_targetgroup.arn)
168+
aws.lb.ListenerDefaultActionArgs(
169+
type="forward", target_group_arn=redis_targetgroup.arn
170+
)
170171
],
171172
)
172173

@@ -235,10 +236,6 @@
235236
port=80,
236237
protocol="TCP",
237238
target_type="ip",
238-
stickiness=aws.lb.TargetGroupStickinessArgs(
239-
enabled=False,
240-
type="lb_cookie",
241-
),
242239
vpc_id=app_vpc.id,
243240
)
244241

@@ -258,7 +255,9 @@
258255
port=80,
259256
protocol="TCP",
260257
default_actions=[
261-
aws.lb.ListenerDefaultActionArgs(type="forward", target_group_arn=flask_targetgroup.arn)
258+
aws.lb.ListenerDefaultActionArgs(
259+
type="forward", target_group_arn=flask_targetgroup.arn
260+
)
262261
],
263262
)
264263

@@ -271,17 +270,25 @@ def get_registry_info(rid):
271270
parts = decoded.split(":")
272271
if len(parts) != 2:
273272
raise Exception("Invalid credentials")
274-
return docker.ImageRegistry(creds.proxy_endpoint, parts[0], parts[1])
273+
return docker_build.RegistryArgs(
274+
address=creds.proxy_endpoint, username=parts[0], password=parts[1]
275+
)
275276

276277

277278
app_registry = app_ecr_repo.registry_id.apply(get_registry_info)
278279

279-
flask_image = docker.Image(
280+
flask_image_dockerbuild = docker_build.Image(
280281
"flask-dockerimage",
281-
image_name=app_ecr_repo.repository_url,
282-
build="./frontend",
283-
skip_push=False,
284-
registry=app_registry,
282+
tags=[
283+
app_ecr_repo.repository_url.apply(
284+
lambda repository_url: f"{repository_url}:latest"
285+
),
286+
],
287+
context=docker_build.BuildContextArgs(
288+
location="./frontend",
289+
),
290+
push=True,
291+
registries=[app_registry],
285292
)
286293

287294
# Creating a task definition for the Flask instance.
@@ -298,15 +305,17 @@ def get_registry_info(rid):
298305
[
299306
{
300307
"name": "flask-container",
301-
"image": flask_image.image_name,
308+
"image": flask_image_dockerbuild.ref,
302309
"memory": 512,
303310
"essential": True,
304-
"portMappings": [{"containerPort": 80, "hostPort": 80, "protocol": "tcp"}],
311+
"portMappings": [
312+
{"containerPort": 80, "hostPort": 80, "protocol": "tcp"}
313+
],
305314
"environment": [ # The Redis endpoint we created is given to Flask, allowing it to communicate with the former
306315
{"name": "REDIS", "value": redis_endpoint["host"]},
307316
{
308317
"name": "REDIS_PORT",
309-
"value": redis_endpoint["port"].apply(lambda x: str(x)),
318+
"value": pulumi.Output.concat(str(redis_endpoint["port"])),
310319
},
311320
{"name": "REDIS_PWD", "value": redis_password},
312321
],

aws-py-voting-app/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pulumi>=3.5.1,<4.0.0
22
pulumi-aws>=6.0.2,<7.0.0
33
pulumi-docker>=4.6.0,<4.7.0
4+
pulumi-docker-build>=0.0.10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
6-
<Nullable>enable</Nullable>
7-
</PropertyGroup>
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
88

9-
<ItemGroup>
10-
<PackageReference Include="Pulumi" Version="3.*" />
11-
<PackageReference Include="Pulumi.AzureNative" Version="2.*" />
12-
<PackageReference Include="Pulumi.Docker" Version="4.*" />
13-
<PackageReference Include="Pulumi.Random" Version="4.*" />
14-
</ItemGroup>
9+
<ItemGroup>
10+
<PackageReference Include="Pulumi" Version="3.*" />
11+
<PackageReference Include="Pulumi.AzureNative" Version="2.*" />
12+
<PackageReference Include="Pulumi.DockerBuild" Version="0.0.10" />
13+
<PackageReference Include="Pulumi.Random" Version="4.*" />
14+
</ItemGroup>
1515

1616
</Project>

azure-cs-appservice-docker/MyStack.cs

+24-15
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using Pulumi.AzureNative.Resources;
77
using Pulumi.AzureNative.Web;
88
using Pulumi.AzureNative.Web.Inputs;
9-
using Pulumi.Docker;
10-
using Pulumi.Random;
9+
using DockerBuild = Pulumi.DockerBuild;
10+
1111

1212
class MyStack : Stack
1313
{
@@ -61,31 +61,40 @@ public MyStack()
6161
//
6262
var customImage = "node-app";
6363

64-
var registry = new Registry("myregistry", new RegistryArgs
64+
var registry = new Registry("myregistry", new Pulumi.AzureNative.ContainerRegistry.RegistryArgs
6565
{
6666
ResourceGroupName = resourceGroup.Name,
6767
Sku = new SkuArgs { Name = "Basic" },
6868
AdminUserEnabled = true
6969
});
7070

7171
var credentials = ListRegistryCredentials.Invoke(new ListRegistryCredentialsInvokeArgs
72-
{
73-
ResourceGroupName = resourceGroup.Name,
74-
RegistryName = registry.Name
75-
});
72+
{
73+
ResourceGroupName = resourceGroup.Name,
74+
RegistryName = registry.Name
75+
});
7676
var adminUsername = credentials.Apply(c => c.Username ?? "");
7777
var adminPassword = credentials.Apply(c => Output.CreateSecret(c.Passwords.First().Value ?? ""));
7878

79-
var myImage = new Image(customImage, new ImageArgs
79+
var myImage = new DockerBuild.Image(customImage, new Pulumi.DockerBuild.ImageArgs
8080
{
81-
ImageName = Output.Format($"{registry.LoginServer}/{customImage}:v1.0.0"),
82-
Build = new DockerBuild { Context = $"./{customImage}" },
83-
Registry = new ImageRegistry
81+
Context = new DockerBuild.Inputs.BuildContextArgs
8482
{
85-
Server = registry.LoginServer,
86-
Username = adminUsername,
87-
Password = adminPassword
83+
Location = $"./{customImage}",
8884
},
85+
Tags = new[]
86+
{
87+
Output.Format($"{registry.LoginServer}/{customImage}:v1.0.0"),
88+
},
89+
Push = true,
90+
Registries = new[]{
91+
new DockerBuild.Inputs.RegistryArgs
92+
{
93+
Address = registry.LoginServer,
94+
Username = adminUsername,
95+
Password = adminPassword,
96+
}
97+
}
8998
});
9099

91100
var getStartedApp = new WebApp("get-started", new WebAppArgs
@@ -123,7 +132,7 @@ public MyStack()
123132
}
124133
},
125134
AlwaysOn = true,
126-
LinuxFxVersion = Output.Format($"DOCKER|{myImage.ImageName}")
135+
LinuxFxVersion = Output.Format($"DOCKER|{myImage.Ref}")
127136
},
128137
HttpsOnly = true
129138
});

0 commit comments

Comments
 (0)