Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
08c85d5
Backend code refactored
BinilTomJose1278 Sep 15, 2025
ec77182
Backend CI Updated
BinilTomJose1278 Sep 15, 2025
1a96eb9
Changed backend ci logic
BinilTomJose1278 Sep 15, 2025
b70ac5d
Frontend files refactored
BinilTomJose1278 Sep 15, 2025
7eee738
Update backend service IPs in frontend/main.js
BinilTomJose1278 Sep 15, 2025
6c19b83
Refactored frontend_ci.yml
BinilTomJose1278 Sep 15, 2025
9bd72dd
Code Refactored
BinilTomJose1278 Sep 15, 2025
ac7fb78
Week09: Updated ACR, AKS, and GitHub Actions workflows
BinilTomJose1278 Sep 26, 2025
d8da143
Fix Docker build commands in workflows
BinilTomJose1278 Sep 26, 2025
a840689
Fix ACR name mismatch: Update to use wk09cacrbinil
BinilTomJose1278 Sep 26, 2025
fd4f53f
Fix Docker BuildKit compatibility issue
BinilTomJose1278 Sep 26, 2025
0fe4fd5
Fix shared workflow call issue
BinilTomJose1278 Sep 26, 2025
d5a6770
Test workflow trigger - check AKS secrets
BinilTomJose1278 Sep 26, 2025
27fa60d
Fix Kubernetes manifest naming consistency
BinilTomJose1278 Sep 26, 2025
f15c160
Test staging deployment - trigger ci-development workflow
BinilTomJose1278 Sep 26, 2025
5e0d7fa
Test staging deployment - trigger ci-development workflow
BinilTomJose1278 Sep 26, 2025
a547149
Remove job-level conditions from ci-development workflow
BinilTomJose1278 Sep 26, 2025
ffab254
Fix test file encoding and Azure logout issues
BinilTomJose1278 Sep 26, 2025
79c1663
Fix null bytes issue in main.py
BinilTomJose1278 Sep 26, 2025
5f4eea2
Fix ACR authentication for frontend deployment
BinilTomJose1278 Sep 26, 2025
d46f730
Fix ACR authentication using Docker login
BinilTomJose1278 Sep 26, 2025
35249b6
Fix ACR authentication using access token
BinilTomJose1278 Sep 26, 2025
58a5ba2
Enable ACR admin access for Docker authentication
BinilTomJose1278 Sep 26, 2025
04394fd
Replace with improved CI development workflow
BinilTomJose1278 Sep 26, 2025
fa4b05e
ci(dev): use plain docker build (no BuildKit); fix image tags and paths
BinilTomJose1278 Sep 26, 2025
342030a
ci(dev): ensure namespace exists before applying manifests
BinilTomJose1278 Sep 26, 2025
ed00cc5
ci(dev): fix rollout and service names to *-w09e1; correct DNS
BinilTomJose1278 Sep 26, 2025
db39939
ci(dev): wait on deploy/frontend (manifest name), keep svc frontend-w…
BinilTomJose1278 Sep 26, 2025
96e68d0
ci(dev): run backend health checks in-cluster using curl pod
BinilTomJose1278 Sep 26, 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
6 changes: 3 additions & 3 deletions .github/workflows/backend-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ on:
aks_cluster_name:
description: 'Name of the AKS Cluster to deploy to'
required: true
default: '<aks_cluster_name>'
default: 'binilweek08aks2'
aks_resource_group:
description: 'Resource Group of the AKS Cluster'
required: true
default: '<resource_group_name>'
default: 'rg-week08'
aks_acr_name:
description: 'Name of ACR'
required: true
default: '<acr_name>'
default: 'binilweek08acr'

jobs:
deploy_backend:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/backend_ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# week08/.github/workflows/backend_ci.yml
# week07/.github/workflows/backend_ci.yml

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

Expand All @@ -20,7 +20,7 @@ on:
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 }}
ACR_LOGIN_SERVER: ${{ secrets.ACR_LOGIN_SERVER }}
# 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 }}
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4 # Action to check out your repository code

