Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
081d583
Update secrets.yaml
Pasindufdo98 Sep 16, 2025
2969641
Update order-service.yaml
Pasindufdo98 Sep 16, 2025
ef297dc
Update product-service.yaml
Pasindufdo98 Sep 16, 2025
689b405
Update frontend.yaml
Pasindufdo98 Sep 16, 2025
917dde5
added a comment
Pasindufdo98 Sep 16, 2025
c8b5ce0
Merge branch 'main' of https://github.com/Pasindufdo98/week08
Pasindufdo98 Sep 16, 2025
4189707
added a comment to frontend
Pasindufdo98 Sep 16, 2025
ea470e4
changed to 9.2c
Pasindufdo98 Sep 26, 2025
869a91c
added changes to 9.2c
Pasindufdo98 Sep 26, 2025
f9e7d3c
Testing backend CI trigger
Pasindufdo98 Sep 26, 2025
2e6479f
updated code with image names
Pasindufdo98 Sep 27, 2025
0185519
Trying to trigger backend CI
Pasindufdo98 Sep 27, 2025
3aa28c3
fix logout
Pasindufdo98 Sep 27, 2025
24ccaac
Merge branch 'main' of https://github.com/Pasindufdo98/week08 into de…
Pasindufdo98 Sep 27, 2025
e52d241
fix logout
Pasindufdo98 Sep 27, 2025
94ba25f
test
Pasindufdo98 Sep 27, 2025
a2d923c
test
Pasindufdo98 Sep 27, 2025
c46c98c
test
Pasindufdo98 Sep 27, 2025
d39411e
test
Pasindufdo98 Sep 27, 2025
c2cb442
test
Pasindufdo98 Sep 27, 2025
494e74a
test123
Pasindufdo98 Sep 27, 2025
cf9cfc2
test1234
Pasindufdo98 Sep 27, 2025
47253ef
testing
Pasindufdo98 Sep 28, 2025
f2105a1
testing
Pasindufdo98 Sep 28, 2025
d539d4a
fix frontend issues
Pasindufdo98 Sep 28, 2025
a6236f5
fix frontend issues
Pasindufdo98 Sep 28, 2025
1734b00
fix frontend issues
Pasindufdo98 Sep 28, 2025
49db581
test the workflow
Pasindufdo98 Sep 28, 2025
a50fee8
fix secret access
Pasindufdo98 Sep 28, 2025
0f2f305
test again
Pasindufdo98 Sep 28, 2025
a3987e8
Test CI trigger via PR
Pasindufdo98 Sep 28, 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
56 changes: 27 additions & 29 deletions .github/workflows/backend-cd.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
name: CD - Deploy Backend Services 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_dispatch: # still allow manual runs
workflow_run: # auto-trigger after CI completes successfully
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

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

steps:
- name: Checkout repository
Expand All @@ -37,15 +29,20 @@ jobs:

