forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
101 lines (90 loc) · 3.34 KB
/
__main__.py
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
# Copyright 2016-2020, Pulumi Corporation. All rights reserved.
import pulumi
import pulumi_azure_native.containerregistry as containerregistry
import pulumi_azure_native.resources as resources
import pulumi_azure_native.web as web
import pulumi_docker as docker
resource_group = resources.ResourceGroup(
"resourceGroup",
)
plan = web.AppServicePlan(
"plan",
resource_group_name=resource_group.name,
kind="Linux",
reserved=True,
sku=web.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/
#
image_in_docker_hub = "microsoft/azure-appservices-go-quickstart"
hello_app = web.WebApp(
"helloApp",
resource_group_name=resource_group.name,
server_farm_id=plan.id,
site_config=web.SiteConfigArgs(
app_settings=[web.NameValuePairArgs(
name="WEBSITES_ENABLE_APP_SERVICE_STORAGE",
value="false"
)],
always_on=True,
linux_fx_version=f"DOCKER|{image_in_docker_hub}",
),
https_only=True)
pulumi.export(
"helloEndpoint",
hello_app.default_host_name.apply(lambda default_host_name: f"https://{default_host_name}/hello"))
#
# Scenario 2: deploying a custom image from Azure Container Registry.
#
custom_image = "node-app"
registry = containerregistry.Registry(
"registry",
resource_group_name=resource_group.name,
sku=containerregistry.SkuArgs(
name="Basic",
),
admin_user_enabled=True)
credentials = containerregistry.list_registry_credentials_output(resource_group_name=resource_group.name,
registry_name=registry.name)
admin_username = credentials.username
admin_password = credentials.passwords[0]["value"]
my_image = docker.Image(
custom_image,
image_name=registry.login_server.apply(
lambda login_server: f"{login_server}/{custom_image}:v1.0.0"),
build=docker.DockerBuild(context=f"./{custom_image}"),
registry=docker.ImageRegistry(
server=registry.login_server,
username=admin_username,
password=admin_password
)
)
get_started_app = web.WebApp(
"getStartedApp",
resource_group_name=resource_group.name,
server_farm_id=plan.id,
site_config=web.SiteConfigArgs(
app_settings=[
web.NameValuePairArgs(name="WEBSITES_ENABLE_APP_SERVICE_STORAGE", value="false"),
web.NameValuePairArgs(name="DOCKER_REGISTRY_SERVER_URL",
value=registry.login_server.apply(
lambda login_server: f"https://{login_server}")),
web.NameValuePairArgs(name="DOCKER_REGISTRY_SERVER_USERNAME",
value=admin_username),
web.NameValuePairArgs(name="DOCKER_REGISTRY_SERVER_PASSWORD",
value=admin_password),
web.NameValuePairArgs(name="WEBSITES_PORT", value="80"),
],
always_on=True,
linux_fx_version=my_image.image_name.apply(lambda image_name: f"DOCKER|{image_name}"),
),
https_only=True)
pulumi.export(
"getStartedEndpoint",
get_started_app.default_host_name.apply(lambda default_host_name: f"https://{default_host_name}"))