From 20550c3002494b39797ee0e6727dce92b452d269 Mon Sep 17 00:00:00 2001 From: Ragini-Microsoft Date: Tue, 6 May 2025 17:08:48 +0530 Subject: [PATCH 1/2] added checkquota script --- infra/scripts/checkquota.sh | 95 +++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 infra/scripts/checkquota.sh diff --git a/infra/scripts/checkquota.sh b/infra/scripts/checkquota.sh new file mode 100644 index 00000000..0d23df79 --- /dev/null +++ b/infra/scripts/checkquota.sh @@ -0,0 +1,95 @@ +#!/bin/bash + +# List of Azure regions to check for quota (update as needed) +IFS=', ' read -ra REGIONS <<< "$AZURE_REGIONS" + +SUBSCRIPTION_ID="${AZURE_SUBSCRIPTION_ID}" +GPT_MIN_CAPACITY="${GPT_MIN_CAPACITY}" +AZURE_CLIENT_ID="${AZURE_CLIENT_ID}" +AZURE_TENANT_ID="${AZURE_TENANT_ID}" +AZURE_CLIENT_SECRET="${AZURE_CLIENT_SECRET}" + +# Authenticate using Managed Identity +echo "Authentication using Managed Identity..." +if ! az login --service-principal -u "$AZURE_CLIENT_ID" -p "$AZURE_CLIENT_SECRET" --tenant "$AZURE_TENANT_ID"; then + echo "❌ Error: Failed to login using Managed Identity." + exit 1 +fi + +echo "🔄 Validating required environment variables..." +if [[ -z "$SUBSCRIPTION_ID" || -z "$GPT_MIN_CAPACITY" || -z "$REGIONS" ]]; then + echo "❌ ERROR: Missing required environment variables." + exit 1 +fi + +echo "🔄 Setting Azure subscription..." +if ! az account set --subscription "$SUBSCRIPTION_ID"; then + echo "❌ ERROR: Invalid subscription ID or insufficient permissions." + exit 1 +fi +echo "✅ Azure subscription set successfully." + +# Define models and their minimum required capacities +declare -A MIN_CAPACITY=( + ["OpenAI.GlobalStandard.gpt-4o"]=$GPT_MIN_CAPACITY +) + +VALID_REGION="" +for REGION in "${REGIONS[@]}"; do + echo "----------------------------------------" + echo "🔍 Checking region: $REGION" + + QUOTA_INFO=$(az cognitiveservices usage list --location "$REGION" --output json) + if [ -z "$QUOTA_INFO" ]; then + echo "⚠️ WARNING: Failed to retrieve quota for region $REGION. Skipping." + continue + fi + + INSUFFICIENT_QUOTA=false + for MODEL in "${!MIN_CAPACITY[@]}"; do + MODEL_INFO=$(echo "$QUOTA_INFO" | awk -v model="\"value\": \"$MODEL\"" ' + BEGIN { RS="},"; FS="," } + $0 ~ model { print $0 } + ') + + if [ -z "$MODEL_INFO" ]; then + echo "⚠️ WARNING: No quota information found for model: $MODEL in $REGION. Skipping." + continue + fi + + CURRENT_VALUE=$(echo "$MODEL_INFO" | awk -F': ' '/"currentValue"/ {print $2}' | tr -d ',' | tr -d ' ') + LIMIT=$(echo "$MODEL_INFO" | awk -F': ' '/"limit"/ {print $2}' | tr -d ',' | tr -d ' ') + + CURRENT_VALUE=${CURRENT_VALUE:-0} + LIMIT=${LIMIT:-0} + + CURRENT_VALUE=$(echo "$CURRENT_VALUE" | cut -d'.' -f1) + LIMIT=$(echo "$LIMIT" | cut -d'.' -f1) + + AVAILABLE=$((LIMIT - CURRENT_VALUE)) + + echo "✅ Model: $MODEL | Used: $CURRENT_VALUE | Limit: $LIMIT | Available: $AVAILABLE" + + if [ "$AVAILABLE" -lt "${MIN_CAPACITY[$MODEL]}" ]; then + echo "❌ ERROR: $MODEL in $REGION has insufficient quota." + INSUFFICIENT_QUOTA=true + break + fi + done + + if [ "$INSUFFICIENT_QUOTA" = false ]; then + VALID_REGION="$REGION" + break + fi + +done + +if [ -z "$VALID_REGION" ]; then + echo "❌ No region with sufficient quota found. Blocking deployment." + echo "QUOTA_FAILED=true" >> "$GITHUB_ENV" + exit 0 +else + echo "✅ Final Region: $VALID_REGION" + echo "VALID_REGION=$VALID_REGION" >> "$GITHUB_ENV" + exit 0 +fi \ No newline at end of file From 4465e82a200560cdccc887f9c1e89d225e54356b Mon Sep 17 00:00:00 2001 From: Ragini-Microsoft Date: Tue, 6 May 2025 17:09:40 +0530 Subject: [PATCH 2/2] removed the image building step from deployment validation workflow --- .github/workflows/deploy.yml | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 845a1b16..27ea0bac 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -168,34 +168,6 @@ jobs: echo "Azure Container Registry name: ${acr_name}" fi - - - name: Build the image and update the container app - id: build-and-update - run: | - - set -e - # Define variables for acr and container app names - acr_name="${{ env.ACR_NAME }}" - echo "ACR name: {$acr_name}" - backend_container_app_name="macae-backend" - backend_build_image_tag="backend:latest" - - echo "Building the container image..." - # Build the image - az acr build -r ${acr_name} -t ${backend_build_image_tag} ./src/backend - echo "Backend image build completed successfully." - - frontend_container_app_name="${{ env.APP_SERVICE_NAME }}" - frontend_build_image_tag="frontend:latest" - - echo "Building the container image..." - # Build the image - az acr build -r ${acr_name} -t ${frontend_build_image_tag} ./src/frontend - echo "Frontend image build completed successfully." - - # Add the new container to the website - 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 - - name: Delete Bicep Deployment if: success()