Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
4b25e03
chore(ci): trigger backend CI
AkankshaNunakani Sep 19, 2025
b4d4371
chore: activate workflow in fork
AkankshaNunakani Sep 19, 2025
9b3fc5c
ci: trigger backend workflow via backend/** change
AkankshaNunakani Sep 19, 2025
ef30802
ci: trigger backend workflows
AkankshaNunakani Sep 19, 2025
94c7373
ci: normalize triggers
AkankshaNunakani Sep 19, 2025
55dd08d
ci: restore backend_ci from upstream
AkankshaNunakani Sep 19, 2025
ad697ff
Update backend-cd.yml
AkankshaNunakani Sep 19, 2025
b6c81cf
Update backend_ci.yml
AkankshaNunakani Sep 19, 2025
be34076
Update backend_ci.yml
AkankshaNunakani Sep 19, 2025
ad360e5
Update backend-cd.yml
AkankshaNunakani Sep 19, 2025
f9f650b
Update backend_ci.yml
AkankshaNunakani Sep 19, 2025
919dddf
Update backend-cd.yml
AkankshaNunakani Sep 19, 2025
ef3f535
Update backend_ci.yml
AkankshaNunakani Sep 19, 2025
20bac2f
Update backend-cd.yml
AkankshaNunakani Sep 19, 2025
57c1074
Update backend_ci.yml
AkankshaNunakani Sep 19, 2025
ef3d953
Update backend_ci.yml
AkankshaNunakani Sep 19, 2025
f4bd676
Update backend-cd.yml
AkankshaNunakani Sep 19, 2025
bcd1f79
Update backend_ci.yml
AkankshaNunakani Sep 20, 2025
86017b7
Update backend_ci.yml
AkankshaNunakani Sep 20, 2025
896af89
Update backend_ci.yml
AkankshaNunakani Sep 20, 2025
8030489
Update backend_ci.yml
AkankshaNunakani Sep 20, 2025
f76de91
Update backend-cd.yml
AkankshaNunakani Sep 20, 2025
7b8b708
Update backend-cd.yml
AkankshaNunakani Sep 20, 2025
49f0fd6
Update backend-cd.yml
AkankshaNunakani Sep 20, 2025
79a4258
Update backend_ci.yml
AkankshaNunakani Sep 20, 2025
6d329d4
Update backend_ci.yml
AkankshaNunakani Sep 20, 2025
76afb5b
Update backend_ci.yml
AkankshaNunakani Sep 20, 2025
d01b0be
Update backend-cd.yml
AkankshaNunakani Sep 20, 2025
f2f40fe
Step 6: point frontend to AKS product/order services
AkankshaNunakani Sep 20, 2025
a80c017
Update frontend APIs to and
AkankshaNunakani Sep 20, 2025
aca16b1
test: trigger Frontend CI only
AkankshaNunakani Sep 29, 2025
c1fc539
ci: add consolidated CI (Frontend & Backend)
AkankshaNunakani Sep 29, 2025
5cbfd0a
ci: add consolidated CI (Frontend & Backend)
AkankshaNunakani Sep 29, 2025
e4f8fd5
chore: disable legacy frontend/backend CI/CD (kept for evidence)
AkankshaNunakani Sep 29, 2025
39d4a2f
Merge pull request #2 from AkankshaNunakani/chore/disable-old-pipelines
AkankshaNunakani Oct 1, 2025
ceef031
test(frontend): prove PR path filter
AkankshaNunakani Oct 1, 2025
e254e19
Merge pull request #3 from AkankshaNunakani/feat/ci-proof-2
AkankshaNunakani Oct 1, 2025
a839315
test(frontend): PR path filter proof (do not merge yet)
AkankshaNunakani Oct 1, 2025
4624cba
Merge pull request #4 from AkankshaNunakani/feat/ci-proof-3
AkankshaNunakani Oct 1, 2025
5b150bc
test(frontend): proof run for 9.2C
AkankshaNunakani Oct 1, 2025
0dc5647
test: retrigger PR CI (frontend-only)
AkankshaNunakani Oct 1, 2025
db07931
Merge pull request #6 from AkankshaNunakani/feat/ci-proof-final
AkankshaNunakani Oct 1, 2025
3a7d712
ci: simplify and remove concurrency to fix pre-run failures
AkankshaNunakani Oct 1, 2025
30912a3
test(frontend): prove paths-filter (frontend only)
AkankshaNunakani Oct 1, 2025
bd64e68
Merge pull request #8 from AkankshaNunakani/feat/ci-proof-final
AkankshaNunakani Oct 1, 2025
aa7829d
test(frontend): paths-filter proof (frontend only)
AkankshaNunakani Oct 1, 2025
c6a7a34
Merge pull request #9 from AkankshaNunakani/feat/ci-proof-frontend2
AkankshaNunakani Oct 1, 2025
3e7bdc9
test(frontend): paths-filter proof (frontend only)
AkankshaNunakani Oct 1, 2025
49df9d6
Merge pull request #10 from AkankshaNunakani/feat/ci-proof-frontend3
AkankshaNunakani Oct 1, 2025
8223427
test(frontend): paths-filter proof (frontend only)
AkankshaNunakani Oct 1, 2025
53ebca9
Merge pull request #11 from AkankshaNunakani/feat/ci-proof-frontend4
AkankshaNunakani Oct 1, 2025
c03b9f4
test(frontend): paths-filter proof (frontend only)
AkankshaNunakani Oct 1, 2025
fdf39f6
test(frontend): paths-filter proof (frontend only)
AkankshaNunakani Oct 1, 2025
33aa274
Merge pull request #12 from AkankshaNunakani/feat/ci-proof-frontend5
AkankshaNunakani Oct 1, 2025
f989403
test(frontend): trigger CI from feat/ci-proof-frontend5
AkankshaNunakani Oct 1, 2025
5978c38
test(frontend): rerun PR CI (frontend only)
AkankshaNunakani Oct 1, 2025
92cc26a
Merge pull request #13 from AkankshaNunakani/feat/ci-proof-frontend5
AkankshaNunakani Oct 1, 2025
844badc
test(frontend): rerun PR CI (frontend only)
AkankshaNunakani Oct 1, 2025
99b71d2
Merge pull request #14 from AkankshaNunakani/feat/ci-proof-frontend5
AkankshaNunakani Oct 1, 2025
efcff45
test: tiny frontend change to trigger Frontend CI (PR only)
AkankshaNunakani Oct 1, 2025
c2e250d
test(backend): trigger backend path only
AkankshaNunakani Oct 1, 2025
282f074
Merge pull request #15 from AkankshaNunakani/chore/use-backend-paths
AkankshaNunakani Oct 1, 2025
8142d67
test(frontend): trigger frontend CI only
AkankshaNunakani Oct 1, 2025
0d311fd
Merge pull request #16 from AkankshaNunakani/proof/frontend-only
AkankshaNunakani Oct 1, 2025
8ad3a60
test(frontend): trigger frontend CI only
AkankshaNunakani Oct 1, 2025
196e347
test(frontend): trigger frontend CI only
AkankshaNunakani Oct 1, 2025
d03f018
Merge pull request #17 from AkankshaNunakani/proof/frontend-only
AkankshaNunakani Oct 1, 2025
bf8262f
test(backend): trigger backend CI only
AkankshaNunakani Oct 1, 2025
08b0b73
test: trigger both frontend & backend CI
AkankshaNunakani Oct 1, 2025
ec09eea
test(backend): trigger backend-only CI
AkankshaNunakani Oct 1, 2025
b86b46a
Merge pull request #19 from AkankshaNunakani/proof/backend-only2
AkankshaNunakani Oct 1, 2025
335b702
Merge pull request #7 from AkankshaNunakani/chore/ci-yaml-fix
AkankshaNunakani Oct 1, 2025
96a62d2
chore: touch backend to trigger CD on main
AkankshaNunakani Oct 2, 2025
d5298a2
Resolve conflict: keep development README
AkankshaNunakani Oct 2, 2025
3a1f468
ci/cd: full workflows with safe Azure guards
AkankshaNunakani Oct 2, 2025
74635d1
ci/cd: add full workflow contents (single-quoted here-strings)
AkankshaNunakani Oct 2, 2025
a30e229
ci: conditional, skip-friendly frontend build
AkankshaNunakani Oct 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 28 additions & 90 deletions .github/workflows/backend-cd.yml
Original file line number Diff line number Diff line change
@@ -1,101 +1,39 @@
name: CD - Deploy Backend Services to AKS
name: Backend CD - Deploy to AKS

on:
workflow_dispatch:
inputs:
aks_cluster_name:
description: 'Name of the AKS Cluster to deploy to'
required: true
default: '<aks_cluster_name>'
aks_resource_group:
description: 'Resource Group of the AKS Cluster'
required: true
default: '<resource_group_name>'
aks_acr_name:
description: 'Name of ACR'
required: true
default: '<acr_name>'
workflow_run:
workflows: ["CI Frontend and Backend"]
types: [completed]
branches: [main]

concurrency:
group: cd-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
id-token: write

jobs:
deploy_backend:
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' && vars.AZURE_CLIENT_ID && vars.AZURE_TENANT_ID && vars.AZURE_SUBSCRIPTION_ID }}
runs-on: ubuntu-latest
environment: Production

outputs:
PRODUCT_API_IP: ${{ steps.get_product_ip.outputs.external_ip }}
ORDER_API_IP: ${{ steps.get_order_ip.outputs.external_ip }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Log in to Azure
uses: azure/login@v1
- name: Azure login (OIDC)
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true

- name: Set Kubernetes context (get AKS credentials)
run: |
az aks get-credentials --resource-group ${{ github.event.inputs.aks_resource_group }} --name ${{ github.event.inputs.aks_cluster_name }} --overwrite-existing

- name: Attach ACR
run: |
az aks update --name ${{ github.event.inputs.aks_cluster_name }} --resource-group ${{ github.event.inputs.aks_resource_group }} --attach-acr ${{ github.event.inputs.aks_acr_name }}

- name: Deploy Backend Infrastructure (Namespace, ConfigMaps, Secrets, Databases)
run: |
echo "Deploying backend infrastructure..."
cd k8s/
kubectl apply -f configmaps.yaml
kubectl apply -f secrets.yaml
kubectl apply -f product-db.yaml
kubectl apply -f order-db.yaml
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}

- name: Deploy Backend Microservices (Product, Order)
- name: Show ACR images
run: |
echo "Deploying backend microservices..."
cd k8s/
kubectl apply -f product-service.yaml
kubectl apply -f order-service.yaml

- name: Wait for Backend LoadBalancer IPs
run: |
echo "Waiting for Product, Order LoadBalancer IPs to be assigned (up to 5 minutes)..."
PRODUCT_IP=""
ORDER_IP=""

for i in $(seq 1 60); do
echo "Attempt $i/60 to get IPs..."
PRODUCT_IP=$(kubectl get service product-service-w08e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
ORDER_IP=$(kubectl get service order-service-w08e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}')

if [[ -n "$PRODUCT_IP" && -n "$ORDER_IP" ]]; then
echo "All backend LoadBalancer IPs assigned!"
echo "Product Service IP: $PRODUCT_IP"
echo "Order Service IP: $ORDER_IP"
break
fi
sleep 5 # Wait 5 seconds before next attempt
done

if [[ -z "$PRODUCT_IP" || -z "$ORDER_IP" ]]; then
echo "Error: One or more LoadBalancer IPs not assigned after timeout."
exit 1 # Fail the job if IPs are not obtained
fi

# These are environment variables for subsequent steps in the *same job*
# And used to set the job outputs
echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_ENV
echo "ORDER_IP=$ORDER_IP" >> $GITHUB_ENV

- name: Capture Product Service IP for Workflow Output
id: get_product_ip
run: echo "external_ip=${{ env.PRODUCT_IP }}" >> $GITHUB_OUTPUT

- name: Capture Order Service IP for Workflow Output
id: get_order_ip
run: echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT
: "${ACR_LOGIN_SERVER?Need env ACR_LOGIN_SERVER (e.g. wk08acr123.azurecr.io)}"
az acr repository list --name "${ACR_LOGIN_SERVER%%.azurecr.io}" -o table

- name: Logout from Azure
run: az logout
# - name: Get AKS creds
# run: az aks get-credentials -g <resource-group> -n <aks-name> --overwrite-existing
# - name: kubectl apply
# run: kubectl apply -f k8s/
62 changes: 62 additions & 0 deletions .github/workflows/backend-cd.yml.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Backend CD - Deploy to AKS

on:
workflow_dispatch:
inputs:
tag:
description: "Image tag to deploy (leave blank to use latest CI SHA)"
required: false
workflow_run:
workflows: [ "Backend CI - Test, Build and Push Images to ACR" ]
types: [ "completed" ]
branches: [ "main" ]

jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
env:
ACR_LOGIN_SERVER: s722acr84438.azurecr.io
SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5
NAMESPACE: default
ORDER_DEPLOY: order-service-w08e1
PRODUCT_DEPLOY: product-service-w08e1
ORDER_CONTAINER: order-service-container
PRODUCT_CONTAINER: product-service-container
TAG: ${{ inputs.tag || github.event.workflow_run.head_sha || github.sha }}

steps:
- uses: actions/checkout@v4

- name: Azure login
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Set subscription
run: az account set --subscription "$SUB_ID"

- name: Set AKS context (admin kubeconfig)
uses: azure/aks-set-context@v3
with:
resource-group: ${{ secrets.AKS_RG }}
cluster-name: ${{ secrets.AKS_NAME }}
admin: true

- name: Patch images to new tag
run: |
set -e
echo "Deploying tag: $TAG"
kubectl set image -n "$NAMESPACE" deploy/$ORDER_DEPLOY $ORDER_CONTAINER=$ACR_LOGIN_SERVER/week08/order-service:$TAG
kubectl set image -n "$NAMESPACE" deploy/$PRODUCT_DEPLOY $PRODUCT_CONTAINER=$ACR_LOGIN_SERVER/week08/product-service:$TAG

- name: Wait for rollout
run: |
set -e
kubectl rollout status -n "$NAMESPACE" deploy/$ORDER_DEPLOY
kubectl rollout status -n "$NAMESPACE" deploy/$PRODUCT_DEPLOY

- name: Show deployed images
run: |
kubectl get deploy -n "$NAMESPACE" \
-o custom-columns=NAME:.metadata.name,IMAGE:.spec.template.spec.containers[0].image,READY:.status.readyReplicas
175 changes: 49 additions & 126 deletions .github/workflows/backend_ci.yml
Original file line number Diff line number Diff line change
@@ -1,146 +1,69 @@
# week08/.github/workflows/backend_ci.yml

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

# Trigger the workflow on pushes to the 'main' branch
# You can also add 'pull_request:' to run on PRs
on:
# Manual trigger
workflow_dispatch:

# Automatically on pushes to main branch
push:
branches:
- main
paths: # Only trigger if changes are in backend directories
- 'backend/**'
- '.github/workflows/backend_ci.yml' # Trigger if this workflow file changes

# Define global environment variables that can be used across jobs
env:
# ACR Login Server (e.g., myregistry.azurecr.io)
# This needs to be set as a GitHub Repository Secret
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 }}
branches: [ "main" ]

jobs:
# Job 1: Run tests and linting for all backend services
test_and_lint_backends:
runs-on: ubuntu-latest # Use a GitHub-hosted runner

services:
# Product DB container
product_db:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: products
# Make pg_isready available so the service is healthy before tests run
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

# Order DB
order_db:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: orders
ports:
- 5433:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
test_build_push:
runs-on: ubuntu-latest
env:
ACR_NAME: s722acr84438
ACR_SERVER: s722acr84438.azurecr.io
SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5
TAG: ${{ github.sha }}

steps:
# 1. Checkout the repository code to the runner
- name: Checkout repository
uses: actions/checkout@v4 # Action to check out your repository code
- uses: actions/checkout@v4

# 2. Set up Python environment
- name: Set up Python 3.10
uses: actions/setup-python@v5 # Action to set up Python environment
- name: Azure login (service principal)
uses: azure/login@v2
with:
python-version: '3.10'
creds: ${{ secrets.AZURE_CREDENTIALS }}

# 3. Install dependencies and run code quality checks
- name: Install dependencies
run: | # Use a multi-line script to install pip dependencies
pip install --upgrade pip
# Loop through each backend service folder
for req in backend/*/requirements.txt; do
echo "Installing $req"
pip install -r "$req"
done
# Install CI tools
pip install pytest httpx
- name: Set subscription
run: az account set --subscription "$SUB_ID"

