Skip to content

Commit 6c953cf

Browse files
Merge pull request #31 from microsoft/dev
chore: merging dev changes to main branch
2 parents cc609e2 + 96b79e7 commit 6c953cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+4348
-1930
lines changed

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E501
4+
exclude = .venv, frontend
5+
ignore = E722,E203, W503, G004, G200, F,E711

.github/dependabot.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Dependabot configuration for Container Migration Solution Accelerator
2+
# This file configures automated dependency updates for all package managers used in the project
3+
4+
version: 2
5+
updates:
6+
# Frontend Node.js dependencies (grouped)
7+
- package-ecosystem: "npm"
8+
directory: "/src/frontend"
9+
schedule:
10+
interval: "monthly"
11+
commit-message:
12+
prefix: "build"
13+
target-branch: "dependabotchanges"
14+
open-pull-requests-limit: 50
15+
groups:
16+
all-npm:
17+
patterns:
18+
- "*"
19+
20+
# Backend API Python dependencies (grouped)
21+
- package-ecosystem: "pip"
22+
directory: "/src/backend-api"
23+
schedule:
24+
interval: "monthly"
25+
commit-message:
26+
prefix: "build"
27+
target-branch: "dependabotchanges"
28+
open-pull-requests-limit: 50
29+
groups:
30+
all-pip:
31+
patterns:
32+
- "*"
33+
34+
# Processor Python dependencies (grouped)
35+
- package-ecosystem: "pip"
36+
directory: "/src/processor"
37+
schedule:
38+
interval: "monthly"
39+
commit-message:
40+
prefix: "build"
41+
target-branch: "dependabotchanges"
42+
open-pull-requests-limit: 50
43+
groups:
44+
all-pip:
45+
patterns:
46+
- "*"
47+
48+
# GitHub Actions dependencies (grouped)
49+
- package-ecosystem: "github-actions"
50+
directory: "/"
51+
schedule:
52+
interval: "monthly"
53+
commit-message:
54+
prefix: "build"
55+
target-branch: "dependabotchanges"
56+
open-pull-requests-limit: 50
57+
groups:
58+
all-actions:
59+
patterns:
60+
- "*"

.github/workflows/ci.yml

