Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f5ed41d
updating the cd and k8's file with correct names
iamrealishaan Sep 17, 2025
2d085fc
updated ip in main.js
iamrealishaan Sep 17, 2025
98096e0
backend_ci to development
iamrealishaan Sep 26, 2025
da417b5
backend_ci to development
iamrealishaan Sep 26, 2025
1ea32ef
frontend_ci to development
iamrealishaan Sep 26, 2025
9221c6b
linkage
iamrealishaan Sep 26, 2025
87a4154
frontend
iamrealishaan Sep 26, 2025
9cd2912
pipeline for development
iamrealishaan Sep 26, 2025
0b511b3
pipeline for development
iamrealishaan Sep 26, 2025
6748377
pipeline for development
iamrealishaan Sep 26, 2025
f932948
Correct linkage and automatic trigger
iamrealishaan Sep 26, 2025
081defe
update piepline
iamrealishaan Sep 26, 2025
f193db7
testing push trigger backend.ci
iamrealishaan Sep 26, 2025
00dee42
testing automatic trigger by push
iamrealishaan Sep 26, 2025
aaefd16
updated frontend and secrets
iamrealishaan Sep 26, 2025
01839a5
Merge branch 'development'
iamrealishaan Sep 26, 2025
215623a
linkage backedn ci to frontend cd
iamrealishaan Sep 26, 2025
9569f88
Test backend ci to backend cd
iamrealishaan Sep 26, 2025
c7fda75
Test backend ci to backend cd
iamrealishaan Sep 26, 2025
d0cd24c
Test backend ci to backend cd
iamrealishaan Sep 26, 2025
18a3c73
Merge remote-tracking branch 'origin/development'
iamrealishaan Sep 26, 2025
65e52ea
Frontend CI/CD pipeline
iamrealishaan Sep 26, 2025
e052c80
Frontend CI/CD pipeline
iamrealishaan Sep 26, 2025
1d4bd54
Frontend CI/CD pipeline
iamrealishaan Sep 26, 2025
dc98f2b
Frontend CI/CD pipeline
iamrealishaan Sep 26, 2025
a3447b7
Frontend CI/CD pipeline
iamrealishaan Sep 26, 2025
285a547
Frontend CI/CD pipeline
iamrealishaan Sep 26, 2025
9608b0b
Frontend CI/CD pipeline
iamrealishaan Sep 26, 2025
cc8141b
Merge pull request #3 from ishaan-markanday/development
ishaan-markanday Sep 26, 2025
9eae369
Frontend CI/CD pipeline
iamrealishaan Sep 26, 2025
c4870da
Frontend CI/CD pipeline
iamrealishaan Sep 26, 2025
a630531
Frontend CI/CD pipeline
iamrealishaan Sep 26, 2025
741745e
Frontend CI/CD pipeline
iamrealishaan Sep 26, 2025
017b811
Merge pull request #4 from ishaan-markanday/development
ishaan-markanday Sep 26, 2025
92b4800
Frontend CI/CD pipeline
iamrealishaan Sep 26, 2025
ec9af6e
Frontend CI/CD pipeline (#5)
ishaan-markanday Sep 26, 2025
1295152
Frontend CI/CD pipeline
iamrealishaan Sep 26, 2025
c197879
Merge pull request #6 from ishaan-markanday/development
ishaan-markanday Sep 26, 2025
c2bac22
updated frontend
iamrealishaan Sep 26, 2025
22d8bbc
Merge branch 'development'
iamrealishaan Sep 26, 2025
4ea8487
Merge branch 'main' of https://github.com/ishaan-markanday/week08
iamrealishaan Sep 26, 2025
3530ad4
fixed frontend name
iamrealishaan Sep 26, 2025
d7961e2
test
iamrealishaan 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
30 changes: 23 additions & 7 deletions .github/workflows/backend-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,31 @@ on:
aks_cluster_name:
description: 'Name of the AKS Cluster to deploy to'
required: true
default: '<aks_cluster_name>'
default: 'ishaanAKS'
aks_resource_group:
description: 'Resource Group of the AKS Cluster'
required: true
default: '<resource_group_name>'
default: 'deakinuni'
aks_acr_name:
description: 'Name of ACR'
required: true
default: '<acr_name>'
default: 'ishaan'

# Add this workflow_call trigger
workflow_call:
inputs:
aks_cluster_name:
required: true
type: string
aks_resource_group:
required: true
type: string
aks_acr_name:
required: true
type: string
secrets:
azure_credentials:
required: true

jobs:
deploy_backend:
Expand All @@ -32,16 +48,16 @@ jobs:
- name: Log in to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
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
az aks get-credentials --resource-group ${{ inputs.aks_resource_group }} --name ${{ 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 }}
az aks update --name ${{ inputs.aks_cluster_name }} --resource-group ${{ inputs.aks_resource_group }} --attach-acr ${{ inputs.aks_acr_name }}

- name: Deploy Backend Infrastructure (Namespace, ConfigMaps, Secrets, Databases)
run: |
Expand Down Expand Up @@ -98,4 +114,4 @@ jobs:
run: echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT

- name: Logout from Azure
run: az logout
run: az logout
125 changes: 56 additions & 69 deletions .github/workflows/backend_ci.yml
Original file line number Diff line number Diff line change
@@ -1,91 +1,74 @@
# 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:
- development
- main
paths:
- 'backend/**'
- '.github/workflows/backend_ci.yml'
pull_request:
branches:
- main
paths: # Only trigger if changes are in backend directories
paths:
- 'backend/**'
- '.github/workflows/backend_ci.yml' # Trigger if this workflow file changes
- '.github/workflows/backend_ci.yml'

# 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 }}

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

runs-on: ubuntu-latest
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
ports:
- 5433:5432

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
uses: actions/setup-python@v5
with:
python-version: '3.10'

# 3. Install dependencies and run code quality checks
- name: Install dependencies
run: | # Use a multi-line script to install pip dependencies
run: |
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

# 5. Run tests for product service
- name: Run product_service tests
working-directory: backend/product_service
env:
Expand All @@ -94,10 +77,8 @@ jobs:
POSTGRES_DB: products
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
run: |
pytest tests --maxfail=1 --disable-warnings -q

# 6. Run tests for order service
run: pytest tests --maxfail=1 --disable-warnings -q

- name: Run order_service tests
working-directory: backend/order_service
env:
Expand All @@ -106,41 +87,47 @@ jobs:
POSTGRES_DB: orders
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
run: |
pytest tests --maxfail=1 --disable-warnings -q
run: pytest tests --maxfail=1 --disable-warnings -q

# 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
if: github.ref == 'refs/heads/main' # Only run on main branch

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

# 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)

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

# 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

# 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

# Logout from Azure for security (runs even if image push fails)
- name: Logout from Azure
run: az logout
if: always()
- 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: 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 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: Logout from Azure
run: az logout
if: always()

trigger_backend_cd:
needs: build_and_push_images
if: github.ref == 'refs/heads/main'
uses: ./.github/workflows/backend-cd.yml
with:
aks_cluster_name: "ishaanAKS"
aks_resource_group: "deakinuni"
aks_acr_name: "ishaan"
secrets:
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
#test
46 changes: 15 additions & 31 deletions .github/workflows/frontend-cd.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# week08/.github/workflows/frontend-cd.yml

name: CD - Deploy Frontend to AKS

# This workflow can be called by other workflows and takes inputs.
Expand All @@ -18,11 +16,11 @@ on:
aks_cluster_name:
description: 'Name of the AKS Cluster to deploy to'
required: true
default: '<aks_name>'
default: 'ishaanAKS'
aks_resource_group:
description: 'Resource Group of the AKS Cluster'
required: true
default: '<<resource_group_name>'
default: 'deakinuni'

workflow_call:
inputs:
Expand All @@ -38,6 +36,9 @@ on:
aks_resource_group:
required: true
type: string
secrets:
azure_credentials:
required: true # <-- must match CI usage

jobs:
deploy_frontend:
Expand All @@ -48,33 +49,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

# Azure login using a Service Principal secret
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

# Login to Azure Container Registry (ACR)
- name: Login to Azure Container Registry
run: az acr login --name ${{ secrets.AZURE_CONTAINER_REGISTRY }}

- name: Inject Backend IPs into Frontend main.js
run: |
echo "Injecting IPs into frontend/static/js/main.js"
# Ensure frontend/main.js is directly in the path for sed
sed -i "s|_PRODUCT_API_URL_|${{ inputs.product_api_ip }}|g" frontend/main.js
sed -i "s|_ORDER_API_URL_|${{ inputs.order_api_ip }}|g" frontend/main.js

# Display the modified file content for debugging
echo "--- Modified main.js content ---"
cat frontend/main.js
echo "---------------------------------"

# Build and Push Docker image for Frontend
- name: Build and Push Frontend Image
run: |
docker build -t ${{ secrets.AZURE_CONTAINER_REGISTRY }}/frontend:latest ./frontend/
docker push ${{ secrets.AZURE_CONTAINER_REGISTRY }}/frontend:latest
creds: ${{ secrets.azure_credentials }}

- name: Set Kubernetes context (get AKS credentials)
uses: azure/aks-set-context@v3
Expand All @@ -84,10 +62,16 @@ jobs:

- name: Deploy Frontend to AKS
run: |
echo "Deploying frontend with latest tag to AKS cluster: ${{ inputs.aks_cluster_name }}"
cd k8s/
# Ensure frontend-service.yaml is configured with your ACR
kubectl apply -f frontend.yaml

- name: Configure Frontend Deployment with Backend IPs
run: |
kubectl set env deployment/frontend \
PRODUCT_API_URL=http://${{ inputs.product_api_ip }}:80 \
ORDER_API_URL=http://${{ inputs.order_api_ip }}:80 \
--overwrite

- name: Logout from Azure (AKS deployment)
- name: Logout from Azure
run: az logout
#1
Loading