Skip to content

Commit 5066fa3

Browse files
author
Erik Parmann
committed
Create webapp from arm template automatically
1 parent f8cd70f commit 5066fa3

File tree

4 files changed

+165
-3
lines changed

4 files changed

+165
-3
lines changed

.pipelines/diabetes_regression-ci.yml

+28
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,35 @@ stages:
186186
python -m ml_service.util.create_scoring_image --output_image_location_file image_location.txt
187187
# Output image location to Azure DevOps job
188188
IMAGE_LOCATION="$(cat image_location.txt)"
189+
export IMAGE_TAGGED="$(sed 's/@sha256.*/:latest/g' image_location.txt)"
189190
echo "##vso[task.setvariable variable=IMAGE_LOCATION]$IMAGE_LOCATION"
191+
echo "##vso[task.setvariable variable=IMAGE_TAGGED]$IMAGE_TAGGED"
192+
- task: AzureResourceGroupDeployment@2
193+
inputs:
194+
azureSubscription: '$(AZURE_RM_SVC_CONNECTION)'
195+
action: 'Create Or Update Resource Group'
196+
resourceGroupName: '$(RESOURCE_GROUP)'
197+
location: $(LOCATION)
198+
templateLocation: 'Linked artifact'
199+
csmFile: '$(Build.SourcesDirectory)/environment_setup/arm-templates/aci-password.json'
200+
overrideParameters: '-baseName $(BASE_NAME)'
201+
deploymentMode: 'Incremental'
202+
deploymentOutputs: 'ACRCREDENTIALS'
203+
displayName: 'Get ACR username and password'
204+
205+
- task: AzureResourceGroupDeployment@2
206+
inputs:
207+
azureSubscription: '$(AZURE_RM_SVC_CONNECTION)'
208+
action: 'Create Or Update Resource Group'
209+
resourceGroupName: '$(RESOURCE_GROUP)'
210+
location: $(LOCATION)
211+
templateLocation: 'Linked artifact'
212+
csmFile: '$(Build.SourcesDirectory)/environment_setup/arm-templates/webapp-env.json'
213+
overrideParameters: '-baseName $(BASE_NAME) -location $(LOCATION) -imagelocation $(IMAGE_TAGGED) -acrcredentials $(ACRCREDENTIALS)'
214+
deploymentMode: 'Incremental'
215+
displayName: 'Create webapp'
216+
217+
190218
- task: AzureWebAppContainer@1
191219
name: WebAppDeploy
192220
displayName: 'Azure Web App on Container Deploy'

docs/getting_started.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ Delete the **ACI_DEPLOYMENT_NAME** variable.
236236

