Skip to content

Commit fd20cd2

Browse files
author
Larry Franks
committed
refactoring to use CLI
1 parent 64d0ace commit fd20cd2

File tree

1 file changed

+125
-14
lines changed

1 file changed

+125
-14
lines changed

articles/machine-learning/service/how-to-deploy-app-service.md

Lines changed: 125 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.topic: conceptual
99
ms.author: aashishb
1010
author: aashishb
1111
ms.reviewer: larryfr
12-
ms.date: 07/01/2019
12+
ms.date: 08/27/2019
1313

1414

1515
---
@@ -35,6 +35,7 @@ For more information on features provided by Azure App Service, see the [App Ser
3535
## Prerequisites
3636

3737
* An Azure Machine Learning service workspace. For more information, see the [Create a workspace](how-to-manage-workspace.md) article.
38+
* The [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli?view=azure-cli-latest).
3839
* A trained machine learning model registered in your workspace. If you do not have a model, use the [Image classification tutorial: train model](tutorial-train-models-with-aml.md) to train and register one.
3940

4041
> [!IMPORTANT]
@@ -94,34 +95,146 @@ For more information on inference configuration, see [Deploy models with the Azu
9495
9596
To create the Docker image that is deployed to Azure App Service, use [Model.package](https://docs.microsoft.com//python/api/azureml-core/azureml.core.model.model?view=azure-ml-py#package-workspace--models--inference-config--generate-dockerfile-false-). The following code snippet demonstrates how to build a new image from the model and inference configuration:
9697
98+
> [!NOTE]
99+
> The code snippet assumes that `model` contains a registered model, and that `inference_config` contains the configuration for the inference environment. For more information, see [Deploy models with the Azure Machine Learning service](how-to-deploy-and-where.md).
100+
97101
```python
102+
from azureml.core import Model
103+
98104
package = Model.package(ws, [model], inference_config)
99105
package.wait_for_creation(show_output=True)
106+
# Display the package location/ACR path
107+
print(package.location)
100108
```
101109
102-
When `show_output=True`, the output of the Docker build process is shown. Once the process finishes, the image has been created in the Azure Container Registry for your workspace.
110+
When `show_output=True`, the output of the Docker build process is shown. Once the process finishes, the image has been created in the Azure Container Registry for your workspace. Once the image has been built, the location in your Azure Container Registry is displayed. The location returned is in the format `<acrinstance>.azurecr.io/package:<imagename>`. For example, `myml08024f78fd10.azurecr.io/package:20190827151241`.
111+
112+
> [!IMPORTANT]
113+
> Save the location information, as it is used when deploying the image.
103114
104115
## Deploy image as a web app
105116
106-
1. From the [Azure portal](https://portal.azure.com), select your Azure Machine Learning workspace. From the __Overview__ section, use the __Registry__ link to access the Azure Container Registry for the workspace.
117+
1. Use the following command to get the login credentials for the Azure Container Registry that contains the image. Replace `<acrinstance>` with th e value returned previously from `package.location`:
107118
108-
[![Screenshot of the overview for the workspace](media/how-to-deploy-app-service/workspace-overview.png)](media/how-to-deploy-app-service/workspace-overview-expanded.png)
119+
```azurecli-interactive
120+
az acr credential show --name <myacr>
121+
```
109122
110-
2. From the Azure Container Registry, select __Repositories__, and then select the __image name__ that you want to deploy. For the version that you want to deploy, select the __...__ entry, and then __Deploy to web app__.
123+
The output of this command is similar to the following JSON document:
111124
112-
[![Screenshot of deploying from ACR to a web app](media/how-to-deploy-app-service/deploy-to-web-app.png)](media/how-to-deploy-app-service/deploy-to-web-app-expanded.png)
125+
```json
126+
{
127+
"passwords": [
128+
{
129+
"name": "password",
130+
"value": "Iv0lRZQ9762LUJrFiffo3P4sWgk4q+nW"
131+
},
132+
{
133+
"name": "password2",
134+
"value": "=pKCxHatX96jeoYBWZLsPR6opszr==mg"
135+
}
136+
],
137+
"username": "myml08024f78fd10"
138+
}
139+
```
113140
114-
3. To create the Web App, provide a site name, subscription, resource group, and select the App service plan/location. Finally, select __Create__.
141+
Save the value for __username__ and one of the __passwords__.
115142
116-
![Screenshot of the new web app dialog](media/how-to-deploy-app-service/web-app-for-containers.png)
143+
1. If you do not already have a resource group or app service plan to deploy the service, the following commands demonstrate how to create both:
117144
118-
## Use the Web App
145+
```azurecli-interactive
146+
az group create --name myresourcegroup --location "West Europe"
147+
az appservice plan create --name myplanname --resource-group myresourcegroup --sku B1 --is-linux
148+
```
119149
120-
From the [Azure portal](https://portal.azure.com), select the Web App created in the previous step. From the __Overview__ section, copy the __URL__. This value is the __base URL__ of the service.
150+
In this example, a __Basic__ pricing tier (`--sku B1`) is used.
121151
122-
[![Screenshot of the overview for the web app](media/how-to-deploy-app-service/web-app-overview.png)](media/how-to-deploy-app-service/web-app-overview-expanded.png)
152+
> [!IMPORTANT]
153+
> Images created by the Azure Machine Learning service use Linux, so you must use the `--is-linux` parameter.
154+
155+
1. To create the web app, use the following command. Replace `<app-name>` with the name you want to use. Replace `<acrinstance>` and `<imagename>` with the values from returned `package.location` earlier:
156+
157+
```azurecli-interactive
158+
az webapp create --resource-group myresourcegroup --plan myplanname --name <app-name> --deployment-container-image-name <acrinstance>.azurecr.io/package:<imagename>
159+
```
160+
161+
This command returns information similar to the following JSON document:
162+
163+
```json
164+
{
165+
"adminSiteName": null,
166+
"appServicePlanName": "myplanname",
167+
"geoRegion": "West Europe",
168+
"hostingEnvironmentProfile": null,
169+
"id": "/subscriptions/0000-0000/resourceGroups/myResourceGroup/providers/Microsoft.Web/serverfarms/myplanname",
170+
"kind": "linux",
171+
"location": "West Europe",
172+
"maximumNumberOfWorkers": 1,
173+
"name": "myplanname",
174+
< JSON data removed for brevity. >
175+
"targetWorkerSizeId": 0,
176+
"type": "Microsoft.Web/serverfarms",
177+
"workerTierName": null
178+
}
179+
```
180+
181+
1. To provide the web app with the credentials needed to access the container registry, use the following command. Replace `<app-name>` with the name you want to use. Replace `<acrinstance>` and `<imagename>` with the values from returned `package.location` earlier. Replace `<username>` and `<password>` with the ACR login information retrieved earlier:
182+
183+
```azurecli-interactive
184+
az webapp config container set --name <app-name> --resource-group myresourcegroup --docker-custom-image-name <acrinstance>.azurecr.io/package:<imagename> --docker-registry-server-url https://<acrinstance>.azurecr.io --docker-registry-server-user <username> --docker-registry-server-password <password>
185+
```
186+
187+
This command returns information similar to the following JSON document:
188+
189+
```json
190+
[
191+
{
192+
"name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
193+
"slotSetting": false,
194+
"value": "false"
195+
},
196+
{
197+
"name": "DOCKER_REGISTRY_SERVER_URL",
198+
"slotSetting": false,
199+
"value": "https://myml08024f78fd10.azurecr.io"
200+
},
201+
{
202+
"name": "DOCKER_REGISTRY_SERVER_USERNAME",
203+
"slotSetting": false,
204+
"value": "myml08024f78fd10"
205+
},
206+
{
207+
"name": "DOCKER_REGISTRY_SERVER_PASSWORD",
208+
"slotSetting": false,
209+
"value": null
210+
},
211+
{
212+
"name": "DOCKER_CUSTOM_IMAGE_NAME",
213+
"value": "DOCKER|myml08024f78fd10.azurecr.io/package:20190827195524"
214+
}
215+
]
216+
```
217+
218+
At this point, the web app begins loading the image.
123219
124-
The web service that passes requests to the model is located at `{baseurl}/score`. For example, `https://mywebapp.azurewebsites.net/score`. The following Python code demonstrates how to submit data to the URL and display the response:
220+
> [!IMPORTANT]
221+
> It may take several minutes before the image has loaded. To monitor progress, use the following command:
222+
>
223+
> ```azurecli-interactive
224+
> az webapp log tail --name <app-name> --resource-group myresourcegroup
225+
> ```
226+
227+
Once the image is deployed, you can find the hostname by using the following command:
228+
229+
```azurecli-interactive
230+
az webapp show --name <app-name> --resource-group myresourcegroup
231+
```
232+
233+
This command returns information similar to the following hostname - `<app-name>.azurewebsites.net`. Use this value as part of the __base url__ for the service.
234+
235+
## Use the Web App
236+
237+
The web service that passes requests to the model is located at `{baseurl}/score`. For example, `https://<app-name>.azurewebsites.net/score`. The following Python code demonstrates how to submit data to the URL and display the response:
125238
126239
```python
127240
import requests
@@ -130,8 +243,6 @@ import json
130243
scoring_uri = "https://mywebapp.azurewebsites.net/score"
131244
132245
headers = {'Content-Type':'application/json'}
133-
134-
print(headers)
135246
136247
test_sample = json.dumps({'data': [
137248
[1,2,3,4,5,6,7,8,9,10],

0 commit comments

Comments
 (0)