Skip to content
10 changes: 7 additions & 3 deletions .github/workflows/backend-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ on:
aks_cluster_name:
description: 'Name of the AKS Cluster to deploy to'
required: true
default: '<aks_cluster_name>'
default: 'mywk8aks'
aks_resource_group:
description: 'Resource Group of the AKS Cluster'
required: true
default: '<resource_group_name>'
default: 'ci-wk8-rg'
aks_acr_name:
description: 'Name of ACR'
required: true
default: '<acr_name>'
default: 'mywk8acr'
workflow_run:
workflows: ["Backend CI - Test, Build and Push Images to ACR"]
types: [completed]

jobs:
deploy_backend:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
environment: Production

Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/backend_ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# week08/.github/workflows/backend_ci.yml
# Comment added to trigger backend CI workflow - Madushika Amarasekara

name: Backend CI - Test, Build and Push Images to ACR

Expand All @@ -11,10 +12,13 @@ on:
# Automatically on pushes to main branch
push:
branches:
- main
- dev
paths: # Only trigger if changes are in backend directories
- 'backend/**'
- '.github/workflows/backend_ci.yml' # Trigger if this workflow file changes
pull_request:
branches:
- main

# Define global environment variables that can be used across jobs
env:
Expand All @@ -23,7 +27,7 @@ env:
ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }}
# Dynamically generate image tags based on Git SHA and GitHub Run ID
# This provides unique, traceable tags for each image build
IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }}
IMAGE_TAG: ${{ github.ref_name }}-${{ github.sha }}

jobs:
# Job 1: Run tests and linting for all backend services
Expand Down Expand Up @@ -131,14 +135,14 @@ jobs:
# Build and Push Docker image for Product Service
- name: Build and Push Product Service Image
run: |
docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:latest ./backend/product_service/
docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:latest
docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:${{ env.IMAGE_TAG }} ./backend/product_service/
docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:${{ env.IMAGE_TAG }}

# Build and Push Docker image for Order Service
- name: Build and Push Order Service Image
run: |
docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:latest ./backend/order_service/
docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:latest
docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:${{ env.IMAGE_TAG }} ./backend/order_service/
docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:${{ env.IMAGE_TAG }}

# Logout from Azure for security (runs even if image push fails)
- name: Logout from Azure
Expand Down