237237
The pipeline uses the [Create Image Script](../ml_service/util/create_scoring_image.py) to create a scoring image. The image will be registered under an Azure Container Registry instance that belongs to the Azure Machine Learning Service. Any dependencies that the scoring file depends on can also be packaged with the container with an image config. Learn more about how to create a container using the Azure ML SDK with the [Image class](https://docs.microsoft.com/en-us/python/api/azureml-core/azureml.core.image.image.image?view=azure-ml-py#create-workspace--name--models--image-config-) API documentation.
238238

239-
Make sure your webapp has the credentials to pull the image from the Azure Container Registry created by the Infrastructure as Code pipeline. Instructions can be found on the [Configure registry credentials in web app](https://docs.microsoft.com/en-us/azure/devops/pipelines/targets/webapp-on-container-linux?view=azure-devops&tabs=dotnet-core%2Cyaml#configure-registry-credentials-in-web-app) page. You'll need to run the pipeline once (including the Deploy to Webapp stage up to the `Create scoring image` step) so an image is present in the registry. After that, you can connect the Webapp to the Azure Container Registry in the Azure Portal.
240-
241-
![build](./images/multi-stage-webapp.png)
239+
The pipeline should create the webapp automatically the first time it is run with **WEBAPP_DEPLOYMENT_NAME** set.
242240

243241
### Example pipelines using R
244242

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"baseName": {
6+
"type": "string",
7+
"maxLength": 10,
8+
"minLength": 3,
9+
"metadata": {
10+
"description": "The base name to use as prefix to create all the resources."
11+
}
12+
},
13+
"acr": {
14+
"type": "string",
15+
"defaultValue": "[concat(toLower(parameters('baseName')),'amlcr')]"
16+
}
17+
},
18+
"resources": []
19+
, "outputs": {
20+
"password": {
21+
"type": "string",
22+
"value": "[listCredentials(resourceId('myResourceGroup','Microsoft.ContainerRegistry/registries',parameters('acr')),'2019-05-01').passwords[1].value]"
23+
},
24+
"username": {
25+
"type": "string",
26+
"value": "[listCredentials(resourceId('Microsoft.ContainerRegistry/registries',parameters('acr')),'2019-05-01').username]"
27+
}
28+
}
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"imagelocation":{
6+
"type": "string"
7+
},
8+
"acrcredentials": {
9+
"type": "secureObject"
10+
},
11+
"baseName": {
12+
"type": "string",
13+
"maxLength": 10,
14+
"minLength": 3,
15+
"metadata": {
16+
"description": "The base name to use as prefix to create all the resources."
17+
}
18+
},
19+
"location": {
20+
"type": "string",
21+
"defaultValue": "eastus",
22+
"allowedValues": [
23+
"eastus",
24+
"eastus2",
25+
"southcentralus",
26+
"southeastasia",
27+
"westcentralus",
28+
"westeurope",
29+
"westus2",
30+
"centralus"
31+
],
32+
"metadata": {
33+
"description": "Specifies the location for all resources."
34+
}
35+
},
36+
"acr": {
37+
"type": "string",
38+
"defaultValue": "[concat(toLower(parameters('baseName')),'amlcr')]"
39+
},
40+
"webAppName": {
41+
"type": "string",
42+
"defaultValue" : "[concat(toLower(parameters('baseName')),'webapp')]",
43+
"metadata": {
44+
"description": "Base name of the resource such as web app name and app service plan "
45+
},
46+
"minLength": 2
47+
}
48+
},
49+
"variables": {
50+
"containerRegistryName": "[parameters('acr')]",
51+
"webAppPortalName": "[concat(parameters('webAppName'), '-webapp')]",
52+
"appServicePlanName": "[concat('AppServicePlan-', parameters('webAppName'))]"
53+
54+
},
55+
"resources": [
56+
{
57+
"type": "Microsoft.Web/serverfarms",
58+
"apiVersion": "2018-02-01",
59+
"name": "[variables('appServicePlanName')]",
60+
"location": "[parameters('location')]",
61+
"sku": {
62+
"name": "S1"
63+
},
64+
"kind": "linux",
65+
"properties":{
66+
"reserved":true,
67+
"maximumElasticWorkerCount": 5
68+
}
69+
},
70+
{
71+
"type": "Microsoft.Web/sites",
72+
"apiVersion": "2018-11-01",
73+
"name": "[variables('webAppPortalName')]",
74+
"location": "[parameters('location')]",
75+
"kind": "app,linux,container",
76+
"dependsOn": [
77+
"[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
78+
],
79+
"properties": {
80+
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]",
81+
"httpsOnly": true,
82+
"siteConfig": {
83+
"linuxFxVersion": "[concat('DOCKER|', parameters('imagelocation'))]",
84+
"appSettings": [
85+
{
86+
"name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
87+
"value": "false"
88+
},
89+
{
90+
"name": "DOCKER_REGISTRY_SERVER_URL",
91+
"value": "[concat('https://', variables('containerRegistryName'), '.azurecr.io')]"
92+
},
93+
{
94+
"name": "DOCKER_REGISTRY_SERVER_USERNAME",
95+
"value": "[parameters('acrcredentials').username.value]"
96+
},
97+
{
98+
"name": "DOCKER_REGISTRY_SERVER_PASSWORD",
99+
"value": "[parameters('acrcredentials').password.value]"
100+
}
101+
]
102+
}
103+
}
104+
}
105+
]
106+
}

0 commit comments

Comments
 (0)