Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
95 changes: 95 additions & 0 deletions infra/scripts/checkquota.sh
Original file line number Diff line number Diff line change
@@ -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
Loading