Skip to content

Commit 4d4e5cc

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

File tree

6 files changed

+77
-94
lines changed

6 files changed

+77
-94
lines changed

aws-py-voting-app/README.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
# AWS Python Voting App
2+
13
[![Deploy this example with Pulumi](https://www.pulumi.com/images/deploy-with-pulumi/dark.svg)](https://app.pulumi.com/new?template=https://github.com/pulumi/examples/blob/master/aws-py-voting-app/README.md#gh-light-mode-only)
24
[![Deploy this example with Pulumi](https://get.pulumi.com/new/button-light.svg)](https://app.pulumi.com/new?template=https://github.com/pulumi/examples/blob/master/aws-py-voting-app/README.md#gh-dark-mode-only)
35

4-
# Voting app Using Redis and Flask
6+
## Voting app Using Redis and Flask
57

6-
A simple voting app that uses Redis for a data store and a Python Flask app for the frontend. The example has been ported from https://github.com/Azure-Samples/azure-voting-app-redis.
8+
A simple voting app that uses Redis for a data store and a Python Flask app for the frontend. The example has been ported from <https://github.com/Azure-Samples/azure-voting-app-redis>.
79

810
The example shows how easy it is to deploy containers into production and to connect them to one another. Since the example defines a custom container, Pulumi does the following:
11+
912
- Builds the Docker image
1013
- Provisions AWS Container Registry (ECR) instance
1114
- Pushes the image to the ECR instance
@@ -23,22 +26,23 @@ The example shows how easy it is to deploy containers into production and to con
2326
1. Create a new stack:
2427

2528
```bash
26-
$ pulumi stack init aws-py-voting-app
29+
pulumi stack init aws-py-voting-app
2730
```
2831

2932
1. Set the AWS region and Redis password:
3033

3134
```bash
32-
$ pulumi config set aws:region us-west-2
33-
$ pulumi config set redis-password <PASSWORD> --secret
35+
pulumi config set aws:region us-west-2
36+
pulumi config set redis-password <PASSWORD> --secret
3437
```
3538

3639
1. Run `pulumi up -y` to deploy changes:
40+
3741
```bash
3842
Updating (aws-py-voting-app):
3943
Type Name Status Info
4044
+ pulumi:pulumi:Stack webserver-py-aws-py-voting-app created
41-
+ ├─ docker:image:Image flask-dockerimage created
45+
+ ├─ docker-build:image:Image flask-dockerimage created
4246
+ ├─ aws:ec2:Vpc app-vpc created
4347
+ ├─ aws:ecs:Cluster app-cluster created
4448
+ ├─ aws:iam:Role app-exec-role created
@@ -83,7 +87,7 @@ The example shows how easy it is to deploy containers into production and to con
8387
8488
```
8589

86-
1. Verify that the EC2 instance exists, by connecting to it in a browser window.
90+
1. Verify that the EC2 instance exists, by connecting to it in a browser window.
8791

8892
## Clean up
8993

aws-py-voting-app/__main__.py

+15-16
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()
@@ -143,10 +144,6 @@
143144
port=redis_port,
144145
protocol="TCP",
145146
target_type="ip",
146-
stickiness=aws.lb.TargetGroupStickinessArgs(
147-
enabled=False,
148-
type="lb_cookie",
149-
),
150147
vpc_id=app_vpc.id,
151148
)
152149

@@ -235,10 +232,6 @@
235232
port=80,
236233
protocol="TCP",
237234
target_type="ip",
238-
stickiness=aws.lb.TargetGroupStickinessArgs(
239-
enabled=False,
240-
type="lb_cookie",
241-
),
242235
vpc_id=app_vpc.id,
243236
)
244237

@@ -271,17 +264,23 @@ def get_registry_info(rid):
271264
parts = decoded.split(":")
272265
if len(parts) != 2:
273266
raise Exception("Invalid credentials")
274-
return docker.ImageRegistry(creds.proxy_endpoint, parts[0], parts[1])
267+
return docker_build.RegistryArgs(
268+
address=creds.proxy_endpoint, username=parts[0], password=parts[1]
269+
)
275270

276271

277272
app_registry = app_ecr_repo.registry_id.apply(get_registry_info)
278273

279-
flask_image = docker.Image(
274+
flask_image_dockerbuild = docker_build.Image(
280275
"flask-dockerimage",
281-
image_name=app_ecr_repo.repository_url,
282-
build="./frontend",
283-
skip_push=False,
284-
registry=app_registry,
276+
tags=[
277+
app_ecr_repo.repository_url.apply(lambda repository_url: f"{repository_url}:latest"),
278+
],
279+
context=docker_build.BuildContextArgs(
280+
location="./frontend",
281+
),
282+
push=True,
283+
registries=[app_registry],
285284
)
286285

287286
# Creating a task definition for the Flask instance.
@@ -298,15 +297,15 @@ def get_registry_info(rid):
298297
[
299298
{
300299
"name": "flask-container",
301-
"image": flask_image.image_name,
300+
"image": flask_image_dockerbuild.ref,
302301
"memory": 512,
303302
"essential": True,
304303
"portMappings": [{"containerPort": 80, "hostPort": 80, "protocol": "tcp"}],
305304
"environment": [ # The Redis endpoint we created is given to Flask, allowing it to communicate with the former
306305
{"name": "REDIS", "value": redis_endpoint["host"]},
307306
{
308307
"name": "REDIS_PORT",
309-
"value": redis_endpoint["port"].apply(lambda x: str(x)),
308+
"value": pulumi.Output.concat(str(redis_endpoint["port"])),
310309
},
311310
{"name": "REDIS_PWD", "value": redis_password},
312311
],

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

+25-46
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
{
@@ -28,64 +28,44 @@ public MyStack()
2828
});
2929

3030
//
31-
// Scenario 1: deploying an image from Docker Hub.
32-
// The example uses a HelloWorld application written in Go.
33-
// Image: https://hub.docker.com/r/microsoft/azure-appservices-go-quickstart/
34-
//
35-
var imageInDockerHub = "microsoft/azure-appservices-go-quickstart";
36-
37-
var helloApp = new WebApp("hello-app", new WebAppArgs
38-
{
39-
ResourceGroupName = resourceGroup.Name,
40-
ServerFarmId = plan.Id,
41-
SiteConfig = new SiteConfigArgs
42-
{
43-
AppSettings = new[]
44-
{
45-
new NameValuePairArgs
46-
{
47-
Name = "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
48-
Value = "false"
49-
}
50-
},
51-
AlwaysOn = true,
52-
LinuxFxVersion = $"DOCKER|{imageInDockerHub}"
53-
},
54-
HttpsOnly = true
55-
});
56-
57-
this.HelloEndpoint = Output.Format($"https://{helloApp.DefaultHostName}/hello");
58-
59-
//
60-
// Scenario 2: deploying a custom image from Azure Container Registry.
31+
// Scenario 1: deploying a custom image from Azure Container Registry.
6132
//
6233
var customImage = "node-app";
6334

64-
var registry = new Registry("myregistry", new RegistryArgs
35+
var registry = new Registry("myregistry", new Pulumi.AzureNative.ContainerRegistry.RegistryArgs
6536
{
6637
ResourceGroupName = resourceGroup.Name,
6738
Sku = new SkuArgs { Name = "Basic" },
6839
AdminUserEnabled = true
6940
});
7041

7142
var credentials = ListRegistryCredentials.Invoke(new ListRegistryCredentialsInvokeArgs
72-
{
73-
ResourceGroupName = resourceGroup.Name,
74-
RegistryName = registry.Name
75-
});
43+
{
44+
ResourceGroupName = resourceGroup.Name,
45+
RegistryName = registry.Name
46+
});
7647
var adminUsername = credentials.Apply(c => c.Username ?? "");
7748
var adminPassword = credentials.Apply(c => Output.CreateSecret(c.Passwords.First().Value ?? ""));
7849

79-
var myImage = new Image(customImage, new ImageArgs
50+
var myImage = new DockerBuild.Image(customImage, new Pulumi.DockerBuild.ImageArgs
8051
{
81-
ImageName = Output.Format($"{registry.LoginServer}/{customImage}:v1.0.0"),
82-
Build = new DockerBuild { Context = $"./{customImage}" },
83-
Registry = new ImageRegistry
52+
Context = new DockerBuild.Inputs.BuildContextArgs
8453
{
85-
Server = registry.LoginServer,
86-
Username = adminUsername,
87-
Password = adminPassword
54+
Location = $"./{customImage}",
8855
},
56+
Tags = new[]
57+
{
58+
Output.Format($"{registry.LoginServer}/{customImage}:v1.0.0"),
59+
},
60+
Push = true,
61+
Registries = new[]{
62+
new DockerBuild.Inputs.RegistryArgs
63+
{
64+
Address = registry.LoginServer,
65+
Username = adminUsername,
66+
Password = adminPassword,
67+
}
68+
}
8969
});
9070

9171
var getStartedApp = new WebApp("get-started", new WebAppArgs
@@ -123,14 +103,13 @@ public MyStack()
123103
}
124104
},
125105
AlwaysOn = true,
126-
LinuxFxVersion = Output.Format($"DOCKER|{myImage.ImageName}")
106+
LinuxFxVersion = Output.Format($"DOCKER|{myImage.Ref}")
127107
},
128108
HttpsOnly = true
129109
});
130110

131111
this.GetStartedEndpoint = Output.Format($"https://{getStartedApp.DefaultHostName}");
132112
}
133113

