forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
107 lines (94 loc) · 3.27 KB
/
index.ts
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
// Copyright 2016-2020, Pulumi Corporation. All rights reserved.
import * as docker from "@pulumi/docker";
import * as pulumi from "@pulumi/pulumi";
import * as containerregistry from "@pulumi/azure-native/containerregistry";
import * as resources from "@pulumi/azure-native/resources";
import * as web from "@pulumi/azure-native/web";
const resourceGroup = new resources.ResourceGroup("appservice-docker-rg");
const plan = new web.AppServicePlan("plan", {
resourceGroupName: resourceGroup.name,
kind: "Linux",
reserved: true,
sku: {
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/
//
const imageInDockerHub = "microsoft/azure-appservices-go-quickstart";
const helloApp = new web.WebApp("helloApp", {
resourceGroupName: resourceGroup.name,
serverFarmId: plan.id,
siteConfig: {
appSettings: [{
name: "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
value: "false",
}],
alwaysOn: true,
linuxFxVersion: `DOCKER|${imageInDockerHub}`,
},
httpsOnly: true,
});
export const helloEndpoint = pulumi.interpolate`https://${helloApp.defaultHostName}/hello`;
//
// Scenario 2: deploying a custom image from Azure Container Registry.
//
const customImage = "node-app";
const registry = new containerregistry.Registry("registry", {
resourceGroupName: resourceGroup.name,
sku: {
name: "Basic",
},
adminUserEnabled: true,
});
const credentials = containerregistry.listRegistryCredentialsOutput({
resourceGroupName: resourceGroup.name,
registryName: registry.name,
});
const adminUsername = credentials.apply(credentials => credentials.username!);
const adminPassword = credentials.apply(credentials => credentials.passwords![0].value!);
const myImage = new docker.Image(customImage, {
imageName: pulumi.interpolate`${registry.loginServer}/${customImage}:v1.0.0`,
build: { context: `./${customImage}` },
registry: {
server: registry.loginServer,
username: adminUsername,
password: adminPassword,
},
});
const getStartedApp = new web.WebApp("getStartedApp", {
resourceGroupName: resourceGroup.name,
serverFarmId: plan.id,
siteConfig: {
appSettings: [
{
name: "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
value: "false",
},
{
name: "DOCKER_REGISTRY_SERVER_URL",
value: pulumi.interpolate`https://${registry.loginServer}`,
},
{
name: "DOCKER_REGISTRY_SERVER_USERNAME",
value: adminUsername,
},
{
name: "DOCKER_REGISTRY_SERVER_PASSWORD",
value: adminPassword,
},
{
name: "WEBSITES_PORT",
value: "80", // Our custom image exposes port 80. Adjust for your app as needed.
},
],
alwaysOn: true,
linuxFxVersion: pulumi.interpolate`DOCKER|${myImage.imageName}`,
},
httpsOnly: true,
});
export const getStartedEndpoint = pulumi.interpolate`https://${getStartedApp.defaultHostName}`;