Skip to content

Commit 220be60

Browse files
committed
Add baseline
1 parent 10a0403 commit 220be60

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM mcr.microsoft.com/azure-cli
2+
3+
# Install jq (for parsing JSON)
4+
RUN apt-get update && apt-get install -y jq
5+
6+
# Install Azure ML CLI extension
7+
RUN az extension add --name ml -y
8+
9+
# Set the working directory
10+
WORKDIR /workspace
11+
12+
# Copy the entrypoint script into the container
13+
COPY entrypoint.sh /workspace/entrypoint.sh
14+
15+
# Set the entrypoint script to be executable
16+
RUN chmod +x /workspace/entrypoint.sh
17+
18+
# Define default command
19+
ENTRYPOINT ["/workspace/entrypoint.sh"]

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Deploy AML Online Endpoint - GitHub Action
2+
3+
This GitHub Action deploys an **Azure Machine Learning Online Endpoint** using **Azure CLI** (via a Bash script).
4+
5+
## 🚀 Usage
6+
7+
### **1. Add to Your Workflow**
8+
9+
```yaml
10+
jobs:
11+
deploy:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Deploy AML Online Endpoint
18+
uses: coding-kitties/create-aml-online-endpoint@v1
19+
with:
20+
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
21+
resource_group: 'my-resource-group'
22+
workspace_name: 'my-workspace'
23+
endpoint_file: './config/endpoint.yml'
24+
deployment_file: './config/deployment.yml'
25+
```

action.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: 'Deploy AML Online Endpoint with Docker'
2+
description: 'Deploy an Azure Machine Learning Online Endpoint using Docker, Azure CLI, and Azure Login'
3+
author: 'Marc van Duyn'
4+
branding:
5+
icon: 'cloud'
6+
color: 'blue'
7+
8+
inputs:
9+
azure_credentials:
10+
description: 'Azure credentials in JSON format (Service Principal)'
11+
required: true
12+
endpointName:
13+
description: 'Name of the endpoint'
14+
required: true
15+
resource_group:
16+
description: 'Azure Resource Group'
17+
required: true
18+
workspace_name:
19+
description: 'Azure ML Workspace Name'
20+
required: true
21+
22+
runs:
23+
using: 'composite'
24+
steps:
25+
# Step 1: Log into Azure using Azure Login action
26+
- name: Log into Azure
27+
uses: azure/login@v1
28+
with:
29+
creds: ${{ secrets.AZURE_CREDENTIALS }}
30+
31+
# Step 2: Checkout repository
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
35+
# Step 3: Set up Docker (if needed) and run the entrypoint script
36+
- name: Run Docker container with entrypoint.sh
37+
run: |
38+
docker build -t aml-deploy .
39+
docker run -v $PWD:/workspace -e AZURE_CREDENTIALS="${{ secrets.AZURE_CREDENTIALS }}" aml-deploy /workspace/entrypoint.sh "${{ inputs.azure_credentials }}" "${{ inputs.endpointName }}" "${{ inputs.workspace_name }}" "${{ inputs.resource_group }}"

entrypoint.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)