Skip to content

Commit a5df67e

Browse files
author
Erik Parmann
committed
Create webapp from arm template automatically
1 parent 27b7d2a commit a5df67e

File tree

6 files changed

+167
-4
lines changed

6 files changed

+167
-4
lines changed

.pipelines/diabetes_regression-cd.yml

+26
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,32 @@ stages:
142142
condaFilePath: '$(Build.SourcesDirectory)/$(SOURCES_DIR_TRAIN)/conda_dependencies.yml'
143143
- script: echo $(IMAGE_LOCATION) >image_location.txt
144144
displayName: "Write image location file"
145+
146+
- task: AzureResourceGroupDeployment@2
147+
inputs:
148+
azureSubscription: '$(AZURE_RM_SVC_CONNECTION)'
149+
action: 'Create Or Update Resource Group'
150+
resourceGroupName: '$(RESOURCE_GROUP)'
151+
location: $(LOCATION)
152+
templateLocation: 'Linked artifact'
153+
csmFile: '$(Build.SourcesDirectory)/environment_setup/arm-templates/aci-password.json'
154+
overrideParameters: '-baseName $(BASE_NAME)'
155+
deploymentMode: 'Incremental'
156+
deploymentOutputs: 'ACRCREDENTIALS'
157+
displayName: 'Get ACR username and password'
158+
159+
- task: AzureResourceGroupDeployment@2
160+
inputs:
161+
azureSubscription: '$(AZURE_RM_SVC_CONNECTION)'
162+
action: 'Create Or Update Resource Group'
163+
resourceGroupName: '$(RESOURCE_GROUP)'
164+
location: $(LOCATION)
165+
templateLocation: 'Linked artifact'
166+
csmFile: '$(Build.SourcesDirectory)/environment_setup/arm-templates/webapp-env.json'
167+
overrideParameters: '-baseName $(BASE_NAME) -location $(LOCATION) -imagelocation $(IMAGE_TAGGED) -acrcredentials $(ACRCREDENTIALS)'
168+
deploymentMode: 'Incremental'
169+
displayName: 'Create webapp'
170+
145171
- task: AzureWebAppContainer@1
146172
name: WebAppDeploy
147173
displayName: 'Azure Web App on Container Deploy'

.pipelines/diabetes_regression-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ stages:
9494
container: mlops
9595
timeoutInMinutes: 0
9696
steps:
97-
- template: diabetes_regression-publish-model-artifact-template.yml
97+
- template: diabetes_regression-publish-model-artifact-template.yml

.pipelines/diabetes_regression-package-model-template.yml

+3
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ steps:
4040
# Set environment variable using the last line of logs that has the package location
4141
IMAGE_LOCATION=$(tail -n 1 image_logs.txt)
4242
echo "##vso[task.setvariable variable=IMAGE_LOCATION]$IMAGE_LOCATION"
43+
echo $IMAGE_LOCATION > image_location.txt
44+
IMAGE_TAGGED="$(sed 's/@sha256.*/:latest/g' image_location.txt)"
45+
echo "##vso[task.setvariable variable=IMAGE_TAGGED]$IMAGE_TAGGED"

docs/getting_started.md

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

350350
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.
351351

352-
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.
353-
354-
![build](./images/multi-stage-webapp.png)
352+
The pipeline should create the webapp automatically the first time it is run with **WEBAPP_DEPLOYMENT_NAME** set.
355353

356354
### Example pipelines using R
357355

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)