- 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 ${{ secrets.AKS_RESOURCE_GROUP }} \
--name ${{ secrets.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 ${{ secrets.AKS_CLUSTER_NAME }} \
--resource-group ${{ secrets.AKS_RESOURCE_GROUP }} \
--attach-acr ${{ secrets.AZURE_CONTAINER_REGISTRY_NAME }}

- name: Deploy Backend Infrastructure (Namespace, ConfigMaps, Secrets, Databases)
- name: Deploy Backend Infrastructure
run: |
echo "Deploying backend infrastructure..."
cd k8s/
kubectl apply -f configmaps.yaml
kubectl apply -f secrets.yaml
Expand All @@ -64,38 +61,39 @@ jobs:
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
- name: Set Product IP Output
id: set_product_ip
run: echo "external_ip=${{ env.PRODUCT_IP }}" >> $GITHUB_OUTPUT

- name: Capture Order Service IP for Workflow Output
id: get_order_ip
- name: Set Order IP Output
id: set_order_ip
run: echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT

# Logout from Azure for security (runs even if image push fails)
- name: Logout from Azure
run: az logout
if: always()
20 changes: 16 additions & 4 deletions .github/workflows/backend_ci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
# week08/.github/workflows/backend_ci.yml
#this is for trigger the pipeline
#test the workflow 123
#test workflow


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
# 'pull_request:' to run on PRs
on:
# Manual trigger
workflow_dispatch:

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

pull_request:
branches:
- development
- main
paths:
- '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)
Expand Down Expand Up @@ -143,4 +155,4 @@ jobs:
# Logout from Azure for security (runs even if image push fails)
- name: Logout from Azure
run: az logout
if: always()
if: always()
75 changes: 24 additions & 51 deletions .github/workflows/frontend-cd.yml
Original file line number Diff line number Diff line change
@@ -1,93 +1,66 @@
# week08/.github/workflows/frontend-cd.yml

name: CD - Deploy Frontend to AKS

# This workflow can be called by other workflows and takes inputs.
# Or it can be run manually if you provide the IPs.
on:
# Allow manual trigger
workflow_dispatch:
inputs:
product_api_ip:
description: 'External IP of Product Service'
required: true
default: 'http://<ip_address>:8000'
order_api_ip:
description: 'External IP of Order Service (e.g., http://Y.Y.Y.Y:8001)'
required: true
default: 'http://<ip_address>:8001'
aks_cluster_name:
description: 'Name of the AKS Cluster to deploy to'
required: true
default: '<aks_name>'
aks_resource_group:
description: 'Resource Group of the AKS Cluster'
required: true
default: '<<resource_group_name>'

workflow_call:
inputs:
product_api_ip:
required: true
type: string
order_api_ip:
required: true
type: string
aks_cluster_name:
required: true
type: string
aks_resource_group:
required: true
type: string
# Automatically run after Frontend CI completes successfully
workflow_run:
workflows: ["CD - Deploy Backend Services to AKS"]
types:
- completed

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

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

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

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

# Inject Backend IPs into Frontend main.js
- 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 ---"
echo "Injecting Product and Order IPs..."
sed -i "s|_PRODUCT_API_URL_|${{ github.event.workflow_run.outputs.PRODUCT_API_IP }}|g" frontend/main.js
sed -i "s|_ORDER_API_URL_|${{ github.event.workflow_run.outputs.ORDER_API_IP }}|g" frontend/main.js
echo "--- Modified main.js ---"
cat frontend/main.js
echo "---------------------------------"
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

# Set Kubernetes context (from secrets instead of workflow inputs)
- name: Set Kubernetes context (get AKS credentials)
uses: azure/aks-set-context@v3
with:
resource-group: ${{ inputs.aks_resource_group }}
cluster-name: ${{ inputs.aks_cluster_name }}
run: |
az aks get-credentials \
--resource-group ${{ secrets.AKS_RESOURCE_GROUP }} \
--name ${{ secrets.AKS_CLUSTER_NAME }} \
--overwrite-existing

- 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: Logout from Azure (AKS deployment)
# Logout from Azure for security (runs even if image push fails)
- name: Logout from Azure
run: az logout
if: always()
53 changes: 18 additions & 35 deletions .github/workflows/frontend_ci.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,36 @@
# week08/.github/workflows/frontend_ci.yml

name: Frontend CI - Build & Push Image
#this is to trigger frontend pipeline
name: Frontend CI - Build Frontend Image

on:
# Manual trigger
workflow_dispatch:

# Automatically on pushes to main branch
# Automatically on pushes to development branch
push:
branches:
- main
paths: # Only trigger if changes are in the frontend directory
- development
paths:
- 'frontend/**'
- '.github/workflows/frontend_ci.yml' # Trigger if this workflow file changes
- '.github/workflows/frontend_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 }}
# Run on pull requests targeting development or main branch
pull_request:
branches:
- development
- main
paths:
- 'frontend/**'
- '.github/workflows/frontend_ci.yml'

jobs:
build_and_push_frontend:
build_frontend:
runs-on: ubuntu-latest

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

# 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 Frontend
- name: Build and Push Frontend Image
run: |
docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/
docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest

# Logout from Azure for security (runs even if image push fails)
- name: Logout from Azure
run: az logout
if: always()
# Build Docker image only (no push)
- name: Build Frontend Image (validation only)
run: docker build -t frontend-ci-test ./frontend/
1 change: 1 addition & 0 deletions frontend/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// week08/frontend/main.js
// this line to trigger frontend CI

document.addEventListener('DOMContentLoaded', () => {
// API endpoints for the Product and Order services.
Expand Down
2 changes: 1 addition & 1 deletion k8s/frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
spec:
containers:
- name: frontend-container
image: durgeshsamariya.azurecr.io/frontend:latest
image: pasindufernando9c.azurecr.io/frontend:latest
imagePullPolicy: Always
ports:
- containerPort: 80
Expand Down
2 changes: 1 addition & 1 deletion k8s/order-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
spec:
containers:
- name: order-service-container
image: durgeshsamariya.azurecr.io/order_service:latest
image: pasindufernando9c.azurecr.io/order_service:latest
imagePullPolicy: Always
ports:
- containerPort: 8000
Expand Down
2 changes: 1 addition & 1 deletion k8s/product-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
spec:
containers:
- name: product-service-container
image: durgeshsamariya.azurecr.io/product_service:latest
image: pasindufernando9c.azurecr.io/product_service:latest
imagePullPolicy: Always
ports:
- containerPort: 8000
Expand Down
4 changes: 2 additions & 2 deletions k8s/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ data:
# Azure Storage Account Credentials for Product Service image uploads
# REPLACE WITH YOUR ACTUAL BASE64 ENCODED VALUES from your Azure Storage Account
# Example: echo -n 'myblobstorageaccount' | base64
AZURE_STORAGE_ACCOUNT_NAME: "ZHVyZ2VzaHNhbWFyaXlh"
AZURE_STORAGE_ACCOUNT_NAME: "cGFzaW5kdWZlcm5hbmRvOWM="
# Example: echo -n 'your_storage_account_key_string' | base64
AZURE_STORAGE_ACCOUNT_KEY: "aEFNQ24rbkh2cmhwSGFEaW5jSnAxNFlHaU5nTnJja2NJR05Bc3Y5VXZPUlpsblJkbkVUR3drdTREdSszblBDR3E4ZEVTVjlFNE1jMytBU3RubmZ5QVE9PQ=="
AZURE_STORAGE_ACCOUNT_KEY: "L1RDWUt3VWIxM1N0TkVnelgrMFpVMkIxcStNMDVRNXN6YnRhU3VVMS9qTVVhbGtIam5uZ2Zwc01JdVpZdFEzUFYwazdNVHgzb21SNCtBU3RzQTBqTHc9PQ=="