# 2. Set up Python environment
# 2. Set up Python environment ( Minimum version 3.10)
- name: Set up Python 3.10
uses: actions/setup-python@v5 # Action to set up Python environment
with:
Expand Down Expand Up @@ -143,4 +143,4 @@ jobs:
# Logout from Azure for security (runs even if image push fails)
- name: Logout from Azure
run: az logout
if: always()
if: always()
262 changes: 262 additions & 0 deletions .github/workflows/cd-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
# CD Pipeline for Production Deployment
name: CD - Production Deployment

on:
push:
branches: [ main ]
paths:
- 'backend/**'
- 'frontend/**'
- 'k8s/**'
- '.github/workflows/cd-production.yml'
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
default: 'production'
type: choice
options:
- production
- staging

env:
ACR_LOGIN_SERVER: ${{ secrets.ACR_LOGIN_SERVER }}
IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }}

jobs:
# Build Production Images
build-production-images:
runs-on: ubuntu-latest

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

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

- name: Login to Azure Container Registry
run: az acr login --name wk09cacrbinil

- name: Build and Push Product Service Image
run: |
DOCKER_BUILDKIT=0 docker build -t wk09cacrbinil.azurecr.io/product_service:prod-${{ env.IMAGE_TAG }} ./backend/product_service/
DOCKER_BUILDKIT=0 docker build -t wk09cacrbinil.azurecr.io/product_service:latest ./backend/product_service/
docker push wk09cacrbinil.azurecr.io/product_service:prod-${{ env.IMAGE_TAG }}
docker push wk09cacrbinil.azurecr.io/product_service:latest

- name: Build and Push Order Service Image
run: |
DOCKER_BUILDKIT=0 docker build -t wk09cacrbinil.azurecr.io/order_service:prod-${{ env.IMAGE_TAG }} ./backend/order_service/
DOCKER_BUILDKIT=0 docker build -t wk09cacrbinil.azurecr.io/order_service:latest ./backend/order_service/
docker push wk09cacrbinil.azurecr.io/order_service:prod-${{ env.IMAGE_TAG }}
docker push wk09cacrbinil.azurecr.io/order_service:latest

- name: Build and Push Frontend Image
run: |
DOCKER_BUILDKIT=0 docker build -t wk09cacrbinil.azurecr.io/frontend:prod-${{ env.IMAGE_TAG }} ./frontend/
DOCKER_BUILDKIT=0 docker build -t wk09cacrbinil.azurecr.io/frontend:latest ./frontend/
docker push wk09cacrbinil.azurecr.io/frontend:prod-${{ env.IMAGE_TAG }}
docker push wk09cacrbinil.azurecr.io/frontend:latest

- name: Logout from Azure
run: az logout
if: always()

# Deploy Backend Services
deploy-backend:
runs-on: ubuntu-latest
needs: build-production-images
environment: Production

outputs:
product_service_ip: ${{ steps.get-backend-ips.outputs.product_ip }}
order_service_ip: ${{ steps.get-backend-ips.outputs.order_ip }}

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

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