# 5. Run tests for product service
- name: Run product_service tests
working-directory: backend/product_service
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_DB: products
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
run: |
pytest tests --maxfail=1 --disable-warnings -q

# 6. Run tests for order service
- name: Run order_service tests
working-directory: backend/order_service
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5433
POSTGRES_DB: orders
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
run: |
pytest tests --maxfail=1 --disable-warnings -q
- name: Login docker to ACR (token-based)
run: az acr login -n "$ACR_NAME"

# Job 2: Build and Push Docker Images (runs only if tests pass)
build_and_push_images:
runs-on: ubuntu-latest
needs: test_and_lint_backends
- name: Find Dockerfiles (order + product)
id: detect
shell: bash
run: |
set -e
# Try smart search first
ORDER=$(find . -type f -iname Dockerfile -path '*order*' | head -n1)
PROD=$( find . -type f -iname Dockerfile -path '*product*' | head -n1)

steps:
- name: Checkout repository
uses: actions/checkout@v4
# Fallback to common paths if needed
[[ -z "$ORDER" && -f "order-service/Dockerfile" ]] && ORDER="order-service/Dockerfile"
[[ -z "$PROD" && -f "product-service/Dockerfile" ]] && PROD="product-service/Dockerfile"

# Azure login using a Service Principal secret
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }} # Needs to be set as a GitHub Secret (Service Principal JSON)
[[ -n "$ORDER" && -f "$ORDER" ]] || { echo "Order Dockerfile not found"; exit 1; }
[[ -n "$PROD" && -f "$PROD" ]] || { echo "Product Dockerfile not found"; exit 1; }

