Skip to content

Commit 5f468ec

Browse files
committed
Updated Workflow Letest
1 parent 54cb9c4 commit 5f468ec

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

.github/workflows/build-deploy.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,68 +13,80 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16+
# ------------------- Checkout Code -------------------
1617
- name: Checkout repository
1718
uses: actions/checkout@v4
1819

1920
- name: Configure Git for Terraform module downloads
2021
run: |
2122
git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"
2223
24+
# ------------------- Login to Azure -------------------
2325
- name: Log in to Azure
2426
uses: azure/login@v2
2527
with:
2628
creds: ${{ secrets.AZURE_CREDENTIALS }}
2729

30+
# ------------------- Login to ACR -------------------
2831
- name: Log in to ACR
2932
run: |
3033
az acr login --name ${{ secrets.ACR_NAME }}
3134
35+
# ------------------- Build and Push Docker Image -------------------
3236
- name: Build and Push Docker image
3337
run: |
3438
IMAGE_TAG=${{ github.run_number }}
3539
az acr build --registry ${{ secrets.ACR_NAME }} \
3640
--image $IMAGE_NAME:$IMAGE_TAG \
3741
--image $IMAGE_NAME:latest .
3842
43+
# ------------------- Terraform Init -------------------
44+
- name: Terraform Init
45+
working-directory: ./terraform # update path to your Terraform files
46+
run: terraform init
47+
48+
# ------------------- Terraform Plan -------------------
49+
- name: Terraform Plan
50+
working-directory: ./terraform
51+
run: terraform plan -out=tfplan
52+
53+
# ------------------- Terraform Apply -------------------
54+
- name: Terraform Apply
55+
working-directory: ./terraform
56+
run: terraform apply -auto-approve tfplan
57+
3958
# ------------------- Determine Idle Slot -------------------
4059
- name: Determine Idle Slot
4160
id: idle-slot
4261
run: |
4362
RESOURCE_GROUP=${{ secrets.AZURE_RESOURCE_GROUP }}
4463
APP_NAME=${{ secrets.AZURE_APP_NAME }}
4564
46-
# Get current production slot's container image
4765
PROD_IMAGE=$(az webapp config container show \
4866
--name $APP_NAME \
4967
--resource-group $RESOURCE_GROUP \
5068
--query "linuxFxVersion" -o tsv)
5169
52-
echo "Current production image: $PROD_IMAGE"
53-
54-
# Decide idle slot
55-
IDLE_SLOT="blue"
5670
SLOT_BLUE_IMAGE=$(az webapp config container show --name $APP_NAME --resource-group $RESOURCE_GROUP --slot blue --query "linuxFxVersion" -o tsv)
5771
SLOT_GREEN_IMAGE=$(az webapp config container show --name $APP_NAME --resource-group $RESOURCE_GROUP --slot green --query "linuxFxVersion" -o tsv)
5872
59-
# If blue is production, deploy to green; else deploy to blue
6073
if [[ "$SLOT_BLUE_IMAGE" == "$PROD_IMAGE" ]]; then
6174
IDLE_SLOT="green"
6275
else
6376
IDLE_SLOT="blue"
6477
fi
6578
66-
echo "Idle slot chosen for deployment: $IDLE_SLOT"
6779
echo "slot_name=$IDLE_SLOT" >> $GITHUB_ENV
80+
echo "Idle slot chosen: $IDLE_SLOT"
6881
6982
# ------------------- Deploy to Idle Slot -------------------
7083
- name: Deploy to Idle Slot
7184
run: |
7285
IMAGE_TAG=${{ github.run_number }}
7386
RESOURCE_GROUP=${{ secrets.AZURE_RESOURCE_GROUP }}
7487
APP_NAME=${{ secrets.AZURE_APP_NAME }}
75-
SLOT_NAME=$slot_name # read from previous step
88+
SLOT_NAME=$slot_name
7689
77-
echo "Deploying image $IMAGE_TAG to $SLOT_NAME slot..."
7890
az webapp config container set \
7991
--name $APP_NAME \
8092
--resource-group $RESOURCE_GROUP \
@@ -89,7 +101,6 @@ jobs:
89101
APP_NAME=${{ secrets.AZURE_APP_NAME }}
90102
SLOT_NAME=$slot_name
91103
92-
echo "Swapping $SLOT_NAME slot with production..."
93104
az webapp deployment slot swap \
94105
--resource-group $RESOURCE_GROUP \
95106
--name $APP_NAME \

0 commit comments

Comments
 (0)