- name: Setup Kubernetes Context
run: |
az aks get-credentials --resource-group ${{ secrets.AKS_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} --overwrite-existing

- name: Deploy Backend Infrastructure
run: |
echo "Deploying backend infrastructure to production..."
cd k8s/

# Update image tags for production
sed -i "s|image: .*product_service:.*|image: wk09cacrbinil.azurecr.io/product_service:latest|g" product-service.yaml
sed -i "s|image: .*order_service:.*|image: wk09cacrbinil.azurecr.io/order_service:latest|g" order-service.yaml

kubectl apply -f configmaps.yaml
kubectl apply -f secrets.yaml
kubectl apply -f product-db.yaml
kubectl apply -f order-db.yaml

- name: Deploy Backend Microservices
run: |
echo "Deploying backend microservices to production..."
cd k8s/
kubectl apply -f product-service.yaml
kubectl apply -f order-service.yaml

- name: Wait for Backend Services
run: |
echo "Waiting for backend services to be ready..."
kubectl wait --for=condition=available --timeout=300s deployment/product-service-w09e1
kubectl wait --for=condition=available --timeout=300s deployment/order-service-w09e1

- name: Get Backend Service IPs
id: get-backend-ips
run: |
echo "Getting backend service IPs..."
PRODUCT_IP=""
ORDER_IP=""

# Wait for IPs to be assigned (up to 5 minutes)
for i in $(seq 1 60); do
echo "Attempt $i/60 to get IPs..."
PRODUCT_IP=$(kubectl get service product-service-w09e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
ORDER_IP=$(kubectl get service order-service-w09e1 -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
done

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

echo "product_ip=http://$PRODUCT_IP:8000" >> $GITHUB_OUTPUT
echo "order_ip=http://$ORDER_IP:8001" >> $GITHUB_OUTPUT

- name: Health Check Backend Services
run: |
echo "Performing health checks on backend services..."
sleep 30 # Wait for services to be fully ready

# Test product service
curl -f ${{ steps.get-backend-ips.outputs.product_ip }}/health || exit 1
echo "✅ Product service health check passed"

# Test order service
curl -f ${{ steps.get-backend-ips.outputs.order_ip }}/health || exit 1
echo "✅ Order service health check passed"

# Deploy Frontend
deploy-frontend:
runs-on: ubuntu-latest
needs: deploy-backend
environment: Production

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

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

- name: Login to Azure Container Registry
run: az acr login --name ${{ env.ACR_LOGIN_SERVER }}

- name: Inject Backend URLs into Frontend
run: |
echo "Injecting backend URLs into frontend configuration..."
sed -i "s|_PRODUCT_API_URL_|${{ needs.deploy-backend.outputs.product_service_ip }}|g" frontend/main.js
sed -i "s|_ORDER_API_URL_|${{ needs.deploy-backend.outputs.order_service_ip }}|g" frontend/main.js

echo "--- main.js after injection ---"
cat frontend/main.js
echo "--------------------------------"

- name: Build and Push Updated Frontend Image
run: |
echo "Building and pushing updated frontend image..."
DOCKER_BUILDKIT=0 docker build -t wk09cacrbinil.azurecr.io/frontend:latest ./frontend/
docker push wk09cacrbinil.azurecr.io/frontend:latest

- name: Setup Kubernetes Context
run: |
az aks get-credentials --resource-group ${{ secrets.AKS_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} --overwrite-existing

- name: Deploy Frontend
run: |
echo "Deploying frontend to production..."
cd k8s/

# Ensure image reference points to latest
sed -i "s|image: .*frontend:.*|image: wk09cacrbinil.azurecr.io/frontend:latest|g" frontend.yaml

kubectl apply -f frontend.yaml
kubectl rollout status deployment/frontend --timeout=300s

- name: Wait for Frontend Service
run: |
echo "Waiting for frontend service to be ready..."
kubectl wait --for=condition=available --timeout=300s deployment/frontend

- name: Get Frontend Service IP
id: get-frontend-ip
run: |
FRONTEND_IP=$(kubectl get service frontend-w09e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo "frontend_ip=http://$FRONTEND_IP" >> $GITHUB_OUTPUT
echo "Frontend deployed at: http://$FRONTEND_IP"

- name: Final Health Check
run: |
echo "Performing final health checks..."
sleep 30 # Wait for all services to be fully ready

# Test all services
curl -f ${{ needs.deploy-backend.outputs.product_service_ip }}/health || exit 1
curl -f ${{ needs.deploy-backend.outputs.order_service_ip }}/health || exit 1
curl -f ${{ steps.get-frontend-ip.outputs.frontend_ip }} || exit 1

echo "✅ All services are healthy!"

- name: Logout from Azure
run: az logout
if: always()

# Post-Deployment Verification
post-deployment-verification:
runs-on: ubuntu-latest
needs: [deploy-backend, deploy-frontend]
if: always() && needs.deploy-backend.result == 'success' && needs.deploy-frontend.result == 'success'

steps:
- name: Deployment Summary
run: |
echo "🎉 Production Deployment Successful!"
echo "=================================="
echo "Frontend URL: ${{ needs.deploy-frontend.outputs.frontend_ip || 'Not available' }}"
echo "Product API: ${{ needs.deploy-backend.outputs.product_service_ip }}"
echo "Order API: ${{ needs.deploy-backend.outputs.order_service_ip }}"
echo "=================================="
echo "Deployment completed at: $(date)"
echo "Git commit: ${{ github.sha }}"
echo "Workflow run: ${{ github.run_id }}"

- name: Create Deployment Notification
run: |
echo "Creating deployment notification..."
# This could be extended to send notifications to Slack, Teams, etc.
echo "Deployment notification created for commit ${{ github.sha }}"
Loading