Skip to content

Commit c2b37ef

Browse files
feat: complete MLOps pipeline with working Azure CI/CD
1 parent 120cbd9 commit c2b37ef

9 files changed

Lines changed: 1116 additions & 203 deletions

File tree

.github/workflows/azure-deploy.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Deploy MLOps Pipeline to Azure
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
env:
9+
IMAGE_NAME: iris-mlops-pipeline
10+
11+
jobs:
12+
deploy:
13+
name: 🚀 Deploy to Azure
14+
runs-on: ubuntu-latest
15+
environment: production
16+
17+
steps:
18+
- name: 📥 Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: 🔧 Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
24+
- name: 🔑 Log in to Azure Container Registry
25+
uses: azure/docker-login@v1
26+
with:
27+
login-server: ${{ secrets.CONTAINER_REGISTRY }}
28+
username: ${{ secrets.ACR_USERNAME }}
29+
password: ${{ secrets.ACR_PASSWORD }}
30+
31+
- name: 🐳 Build and push Docker image
32+
uses: docker/build-push-action@v5
33+
with:
34+
context: .
35+
file: ./Dockerfile.azure
36+
push: true
37+
tags: |
38+
${{ secrets.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
39+
${{ secrets.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
40+
cache-from: type=gha
41+
cache-to: type=gha,mode=max
42+
platforms: linux/amd64
43+
44+
- name: 🔑 Azure Login
45+
uses: azure/login@v1
46+
with:
47+
creds: ${{ secrets.AZURE_CREDENTIALS }}
48+
49+
- name: 🚀 Deploy to Azure Web App
50+
uses: azure/webapps-deploy@v2
51+
with:
52+
app-name: ${{ secrets.AZURE_WEBAPP_NAME }}
53+
images: ${{ secrets.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
54+
55+
- name: ⚙️ Configure App Settings
56+
uses: azure/CLI@v1
57+
with:
58+
inlineScript: |
59+
az webapp config appsettings set \
60+
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
61+
--name ${{ secrets.AZURE_WEBAPP_NAME }} \
62+
--settings \
63+
AZURE_STORAGE_ACCOUNT="${{ secrets.AZURE_STORAGE_ACCOUNT }}" \
64+
AZURE_STORAGE_KEY="${{ secrets.AZURE_STORAGE_KEY }}" \
65+
APPINSIGHTS_INSTRUMENTATION_KEY="${{ secrets.APPINSIGHTS_INSTRUMENTATION_KEY }}" \
66+
WEBSITES_PORT="8000" \
67+
ENVIRONMENT="production" \
68+
COMMIT_SHA="${{ github.sha }}" \
69+
BUILD_NUMBER="${{ github.run_number }}"
70+
71+
- name: 🔄 Restart Web App
72+
uses: azure/CLI@v1
73+
with:
74+
inlineScript: |
75+
az webapp restart \
76+
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
77+
--name ${{ secrets.AZURE_WEBAPP_NAME }}
78+
79+
- name: ⏳ Wait for deployment
80+
run: sleep 60
81+
82+
- name: 🏥 Health Check
83+
run: |
84+
echo "Performing health check..."
85+
max_attempts=10
86+
attempt=1
87+
88+
while [ $attempt -le $max_attempts ]; do
89+
echo "Health check attempt $attempt of $max_attempts"
90+
91+
# Construct URL from secrets
92+
app_name="${{ secrets.AZURE_WEBAPP_NAME }}"
93+
health_url="https://${app_name}.azurewebsites.net/health"
94+
95+
if curl -f --max-time 30 "$health_url"; then
96+
echo "✅ Health check passed!"
97+
break
98+
else
99+
echo "❌ Health check failed, retrying in 30 seconds..."
100+
if [ $attempt -eq $max_attempts ]; then
101+
echo "🚨 Health check failed after $max_attempts attempts"
102+
exit 1
103+
fi
104+
sleep 30
105+
attempt=$((attempt + 1))
106+
fi
107+
done
108+
109+
- name: 📊 Deployment Summary
110+
run: |
111+
echo "=== DEPLOYMENT SUMMARY ==="
112+
echo "Environment: production"
113+
echo "Image: ${{ secrets.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
114+
echo "Web App: ${{ secrets.AZURE_WEBAPP_NAME }}"
115+
echo "Commit: ${{ github.sha }}"
116+
echo "Build: ${{ github.run_number }}"
117+
echo "✅ Deployment completed successfully!"

.github/workflows/ci-cd.yml

Lines changed: 0 additions & 203 deletions
This file was deleted.

0 commit comments

Comments
 (0)