|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Log into Azure using the provided credentials |
| 5 | +echo "Logging into Azure..." |
| 6 | +echo "$1" > azure_credentials.json |
| 7 | +az login --service-principal --username $(jq -r .clientId azure_credentials.json) --password $(jq -r .clientSecret azure_credentials.json) --tenant $(jq -r .tenantId azure_credentials.json) |
| 8 | + |
| 9 | +local endpoint="$2" # The endpoint to which the deployment belongs |
| 10 | +local workspace="$3" # The machine learning workspace name where the endpoint belongs |
| 11 | +local resourceGroup="$4" # The resource group where the deployment and endpoint belong |
| 12 | + |
| 13 | +# Set up Azure CLI and ML extension |
| 14 | +echo "Setting up Azure CLI..." |
| 15 | +az account show |
| 16 | +az extension add --name ml -y |
| 17 | + |
| 18 | +echo "Creating Endpoint $endpoint in Workspace $workspace in Resource Group $resourceGroup..." |
| 19 | + |
| 20 | +# Check if workspace exists |
| 21 | +local workspaceExists |
| 22 | +workspaceExists=$(az ml workspace show \ |
| 23 | + --resource-group "$resourceGroup" \ |
| 24 | + --workspace-name "$workspace" 2>/dev/null) |
| 25 | + |
| 26 | +if [ -z "$workspaceExists" ]; then |
| 27 | + echo "Workspace $workspace does not exist. Cannot deploy endpoint." |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +# Check if endpoint already exists |
| 32 | +local endpointExists |
| 33 | +endpointExists=$(az ml online-endpoint show \ |
| 34 | + --name "$endpoint" \ |
| 35 | + --resource-group "$resourceGroup" \ |
| 36 | + --workspace-name "$workspace" 2>/dev/null) |
| 37 | + |
| 38 | +if [ -n "$endpointExists" ]; then |
| 39 | + echo "Endpoint $endpoint exists; updating the endpoint" |
| 40 | + az ml online-endpoint update \ |
| 41 | + --name "$endpoint" \ |
| 42 | + --file endpoint-apply.yaml \ |
| 43 | + --resource-group "$resourceGroup" \ |
| 44 | + --workspace-name "$workspace" |
| 45 | +else |
| 46 | + echo "Creating endpoint $endpoint" |
| 47 | + cat endpoint-apply.yml |
| 48 | + az ml online-endpoint create \ |
| 49 | + --file endpoint-apply.yaml \ |
| 50 | + --resource-group "$resourceGroup" \ |
| 51 | + --workspace-name "$workspace" |
| 52 | +fi |
| 53 | + |
| 54 | +endpointExists=$(az ml online-endpoint show \ |
| 55 | + --name "$endpoint" \ |
| 56 | + --resource-group "$resourceGroup" \ |
| 57 | + --workspace-name "$workspace" 2>/dev/null) |
| 58 | + |
| 59 | +if [ -n "$endpointExists" ]; then |
| 60 | + echo "Endpoint $endpoint created successfully" |
| 61 | + exit 0 |
| 62 | +else |
| 63 | + echo "Endpoint $endpoint creation failed" |
| 64 | + exit 1 |
| 65 | +fi |
0 commit comments