Skip to content

Commit e6ff204

Browse files
feat: Bicep Validation (microsoft#26)
* feat: added automation deployment pipeline * added parameters of deployment * testing automation flow * testing automation flow * testing automation flow * testing automation flow * testing automation flow * testing automation flow * testing automation flow * testing automation flow * testing automation flow * testing automation flow * testing automation flow * testing automation flow * testing automation flow * testing automation flow * testing automation flow * testing automation flow * testing automation flow * added release file * testing automation code * removed release file
1 parent 9d67d59 commit e6ff204

File tree

1 file changed

+240
-0
lines changed

1 file changed

+240
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
name: CI-Validate Deployment-Multi-Agent-Custom-Automation-Engine-Solution-Accelerator
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Code
13+
uses: actions/checkout@v3
14+
15+
- name: Setup Azure CLI
16+
run: |
17+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
18+
az --version # Verify installation
19+
20+
- name: Login to Azure
21+
run: |
22+
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
23+
24+
- name: Install Bicep CLI
25+
run: az bicep install
26+
27+
- name: Generate Resource Group Name
28+
id: generate_rg_name
29+
run: |
30+
echo "Generating a unique resource group name..."
31+
TIMESTAMP=$(date +%Y%m%d%H%M%S)
32+
COMMON_PART="ci-biab"
33+
UNIQUE_RG_NAME="${COMMON_PART}${TIMESTAMP}"
34+
echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
35+
echo "Generated Resource_GROUP_PREFIX: ${UNIQUE_RG_NAME}"
36+
37+
38+
- name: Check and Create Resource Group
39+
id: check_create_rg
40+
run: |
41+
set -e
42+
echo "Checking if resource group exists..."
43+
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
44+
if [ "$rg_exists" = "false" ]; then
45+
echo "Resource group does not exist. Creating..."
46+
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location eastus || { echo "Error creating resource group"; exit 1; }
47+
else
48+
echo "Resource group already exists."
49+
fi
50+
51+
52+
- name: Deploy Bicep Template
53+
id: deploy
54+
run: |
55+
set -e
56+
az deployment group create \
57+
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
58+
--template-file deploy/macae.bicep \
59+
--parameters azureOpenAILocation=eastus cosmosLocation=eastus
60+
61+
62+
- name: Send Notification on Failure
63+
if: failure()
64+
run: |
65+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
66+
67+
# Construct the email body
68+
EMAIL_BODY=$(cat <<EOF
69+
{
70+
"body": "<p>Dear Team,</p><p>We would like to inform you that the Multi-Agent-Custom-Automation-Engine-Solution-Accelerator Automation process has encountered an issue and has failed to complete successfully.</p><p><strong>Build URL:</strong> ${RUN_URL}<br> ${OUTPUT}</p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>"
71+
}
72+
EOF
73+
)
74+
75+
# Send the notification
76+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
77+
-H "Content-Type: application/json" \
78+
-d "$EMAIL_BODY" || echo "Failed to send notification"
79+
80+
81+
- name: Get OpenAI, App Service and Container Registry Resource from Resource Group
82+
id: get_openai_resource
83+
run: |
84+
85+
86+
set -e
87+
echo "Fetching OpenAI resource from resource group ${{ env.RESOURCE_GROUP_NAME }}..."
88+
89+
# Run the az resource list command to get the OpenAI resource name
90+
openai_resource_name=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --resource-type "Microsoft.CognitiveServices/accounts" --query "[0].name" -o tsv)
91+
92+
if [ -z "$openai_resource_name" ]; then
93+
echo "No OpenAI resource found in resource group ${{ env.RESOURCE_GROUP_NAME }}."
94+
exit 1
95+
else
96+
echo "OPENAI_RESOURCE_NAME=${openai_resource_name}" >> $GITHUB_ENV
97+
echo "OpenAI resource name: ${openai_resource_name}"
98+
fi
99+
100+
echo "Fetching Azure App Service resource from resource group ${{ env.RESOURCE_GROUP_NAME }}..."
101+
102+
# Run the az resource list command to get the App Service resource name
103+
app_service_name=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --resource-type "Microsoft.Web/sites" --query "[0].name" -o tsv)
104+
105+
if [ -z "$app_service_name" ]; then
106+
echo "No Azure App Service resource found in resource group ${{ env.RESOURCE_GROUP_NAME }}."
107+
exit 1
108+
else
109+
echo "APP_SERVICE_NAME=${app_service_name}" >> $GITHUB_ENV
110+
echo "Azure App Service resource name: ${app_service_name}"
111+
fi
112+
113+
echo "Fetching container registry resource from resource group ${{ env.RESOURCE_GROUP_NAME }}..."
114+
115+
# Fetch Azure Container Registry name
116+
acr_name=$(az acr list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --query "[0].name" -o tsv)
117+
118+
if [ -z "$acr_name" ]; then
119+
echo "No Azure Container Registry found in resource group ${{ env.RESOURCE_GROUP_NAME }}."
120+
exit 1
121+
else
122+
echo "ACR_NAME=${acr_name}" >> $GITHUB_ENV
123+
echo "Azure Container Registry name: ${acr_name}"
124+
fi
125+
126+
127+
- name: Build the image and update the container app
128+
id: build-and-update
129+
run: |
130+
131+
set -e
132+
# Define variables for acr and container app names
133+
acr_name="${{ env.ACR_NAME }}"
134+
echo "ACR name: {$acr_name}"
135+
backend_container_app_name="macae-backend"
136+
backend_build_image_tag="backend:latest"
137+
138+
echo "Building the container image..."
139+
# Build the image
140+
az acr build -r ${acr_name} -t ${backend_build_image_tag} ./src/backend
141+
echo "Backend image build completed successfully."
142+
143+
frontend_container_app_name="${{ env.APP_SERVICE_NAME }}"
144+
frontend_build_image_tag="frontend:latest"
145+
146+
echo "Building the container image..."
147+
# Build the image
148+
az acr build -r ${acr_name} -t ${frontend_build_image_tag} ./src/frontend
149+
echo "Frontend image build completed successfully."
150+
151+
# Add the new container to the website
152+
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
153+
154+
155+
- name: Delete Bicep Deployment
156+
if: success()
157+
run: |
158+
set -e
159+
echo "Checking if resource group exists..."
160+
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
161+
if [ "$rg_exists" = "true" ]; then
162+
echo "Resource group exist. Cleaning..."
163+
az group delete \
164+
--name ${{ env.RESOURCE_GROUP_NAME }} \
165+
--yes \
166+
--no-wait
167+
echo "Resource group deleted... ${{ env.RESOURCE_GROUP_NAME }}"
168+
else
169+
echo "Resource group does not exists."
170+
fi
171+
172+
173+
- name: Wait for resource deletion to complete
174+
run: |
175+
176+
177+
# Add resources to the array
178+
resources_to_check=("${{ env.OPENAI_RESOURCE_NAME }}")
179+
180+
echo "List of resources to check: ${resources_to_check[@]}"
181+
182+
# Maximum number of retries
183+
max_retries=3
184+
185+
# Retry intervals in seconds (30, 60, 120)
186+
retry_intervals=(30 60 120)
187+
188+
# Retry mechanism to check resources
189+
retries=0
190+
while true; do
191+
resource_found=false
192+
193+
# Get the list of resources in YAML format again on each retry
194+
resource_list=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --output yaml)
195+
196+
# Iterate through the resources to check
197+
for resource in "${resources_to_check[@]}"; do
198+
echo "Checking resource: $resource"
199+
if echo "$resource_list" | grep -q "name: $resource"; then
200+
echo "Resource '$resource' exists in the resource group."
201+
resource_found=true
202+
else
203+
echo "Resource '$resource' does not exist in the resource group."
204+
fi
205+
done
206+
207+
# If any resource exists, retry
208+
if [ "$resource_found" = true ]; then
209+
retries=$((retries + 1))
210+
if [ "$retries" -gt "$max_retries" ]; then
211+
echo "Maximum retry attempts reached. Exiting."
212+
break
213+
else
214+
# Wait for the appropriate interval for the current retry
215+
echo "Waiting for ${retry_intervals[$retries-1]} seconds before retrying..."
216+
sleep ${retry_intervals[$retries-1]}
217+
fi
218+
else
219+
echo "No resources found. Exiting."
220+
break
221+
fi
222+
done
223+
224+
225+
- name: Purging the Resources
226+
if: success()
227+
run: |
228+
229+
set -e
230+
echo "Azure OpenAI: ${{ env.OPENAI_RESOURCE_NAME }}"
231+
232+
# Purge OpenAI Resource
233+
echo "Purging the OpenAI Resource..."
234+
if ! az resource delete --ids /subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/providers/Microsoft.CognitiveServices/locations/eastus/resourceGroups/${{ env.RESOURCE_GROUP_NAME }}/deletedAccounts/${{ env.OPENAI_RESOURCE_NAME }} --verbose; then
235+
echo "Failed to purge openai resource: ${{ env.OPENAI_RESOURCE_NAME }}"
236+
else
237+
echo "Purged the openai resource: ${{ env.OPENAI_RESOURCE_NAME }}"
238+
fi
239+
240+
echo "Resource purging completed successfully"

0 commit comments

Comments
 (0)