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

Updating to fix DockerBuild Settings, Fixes #1869 #2056

Merged
merged 1 commit into from
Mar 5, 2025
Merged
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
18 changes: 11 additions & 7 deletions aws-py-voting-app/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# AWS Python Voting App

[![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)
[![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)

# Voting app Using Redis and Flask
## Voting app Using Redis and Flask

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.
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>.

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:

- Builds the Docker image
- Provisions AWS Container Registry (ECR) instance
- Pushes the image to the ECR instance
Expand All @@ -23,22 +26,23 @@ The example shows how easy it is to deploy containers into production and to con
1. Create a new stack:

```bash
$ pulumi stack init aws-py-voting-app
pulumi stack init aws-py-voting-app
```

1. Set the AWS region and Redis password:

```bash
$ pulumi config set aws:region us-west-2
$ pulumi config set redis-password <PASSWORD> --secret
pulumi config set aws:region us-west-2
pulumi config set redis-password <PASSWORD> --secret
```

1. Run `pulumi up -y` to deploy changes:

```bash
Updating (aws-py-voting-app):
Type Name Status Info
+ pulumi:pulumi:Stack webserver-py-aws-py-voting-app created
+ ├─ docker:image:Image flask-dockerimage created
+ ├─ docker-build:image:Image flask-dockerimage created
+ ├─ aws:ec2:Vpc app-vpc created
+ ├─ aws:ecs:Cluster app-cluster created
+ ├─ aws:iam:Role app-exec-role created
Expand Down Expand Up @@ -83,7 +87,7 @@ The example shows how easy it is to deploy containers into production and to con

```

1. Verify that the EC2 instance exists, by connecting to it in a browser window.
1. Verify that the EC2 instance exists, by connecting to it in a browser window.

## Clean up

Expand Down
31 changes: 15 additions & 16 deletions aws-py-voting-app/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pulumi
import pulumi_aws as aws
import pulumi_docker as docker
import pulumi_docker_build as docker_build

# Get the password to use for Redis from the pulumi config
config = pulumi.Config()
Expand Down Expand Up @@ -143,10 +144,6 @@
port=redis_port,
protocol="TCP",
target_type="ip",
stickiness=aws.lb.TargetGroupStickinessArgs(
enabled=False,
type="lb_cookie",
),
vpc_id=app_vpc.id,
)

Expand Down Expand Up @@ -235,10 +232,6 @@
port=80,
protocol="TCP",
target_type="ip",
stickiness=aws.lb.TargetGroupStickinessArgs(
enabled=False,
type="lb_cookie",
),
vpc_id=app_vpc.id,
)

Expand Down Expand Up @@ -271,17 +264,23 @@ def get_registry_info(rid):
parts = decoded.split(":")
if len(parts) != 2:
raise Exception("Invalid credentials")
return docker.ImageRegistry(creds.proxy_endpoint, parts[0], parts[1])
return docker_build.RegistryArgs(
address=creds.proxy_endpoint, username=parts[0], password=parts[1]
)


app_registry = app_ecr_repo.registry_id.apply(get_registry_info)