134-
[Output] public Output<string> HelloEndpoint { get; set; }
135114
[Output] public Output<string> GetStartedEndpoint { get; set; }
136115
}

azure-cs-appservice-docker/README.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
# Azure App Service Running Docker Containers on Linux
2+
13
[![Deploy this example with Pulumi](https://www.pulumi.com/images/deploy-with-pulumi/dark.svg)](https://app.pulumi.com/new?template=https://github.com/pulumi/examples/blob/master/azure-cs-appservice-docker/README.md#gh-light-mode-only)
24
[![Deploy this example with Pulumi](https://get.pulumi.com/new/button-light.svg)](https://app.pulumi.com/new?template=https://github.com/pulumi/examples/blob/master/azure-cs-appservice-docker/README.md#gh-dark-mode-only)
35

4-
# Azure App Service Running Docker Containers on Linux
5-
66
Starting point for building web application hosted in Azure App Service from Docker images.
77

88
The example shows two scenarios:
@@ -12,27 +12,27 @@ The example shows two scenarios:
1212

1313
## Running the App
1414

15-
1. Create a new stack:
15+
1. Create a new stack:
1616

17-
```
18-
$ pulumi stack init dev
17+
```bash
18+
pulumi stack init dev
1919
```
2020

21-
1. Login to Azure CLI (you will be prompted to do this during deployment if you forget this step):
21+
1. Login to Azure CLI (you will be prompted to do this during deployment if you forget this step):
2222

23-
```
24-
$ az login
23+
```bash
24+
az login
2525
```
2626

2727
1. Set the Azure region location to use:
2828

29-
```
30-
$ pulumi config set azure-native:location westus2
29+
```bash
30+
pulumi config set azure-native:location westus2
3131
```
3232

33-
1. Run `pulumi up` to preview and deploy changes:
33+
1. Run `pulumi up` to preview and deploy changes:
3434

35-
```
35+
```bash
3636
$ pulumi up
3737
Previewing changes:
3838
...
@@ -45,9 +45,9 @@ The example shows two scenarios:
4545
Duration: 56s
4646
```
4747

48-
1. Check the deployed endpoints:
48+
1. Check the deployed endpoints:
4949

50-
```
50+
```bash
5151
$ pulumi stack output HelloEndpoint
5252
http://hello-app-91dfea.azurewebsites.net/hello
5353
$ curl "$(pulumi stack output HelloEndpoint)"

0 commit comments

Comments
 (0)