forked from Azure/azureml-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-custom-container-minimal-single-model.sh
75 lines (58 loc) · 2.86 KB
/
deploy-custom-container-minimal-single-model.sh
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
#!/bin/bash
set -e
# <set_variables>
export ENDPOINT_NAME="<ENDPOINT_NAME>"
export ACR_NAME="<CONTAINER_REGISTRY_NAME>"
# </set_variables>
export ENDPOINT_NAME=endpt-moe-`echo $RANDOM`
export ACR_NAME=$(az ml workspace show --query container_registry -o tsv | cut -d'/' -f9-)
export BASE_PATH=endpoints/online/custom-container/minimal/single-model
export ASSET_PATH=endpoints/online/model-1
# Helper function to change parameters in yaml files
change_vars() {
for FILE in "$@"; do
TMP="${FILE}_"
cp $FILE $TMP
readarray -t VARS < <(cat $TMP | grep -oP '{{.*?}}' | sed -e 's/[}{]//g');
for VAR in "${VARS[@]}"; do
sed -i "s/{{${VAR}}}/${!VAR}/g" $TMP
done
done
}
# <create_endpoint>
change_vars $BASE_PATH/minimal-single-model-endpoint.yml
az ml online-endpoint create -f $BASE_PATH/minimal-single-model-endpoint.yml_
# </create_endpoint>
rm $BASE_PATH/minimal-single-model-endpoint.yml_
# Get key and url
echo "Getting access key and scoring URL..."
KEY=$(az ml online-endpoint get-credentials -n $ENDPOINT_NAME --query primaryKey -o tsv)
SCORING_URL=$(az ml online-endpoint show -n $ENDPOINT_NAME --query scoring_uri -o tsv)
echo "Scoring url is $SCORING_URL"
# <build_image_pip_in_dockerfile>
az acr build -f $BASE_PATH/pip-in-dockerfile/minimal-single-model-pip-in-dockerfile.dockerfile -t azureml-examples/minimal-single-model-pip-in-dockerfile:1 -r $ACR_NAME $ASSET_PATH
# </build_with_pip_in_dockerfile>
# <create_deployment_pip_in_dockerfile>
DEPLOYMENT_YML=$BASE_PATH/pip-in-dockerfile/minimal-single-model-pip-in-dockerfile-deployment.yml
change_vars $DEPLOYMENT_YML
az ml online-deployment create --endpoint-name $ENDPOINT_NAME -f "${DEPLOYMENT_YML}_" --all-traffic
# </create_deployment_pip_in_dockerfile>
# <test_deployment_pip_in_dockerfile>
curl -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" -d @$ASSET_PATH/sample-request.json $SCORING_URL
# </test_deployment_pip_in_dockerfile>
rm $BASE_PATH/pip-in-dockerfile/*.yml_
# <build_image_conda_in_dockerfile>
az acr build -f $BASE_PATH/conda-in-dockerfile/minimal-single-model-conda-in-dockerfile.dockerfile -t azureml-examples/minimal-single-model-conda-in-dockerfile:1 -r $ACR_NAME $ASSET_PATH
# </build_with_conda_in_dockerfile>
# <create_deployment_conda_in_dockerfile>
DEPLOYMENT_YML=$BASE_PATH/conda-in-dockerfile/minimal-single-model-conda-in-dockerfile-deployment.yml
change_vars $DEPLOYMENT_YML
az ml online-deployment create --endpoint-name $ENDPOINT_NAME -f "${DEPLOYMENT_YML}_" --all-traffic
# </create_deployment_conda_in_dockerfile>
# <test_deployment_conda_in_dockerfile>
curl -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" -d @$ASSET_PATH/sample-request.json $SCORING_URL
# </test_deployment_conda_in_dockerfile>
rm $BASE_PATH/conda-in-dockerfile/*.yml_
# <delete_online_endpoint>
az ml online-endpoint delete -y -n $ENDPOINT_NAME
# </delete_online_endpoint>