# Login to Azure Container Registry (ACR)
- name: Login to Azure Container Registry
run: az acr login --name ${{ env.ACR_LOGIN_SERVER }}
echo "order=$ORDER" >> "$GITHUB_OUTPUT"
echo "product=$PROD" >> "$GITHUB_OUTPUT"
echo "Found ORDER=$ORDER"
echo "Found PRODUCT=$PROD"

# 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
- name: Build & push order-service (Docker)
run: |
ORDER_DF="${{ steps.detect.outputs.order }}"
ORDER_CTX="$(dirname "$ORDER_DF")"
docker build -t "$ACR_SERVER/week08/order-service:${TAG}" -f "$ORDER_DF" "$ORDER_CTX"
docker push "$ACR_SERVER/week08/order-service:${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
- name: Build & push product-service (Docker)
run: |
PROD_DF="${{ steps.detect.outputs.product }}"
PROD_CTX="$(dirname "$PROD_DF")"
docker build -t "$ACR_SERVER/week08/product-service:${TAG}" -f "$PROD_DF" "$PROD_CTX"
docker push "$ACR_SERVER/week08/product-service:${TAG}"

# Logout from Azure for security (runs even if image push fails)
- name: Logout from Azure
run: az logout
if: always()
- name: Show image URIs
run: |
echo "$ACR_SERVER/week08/order-service:${TAG}"
echo "$ACR_SERVER/week08/product-service:${TAG}"
Loading