User Tools

Site Tools


wiki:ai:github-actions-azure-pipeline

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
wiki:ai:github-actions-azure-pipeline [2025/06/19 21:35] ddehamerwiki:ai:github-actions-azure-pipeline [2025/06/20 14:58] (current) ddehamer
Line 78: Line 78:
  
 \\ The root cause of repeated deployment failures was a mix of deprecated image references, misaligned configurations in score.py, and environment packaging. \\ Success was achieved by manually correcting the image in the Azure portal, aligning all references to the valid environment and base image, and confirming logging with App Insights.\\ All CLI scripts were validated against working deployment state. \\ The root cause of repeated deployment failures was a mix of deprecated image references, misaligned configurations in score.py, and environment packaging. \\ Success was achieved by manually correcting the image in the Azure portal, aligning all references to the valid environment and base image, and confirming logging with App Insights.\\ All CLI scripts were validated against working deployment state.
 +
 +====== Github Pipeline Test ======
 +
 +Git files: {{ :wiki:ai:ml-cicd-demo.zip |}}
 +
 +Have it on my repo:  [[https://github.com/ddehamer/ml-cicd-demo.git]]
 +
 +Actions Secrets:
 +
 +{{:wiki:ai:screenshot_2025-06-19_at_5.39.54 pm.png?600|}}
 +
 +===== Final Working Commands =====
 +
 +=== 1. Register the Model ===
 +<code bash>
 +az ml model create \
 +  --name iris-model \
 +  --version 1 \
 +  --type mlflow_model \
 +  --path ./model \
 +  --resource-group don-test-rg \
 +  --workspace-name don-ml-workspace
 +</code>
 +
 +=== 2. Create the Environment (from working YAML) ===
 +<code bash>
 +az ml environment create \
 +  --name inference-env \
 +  --version 6 \
 +  --file environment.yml \
 +  --resource-group don-test-rg \
 +  --workspace-name don-ml-workspace
 +</code>
 +
 +*Working base image (set via portal):*
 +<code yaml>
 +base_image: mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04:latest
 +</code>
 +
 +=== 3. Create the Online Endpoint ===
 +<code bash>
 +az ml online-endpoint create \
 +  --name don-iris-endpoint \
 +  --resource-group don-test-rg \
 +  --workspace-name don-ml-workspace \
 +  --file online-endpoint.yml
 +</code>
 +
 +=== 4. Deploy to the Endpoint ===
 +<code bash>
 +az ml online-deployment create \
 +  --name don-iris-deployment \
 +  --endpoint-name don-iris-endpoint \
 +  --resource-group don-test-rg \
 +  --workspace-name don-ml-workspace \
 +  --file online-deployment.yml
 +</code>
 +
 +=== 5. Test the Endpoint with a Request ===
 +<code bash>
 +az ml online-endpoint invoke \
 +  --name don-iris-endpoint \
 +  --resource-group don-test-rg \
 +  --workspace-name don-ml-workspace \
 +  --request-file request.json
 +</code>
 +
 +Expected Output:
 +<code>
 +"[0]"
 +</code>
 +
 +=== 6. Query Log Analytics for Predictions ===
 +<code bash>
 +az monitor log-analytics query \
 +  --workspace &lt;workspace-id&gt; \
 +  --analytics-query "
 +customEvents
 +| where name == 'Request'
 +| extend prediction = tostring(customDimensions.Response)
 +| where prediction in ('[\"0\"]', '[\"1\"]')
 +| summarize count() by prediction, bin(timestamp, 5m)
 +| order by timestamp desc" \
 +  --timespan PT1H
 +</code>
 +
 +=== 7. Clean Up for Re-deployments ===
 +<code bash>
 +az ml online-deployment update-traffic \
 +  --name don-iris-endpoint \
 +  --resource-group don-test-rg \
 +  --workspace-name don-ml-workspace \
 +  --traffic "{don-iris-deployment: 0}"
 +</code>
 +
 +<code bash>
 +az ml online-deployment delete \
 +  --name don-iris-deployment \
 +  --endpoint-name don-iris-endpoint \
 +  --resource-group don-test-rg \
 +  --workspace-name don-ml-workspace
 +</code>
  
 ====== Final Working Files ====== ====== Final Working Files ======
Line 232: Line 334:
 joblib.dump(clf, "outputs/model.joblib") joblib.dump(clf, "outputs/model.joblib")
 print("✅ Model saved to ./outputs/model.joblib") print("✅ Model saved to ./outputs/model.joblib")
 +</code>
 +
 +<code - .github/workflows/train-deploy.yml>
 +name: Train and Register Model in Azure ML
 +
 +on:
 +  push:
 +    branches: [ main ]
 +
 +jobs:
 +  train-register:
 +    runs-on: ubuntu-latest
 +
 +    env:
 +      AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
 +      AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
 +      AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
 +      AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
 +      AZURE_RESOURCE_GROUP: ${{ secrets.AZURE_RESOURCE_GROUP }}
 +      AZURE_WORKSPACE_NAME: ${{ secrets.AZURE_WORKSPACE_NAME }}
 +
 +    steps:
 +      - name: ✅ Checkout code
 +        uses: actions/checkout@v4
 +
 +      - name: 🔐 Login to Azure
 +        uses: azure/login@v1
 +        with:
 +          creds: ${{ secrets.AZURE_CREDENTIALS }}
 +
 +      - name: 🐍 Set up Python
 +        uses: actions/setup-python@v5
 +        with:
 +          python-version: '3.10'
 +
 +      - name: 📦 Install dependencies
 +        run: |
 +          python -m pip install --upgrade pip
 +          pip install -r requirements.txt
 +          az extension add -n ml -y
 +
 +      - name: 🚀 Submit Azure ML pipeline job
 +        run: |
 +          az ml job create \
 +            --file pipeline-job.yml \
 +            --resource-group $AZURE_RESOURCE_GROUP \
 +            --workspace-name $AZURE_WORKSPACE_NAME
 </code> </code>
  
wiki/ai/github-actions-azure-pipeline.1750368920.txt.gz · Last modified: by ddehamer