Skip to content

Commit 7c56aec

Browse files
Merge pull request #184 from microsoft/psl-checkquota-rc
fix: Validate deployment pipeline fix with quota check
2 parents 47f057f + 4465e82 commit 7c56aec

File tree

2 files changed

+95
-28
lines changed

2 files changed

+95
-28
lines changed

.github/workflows/deploy.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -168,34 +168,6 @@ jobs:
168168
echo "Azure Container Registry name: ${acr_name}"
169169
fi
170170
171-
172-
- name: Build the image and update the container app
173-
id: build-and-update
174-
run: |
175-
176-
set -e
177-
# Define variables for acr and container app names
178-
acr_name="${{ env.ACR_NAME }}"
179-
echo "ACR name: {$acr_name}"
180-
backend_container_app_name="macae-backend"
181-
backend_build_image_tag="backend:latest"
182-
183-
echo "Building the container image..."
184-
# Build the image
185-
az acr build -r ${acr_name} -t ${backend_build_image_tag} ./src/backend
186-
echo "Backend image build completed successfully."
187-
188-
frontend_container_app_name="${{ env.APP_SERVICE_NAME }}"
189-
frontend_build_image_tag="frontend:latest"
190-
191-
echo "Building the container image..."
192-
# Build the image
193-
az acr build -r ${acr_name} -t ${frontend_build_image_tag} ./src/frontend
194-
echo "Frontend image build completed successfully."
195-
196-
# Add the new container to the website
197-
az webapp config container set --resource-group ${{ env.RESOURCE_GROUP_NAME }} --name ${frontend_container_app_name} --container-image-name ${acr_name}.azurecr.io/frontend:latest --container-registry-url https://${acr_name}.azurecr.io
198-
199171
200172
- name: Delete Bicep Deployment
201173
if: success()

infra/scripts/checkquota.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
# List of Azure regions to check for quota (update as needed)
4+
IFS=', ' read -ra REGIONS <<< "$AZURE_REGIONS"
5+
6+
SUBSCRIPTION_ID="${AZURE_SUBSCRIPTION_ID}"
7+
GPT_MIN_CAPACITY="${GPT_MIN_CAPACITY}"
8+
AZURE_CLIENT_ID="${AZURE_CLIENT_ID}"
9+
AZURE_TENANT_ID="${AZURE_TENANT_ID}"
10+
AZURE_CLIENT_SECRET="${AZURE_CLIENT_SECRET}"
11+
12+
# Authenticate using Managed Identity
13+
echo "Authentication using Managed Identity..."
14+
if ! az login --service-principal -u "$AZURE_CLIENT_ID" -p "$AZURE_CLIENT_SECRET" --tenant "$AZURE_TENANT_ID"; then
15+
echo "❌ Error: Failed to login using Managed Identity."
16+
exit 1
17+
fi
18+
19+
echo "🔄 Validating required environment variables..."
20+
if [[ -z "$SUBSCRIPTION_ID" || -z "$GPT_MIN_CAPACITY" || -z "$REGIONS" ]]; then
21+
echo "❌ ERROR: Missing required environment variables."
22+
exit 1
23+
fi
24+
25+
echo "🔄 Setting Azure subscription..."
26+
if ! az account set --subscription "$SUBSCRIPTION_ID"; then
27+
echo "❌ ERROR: Invalid subscription ID or insufficient permissions."
28+
exit 1
29+
fi
30+
echo "✅ Azure subscription set successfully."
31+
32+
# Define models and their minimum required capacities
33+
declare -A MIN_CAPACITY=(
34+
["OpenAI.GlobalStandard.gpt-4o"]=$GPT_MIN_CAPACITY
35+
)
36+
37+
VALID_REGION=""
38+
for REGION in "${REGIONS[@]}"; do
39+
echo "----------------------------------------"
40+
echo "🔍 Checking region: $REGION"
41+
42+
QUOTA_INFO=$(az cognitiveservices usage list --location "$REGION" --output json)
43+
if [ -z "$QUOTA_INFO" ]; then
44+
echo "⚠️ WARNING: Failed to retrieve quota for region $REGION. Skipping."
45+
continue
46+
fi
47+
48+
INSUFFICIENT_QUOTA=false
49+
for MODEL in "${!MIN_CAPACITY[@]}"; do
50+
MODEL_INFO=$(echo "$QUOTA_INFO" | awk -v model="\"value\": \"$MODEL\"" '
51+
BEGIN { RS="},"; FS="," }
52+
$0 ~ model { print $0 }
53+
')
54+
55+
if [ -z "$MODEL_INFO" ]; then
56+
echo "⚠️ WARNING: No quota information found for model: $MODEL in $REGION. Skipping."
57+
continue
58+
fi
59+
60+
CURRENT_VALUE=$(echo "$MODEL_INFO" | awk -F': ' '/"currentValue"/ {print $2}' | tr -d ',' | tr -d ' ')
61+
LIMIT=$(echo "$MODEL_INFO" | awk -F': ' '/"limit"/ {print $2}' | tr -d ',' | tr -d ' ')
62+
63+
CURRENT_VALUE=${CURRENT_VALUE:-0}
64+
LIMIT=${LIMIT:-0}
65+
66+
CURRENT_VALUE=$(echo "$CURRENT_VALUE" | cut -d'.' -f1)
67+
LIMIT=$(echo "$LIMIT" | cut -d'.' -f1)
68+
69+
AVAILABLE=$((LIMIT - CURRENT_VALUE))
70+
71+
echo "✅ Model: $MODEL | Used: $CURRENT_VALUE | Limit: $LIMIT | Available: $AVAILABLE"
72+
73+
if [ "$AVAILABLE" -lt "${MIN_CAPACITY[$MODEL]}" ]; then
74+
echo "❌ ERROR: $MODEL in $REGION has insufficient quota."
75+
INSUFFICIENT_QUOTA=true
76+
break
77+
fi
78+
done
79+
80+
if [ "$INSUFFICIENT_QUOTA" = false ]; then
81+
VALID_REGION="$REGION"
82+
break
83+
fi
84+
85+
done
86+
87+
if [ -z "$VALID_REGION" ]; then
88+
echo "❌ No region with sufficient quota found. Blocking deployment."
89+
echo "QUOTA_FAILED=true" >> "$GITHUB_ENV"
90+
exit 0
91+
else
92+
echo "✅ Final Region: $VALID_REGION"
93+
echo "VALID_REGION=$VALID_REGION" >> "$GITHUB_ENV"
94+
exit 0
95+
fi

0 commit comments

Comments
 (0)