Lines changed: 322 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,322 @@
1+
name: Validate Deployment
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- dev
7+
- demo
8+
schedule:
9+
- cron: '0 9,21 * * *' # Runs at 9:00 AM and 9:00 PM GMT
10+
workflow_dispatch: # Allow manual triggering
11+
env:
12+
GPT_MIN_CAPACITY: 150
13+
BRANCH_NAME: ${{ github.event.workflow_run.head_branch || github.head_ref || github.ref_name }}
14+
jobs:
15+
deploy:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
RESOURCE_GROUP_NAME: ${{ steps.check_create_rg.outputs.RESOURCE_GROUP_NAME }}
19+
DEPLOYMENT_SUCCESS: ${{ steps.deployment_status.outputs.SUCCESS }}
20+
steps:
21+
- name: Checkout Code
22+
uses: actions/checkout@v4
23+
- name: Setup Azure CLI
24+
run: |
25+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
26+
az --version
27+
- name: Login to Azure
28+
run: |
29+
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
30+
- name: Run Quota Check
31+
id: quota-check
32+
run: |
33+
export AZURE_CLIENT_ID=${{ secrets.AZURE_CLIENT_ID }}
34+
export AZURE_TENANT_ID=${{ secrets.AZURE_TENANT_ID }}
35+
export AZURE_CLIENT_SECRET=${{ secrets.AZURE_CLIENT_SECRET }}
36+
export AZURE_SUBSCRIPTION_ID="${{ secrets.AZURE_SUBSCRIPTION_ID }}"
37+
export AZURE_REGIONS="${{ vars.AZURE_REGIONS }}"
38+
chmod +x scripts/checkquota.sh
39+
if ! scripts/checkquota.sh; then
40+
# If quota check fails due to insufficient quota, set the flag
41+
if grep -q "No region with sufficient quota found" scripts/checkquota.sh; then
42+
echo "QUOTA_FAILED=true" >> $GITHUB_ENV
43+
fi
44+
exit 1 # Fail the pipeline if any other failure occurs
45+
fi
46+
- name: Send Notification on Quota Failure
47+
if: env.QUOTA_FAILED == 'true'
48+
run: |
49+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
50+
EMAIL_BODY=$(cat <<EOF
51+
{
52+
"body": "<p>Dear Team,</p><p>The Container Migration quota check has failed, and the pipeline cannot proceed.</p><p><strong>Build URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a></p><p>Please take necessary action.</p><p>Best regards,<br>Your Automation Team</p>",
53+
"subject": "Container Migration Deployment - Quota Check Failed"
54+
}
55+
EOF
56+
)
57+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
58+
-H "Content-Type: application/json" \
59+
-d "$EMAIL_BODY" || echo "Failed to send notification"
60+
- name: Fail Pipeline if Quota Check Fails
61+
if: env.QUOTA_FAILED == 'true'
62+
run: exit 1
63+
- name: Install Bicep CLI
64+
run: az bicep install
65+
66+
- name: Set Deployment Region
67+
run: |
68+
echo "Selected Region: $VALID_REGION"
69+
echo "AZURE_LOCATION=$VALID_REGION" >> $GITHUB_ENV
70+
- name: Generate Resource Group Name
71+
id: generate_rg_name
72+
run: |
73+
echo "Generating a unique resource group name..."
74+
75+
ACCL_NAME="CM"
76+
77+
SHORT_UUID=$(uuidgen | cut -d'-' -f1)
78+
UNIQUE_RG_NAME="arg-${ACCL_NAME}-${SHORT_UUID}"
79+
echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
80+
echo "Generated RESOURCE_GROUP_NAME: ${UNIQUE_RG_NAME}"
81+
82+
- name: Check and Create Resource Group
83+
id: check_create_rg
84+
run: |
85+
set -e
86+
echo "Checking if resource group exists..."
87+
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
88+
if [ "$rg_exists" = "false" ]; then
89+
echo "Resource group does not exist. Creating..."
90+
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location ${{ env.AZURE_LOCATION }} || { echo "Error creating resource group"; exit 1; }
91+
else
92+
echo "Resource group already exists."
93+
fi
94+
echo "RESOURCE_GROUP_NAME=${{ env.RESOURCE_GROUP_NAME }}" >> $GITHUB_OUTPUT
95+
- name: Generate Unique Solution Prefix
96+
id: generate_solution_prefix
97+
run: |
98+
set -e
99+
COMMON_PART="Cm"
100+
TIMESTAMP=$(date +%s)
101+
UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 6)
102+
UNIQUE_SOLUTION_PREFIX="${COMMON_PART}${UPDATED_TIMESTAMP}"
103+
echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
104+
echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
105+
106+
- name: Deploy Bicep Template
107+
id: deploy
108+
run: |
109+
set -e
110+
az deployment group create \
111+
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
112+
--template-file infra/main.bicep \
113+
--parameters solutionName=${{env.SOLUTION_PREFIX}} \
114+
--parameters location=${{ env.AZURE_LOCATION }} \
115+
--parameters aiDeploymentLocation=${{ env.AZURE_LOCATION }} \
116+
--parameters azureAiServiceLocation=${{ env.AZURE_LOCATION }}
117+
118+
119+
- name: Extract AI Services and Key Vault Names
120+
if: always()
121+
run: |
122+
echo "Fetching AI Services and Key Vault names before deletion..."
123+
124+
# Get Key Vault name
125+
KEYVAULT_NAME=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --resource-type "Microsoft.KeyVault/vaults" --query "[].name" -o tsv)
126+
echo "Detected Key Vault: $KEYVAULT_NAME"
127+
echo "KEYVAULT_NAME=$KEYVAULT_NAME" >> $GITHUB_ENV
128+
129+
# Get AI Services names and convert them into a space-separated string
130+
AI_SERVICES=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --resource-type "Microsoft.CognitiveServices/accounts" --query "[].name" -o tsv | tr '\n' ' ')
131+
132+
echo "Detected AI Services: $AI_SERVICES"
133+
echo "AI_SERVICES=$AI_SERVICES" >> $GITHUB_ENV
134+
- name: Set Deployment Status
135+
id: deployment_status
136+
if: always()
137+
run: |
138+
if [ "${{ job.status }}" == "success" ]; then
139+
echo "SUCCESS=true" >> $GITHUB_OUTPUT
140+
else
141+
echo "SUCCESS=false" >> $GITHUB_OUTPUT
142+
fi
143+
- name: Logout from Azure
144+
if: always()
145+
run: |
146+
az logout
147+
echo "Logged out from Azure."
148+
cleanup-deployment:
149+
if: always() && needs.deploy.outputs.RESOURCE_GROUP_NAME != ''
150+
needs: [deploy]
151+
runs-on: ubuntu-latest
152+
env:
153+
RESOURCE_GROUP_NAME: ${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}
154+
steps:
155+
- name: Setup Azure CLI
156+
run: |
157+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
158+
az --version
159+
- name: Login to Azure
160+
run: |
161+
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
162+
az account set --subscription "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
163+
- name: Extract AI Services and Key Vault Names
164+
if: always()
165+
run: |
166+
echo "Fetching AI Services and Key Vault names before deletion..."
167+
168+
# Get Key Vault name
169+
KEYVAULT_NAME=$(az resource list --resource-group "${{ env.RESOURCE_GROUP_NAME }}" --resource-type "Microsoft.KeyVault/vaults" --query "[].name" -o tsv)
170+
echo "Detected Key Vault: $KEYVAULT_NAME"
171+
echo "KEYVAULT_NAME=$KEYVAULT_NAME" >> $GITHUB_ENV
172+
# Extract AI Services names
173+
echo "Fetching AI Services..."
174+
AI_SERVICES=$(az resource list --resource-group '${{ env.RESOURCE_GROUP_NAME }}' --resource-type "Microsoft.CognitiveServices/accounts" --query "[].name" -o tsv)
175+
# Flatten newline-separated values to space-separated
176+
AI_SERVICES=$(echo "$AI_SERVICES" | paste -sd ' ' -)
177+
echo "Detected AI Services: $AI_SERVICES"
178+
echo "AI_SERVICES=$AI_SERVICES" >> $GITHUB_ENV
179+
180+
- name: Delete Bicep Deployment
181+
if: always()
182+
run: |
183+
set -e
184+
echo "Checking if resource group exists..."
185+
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
186+
if [ "$rg_exists" = "true" ]; then
187+
echo "Resource group exists. Cleaning..."
188+
az group delete \
189+
--name ${{ env.RESOURCE_GROUP_NAME }} \
190+
--yes \
191+
--no-wait
192+
echo "Resource group deleted... ${{ env.RESOURCE_GROUP_NAME }}"
193+
else
194+
echo "Resource group does not exist."
195+
fi
196+
- name: Wait for Resource Deletion to Complete
197+
if: always()
198+
run: |
199+
echo "Waiting for all deployed resources (including AI Services) to be deleted..."
200+
201+
# Convert AI_SERVICES space-separated string into an array
202+
IFS=' ' read -r -a resources_to_check <<< "${{ env.AI_SERVICES }}"
203+
204+
echo "Resources to check for deletion:"
205+
printf '%s\n' "${resources_to_check[@]}"
206+
207+
# Get the current resource list in YAML
208+
resource_list=$(az resource list --subscription "${{ secrets.AZURE_SUBSCRIPTION_ID }}" --output yaml)
209+
210+
# Set up retry logic
211+
max_retries=3
212+
retry_intervals=(30 60 120)
213+
retries=0
214+
215+
while true; do
216+
resource_found=false
217+
for resource in "${resources_to_check[@]}"; do
218+
echo "Checking if resource '$resource' still exists..."
219+
if echo "$resource_list" | grep -q "name: $resource"; then
220+
echo "Resource '$resource' still exists."
221+
resource_found=true
222+
else
223+
echo "Resource '$resource' has been deleted."
224+
fi
225+
done
226+
227+
if [ "$resource_found" = true ]; then
228+
retries=$((retries + 1))
229+
if [ "$retries" -ge "$max_retries" ]; then
230+
echo "Reached max retry attempts. Exiting wait loop."
231+
break
232+
else
233+
echo "Some resources still exist. Waiting for ${retry_intervals[$((retries-1))]} seconds..."
234+
sleep "${retry_intervals[$((retries-1))]}"
235+
resource_list=$(az resource list --subscription "${{ secrets.AZURE_SUBSCRIPTION_ID }}" --output yaml)
236+
fi
237+
else
238+
echo "All resources have been deleted."
239+
break
240+
fi
241+
done
242+
- name: Wait for Soft Deletion of Key Vault and AI Services
243+
if: always()
244+
run: |
245+
echo "Waiting for resources to be soft deleted..."
246+
247+
# Wait for Key Vault to be soft deleted
248+
if [ -n "${{ env.KEYVAULT_NAME }}" ]; then
249+
while true; do
250+
DELETED_VAULT=$(az keyvault show-deleted --name ${{ env.KEYVAULT_NAME }} --query "id" -o tsv 2>/dev/null || echo "")
251+
if [ -n "$DELETED_VAULT" ]; then
252+
echo "Key Vault soft deleted!"
253+
break
254+
fi
255+
echo "Key Vault not yet soft deleted. Retrying in 15s..."
256+
sleep 15
257+
done
258+
fi
259+
# Wait for AI Services to be soft deleted
260+
for AI_SERVICE in ${{ env.AI_SERVICES }}; do
261+
while true; do
262+
DELETED_AI_SERVICE=$(az cognitiveservices account list-deleted --query "[?name=='$AI_SERVICE'].id" -o tsv 2>/dev/null || echo "")
263+
if [ -n "$DELETED_AI_SERVICE" ]; then
264+
echo "AI Service $AI_SERVICE is soft deleted!"
265+
break
266+
fi
267+
echo "AI Service $AI_SERVICE not yet soft deleted. Retrying in 15s..."
268+
sleep 15
269+
done
270+
done
271+
272+
- name: Purge Key Vault and AI Services
273+
if: always()
274+
run: |
275+
echo "Purging soft deleted resources..."
276+
277+
# Ensure AI_SERVICES is properly split into individual services
278+
IFS=' ' read -r -a SERVICES <<< "${{ env.AI_SERVICES }}"
279+
for AI_SERVICE in "${SERVICES[@]}"; do
280+
echo "Checking location for AI Service: $AI_SERVICE"
281+
# Fetch AI Service location
282+
SERVICE_LOCATION=$(az cognitiveservices account list-deleted --query "[?name=='$AI_SERVICE'].location" -o tsv 2>/dev/null || echo "")
283+
if [ -n "$SERVICE_LOCATION" ]; then
284+
echo "Purging AI Service $AI_SERVICE in $SERVICE_LOCATION"
285+
az cognitiveservices account purge --location "$SERVICE_LOCATION" --resource-group "${{ env.RESOURCE_GROUP_NAME }}" --name "$AI_SERVICE"
286+
else
287+
echo "Could not determine location for AI Service: $AI_SERVICE. Skipping purge."
288+
fi
289+
done
290+
# Purge Key Vaults
291+
echo "Starting purge for Key Vaults..."
292+
IFS=' ' read -r -a VAULTS <<< "${{ env.KEYVAULT_NAME }}"
293+
for VAULT in "${VAULTS[@]}"; do
294+
echo "Checking location for Key Vault: $VAULT"
295+
# Fetch Key Vault location
296+
VAULT_LOCATION=$(az keyvault list-deleted --query "[?name=='$VAULT'].properties.location" -o tsv 2>/dev/null || echo "")
297+
if [ -n "$VAULT_LOCATION" ]; then
298+
echo "Purging Key Vault $VAULT in $VAULT_LOCATION"
299+
az keyvault purge --name "$VAULT" --location "$VAULT_LOCATION"
300+
else
301+
echo "Could not determine location for Key Vault: $VAULT. Skipping purge."
302+
fi
303+
done
304+
- name: Send Notification on Failure
305+
if: failure() || needs.deploy.result == 'failure'
306+
run: |
307+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
308+
EMAIL_BODY=$(cat <<EOF
309+
{
310+
"body": "<p>Dear Team,</p><p>We would like to inform you that the Container Migration Deployment Automation process has encountered an issue and has failed to complete successfully.</p><p><strong>Build URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a><br></p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>",
311+
"subject": "Container Migration - Pipeline Failed"
312+
}
313+
EOF
314+
)
315+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
316+
-H "Content-Type: application/json" \
317+
-d "$EMAIL_BODY" || echo "Failed to send notification"
318+
- name: Logout from Azure
319+
if: always()
320+
run: |
321+
az logout
322+
echo "Logged out from Azure."

0 commit comments

Comments
 (0)