-
Notifications
You must be signed in to change notification settings - Fork 878
/
Copy pathMyStack.cs
115 lines (105 loc) · 3.88 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
// Copyright 2016-2025, 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 DockerBuild = Pulumi.DockerBuild;
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 a custom image from Azure Container Registry.
//
var customImage = "node-app";
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
});
var adminUsername = credentials.Apply(c => c.Username ?? "");
var adminPassword = credentials.Apply(c => Output.CreateSecret(c.Passwords.First().Value ?? ""));
var myImage = new DockerBuild.Image(customImage, new Pulumi.DockerBuild.ImageArgs
{
Context = new DockerBuild.Inputs.BuildContextArgs
{
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
{
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.Ref}")
},
HttpsOnly = true
});
this.GetStartedEndpoint = Output.Format($"https://{getStartedApp.DefaultHostName}");
}
[Output] public Output<string> GetStartedEndpoint { get; set; }
}