flask_image = docker.Image(
flask_image_dockerbuild = docker_build.Image(
"flask-dockerimage",
image_name=app_ecr_repo.repository_url,
build="./frontend",
skip_push=False,
registry=app_registry,
tags=[
app_ecr_repo.repository_url.apply(lambda repository_url: f"{repository_url}:latest"),
],
context=docker_build.BuildContextArgs(
location="./frontend",
),
push=True,
registries=[app_registry],
)

# Creating a task definition for the Flask instance.
Expand All @@ -298,15 +297,15 @@ def get_registry_info(rid):
[
{
"name": "flask-container",
"image": flask_image.image_name,
"image": flask_image_dockerbuild.ref,
"memory": 512,
"essential": True,
"portMappings": [{"containerPort": 80, "hostPort": 80, "protocol": "tcp"}],
"environment": [ # The Redis endpoint we created is given to Flask, allowing it to communicate with the former
{"name": "REDIS", "value": redis_endpoint["host"]},
{
"name": "REDIS_PORT",
"value": redis_endpoint["port"].apply(lambda x: str(x)),
"value": pulumi.Output.concat(str(redis_endpoint["port"])),
},
{"name": "REDIS_PWD", "value": redis_password},
],
Expand Down
1 change: 1 addition & 0 deletions aws-py-voting-app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pulumi>=3.5.1,<4.0.0
pulumi-aws>=6.0.2,<7.0.0
pulumi-docker>=4.6.0,<4.7.0
pulumi-docker-build>=0.0.10
22 changes: 11 additions & 11 deletions azure-cs-appservice-docker/Azure.AppService.Docker.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pulumi" Version="3.*" />
<PackageReference Include="Pulumi.AzureNative" Version="2.*" />
<PackageReference Include="Pulumi.Docker" Version="4.*" />
<PackageReference Include="Pulumi.Random" Version="4.*" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Pulumi" Version="3.*" />
<PackageReference Include="Pulumi.AzureNative" Version="2.*" />
<PackageReference Include="Pulumi.DockerBuild" Version="0.0.10" />
<PackageReference Include="Pulumi.Random" Version="4.*" />
</ItemGroup>

</Project>
71 changes: 25 additions & 46 deletions azure-cs-appservice-docker/MyStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using Pulumi.AzureNative.Resources;
using Pulumi.AzureNative.Web;
using Pulumi.AzureNative.Web.Inputs;
using Pulumi.Docker;
using Pulumi.Random;
using DockerBuild = Pulumi.DockerBuild;


class MyStack : Stack
{
Expand All @@ -28,64 +28,44 @@ public MyStack()
});

//
// Scenario 1: deploying an image from Docker Hub.
// The example uses a HelloWorld application written in Go.
// Image: https://hub.docker.com/r/microsoft/azure-appservices-go-quickstart/
//
var imageInDockerHub = "microsoft/azure-appservices-go-quickstart";

var helloApp = new WebApp("hello-app", new WebAppArgs
{
ResourceGroupName = resourceGroup.Name,
ServerFarmId = plan.Id,
SiteConfig = new SiteConfigArgs
{
AppSettings = new[]
{
new NameValuePairArgs
{
Name = "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
Value = "false"
}
},
AlwaysOn = true,
LinuxFxVersion = $"DOCKER|{imageInDockerHub}"
},
HttpsOnly = true
});

this.HelloEndpoint = Output.Format($"https://{helloApp.DefaultHostName}/hello");

//
// Scenario 2: deploying a custom image from Azure Container Registry.
// Scenario 1: deploying a custom image from Azure Container Registry.
//
var customImage = "node-app";

var registry = new Registry("myregistry", new RegistryArgs
var registry = new Registry("myregistry", new Pulumi.AzureNative.ContainerRegistry.RegistryArgs
{
ResourceGroupName = resourceGroup.Name,
Sku = new SkuArgs { Name = "Basic" },
AdminUserEnabled = true
});

var credentials = ListRegistryCredentials.Invoke(new ListRegistryCredentialsInvokeArgs
{
ResourceGroupName = resourceGroup.Name,
RegistryName = registry.Name
});
{
ResourceGroupName = resourceGroup.Name,
RegistryName = registry.Name
});
var adminUsername = credentials.Apply(c => c.Username ?? "");
var adminPassword = credentials.Apply(c => Output.CreateSecret(c.Passwords.First().Value ?? ""));

var myImage = new Image(customImage, new ImageArgs
var myImage = new DockerBuild.Image(customImage, new Pulumi.DockerBuild.ImageArgs
{
ImageName = Output.Format($"{registry.LoginServer}/{customImage}:v1.0.0"),
Build = new DockerBuild { Context = $"./{customImage}" },
Registry = new ImageRegistry
Context = new DockerBuild.Inputs.BuildContextArgs
{
Server = registry.LoginServer,
Username = adminUsername,
Password = adminPassword
Location = $"./{customImage}",
},
Tags = new[]
{
Output.Format($"{registry.LoginServer}/{customImage}:v1.0.0"),
},
Push = true,
Registries = new[]{
new DockerBuild.Inputs.RegistryArgs
{
Address = registry.LoginServer,
Username = adminUsername,
Password = adminPassword,
}
}
});

var getStartedApp = new WebApp("get-started", new WebAppArgs
Expand Down Expand Up @@ -123,14 +103,13 @@ public MyStack()
}
},
AlwaysOn = true,
LinuxFxVersion = Output.Format($"DOCKER|{myImage.ImageName}")
LinuxFxVersion = Output.Format($"DOCKER|{myImage.Ref}")
},
HttpsOnly = true
});

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

[Output] public Output<string> HelloEndpoint { get; set; }
[Output] public Output<string> GetStartedEndpoint { get; set; }
}
32 changes: 14 additions & 18 deletions azure-cs-appservice-docker/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Azure App Service Running Docker Containers on Linux

[![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)
[![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)

# Azure App Service Running Docker Containers on Linux

Starting point for building web application hosted in Azure App Service from Docker images.

The example shows two scenarios:
Expand All @@ -12,27 +12,27 @@ The example shows two scenarios:

## Running the App

1. Create a new stack:
1. Create a new stack:

```
$ pulumi stack init dev
```bash
pulumi stack init dev
```

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

```
$ az login
```bash
az login
```

1. Set the Azure region location to use:

```
$ pulumi config set azure-native:location westus2
```bash
pulumi config set azure-native:location westus2
```

1. Run `pulumi up` to preview and deploy changes:
1. Run `pulumi up` to preview and deploy changes:

```
```bash
$ pulumi up
Previewing changes:
...
Expand All @@ -45,13 +45,9 @@ The example shows two scenarios:
Duration: 56s
```

1. Check the deployed endpoints:
1. Check the deployed endpoints:

```
$ pulumi stack output HelloEndpoint
http://hello-app-91dfea.azurewebsites.net/hello
$ curl "$(pulumi stack output HelloEndpoint)"
Hello, world!
```bash

$ pulumi stack output GetStartedEndpoint
http://get-started-15da13.azurewebsites.net
Expand Down
Loading