Skip to content

Commit 1242dcb

Browse files
Enhance deploy workflow with new branch and region logic
Updated the deploy workflow to include a new branch for triggering the pipeline and modified the region selection logic for Azure resources based on quota availability.
1 parent 6cff4f2 commit 1242dcb

1 file changed

Lines changed: 36 additions & 28 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
name: Deploy-Test-Cleanup Pipeline
22

33
on:
4-
workflow_run:
5-
workflows: ["Build Docker and Optional Push"]
6-
types:
7-
- completed
8-
branches:
9-
- main
10-
- dev
11-
- demo
12-
schedule:
13-
- cron: '0 5,17 * * *' # Runs at 5:00 AM and 5:00 PM GMT
14-
workflow_dispatch:
4+
workflow_run:
5+
workflows: ["Build Docker and Optional Push"]
6+
types:
7+
- completed
8+
branches:
9+
- main
10+
- dev
11+
- demo
12+
- vee-pipeline-fixes
13+
schedule:
14+
- cron: '0 5,17 * * *' # Runs at 5:00 AM and 5:00 PM GMT
15+
workflow_dispatch:
1516

1617
env:
1718
GPT_MIN_CAPACITY: 150
@@ -36,22 +37,28 @@ jobs:
3637
run: |
3738
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
3839
39-
- name: Run Quota Check
40-
id: quota-check
40+
- name: Select Region with Sufficient OpenAI Quota
41+
id: select_region
4142
run: |
42-
export AZURE_CLIENT_ID=${{ secrets.AZURE_CLIENT_ID }}
43-
export AZURE_TENANT_ID=${{ secrets.AZURE_TENANT_ID }}
44-
export AZURE_CLIENT_SECRET=${{ secrets.AZURE_CLIENT_SECRET }}
45-
export AZURE_SUBSCRIPTION_ID="${{ secrets.AZURE_SUBSCRIPTION_ID }}"
46-
export GPT_MIN_CAPACITY="${{ env.GPT_MIN_CAPACITY }}"
47-
export AZURE_REGIONS="${{ vars.AZURE_REGIONS }}"
48-
chmod +x scripts/checkquota.sh
49-
if ! scripts/checkquota.sh; then
50-
# If quota check fails due to insufficient quota, set the flag
51-
if grep -q "No region with sufficient quota found" scripts/checkquota.sh; then
52-
echo "QUOTA_FAILED=true" >> $GITHUB_ENV
43+
regions=("eastus2" "francecentral" "westus3" "southcentralus")
44+
required_quota=150
45+
selected_region=""
46+
for region in "${regions[@]}"; do
47+
available_quota=$(az openai quota show --location "$region" --query "quotas[?name=='OpenAI.GlobalStandard.gpt-4o'].limit" -o tsv)
48+
used_quota=$(az openai quota show --location "$region" --query "quotas[?name=='OpenAI.GlobalStandard.gpt-4o'].used" -o tsv)
49+
if [[ $((available_quota - used_quota)) -ge $required_quota ]]; then
50+
selected_region="$region"
51+
break
5352
fi
54-
exit 1 # Fail the pipeline if any other failure occurs
53+
done
54+
if [[ -z "$selected_region" ]]; then
55+
echo "No region with sufficient quota found."
56+
echo "QUOTA_FAILED=true" >> $GITHUB_ENV
57+
exit 1
58+
else
59+
echo "Selected region: $selected_region"
60+
echo "SELECTED_REGION=$selected_region" >> $GITHUB_ENV
61+
echo "selected_region=$selected_region" >> $GITHUB_OUTPUT
5562
fi
5663
5764
- name: Send Notification on Quota Failure
@@ -94,7 +101,7 @@ jobs:
94101
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
95102
if [ "$rg_exists" = "false" ]; then
96103
echo "Resource group does not exist. Creating..."
97-
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location northcentralus || { echo "Error creating resource group"; exit 1; }
104+
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location ${{ env.SELECTED_REGION }} || { echo "Error creating resource group"; exit 1; }
98105
else
99106
echo "Resource group already exists."
100107
fi
@@ -132,11 +139,12 @@ jobs:
132139
--template-file infra/main.bicep \
133140
--parameters \
134141
solutionName="${{ env.SOLUTION_PREFIX }}" \
135-
aiDeploymentsLocation="eastus" \
142+
aiDeploymentsLocation="${{ env.SELECTED_REGION }}" \
136143
useWafAlignedArchitecture=false \
137144
capacity=${{ env.GPT_MIN_CAPACITY }} \
138145
imageVersion="${IMAGE_TAG}" \
139146
createdBy="Pipeline"
147+
140148
- name: Assign Contributor role to Service Principal
141149
if: always()
142150
run: |
@@ -356,7 +364,7 @@ jobs:
356364
357365
# Purge OpenAI Resource
358366
echo "Purging the OpenAI Resource..."
359-
if ! az resource delete --ids /subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/providers/Microsoft.CognitiveServices/locations/northcentralus/resourceGroups/${{ env.RESOURCE_GROUP_NAME }}/deletedAccounts/${{ env.OPENAI_RESOURCE_NAME }} --verbose; then
367+
if ! az resource delete --ids /subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/providers/Microsoft.CognitiveServices/locations/${{ env.SELECTED_REGION }}/resourceGroups/${{ env.RESOURCE_GROUP_NAME }}/deletedAccounts/${{ env.OPENAI_RESOURCE_NAME }} --verbose; then
360368
echo "Failed to purge openai resource: ${{ env.OPENAI_RESOURCE_NAME }}"
361369
else
362370
echo "Purged the openai resource: ${{ env.OPENAI_RESOURCE_NAME }}"

0 commit comments

Comments
 (0)