forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyStack.cs
159 lines (145 loc) · 5.62 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Copyright 2016-2020, Pulumi Corporation. All rights reserved.
using System.Linq;
using Pulumi;
using Pulumi.AzureNextGen.ContainerRegistry.Latest;
using Pulumi.AzureNextGen.ContainerRegistry.Latest.Inputs;
using Pulumi.AzureNextGen.Resources.Latest;
using Pulumi.AzureNextGen.Web.Latest;
using Pulumi.AzureNextGen.Web.Latest.Inputs;
using Pulumi.Docker;
using Pulumi.Random;
class MyStack : Stack
{
public MyStack()
{
var config = new Pulumi.Config();
var location = config.Get("location") ?? "WestUS";
var resourceGroup = new ResourceGroup("resourceGroup", new ResourceGroupArgs
{
ResourceGroupName = "appservice-docker-rg",
Location = location
});
var plan = new AppServicePlan("linux-apps", new AppServicePlanArgs
{
ResourceGroupName = resourceGroup.Name,
Name = "linux-asp",
Location = resourceGroup.Location,
Kind = "Linux",
Reserved = true,
Sku = new SkuDescriptionArgs
{
Name = "B1",
Tier = "Basic"
}
});
var suffix = new RandomString("random", new RandomStringArgs
{
Length = 6,
Special = false,
Upper = false,
});
//
// 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,
Location = plan.Location,
Name = Output.Format($"hello-app-{suffix.Result}"),
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,
RegistryName = Output.Format($"registry{suffix.Result}"),
Location = resourceGroup.Location,
Sku = new SkuArgs { Name = "Basic" },
AdminUserEnabled = true
});
var credentials = Output.Tuple(resourceGroup.Name, registry.Name).Apply(values =>
ListRegistryCredentials.InvokeAsync(new ListRegistryCredentialsArgs
{
ResourceGroupName = values.Item1,
RegistryName = values.Item2
}));
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,
Location = plan.Location,
Name = Output.Format($"get-started-{suffix.Result}"),
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; }
}