-
Notifications
You must be signed in to change notification settings - Fork 879
/
MyStack.cs
136 lines (124 loc) · 4.7 KB
/
MyStack.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
using System.Linq;
using Pulumi;
using Pulumi.AzureNative.ContainerRegistry;
using Pulumi.AzureNative.ContainerRegistry.Inputs;
using Pulumi.AzureNative.Resources;
using Pulumi.AzureNative.Web;
using Pulumi.AzureNative.Web.Inputs;
using Pulumi.Docker;
using Pulumi.Random;
class MyStack : Stack
{
public MyStack()
{
var resourceGroup = new ResourceGroup("appservice-docker-rg");
var plan = new AppServicePlan("linux-apps", new AppServicePlanArgs
{
ResourceGroupName = resourceGroup.Name,
Kind = "Linux",
Reserved = true,
Sku = new SkuDescriptionArgs
{
Name = "B1",
Tier = "Basic"
}
});
//
// 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.
//
var customImage = "node-app";
var registry = new Registry("myregistry", new RegistryArgs
{
ResourceGroupName = resourceGroup.Name,
Sku = new SkuArgs { Name = "Basic" },
AdminUserEnabled = true
});
var credentials = ListRegistryCredentials.Invoke(new ListRegistryCredentialsInvokeArgs
{
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
{
ImageName = Output.Format($"{registry.LoginServer}/{customImage}:v1.0.0"),
Build = new DockerBuild { Context = $"./{customImage}" },
Registry = new ImageRegistry
{
Server = registry.LoginServer,
Username = adminUsername,
Password = adminPassword
},
});
var getStartedApp = new WebApp("get-started", new WebAppArgs
{
ResourceGroupName = resourceGroup.Name,
ServerFarmId = plan.Id,
SiteConfig = new SiteConfigArgs
{
AppSettings = new[]
{
new NameValuePairArgs
{
Name = "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
Value = "false"
},
new NameValuePairArgs
{
Name = "DOCKER_REGISTRY_SERVER_URL",
Value = Output.Format($"https://{registry.LoginServer}")
},
new NameValuePairArgs
{
Name = "DOCKER_REGISTRY_SERVER_USERNAME",
Value = adminUsername
},
new NameValuePairArgs
{
Name = "DOCKER_REGISTRY_SERVER_PASSWORD",
Value = adminPassword
},
new NameValuePairArgs
{
Name = "WEBSITES_PORT",
Value = "80" // Our custom image exposes port 80. Adjust for your app as needed.
}
},
AlwaysOn = true,
LinuxFxVersion = Output.Format($"DOCKER|{myImage.ImageName}")
},
HttpsOnly = true
});
this.GetStartedEndpoint = Output.Format($"https://{getStartedApp.DefaultHostName}");
}
[Output] public Output<string> HelloEndpoint { get; set; }
[Output] public Output<string> GetStartedEndpoint { get; set; }
}