From 62e94f1a140089dad8f4fcdc2db273377bfddb64 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 14:50:46 +0530 Subject: [PATCH 001/105] 'jk' --- .github/workflows/backend-cd.yml | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 6035ed15..6e8cd403 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -6,21 +6,21 @@ on: aks_cluster_name: description: 'Name of the AKS Cluster to deploy to' required: true - default: '' + default: 'MYAKSCLUSTER' aks_resource_group: description: 'Resource Group of the AKS Cluster' required: true - default: '' + default: 'deakinuni' aks_acr_name: description: 'Name of ACR' required: true - default: '' + default: 'week8' jobs: deploy_backend: 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 }} @@ -35,14 +35,16 @@ jobs: 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 - + # Attach ACR to the AKS cluster - 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 }} + # Get AKS credentials for kubectl context + - 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: Deploy Backend Infrastructure (Namespace, ConfigMaps, Secrets, Databases) run: | echo "Deploying backend infrastructure..." @@ -58,13 +60,13 @@ jobs: 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}') @@ -78,12 +80,12 @@ jobs: 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 @@ -92,7 +94,7 @@ jobs: - 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 From 5ba43640444b9af52bdc1180cf03d01b314c8d02 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 14:56:38 +0530 Subject: [PATCH 002/105] 'jk' --- .github/workflows/backend-cd.yml | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 6e8cd403..3bb291f8 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -20,7 +20,7 @@ jobs: deploy_backend: 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 }} @@ -35,16 +35,15 @@ jobs: creds: ${{ secrets.AZURE_CREDENTIALS }} enable-AzPSSession: true - # Attach ACR to the AKS cluster - - 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 }} - - # Get AKS credentials for kubectl context - 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 login + 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..." @@ -60,13 +59,13 @@ jobs: 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}') @@ -80,12 +79,12 @@ jobs: 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 @@ -94,7 +93,7 @@ jobs: - 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 From 2a7cfe119b460defa6d801d4e06db8666f2db98f Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 16:18:43 +0530 Subject: [PATCH 003/105] 'kl' --- k8s/frontend.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/frontend.yaml b/k8s/frontend.yaml index 1948536d..238d0ffd 100644 --- a/k8s/frontend.yaml +++ b/k8s/frontend.yaml @@ -18,7 +18,7 @@ spec: spec: containers: - name: frontend-container - image: durgeshsamariya.azurecr.io/frontend:latest + image: week8.azurecr.io/frontend:latest imagePullPolicy: Always ports: - containerPort: 80 From 54754e00dc37ceb74b97cf71c255987601ae88b5 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 16:19:34 +0530 Subject: [PATCH 004/105] 'kl' --- k8s/order-service.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/order-service.yaml b/k8s/order-service.yaml index c9d92e4d..9730130c 100644 --- a/k8s/order-service.yaml +++ b/k8s/order-service.yaml @@ -18,7 +18,7 @@ spec: spec: containers: - name: order-service-container - image: durgeshsamariya.azurecr.io/order_service:latest + image: week8.azurecr.io/order_service:latest imagePullPolicy: Always ports: - containerPort: 8000 From 3e65a7937cc3e9a4d84bd5fc89b3fc9a0e551d4f Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 16:21:38 +0530 Subject: [PATCH 005/105] 'kl' --- k8s/product-service.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/product-service.yaml b/k8s/product-service.yaml index 0cbbd505..f56b07fe 100644 --- a/k8s/product-service.yaml +++ b/k8s/product-service.yaml @@ -18,7 +18,7 @@ spec: spec: containers: - name: product-service-container - image: durgeshsamariya.azurecr.io/product_service:latest + image: week8.azurecr.io/product_service:latest imagePullPolicy: Always ports: - containerPort: 8000 From fb24f8b4e6924aa34f74035d115b3d8ca4534517 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 16:22:12 +0530 Subject: [PATCH 006/105] 'kl' --- k8s/secrets.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/k8s/secrets.yaml b/k8s/secrets.yaml index 5eebe1fa..e3bab4c2 100644 --- a/k8s/secrets.yaml +++ b/k8s/secrets.yaml @@ -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: "d2VlazA4" # Example: echo -n 'your_storage_account_key_string' | base64 - AZURE_STORAGE_ACCOUNT_KEY: "aEFNQ24rbkh2cmhwSGFEaW5jSnAxNFlHaU5nTnJja2NJR05Bc3Y5VXZPUlpsblJkbkVUR3drdTREdSszblBDR3E4ZEVTVjlFNE1jMytBU3RubmZ5QVE9PQ==" + AZURE_STORAGE_ACCOUNT_KEY: "b2VWTmZvNXJ1QXdKMFlMMDc2TEVZRjI5SXhhVzhhaS9OT215bkdvV3M1a2R2aENHTG9Sd3lEQyt4Nm9OWmZWTjdtZU9Ia1djTWkxbitBU3R3OXozdXc9PQ==" From addf4d42bb9180e37e6ff14c7faa508cd81b1974 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 17:01:40 +0530 Subject: [PATCH 007/105] 'kl' --- .github/workflows/frontend-cd.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml index 0a0879c8..11de8809 100644 --- a/.github/workflows/frontend-cd.yml +++ b/.github/workflows/frontend-cd.yml @@ -10,19 +10,19 @@ on: product_api_ip: description: 'External IP of Product Service' required: true - default: 'http://:8000' + default: 'http://4.254.68.20:8000' order_api_ip: description: 'External IP of Order Service (e.g., http://Y.Y.Y.Y:8001)' required: true - default: 'http://:8001' + default: 'http://20.227.92.216:8001' aks_cluster_name: description: 'Name of the AKS Cluster to deploy to' required: true - default: '' + default: 'MYAKSCLUSTER' aks_resource_group: description: 'Resource Group of the AKS Cluster' required: true - default: '<' + default: 'deakinuni' workflow_call: inputs: From b4c1d86b061e1f4b4de32f465541fc8d714069e9 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 20:17:03 +0530 Subject: [PATCH 008/105] Delete .github/workflows/backend_ci.yml --- .github/workflows/backend_ci.yml | 146 ------------------------------- 1 file changed, 146 deletions(-) delete mode 100644 .github/workflows/backend_ci.yml diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml deleted file mode 100644 index d69725aa..00000000 --- a/.github/workflows/backend_ci.yml +++ /dev/null @@ -1,146 +0,0 @@ -# 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 }} - -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 - - steps: - # 1. Checkout the repository code to the runner - - name: Checkout repository - uses: actions/checkout@v4 # Action to check out your repository code - - # 2. Set up Python environment - - name: Set up Python 3.10 - uses: actions/setup-python@v5 # Action to set up Python environment - 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 - 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: - 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 - - # 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 - - 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() From c9e703bd488c8306d80d44a572ccca8afaa4e573 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 20:17:15 +0530 Subject: [PATCH 009/105] Delete .github/workflows/frontend-cd.yml --- .github/workflows/frontend-cd.yml | 93 ------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 .github/workflows/frontend-cd.yml diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml deleted file mode 100644 index 11de8809..00000000 --- a/.github/workflows/frontend-cd.yml +++ /dev/null @@ -1,93 +0,0 @@ -# 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: - workflow_dispatch: - inputs: - product_api_ip: - description: 'External IP of Product Service' - required: true - default: 'http://4.254.68.20:8000' - order_api_ip: - description: 'External IP of Order Service (e.g., http://Y.Y.Y.Y:8001)' - required: true - default: 'http://20.227.92.216:8001' - aks_cluster_name: - description: 'Name of the AKS Cluster to deploy to' - required: true - default: 'MYAKSCLUSTER' - aks_resource_group: - description: 'Resource Group of the AKS Cluster' - required: true - default: 'deakinuni' - - 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 - -jobs: - deploy_frontend: - runs-on: ubuntu-latest - environment: Production - - 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 ${{ 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 - - - 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 }} - - - 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) - run: az logout From 6b23e8c6ac00f3f48a75cb56c4c35f5c6ca82b44 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 20:17:31 +0530 Subject: [PATCH 010/105] Delete .github/workflows/frontend_ci.yml --- .github/workflows/frontend_ci.yml | 53 ------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 .github/workflows/frontend_ci.yml diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml deleted file mode 100644 index 9f9e76d9..00000000 --- a/.github/workflows/frontend_ci.yml +++ /dev/null @@ -1,53 +0,0 @@ -# week08/.github/workflows/frontend_ci.yml - -name: Frontend CI - Build & Push Image - -on: - # Manual trigger - workflow_dispatch: - - # Automatically on pushes to main branch - push: - branches: - - main - paths: # Only trigger if changes are in the frontend directory - - 'frontend/**' - - '.github/workflows/frontend_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 }} - -jobs: - build_and_push_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() From 4743ffc1c3dcafe6cde896fd28bc3638ccd1d964 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 20:20:07 +0530 Subject: [PATCH 011/105] Create ci-cd.yml --- .github/workflows/ci-cd.yml | 131 ++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 .github/workflows/ci-cd.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 00000000..21500255 --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,131 @@ +name: Unified CI/CD Pipeline + +on: + push: + branches: + - main + - development + pull_request: + branches: + - main # Run tests on PRs targeting main + +env: + ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} + IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} + +jobs: + # Common setup job + setup: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Backend build & test + backend: + runs-on: ubuntu-latest + needs: setup + services: + postgres: + image: postgres:15 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: products + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Install dependencies + run: | + pip install --upgrade pip + for req in backend/*/requirements.txt; do + pip install -r "$req" + done + pip install pytest httpx + + - name: Run backend tests + run: | + pytest backend/product_service/tests --disable-warnings -q + pytest backend/order_service/tests --disable-warnings -q + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Build & Push Backend Images + run: | + 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 }} + 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 }} + + # Frontend build + frontend: + runs-on: ubuntu-latest + needs: setup + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Build & Push Frontend Image + run: | + docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:${{ env.IMAGE_TAG }} ./frontend/ + docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:${{ env.IMAGE_TAG }} + + # Deployment + deploy: + runs-on: ubuntu-latest + needs: [backend, frontend] + if: github.ref == 'refs/heads/main' # Only deploy from main + environment: Production + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Set Kubernetes context + run: | + 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 ${{ secrets.AKS_CLUSTER_NAME }} \ + --resource-group ${{ secrets.AKS_RESOURCE_GROUP }} \ + --attach-acr ${{ secrets.AZURE_CONTAINER_REGISTRY }} + + - name: Deploy all services + run: | + kubectl apply -f k8s/configmaps.yaml + kubectl apply -f k8s/secrets.yaml + kubectl apply -f k8s/product-db.yaml + kubectl apply -f k8s/order-db.yaml + kubectl apply -f k8s/product-service.yaml + kubectl apply -f k8s/order-service.yaml + kubectl apply -f k8s/frontend.yaml From 01e8a2143ff565b0bdae67ecb7a9c8d41cedb283 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 20:30:53 +0530 Subject: [PATCH 012/105] Update secrets.yaml --- k8s/secrets.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/secrets.yaml b/k8s/secrets.yaml index e3bab4c2..3665900e 100644 --- a/k8s/secrets.yaml +++ b/k8s/secrets.yaml @@ -15,4 +15,4 @@ data: # Example: echo -n 'myblobstorageaccount' | base64 AZURE_STORAGE_ACCOUNT_NAME: "d2VlazA4" # Example: echo -n 'your_storage_account_key_string' | base64 - AZURE_STORAGE_ACCOUNT_KEY: "b2VWTmZvNXJ1QXdKMFlMMDc2TEVZRjI5SXhhVzhhaS9OT215bkdvV3M1a2R2aENHTG9Sd3lEQyt4Nm9OWmZWTjdtZU9Ia1djTWkxbitBU3R3OXozdXc9PQ==" + AZURE_STORAGE_ACCOUNT_KEY: "bFZ4bW5panRoSGk4dTBZeUZxL3l6NjBQNmt2cDkxYmFvS3lHczlTdW54dVFNdE9sdXhNL2FkTmtMZG1nckNDUzBicHFBaDNUQkpxWStBU3R0Y25zekE9PQ==" From c51aba2f5aa47fb91633fc02c3728299951ee081 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 20:32:25 +0530 Subject: [PATCH 013/105] Update docker-compose.yml --- docker-compose.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ffe144c7..dd7d9b24 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -53,9 +53,9 @@ services: - "8000:8000" environment: POSTGRES_HOST: product_db # Connects to the 'product_db' service within Docker network - AZURE_STORAGE_ACCOUNT_NAME: # Replace with your Azure Storage account name - AZURE_STORAGE_ACCOUNT_KEY: # Replace with your Azure Storage account key - AZURE_STORAGE_CONTAINER_NAME: # Replace with your Azure Storage container name + AZURE_STORAGE_ACCOUNT_NAME: week08 # Replace with your Azure Storage account name + AZURE_STORAGE_ACCOUNT_KEY: lVxmnijthHi8u0YyFq/yz60P6kvp91baoKyGs9SunxuQMtOluxM/adNkLdmgrCCS0bpqAh3TBJqY+ASttcnszA== # Replace with your Azure Storage account key + AZURE_STORAGE_CONTAINER_NAME: pjctcont # Replace with your Azure Storage container name AZURE_SAS_TOKEN_EXPIRY_HOURS: 24 depends_on: product_db: From 44f98dc807bdf65d4f934c1af6a4e4f48c46bb9a Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 20:40:20 +0530 Subject: [PATCH 014/105] Update backend-cd.yml From 1559c4569d27841baae8c42949777f7beec97a5a Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 20:46:13 +0530 Subject: [PATCH 015/105] Update ci-cd.yml --- .github/workflows/ci-cd.yml | 122 ++++++++++++------------------------ 1 file changed, 40 insertions(+), 82 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 21500255..40e1c267 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -1,62 +1,58 @@ -name: Unified CI/CD Pipeline +name: CI/CD Pipeline - Build, Test, Push & Deploy on: push: branches: - main - - development pull_request: branches: - - main # Run tests on PRs targeting main + - main + workflow_dispatch: env: ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} - IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} jobs: - # Common setup job - setup: + build-test-push: runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - # Backend build & test - backend: - runs-on: ubuntu-latest - needs: setup services: postgres: image: postgres:15 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - POSTGRES_DB: products - options: >- - --health-cmd "pg_isready -U postgres" - --health-interval 10s - --health-timeout 5s - --health-retries 5 + POSTGRES_DB: orders ports: - 5432:5432 + options: >- + --health-cmd="pg_isready -U postgres -d orders" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + steps: - name: Checkout code uses: actions/checkout@v4 - - name: Set up Python 3.10 - uses: actions/setup-python@v5 + - name: Set up Python + uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: "3.10" - name: Install dependencies + run: pip install -r requirements.txt + + - name: Wait for Postgres run: | - pip install --upgrade pip - for req in backend/*/requirements.txt; do - pip install -r "$req" + until pg_isready -h localhost -U postgres -d orders; do + echo "Waiting for postgres..."; + sleep 2; done - pip install pytest httpx - - name: Run backend tests + - name: Run Backend Tests + env: + DATABASE_URL: postgresql://postgres:postgres@localhost:5432/orders run: | pytest backend/product_service/tests --disable-warnings -q pytest backend/order_service/tests --disable-warnings -q @@ -66,66 +62,28 @@ jobs: with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Build & Push Backend Images - run: | - 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 }} - 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 }} - - # Frontend build - frontend: - runs-on: ubuntu-latest - needs: setup - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Azure Login - uses: azure/login@v1 + - name: Docker login to ACR + uses: docker/login-action@v2 with: - creds: ${{ secrets.AZURE_CREDENTIALS }} + registry: ${{ env.ACR_LOGIN_SERVER }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} - - name: Build & Push Frontend Image + - name: Build and Push Backend Product Service Image run: | - docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:${{ env.IMAGE_TAG }} ./frontend/ - docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:${{ env.IMAGE_TAG }} - - # Deployment - deploy: - runs-on: ubuntu-latest - needs: [backend, frontend] - if: github.ref == 'refs/heads/main' # Only deploy from main - environment: Production - steps: - - name: Checkout repository - uses: actions/checkout@v4 + docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:${{ github.sha }} ./backend/product_service + docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:${{ github.sha }} - - name: Azure Login - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - - - name: Set Kubernetes context + - name: Build and Push Backend Order Service Image run: | - az aks get-credentials \ - --resource-group ${{ secrets.AKS_RESOURCE_GROUP }} \ - --name ${{ secrets.AKS_CLUSTER_NAME }} \ - --overwrite-existing + docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:${{ github.sha }} ./backend/order_service + docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:${{ github.sha }} - - name: Attach ACR + - name: Build and Push Frontend Image run: | - az aks update \ - --name ${{ secrets.AKS_CLUSTER_NAME }} \ - --resource-group ${{ secrets.AKS_RESOURCE_GROUP }} \ - --attach-acr ${{ secrets.AZURE_CONTAINER_REGISTRY }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:${{ github.sha }} ./frontend + docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:${{ github.sha }} - - name: Deploy all services - run: | - kubectl apply -f k8s/configmaps.yaml - kubectl apply -f k8s/secrets.yaml - kubectl apply -f k8s/product-db.yaml - kubectl apply -f k8s/order-db.yaml - kubectl apply -f k8s/product-service.yaml - kubectl apply -f k8s/order-service.yaml - kubectl apply -f k8s/frontend.yaml + - name: Logout from Azure + if: always() + run: az logout From b1d3b0cbbf967bc612d0e9659a4207d4a69e1ad1 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 20:50:49 +0530 Subject: [PATCH 016/105] Update ci-cd.yml --- .github/workflows/ci-cd.yml | 109 ++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 56 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 40e1c267..88be87de 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -1,89 +1,86 @@ -name: CI/CD Pipeline - Build, Test, Push & Deploy +name: CI/CD Pipeline on: push: branches: - main + - development pull_request: branches: - main - workflow_dispatch: - -env: - ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} + - development jobs: - build-test-push: + build-and-deploy: runs-on: ubuntu-latest - - services: - postgres: - image: postgres:15 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: orders - ports: - - 5432:5432 - options: >- - --health-cmd="pg_isready -U postgres -d orders" - --health-interval=10s - --health-timeout=5s - --health-retries=5 + env: + ACR_LOGIN_SERVER: ${{ secrets.ACR_LOGIN_SERVER }} + ACR_USERNAME: ${{ secrets.ACR_USERNAME }} + ACR_PASSWORD: ${{ secrets.ACR_PASSWORD }} steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v3 + # --- Python setup --- - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.10" - - - name: Install dependencies - run: pip install -r requirements.txt + python-version: '3.10' - - name: Wait for Postgres + # --- Install backend dependencies --- + - name: Install Python dependencies run: | - until pg_isready -h localhost -U postgres -d orders; do - echo "Waiting for postgres..."; - sleep 2; - done + pip install --upgrade pip + pip install -r backend/product_service/requirements.txt + pip install -r backend/order_service/requirements.txt + pip install pytest - - name: Run Backend Tests - env: - DATABASE_URL: postgresql://postgres:postgres@localhost:5432/orders + # --- Run backend tests --- + - name: Run backend tests run: | - pytest backend/product_service/tests --disable-warnings -q - pytest backend/order_service/tests --disable-warnings -q + pytest backend/product_service/tests + pytest backend/order_service/tests - - name: Azure Login - uses: azure/login@v1 + # --- Node setup (optional frontend) --- + - name: Set up Node + uses: actions/setup-node@v3 with: - creds: ${{ secrets.AZURE_CREDENTIALS }} + node-version: '18' - - name: Docker login to ACR - uses: docker/login-action@v2 + - name: Install frontend dependencies + run: | + if [ -f frontend/package.json ]; then + cd frontend + npm install + fi + + # --- Docker login to ACR --- + - name: Login to Azure Container Registry + uses: azure/docker-login@v1 with: - registry: ${{ env.ACR_LOGIN_SERVER }} - username: ${{ secrets.ACR_USERNAME }} - password: ${{ secrets.ACR_PASSWORD }} + login-server: ${{ env.ACR_LOGIN_SERVER }} + username: ${{ env.ACR_USERNAME }} + password: ${{ env.ACR_PASSWORD }} - - name: Build and Push Backend Product Service Image + # --- Build Docker images --- + - name: Build Docker images run: | - docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:${{ github.sha }} ./backend/product_service - docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:${{ github.sha }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:latest backend/product_service + docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:latest backend/order_service - - name: Build and Push Backend Order Service Image + # --- Push Docker images to ACR --- + - name: Push Docker images run: | - docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:${{ github.sha }} ./backend/order_service - docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:${{ github.sha }} + docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:latest + docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:latest - - name: Build and Push Frontend Image + # --- Optional: deploy to Azure --- + - name: Deploy to Azure (optional) run: | - docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:${{ github.sha }} ./frontend - docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:${{ github.sha }} + echo "Add your kubectl / azure deployment commands here" - - name: Logout from Azure - if: always() - run: az logout + # --- Logout from Azure --- + - name: Azure logout + run: | + az logout || echo "No active session to logout" From 3298531510778c5ebb9c5417ed5a7420d79d269a Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 21:13:32 +0530 Subject: [PATCH 017/105] Delete .github/workflows/ci-cd.yml --- .github/workflows/ci-cd.yml | 86 ------------------------------------- 1 file changed, 86 deletions(-) delete mode 100644 .github/workflows/ci-cd.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml deleted file mode 100644 index 88be87de..00000000 --- a/.github/workflows/ci-cd.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: CI/CD Pipeline - -on: - push: - branches: - - main - - development - pull_request: - branches: - - main - - development - -jobs: - build-and-deploy: - runs-on: ubuntu-latest - env: - ACR_LOGIN_SERVER: ${{ secrets.ACR_LOGIN_SERVER }} - ACR_USERNAME: ${{ secrets.ACR_USERNAME }} - ACR_PASSWORD: ${{ secrets.ACR_PASSWORD }} - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - # --- Python setup --- - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - # --- Install backend dependencies --- - - name: Install Python dependencies - run: | - pip install --upgrade pip - pip install -r backend/product_service/requirements.txt - pip install -r backend/order_service/requirements.txt - pip install pytest - - # --- Run backend tests --- - - name: Run backend tests - run: | - pytest backend/product_service/tests - pytest backend/order_service/tests - - # --- Node setup (optional frontend) --- - - name: Set up Node - uses: actions/setup-node@v3 - with: - node-version: '18' - - - name: Install frontend dependencies - run: | - if [ -f frontend/package.json ]; then - cd frontend - npm install - fi - - # --- Docker login to ACR --- - - name: Login to Azure Container Registry - uses: azure/docker-login@v1 - with: - login-server: ${{ env.ACR_LOGIN_SERVER }} - username: ${{ env.ACR_USERNAME }} - password: ${{ env.ACR_PASSWORD }} - - # --- Build Docker images --- - - name: Build Docker images - run: | - docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:latest backend/product_service - docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:latest backend/order_service - - # --- Push Docker images to ACR --- - - name: Push Docker images - run: | - docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:latest - docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:latest - - # --- Optional: deploy to Azure --- - - name: Deploy to Azure (optional) - run: | - echo "Add your kubectl / azure deployment commands here" - - # --- Logout from Azure --- - - name: Azure logout - run: | - az logout || echo "No active session to logout" From 217155e4a63832db9bade56623256bd52ef306d8 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 21:14:05 +0530 Subject: [PATCH 018/105] Create backend_ci.yml --- .github/workflows/backend_ci.yml | 146 +++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 .github/workflows/backend_ci.yml diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml new file mode 100644 index 00000000..d69725aa --- /dev/null +++ b/.github/workflows/backend_ci.yml @@ -0,0 +1,146 @@ +# 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 }} + +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 + + steps: + # 1. Checkout the repository code to the runner + - name: Checkout repository + uses: actions/checkout@v4 # Action to check out your repository code + + # 2. Set up Python environment + - name: Set up Python 3.10 + uses: actions/setup-python@v5 # Action to set up Python environment + 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 + 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: + 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 + + # 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 + + 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() From 7fca6c3914b2b7aca6f9fc94d689bf24278e4edb Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 21:15:20 +0530 Subject: [PATCH 019/105] Create frontend_ci.yml --- .github/workflows/frontend_ci.yml | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/frontend_ci.yml diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml new file mode 100644 index 00000000..9f9e76d9 --- /dev/null +++ b/.github/workflows/frontend_ci.yml @@ -0,0 +1,53 @@ +# week08/.github/workflows/frontend_ci.yml + +name: Frontend CI - Build & Push Image + +on: + # Manual trigger + workflow_dispatch: + + # Automatically on pushes to main branch + push: + branches: + - main + paths: # Only trigger if changes are in the frontend directory + - 'frontend/**' + - '.github/workflows/frontend_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 }} + +jobs: + build_and_push_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() From 1777a67481c83bf9026fea77e38962dc6203b67b Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 20 Sep 2025 21:15:43 +0530 Subject: [PATCH 020/105] Create frontend-cd.yml --- .github/workflows/frontend-cd.yml | 93 +++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .github/workflows/frontend-cd.yml diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml new file mode 100644 index 00000000..11de8809 --- /dev/null +++ b/.github/workflows/frontend-cd.yml @@ -0,0 +1,93 @@ +# 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: + workflow_dispatch: + inputs: + product_api_ip: + description: 'External IP of Product Service' + required: true + default: 'http://4.254.68.20:8000' + order_api_ip: + description: 'External IP of Order Service (e.g., http://Y.Y.Y.Y:8001)' + required: true + default: 'http://20.227.92.216:8001' + aks_cluster_name: + description: 'Name of the AKS Cluster to deploy to' + required: true + default: 'MYAKSCLUSTER' + aks_resource_group: + description: 'Resource Group of the AKS Cluster' + required: true + default: 'deakinuni' + + 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 + +jobs: + deploy_frontend: + runs-on: ubuntu-latest + environment: Production + + 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 ${{ 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 + + - 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 }} + + - 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) + run: az logout From 1f0bc11cacf4fd34cb118ff6757804b31e9c597e Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 06:31:18 +0530 Subject: [PATCH 021/105] Update backend-cd.yml --- .github/workflows/backend-cd.yml | 120 +++++++++++++++++++++---------- 1 file changed, 83 insertions(+), 37 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 3bb291f8..54936763 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -1,10 +1,10 @@ -name: CD - Deploy Backend Services to AKS +name: Unified CD - Deploy Backend & Frontend to AKS on: workflow_dispatch: inputs: aks_cluster_name: - description: 'Name of the AKS Cluster to deploy to' + description: 'Name of the AKS Cluster' required: true default: 'MYAKSCLUSTER' aks_resource_group: @@ -12,91 +12,137 @@ on: required: true default: 'deakinuni' aks_acr_name: - description: 'Name of ACR' + description: 'Azure Container Registry name' required: true default: 'week8' +env: + ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} + jobs: + # ---------------- BACKEND DEPLOYMENT ---------------- deploy_backend: 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 + - name: Checkout repo uses: actions/checkout@v4 - - name: Log in to Azure + - name: Azure Login uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - enable-AzPSSession: true - - name: Set Kubernetes context (get AKS credentials) + - name: Set AKS Context 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 ${{ github.event.inputs.aks_resource_group }} \ + --name ${{ github.event.inputs.aks_cluster_name }} \ + --overwrite-existing - name: Attach ACR run: | - az login - 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 ${{ 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) + - name: Deploy Backend Infra (ConfigMaps, Secrets, DBs) 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 - - name: Deploy Backend Microservices (Product, Order) + - name: Deploy Backend Services (Product, Order) 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..." + echo "Waiting for Product & Order LoadBalancer IPs..." + for i in {1..60}; do 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" + echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_ENV + echo "ORDER_IP=$ORDER_IP" >> $GITHUB_ENV break fi - sleep 5 # Wait 5 seconds before next attempt + sleep 5 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 + echo "❌ Failed to get backend IPs" + exit 1 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 + - name: Capture Product IP id: get_product_ip run: echo "external_ip=${{ env.PRODUCT_IP }}" >> $GITHUB_OUTPUT - - - name: Capture Order Service IP for Workflow Output + + - name: Capture Order IP id: get_order_ip run: echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT - - name: Logout from Azure + - name: Logout Azure + if: always() + run: az logout + + # ---------------- FRONTEND DEPLOYMENT ---------------- + deploy_frontend: + runs-on: ubuntu-latest + environment: Production + needs: deploy_backend + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: ACR Login + uses: docker/login-action@v2 + with: + registry: ${{ env.ACR_LOGIN_SERVER }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Inject Backend IPs into Frontend + run: | + echo "Injecting Backend IPs into frontend/main.js" + sed -i "s|_PRODUCT_API_URL_|http://${{ needs.deploy_backend.outputs.PRODUCT_API_IP }}:8000|g" frontend/main.js + sed -i "s|_ORDER_API_URL_|http://${{ needs.deploy_backend.outputs.ORDER_API_IP }}:8001|g" frontend/main.js + cat frontend/main.js + + - name: Build & Push Frontend Image + run: | + docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/ + docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest + + - name: Set AKS Context + uses: azure/aks-set-context@v3 + with: + resource-group: ${{ github.event.inputs.aks_resource_group }} + cluster-name: ${{ github.event.inputs.aks_cluster_name }} + + - name: Deploy Frontend + run: | + cd k8s/ + kubectl apply -f frontend.yaml + + - name: Logout Azure + if: always() run: az logout From 42ce283151eadc30cff437b73101f3408acac04b Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 06:31:56 +0530 Subject: [PATCH 022/105] Delete .github/workflows/frontend-cd.yml --- .github/workflows/frontend-cd.yml | 93 ------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 .github/workflows/frontend-cd.yml diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml deleted file mode 100644 index 11de8809..00000000 --- a/.github/workflows/frontend-cd.yml +++ /dev/null @@ -1,93 +0,0 @@ -# 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: - workflow_dispatch: - inputs: - product_api_ip: - description: 'External IP of Product Service' - required: true - default: 'http://4.254.68.20:8000' - order_api_ip: - description: 'External IP of Order Service (e.g., http://Y.Y.Y.Y:8001)' - required: true - default: 'http://20.227.92.216:8001' - aks_cluster_name: - description: 'Name of the AKS Cluster to deploy to' - required: true - default: 'MYAKSCLUSTER' - aks_resource_group: - description: 'Resource Group of the AKS Cluster' - required: true - default: 'deakinuni' - - 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 - -jobs: - deploy_frontend: - runs-on: ubuntu-latest - environment: Production - - 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 ${{ 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 - - - 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 }} - - - 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) - run: az logout From 590906cbc53215f2b88650b31f09eb534563afe0 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 06:32:26 +0530 Subject: [PATCH 023/105] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 134 +++++++++++++++---------------- 1 file changed, 64 insertions(+), 70 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index d69725aa..5c4ba275 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -1,44 +1,31 @@ -# week08/.github/workflows/backend_ci.yml +name: Unified CI - Backend & Frontend -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 + paths: - 'backend/**' - - '.github/workflows/backend_ci.yml' # Trigger if this workflow file changes + - 'frontend/**' + - '.github/workflows/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 - + # ---------------- BACKEND JOB ---------------- + backend: + runs-on: ubuntu-latest + if: contains(github.event.head_commit.message, 'backend') || contains(join(github.event.commits.*.modified, ''), 'backend/') 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 @@ -46,8 +33,6 @@ jobs: --health-retries 5 ports: - 5432:5432 - - # Order DB order_db: image: postgres:15 env: @@ -63,29 +48,22 @@ jobs: --health-retries 5 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: @@ -94,10 +72,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: @@ -106,41 +82,59 @@ jobs: POSTGRES_DB: orders POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres + run: pytest tests --maxfail=1 --disable-warnings -q + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Docker login + uses: docker/login-action@v2 + with: + registry: ${{ env.ACR_LOGIN_SERVER }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Build & Push Product Service + run: | + 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 }} + + - name: Build & Push Order Service run: | - pytest tests --maxfail=1 --disable-warnings -q + 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 }} - # Job 2: Build and Push Docker Images (runs only if tests pass) - build_and_push_images: + - name: Logout Azure + if: always() + run: az logout + + # ---------------- FRONTEND JOB ---------------- + frontend: runs-on: ubuntu-latest - needs: test_and_lint_backends + if: contains(github.event.head_commit.message, 'frontend') || contains(join(github.event.commits.*.modified, ''), 'frontend/') 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() + - uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Docker login + uses: docker/login-action@v2 + with: + registry: ${{ env.ACR_LOGIN_SERVER }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Build & Push Frontend + run: | + docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:${{ env.IMAGE_TAG }} ./frontend + docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:${{ env.IMAGE_TAG }} + + - name: Logout Azure + if: always() + run: az logout From 0a428600f7a87f34ab0db2bd5b6a0a76d7774c3f Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 06:32:47 +0530 Subject: [PATCH 024/105] Delete .github/workflows/frontend_ci.yml --- .github/workflows/frontend_ci.yml | 53 ------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 .github/workflows/frontend_ci.yml diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml deleted file mode 100644 index 9f9e76d9..00000000 --- a/.github/workflows/frontend_ci.yml +++ /dev/null @@ -1,53 +0,0 @@ -# week08/.github/workflows/frontend_ci.yml - -name: Frontend CI - Build & Push Image - -on: - # Manual trigger - workflow_dispatch: - - # Automatically on pushes to main branch - push: - branches: - - main - paths: # Only trigger if changes are in the frontend directory - - 'frontend/**' - - '.github/workflows/frontend_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 }} - -jobs: - build_and_push_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() From c9c1f0645d187782ee3bcf20a120306686d9fb97 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 06:33:27 +0530 Subject: [PATCH 025/105] Update backend-cd.yml --- .github/workflows/backend-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 54936763..0dd8447e 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -6,7 +6,7 @@ on: aks_cluster_name: description: 'Name of the AKS Cluster' required: true - default: 'MYAKSCLUSTER' + default: 'myAKSCluster' aks_resource_group: description: 'Resource Group of the AKS Cluster' required: true From 1ab5a66f7fcd0d5c3d66058b87b02190c09c4ca4 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 06:47:18 +0530 Subject: [PATCH 026/105] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 5c4ba275..f7fbc854 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -89,12 +89,8 @@ jobs: with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Docker login - uses: docker/login-action@v2 - with: - registry: ${{ env.ACR_LOGIN_SERVER }} - username: ${{ secrets.ACR_USERNAME }} - password: ${{ secrets.ACR_PASSWORD }} + - name: Login to Azure Container Registry + run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} - name: Build & Push Product Service run: | @@ -123,12 +119,8 @@ jobs: with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Docker login - uses: docker/login-action@v2 - with: - registry: ${{ env.ACR_LOGIN_SERVER }} - username: ${{ secrets.ACR_USERNAME }} - password: ${{ secrets.ACR_PASSWORD }} + - name: Login to Azure Container Registry + run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} - name: Build & Push Frontend run: | From b56394cba1acf26a888015ccf69a8610232a6f27 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 06:56:15 +0530 Subject: [PATCH 027/105] Rename backend-cd.yml to unified-cd.yml --- .github/workflows/{backend-cd.yml => unified-cd.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{backend-cd.yml => unified-cd.yml} (100%) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/unified-cd.yml similarity index 100% rename from .github/workflows/backend-cd.yml rename to .github/workflows/unified-cd.yml From f814ee635965a61e6c0db9f32844955a186ec193 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 06:56:48 +0530 Subject: [PATCH 028/105] Update unified-cd.yml --- .github/workflows/unified-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unified-cd.yml b/.github/workflows/unified-cd.yml index 0dd8447e..13bd8b70 100644 --- a/.github/workflows/unified-cd.yml +++ b/.github/workflows/unified-cd.yml @@ -20,7 +20,7 @@ env: ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} jobs: - # ---------------- BACKEND DEPLOYMENT ---------------- + deploy_backend: runs-on: ubuntu-latest environment: Production From c049e9a533bc174b81a6fa9d96e1718cce58a4e7 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 06:57:30 +0530 Subject: [PATCH 029/105] Rename backend_ci.yml to unified.yml --- .github/workflows/{backend_ci.yml => unified.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{backend_ci.yml => unified.yml} (100%) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/unified.yml similarity index 100% rename from .github/workflows/backend_ci.yml rename to .github/workflows/unified.yml From f3d2f322c7a57caf2cfb1959da42a49f6c9fadba Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 06:58:10 +0530 Subject: [PATCH 030/105] Rename unified.yml to unified-ci.yml --- .github/workflows/{unified.yml => unified-ci.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{unified.yml => unified-ci.yml} (100%) diff --git a/.github/workflows/unified.yml b/.github/workflows/unified-ci.yml similarity index 100% rename from .github/workflows/unified.yml rename to .github/workflows/unified-ci.yml From 173e72c7b413c2fea7f503572319c593d337e02e Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 07:10:33 +0530 Subject: [PATCH 031/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index f7fbc854..2393b477 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -4,12 +4,22 @@ on: workflow_dispatch: push: branches: + - development - main paths: - 'backend/**' - 'frontend/**' - '.github/workflows/ci.yml' + pull_request: + branches: + - main + - development + paths: + - 'backend/**' + - 'frontend/**' + - '.github/workflows/ci.yml' + env: ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} @@ -94,13 +104,15 @@ jobs: - name: Build & Push Product Service run: | - 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 }} + TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG ./backend/product_service + docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG - name: Build & Push Order Service run: | - 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 }} + TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG ./backend/order_service + docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG - name: Logout Azure if: always() @@ -124,8 +136,9 @@ jobs: - name: Build & Push Frontend run: | - docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:${{ env.IMAGE_TAG }} ./frontend - docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:${{ env.IMAGE_TAG }} + TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG ./frontend + docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG - name: Logout Azure if: always() From f30719bd7c9f05dfd440dcba9407ee9bb7ecc0bf Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 07:29:31 +0530 Subject: [PATCH 032/105] 'updated_unified-ci.yml' --- .github/workflows/unified-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 2393b477..ccf2b77f 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -25,7 +25,6 @@ env: IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} jobs: - # ---------------- BACKEND JOB ---------------- backend: runs-on: ubuntu-latest if: contains(github.event.head_commit.message, 'backend') || contains(join(github.event.commits.*.modified, ''), 'backend/') From 01c583558517cc50d025da4f5e202669f177982a Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 07:48:01 +0530 Subject: [PATCH 033/105] Updated unified-ci.yml --- .github/workflows/unified-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index ccf2b77f..0dc0fad7 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -5,7 +5,7 @@ on: push: branches: - development - - main + paths: - 'backend/**' - 'frontend/**' @@ -14,7 +14,7 @@ on: pull_request: branches: - main - - development + paths: - 'backend/**' - 'frontend/**' From 3efe3e143b9216d2e5e3eea64df7af8061f54cc0 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 07:56:47 +0530 Subject: [PATCH 034/105] updated unified-ci.yml --- .github/workflows/unified-ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 0dc0fad7..57ffa6bd 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -96,7 +96,10 @@ jobs: - name: Azure Login uses: azure/login@v1 with: - creds: ${{ secrets.AZURE_CREDENTIALS }} + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + client-secret: ${{secrets.AZURE_CLIENT_SECRET}} - name: Login to Azure Container Registry run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} From 8604cdc85a494c85e8ff604849d0151d69c1c80a Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 08:04:42 +0530 Subject: [PATCH 035/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 57ffa6bd..3d760980 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -145,3 +145,27 @@ jobs: - name: Logout Azure if: always() run: az logout + + integration-tests: + runs-on: ubuntu-latest + needs: [backend] + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Install dependencies + run: | + pip install --upgrade pip + for req in backend/*/requirements.txt; do + echo "Installing $req" + pip install -r "$req" + done + pip install pytest httpx + + - name: Run Integration Tests + run: | + pytest tests/integration/ From 6084a381dc92e58bc956a8c92506bbcac0b75e5f Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 08:08:49 +0530 Subject: [PATCH 036/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 3d760980..7f5fd62f 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -58,6 +58,14 @@ jobs: steps: - uses: actions/checkout@v4 + + - name: Cache Docker layers + uses: actions/cache@v4 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-docker-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-docker- - name: Set up Python 3.10 uses: actions/setup-python@v5 From d2e05430b9f3ef4373882af104ed356188fbc20d Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 08:11:17 +0530 Subject: [PATCH 037/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 7f5fd62f..d41323ef 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -104,10 +104,7 @@ jobs: - name: Azure Login uses: azure/login@v1 with: - client-id: ${{ secrets.AZURE_CLIENT_ID }} - tenant-id: ${{ secrets.AZURE_TENANT_ID }} - subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - client-secret: ${{secrets.AZURE_CLIENT_SECRET}} + creds: ${{ secrets.AZURE_CREDENTIALS }} - name: Login to Azure Container Registry run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} From 80851b8ee6ffcdf7db1352a4e3ddd2397f3f1f42 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 09:29:15 +0530 Subject: [PATCH 038/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index d41323ef..5f5e426d 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -27,7 +27,7 @@ env: jobs: backend: runs-on: ubuntu-latest - if: contains(github.event.head_commit.message, 'backend') || contains(join(github.event.commits.*.modified, ''), 'backend/') + if: github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, 'backend') || contains(join(github.event.commits.*.modified, ''), 'backend/') services: product_db: image: postgres:15 @@ -128,7 +128,7 @@ jobs: # ---------------- FRONTEND JOB ---------------- frontend: runs-on: ubuntu-latest - if: contains(github.event.head_commit.message, 'frontend') || contains(join(github.event.commits.*.modified, ''), 'frontend/') + if: github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, 'frontend') || contains(join(github.event.commits.*.modified, ''), 'frontend/') steps: - uses: actions/checkout@v4 From 483891767cffd9c64955a0b69769962d2a365a01 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 09:31:50 +0530 Subject: [PATCH 039/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 35 +++++++++----------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 5f5e426d..086e1872 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -5,16 +5,13 @@ on: push: branches: - development - paths: - 'backend/**' - 'frontend/**' - '.github/workflows/ci.yml' - pull_request: branches: - main - paths: - 'backend/**' - 'frontend/**' @@ -27,7 +24,10 @@ env: jobs: backend: runs-on: ubuntu-latest - if: github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, 'backend') || contains(join(github.event.commits.*.modified, ''), 'backend/') + if: | + github.event_name == 'workflow_dispatch' || + contains(github.event.head_commit.message, 'backend') || + contains(join(github.event.commits.*.modified, ''), 'backend/') services: product_db: image: postgres:15 @@ -58,7 +58,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Cache Docker layers uses: actions/cache@v4 with: @@ -66,12 +65,10 @@ jobs: key: ${{ runner.os }}-docker-${{ github.sha }} restore-keys: | ${{ runner.os }}-docker- - - name: Set up Python 3.10 uses: actions/setup-python@v5 with: python-version: '3.10' - - name: Install dependencies run: | pip install --upgrade pip @@ -80,7 +77,6 @@ jobs: pip install -r "$req" done pip install pytest httpx - - name: Run product_service tests working-directory: backend/product_service env: @@ -90,7 +86,6 @@ jobs: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres run: pytest tests --maxfail=1 --disable-warnings -q - - name: Run order_service tests working-directory: backend/order_service env: @@ -100,68 +95,59 @@ jobs: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres run: pytest tests --maxfail=1 --disable-warnings -q - - 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 & Push Product Service run: | TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG ./backend/product_service docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG - - name: Build & Push Order Service run: | TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG ./backend/order_service docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG - - name: Logout Azure if: always() run: az logout - # ---------------- FRONTEND JOB ---------------- frontend: runs-on: ubuntu-latest - if: github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, 'frontend') || contains(join(github.event.commits.*.modified, ''), 'frontend/') + if: | + github.event_name == 'workflow_dispatch' || + contains(github.event.head_commit.message, 'frontend') || + contains(join(github.event.commits.*.modified, ''), 'frontend/') steps: - 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 & Push Frontend run: | TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG ./frontend docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG - - name: Logout Azure if: always() run: az logout integration-tests: runs-on: ubuntu-latest - needs: [backend] + needs: [backend, frontend] # Added frontend as dependency steps: - uses: actions/checkout@v4 - - name: Set up Python 3.10 uses: actions/setup-python@v5 with: python-version: '3.10' - - name: Install dependencies run: | pip install --upgrade pip @@ -170,7 +156,6 @@ jobs: pip install -r "$req" done pip install pytest httpx - - name: Run Integration Tests run: | - pytest tests/integration/ + pytest tests/integration/ From e98962776a982f7a41f218c70fc2cc609572bcd9 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 22 Sep 2025 09:41:02 +0530 Subject: [PATCH 040/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 086e1872..69dd5382 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -156,6 +156,22 @@ jobs: pip install -r "$req" done pip install pytest httpx + - name: Create tests/integration directory if not exists + run: | + if [ ! -d "tests/integration" ]; then + echo "Creating tests/integration directory" + mkdir -p tests/integration + # You can add a placeholder test file if needed + echo "import pytest" > tests/integration/test_placeholder.py + echo "def test_placeholder():" >> tests/integration/test_placeholder.py + echo " assert True" >> tests/integration/test_placeholder.py + fi - name: Run Integration Tests run: | - pytest tests/integration/ + if [ -d "tests/integration" ]; then + echo "Running integration tests..." + pytest tests/integration/ --maxfail=1 --disable-warnings -q + else + echo "No integration tests found!" + exit 0 + fi From e5794dd8dc8a014f81e1cb4f5fa66932777fa7d6 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 12:27:55 +0530 Subject: [PATCH 041/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 252 ++++++++++++------------------- 1 file changed, 97 insertions(+), 155 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 69dd5382..ef6406b2 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -1,177 +1,119 @@ -name: Unified CI - Backend & Frontend +name: CI/CD Pipeline for SIT722 +# Trigger pipeline when code is pushed to `testing` branch on: - workflow_dispatch: push: branches: - - development - paths: - - 'backend/**' - - 'frontend/**' - - '.github/workflows/ci.yml' + - testing # Trigger pipeline on pushing to `testing` branch pull_request: branches: - - main - paths: - - 'backend/**' - - 'frontend/**' - - '.github/workflows/ci.yml' - -env: - ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} - IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} + - main # Trigger pipeline on pull request to `main` branch jobs: - backend: + # Stage 1: CI pipeline for testing, building, and pushing Docker images + ci-pipeline: runs-on: ubuntu-latest - if: | - github.event_name == 'workflow_dispatch' || - contains(github.event.head_commit.message, 'backend') || - contains(join(github.event.commits.*.modified, ''), 'backend/') - services: - product_db: - image: postgres:15 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: products - options: >- - --health-cmd "pg_isready -U postgres" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 5432:5432 - 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 steps: - - uses: actions/checkout@v4 - - name: Cache Docker layers - uses: actions/cache@v4 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-docker-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-docker- - - name: Set up Python 3.10 - uses: actions/setup-python@v5 - with: - python-version: '3.10' - - name: Install dependencies + - name: Checkout Repository + uses: actions/checkout@v2 + + # Set up Docker Buildx for building multi-platform images + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + # Set up Azure CLI to interact with Azure services + - name: Set up Azure CLI + uses: azure/setup-azure-cli@v1 + + # Log in to Azure and ACR using credentials stored in GitHub secrets + - name: Log in to Azure and ACR run: | - pip install --upgrade pip - for req in backend/*/requirements.txt; do - echo "Installing $req" - pip install -r "$req" - done - pip install pytest httpx - - 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 - - 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: 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 & Push Product Service + echo ${{ secrets.AZURE_CREDENTIALS }} | az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ secrets.AZURE_RESOURCE_GROUP }}" > azure_credentials.json + az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) + az acr login --name ${{ secrets.ACR_NAME }} + + # Build and push Docker images to ACR if tests pass + - name: Build Docker images and push to ACR run: | - TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} - docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG ./backend/product_service - docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG - - name: Build & Push Order Service + docker buildx build --file Dockerfile.product_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push . + docker buildx build --file Dockerfile.order_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push . + docker buildx build --file Dockerfile.frontend --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push . + + # Run tests for product service + - name: Run tests for Product Service run: | - TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} - docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG ./backend/order_service - docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG - - name: Logout Azure - if: always() - run: az logout - - frontend: + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest pytest --maxfail=5 --disable-warnings -q + + # Run tests for order service + - name: Run tests for Order Service + run: | + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest pytest --maxfail=5 --disable-warnings -q + + # Run tests for frontend service + - name: Run tests for Frontend Service + run: | + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q + + # If tests pass, proceed to deploy to staging environment + - name: Trigger Staging Deployment + if: success() + run: | + echo "Tests passed! Triggering staging deployment." + + # Stage 2: Staging Environment deployment and testing + staging-deployment: + needs: ci-pipeline runs-on: ubuntu-latest - if: | - github.event_name == 'workflow_dispatch' || - contains(github.event.head_commit.message, 'frontend') || - contains(join(github.event.commits.*.modified, ''), 'frontend/') + if: success() # Proceed only if the CI pipeline was successful steps: - - 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 & Push Frontend + # Log in to Azure and set up kubectl (Azure Kubernetes Service) + - name: Log in to Azure and AKS + uses: azure/setup-azure-cli@v1 run: | - TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} - docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG ./frontend - docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG - - name: Logout Azure - if: always() - run: az logout - - integration-tests: + echo ${{ secrets.AZURE_CREDENTIALS }} | az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ secrets.AZURE_RESOURCE_GROUP }}" > azure_credentials.json + az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) + az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} + + # Apply Kubernetes YAML files to deploy to staging environment + - name: Deploy to Staging Environment + run: | + kubectl apply -f k8s/ # Deploy services using the Kubernetes YAML files + + # Wait for the deployment to stabilize (optional: you could implement a health check here) + - name: Wait for Deployment + run: | + kubectl rollout status deployment/product-service-w08e1 + kubectl rollout status deployment/order-service-w08e1 + kubectl rollout status deployment/frontend + + # Perform manual acceptance tests (or automated tests) in the staging environment + - name: Run acceptance tests on Staging Environment + run: | + echo "Running acceptance tests on staging..." + + # Clean up staging environment after testing + - name: Clean up Staging Environment + run: | + kubectl delete -f k8s/ # Delete the staging environment after testing + + # Stage 3: Production Deployment after merging to `main` + production-deployment: + needs: staging-deployment runs-on: ubuntu-latest - needs: [backend, frontend] # Added frontend as dependency + if: github.ref == 'refs/heads/main' # Only run on merge to `main` branch + steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.10 - uses: actions/setup-python@v5 - with: - python-version: '3.10' - - name: Install dependencies - run: | - pip install --upgrade pip - for req in backend/*/requirements.txt; do - echo "Installing $req" - pip install -r "$req" - done - pip install pytest httpx - - name: Create tests/integration directory if not exists + # Log in to Azure and AKS + - name: Log in to Azure and AKS for Production + uses: azure/setup-azure-cli@v1 run: | - if [ ! -d "tests/integration" ]; then - echo "Creating tests/integration directory" - mkdir -p tests/integration - # You can add a placeholder test file if needed - echo "import pytest" > tests/integration/test_placeholder.py - echo "def test_placeholder():" >> tests/integration/test_placeholder.py - echo " assert True" >> tests/integration/test_placeholder.py - fi - - name: Run Integration Tests + echo ${{ secrets.AZURE_CREDENTIALS }} | az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ secrets.AZURE_RESOURCE_GROUP }}" > azure_credentials.json + az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) + az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} + + # Deploy to Production + - name: Deploy to Production Environment run: | - if [ -d "tests/integration" ]; then - echo "Running integration tests..." - pytest tests/integration/ --maxfail=1 --disable-warnings -q - else - echo "No integration tests found!" - exit 0 - fi + kubectl apply -f k8s/ # Apply Kubernetes YAML files to deploy to production From 7f41451355ffd64be3018f88da8a800c9fdad452 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 12:28:18 +0530 Subject: [PATCH 042/105] Delete .github/workflows/unified-cd.yml --- .github/workflows/unified-cd.yml | 148 ------------------------------- 1 file changed, 148 deletions(-) delete mode 100644 .github/workflows/unified-cd.yml diff --git a/.github/workflows/unified-cd.yml b/.github/workflows/unified-cd.yml deleted file mode 100644 index 13bd8b70..00000000 --- a/.github/workflows/unified-cd.yml +++ /dev/null @@ -1,148 +0,0 @@ -name: Unified CD - Deploy Backend & Frontend to AKS - -on: - workflow_dispatch: - inputs: - aks_cluster_name: - description: 'Name of the AKS Cluster' - required: true - default: 'myAKSCluster' - aks_resource_group: - description: 'Resource Group of the AKS Cluster' - required: true - default: 'deakinuni' - aks_acr_name: - description: 'Azure Container Registry name' - required: true - default: 'week8' - -env: - ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} - -jobs: - - deploy_backend: - 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 repo - uses: actions/checkout@v4 - - - name: Azure Login - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - - - name: Set AKS Context - 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 Infra (ConfigMaps, Secrets, DBs) - run: | - cd k8s/ - 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 Services (Product, Order) - run: | - 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..." - for i in {1..60}; do - 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 "Product Service IP: $PRODUCT_IP" - echo "Order Service IP: $ORDER_IP" - echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_ENV - echo "ORDER_IP=$ORDER_IP" >> $GITHUB_ENV - break - fi - sleep 5 - done - if [[ -z "$PRODUCT_IP" || -z "$ORDER_IP" ]]; then - echo "❌ Failed to get backend IPs" - exit 1 - fi - - - name: Capture Product IP - id: get_product_ip - run: echo "external_ip=${{ env.PRODUCT_IP }}" >> $GITHUB_OUTPUT - - - name: Capture Order IP - id: get_order_ip - run: echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT - - - name: Logout Azure - if: always() - run: az logout - - # ---------------- FRONTEND DEPLOYMENT ---------------- - deploy_frontend: - runs-on: ubuntu-latest - environment: Production - needs: deploy_backend - - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Azure Login - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - - - name: ACR Login - uses: docker/login-action@v2 - with: - registry: ${{ env.ACR_LOGIN_SERVER }} - username: ${{ secrets.ACR_USERNAME }} - password: ${{ secrets.ACR_PASSWORD }} - - - name: Inject Backend IPs into Frontend - run: | - echo "Injecting Backend IPs into frontend/main.js" - sed -i "s|_PRODUCT_API_URL_|http://${{ needs.deploy_backend.outputs.PRODUCT_API_IP }}:8000|g" frontend/main.js - sed -i "s|_ORDER_API_URL_|http://${{ needs.deploy_backend.outputs.ORDER_API_IP }}:8001|g" frontend/main.js - cat frontend/main.js - - - name: Build & Push Frontend Image - run: | - docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/ - docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest - - - name: Set AKS Context - uses: azure/aks-set-context@v3 - with: - resource-group: ${{ github.event.inputs.aks_resource_group }} - cluster-name: ${{ github.event.inputs.aks_cluster_name }} - - - name: Deploy Frontend - run: | - cd k8s/ - kubectl apply -f frontend.yaml - - - name: Logout Azure - if: always() - run: az logout From 1e403a6408b9c99b489b0de0fe6330b950c6c4ab Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 12:45:47 +0530 Subject: [PATCH 043/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index ef6406b2..5adcfe31 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -7,7 +7,8 @@ on: - testing # Trigger pipeline on pushing to `testing` branch pull_request: branches: - - main # Trigger pipeline on pull request to `main` branch + - main + workflow_dispatch: # Trigger pipeline on pull request to `main` branch jobs: # Stage 1: CI pipeline for testing, building, and pushing Docker images From d384e7d79072824d3eb07d3d39833db4146a3616 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 12:49:48 +0530 Subject: [PATCH 044/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 94 +++++++++++++++----------------- 1 file changed, 45 insertions(+), 49 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 5adcfe31..301a2756 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -1,17 +1,16 @@ name: CI/CD Pipeline for SIT722 -# Trigger pipeline when code is pushed to `testing` branch on: push: branches: - - testing # Trigger pipeline on pushing to `testing` branch + - testing pull_request: branches: - - main - workflow_dispatch: # Trigger pipeline on pull request to `main` branch + - main + workflow_dispatch: # Allows manual trigger from GitHub UI jobs: - # Stage 1: CI pipeline for testing, building, and pushing Docker images + # Stage 1: CI pipeline ci-pipeline: runs-on: ubuntu-latest @@ -19,102 +18,99 @@ jobs: - name: Checkout Repository uses: actions/checkout@v2 - # Set up Docker Buildx for building multi-platform images - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - # Set up Azure CLI to interact with Azure services - name: Set up Azure CLI uses: azure/setup-azure-cli@v1 - # Log in to Azure and ACR using credentials stored in GitHub secrets - name: Log in to Azure and ACR run: | - echo ${{ secrets.AZURE_CREDENTIALS }} | az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ secrets.AZURE_RESOURCE_GROUP }}" > azure_credentials.json - az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) az acr login --name ${{ secrets.ACR_NAME }} - # Build and push Docker images to ACR if tests pass - - name: Build Docker images and push to ACR + - name: Build and Push Docker Images to ACR run: | docker buildx build --file Dockerfile.product_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push . docker buildx build --file Dockerfile.order_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push . docker buildx build --file Dockerfile.frontend --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push . - # Run tests for product service - - name: Run tests for Product Service + - name: Run Tests for Product Service run: | docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest pytest --maxfail=5 --disable-warnings -q - # Run tests for order service - - name: Run tests for Order Service + - name: Run Tests for Order Service run: | docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest pytest --maxfail=5 --disable-warnings -q - # Run tests for frontend service - - name: Run tests for Frontend Service + - name: Run Tests for Frontend Service run: | docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q - # If tests pass, proceed to deploy to staging environment - - name: Trigger Staging Deployment - if: success() - run: | - echo "Tests passed! Triggering staging deployment." - - # Stage 2: Staging Environment deployment and testing + # Stage 2: Staging deployment staging-deployment: needs: ci-pipeline runs-on: ubuntu-latest - if: success() # Proceed only if the CI pipeline was successful + if: success() steps: - # Log in to Azure and set up kubectl (Azure Kubernetes Service) - - name: Log in to Azure and AKS + - name: Set up Azure CLI uses: azure/setup-azure-cli@v1 + + - name: Log in to Azure and Get AKS Credentials run: | - echo ${{ secrets.AZURE_CREDENTIALS }} | az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ secrets.AZURE_RESOURCE_GROUP }}" > azure_credentials.json - az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) - az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + az aks get-credentials \ + --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ + --name ${{ secrets.AKS_CLUSTER_NAME }} - # Apply Kubernetes YAML files to deploy to staging environment - name: Deploy to Staging Environment run: | - kubectl apply -f k8s/ # Deploy services using the Kubernetes YAML files + kubectl apply -f k8s/ - # Wait for the deployment to stabilize (optional: you could implement a health check here) - - name: Wait for Deployment + - name: Wait for Deployments to Stabilize run: | kubectl rollout status deployment/product-service-w08e1 kubectl rollout status deployment/order-service-w08e1 kubectl rollout status deployment/frontend - # Perform manual acceptance tests (or automated tests) in the staging environment - - name: Run acceptance tests on Staging Environment + - name: Run Acceptance Tests run: | echo "Running acceptance tests on staging..." - # Clean up staging environment after testing - - name: Clean up Staging Environment + - name: Clean Up Staging Environment run: | - kubectl delete -f k8s/ # Delete the staging environment after testing + kubectl delete -f k8s/ - # Stage 3: Production Deployment after merging to `main` + # Stage 3: Production deployment production-deployment: needs: staging-deployment runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' # Only run on merge to `main` branch + if: github.ref == 'refs/heads/main' steps: - # Log in to Azure and AKS - - name: Log in to Azure and AKS for Production + - name: Set up Azure CLI uses: azure/setup-azure-cli@v1 + + - name: Log in to Azure and Get AKS Credentials for Production run: | - echo ${{ secrets.AZURE_CREDENTIALS }} | az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ secrets.AZURE_RESOURCE_GROUP }}" > azure_credentials.json - az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) - az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + az aks get-credentials \ + --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ + --name ${{ secrets.AKS_CLUSTER_NAME }} - # Deploy to Production - name: Deploy to Production Environment run: | - kubectl apply -f k8s/ # Apply Kubernetes YAML files to deploy to production + kubectl apply -f k8s/ From b690948dd9c6266bf09a1764ad9d722dec0e220f Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 12:53:20 +0530 Subject: [PATCH 045/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 67 ++++++++++++++------------------ 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 301a2756..7bfb4d0d 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -3,14 +3,14 @@ name: CI/CD Pipeline for SIT722 on: push: branches: - - testing + - testing # Trigger on push to testing branch pull_request: branches: - main - workflow_dispatch: # Allows manual trigger from GitHub UI + workflow_dispatch: # Manual trigger option jobs: - # Stage 1: CI pipeline + # Stage 1: CI pipeline - build, test, and push Docker images ci-pipeline: runs-on: ubuntu-latest @@ -22,7 +22,7 @@ jobs: uses: docker/setup-buildx-action@v1 - name: Set up Azure CLI - uses: azure/setup-azure-cli@v1 + uses: azure/cli@v1 - name: Log in to Azure and ACR run: | @@ -33,25 +33,26 @@ jobs: --tenant $(jq -r .tenantId azure_credentials.json) az acr login --name ${{ secrets.ACR_NAME }} - - name: Build and Push Docker Images to ACR + - name: Build Docker images and push to ACR run: | docker buildx build --file Dockerfile.product_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push . docker buildx build --file Dockerfile.order_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push . docker buildx build --file Dockerfile.frontend --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push . - - name: Run Tests for Product Service - run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest pytest --maxfail=5 --disable-warnings -q + - name: Run tests for Product Service + run: docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest pytest --maxfail=5 --disable-warnings -q - - name: Run Tests for Order Service - run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest pytest --maxfail=5 --disable-warnings -q + - name: Run tests for Order Service + run: docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest pytest --maxfail=5 --disable-warnings -q - - name: Run Tests for Frontend Service - run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q + - name: Run tests for Frontend Service + run: docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q + + - name: Trigger Staging Deployment + if: success() + run: echo "Tests passed! Triggering staging deployment." - # Stage 2: Staging deployment + # Stage 2: Staging deployment and testing staging-deployment: needs: ci-pipeline runs-on: ubuntu-latest @@ -59,38 +60,33 @@ jobs: steps: - name: Set up Azure CLI - uses: azure/setup-azure-cli@v1 + uses: azure/cli@v1 - - name: Log in to Azure and Get AKS Credentials + - name: Log in to Azure and AKS run: | echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json az login --service-principal \ -u $(jq -r .clientId azure_credentials.json) \ -p $(jq -r .clientSecret azure_credentials.json) \ --tenant $(jq -r .tenantId azure_credentials.json) - az aks get-credentials \ - --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ - --name ${{ secrets.AKS_CLUSTER_NAME }} + az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - name: Deploy to Staging Environment - run: | - kubectl apply -f k8s/ + run: kubectl apply -f k8s/ - - name: Wait for Deployments to Stabilize + - name: Wait for Deployment rollout run: | kubectl rollout status deployment/product-service-w08e1 kubectl rollout status deployment/order-service-w08e1 kubectl rollout status deployment/frontend - - name: Run Acceptance Tests - run: | - echo "Running acceptance tests on staging..." + - name: Run acceptance tests on Staging Environment + run: echo "Running acceptance tests on staging..." - - name: Clean Up Staging Environment - run: | - kubectl delete -f k8s/ + - name: Clean up Staging Environment + run: kubectl delete -f k8s/ - # Stage 3: Production deployment + # Stage 3: Production Deployment on merge to main production-deployment: needs: staging-deployment runs-on: ubuntu-latest @@ -98,19 +94,16 @@ jobs: steps: - name: Set up Azure CLI - uses: azure/setup-azure-cli@v1 + uses: azure/cli@v1 - - name: Log in to Azure and Get AKS Credentials for Production + - name: Log in to Azure and AKS for Production run: | echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json az login --service-principal \ -u $(jq -r .clientId azure_credentials.json) \ -p $(jq -r .clientSecret azure_credentials.json) \ --tenant $(jq -r .tenantId azure_credentials.json) - az aks get-credentials \ - --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ - --name ${{ secrets.AKS_CLUSTER_NAME }} + az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - name: Deploy to Production Environment - run: | - kubectl apply -f k8s/ + run: kubectl apply -f k8s/ From d4948550084cacc06ce59cf70795ceb7f8279113 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 12:58:45 +0530 Subject: [PATCH 046/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 86 +++++++++++++++----------------- 1 file changed, 41 insertions(+), 45 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 7bfb4d0d..e4355227 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -3,14 +3,14 @@ name: CI/CD Pipeline for SIT722 on: push: branches: - - testing # Trigger on push to testing branch + - testing pull_request: branches: - main - workflow_dispatch: # Manual trigger option + workflow_dispatch: jobs: - # Stage 1: CI pipeline - build, test, and push Docker images + # Stage 1: CI pipeline ci-pipeline: runs-on: ubuntu-latest @@ -21,24 +21,26 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: Set up Azure CLI - uses: azure/cli@v1 - + # Log in to Azure and ACR using Azure CLI - name: Log in to Azure and ACR - run: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) - az acr login --name ${{ secrets.ACR_NAME }} - - - name: Build Docker images and push to ACR + uses: azure/cli@v1 + with: + inlineScript: | + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + az acr login --name ${{ secrets.ACR_NAME }} + + # Build and push Docker images + - name: Build and Push Docker Images run: | docker buildx build --file Dockerfile.product_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push . docker buildx build --file Dockerfile.order_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push . docker buildx build --file Dockerfile.frontend --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push . + # Run tests - name: Run tests for Product Service run: docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest pytest --maxfail=5 --disable-warnings -q @@ -48,62 +50,56 @@ jobs: - name: Run tests for Frontend Service run: docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q - - name: Trigger Staging Deployment - if: success() - run: echo "Tests passed! Triggering staging deployment." - - # Stage 2: Staging deployment and testing + # Stage 2: Staging Environment staging-deployment: needs: ci-pipeline runs-on: ubuntu-latest if: success() steps: - - name: Set up Azure CLI + - name: Login to Azure and AKS uses: azure/cli@v1 - - - name: Log in to Azure and AKS - run: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) - az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} + with: + inlineScript: | + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - name: Deploy to Staging Environment run: kubectl apply -f k8s/ - - name: Wait for Deployment rollout + - name: Wait for Deployment to Stabilize run: | kubectl rollout status deployment/product-service-w08e1 kubectl rollout status deployment/order-service-w08e1 kubectl rollout status deployment/frontend - - name: Run acceptance tests on Staging Environment + - name: Run Acceptance Tests on Staging run: echo "Running acceptance tests on staging..." - name: Clean up Staging Environment run: kubectl delete -f k8s/ - # Stage 3: Production Deployment on merge to main + # Stage 3: Production Deployment production-deployment: needs: staging-deployment runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' steps: - - name: Set up Azure CLI + - name: Login to Azure and AKS uses: azure/cli@v1 - - - name: Log in to Azure and AKS for Production - run: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) - az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - - - name: Deploy to Production Environment + with: + inlineScript: | + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} + + - name: Deploy to Production run: kubectl apply -f k8s/ From f777eb1ed0e382529716f81e88fdcfb04b0e7508 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 13:03:56 +0530 Subject: [PATCH 047/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 107 +++++++++++++++++-------------- 1 file changed, 59 insertions(+), 48 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index e4355227..fd9244e6 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -3,14 +3,14 @@ name: CI/CD Pipeline for SIT722 on: push: branches: - - testing + - testing # Trigger pipeline on pushing to `testing` branch pull_request: branches: - - main - workflow_dispatch: + - main # Trigger pipeline on pull requests to `main` branch + workflow_dispatch: # Manual trigger jobs: - # Stage 1: CI pipeline + # Stage 1: CI pipeline for testing, building, and pushing Docker images ci-pipeline: runs-on: ubuntu-latest @@ -21,57 +21,63 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - # Log in to Azure and ACR using Azure CLI + - name: Install jq + run: sudo apt-get update && sudo apt-get install -y jq + - name: Log in to Azure and ACR - uses: azure/cli@v1 - with: - inlineScript: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) - az acr login --name ${{ secrets.ACR_NAME }} - - # Build and push Docker images - - name: Build and Push Docker Images + run: | + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + az acr login --name ${{ secrets.ACR_NAME }} + + - name: Build Docker images and push to ACR run: | docker buildx build --file Dockerfile.product_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push . docker buildx build --file Dockerfile.order_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push . docker buildx build --file Dockerfile.frontend --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push . - # Run tests - name: Run tests for Product Service - run: docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest pytest --maxfail=5 --disable-warnings -q + run: | + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest pytest --maxfail=5 --disable-warnings -q - name: Run tests for Order Service - run: docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest pytest --maxfail=5 --disable-warnings -q + run: | + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest pytest --maxfail=5 --disable-warnings -q - name: Run tests for Frontend Service - run: docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q + run: | + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q - # Stage 2: Staging Environment + # Stage 2: Staging Deployment staging-deployment: needs: ci-pipeline runs-on: ubuntu-latest if: success() steps: - - name: Login to Azure and AKS - uses: azure/cli@v1 - with: - inlineScript: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) - az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Install jq + run: sudo apt-get update && sudo apt-get install -y jq + + - name: Log in to Azure and AKS + run: | + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - name: Deploy to Staging Environment - run: kubectl apply -f k8s/ + run: | + kubectl apply -f k8s/ - - name: Wait for Deployment to Stabilize + - name: Wait for Deployment to Complete run: | kubectl rollout status deployment/product-service-w08e1 kubectl rollout status deployment/order-service-w08e1 @@ -80,7 +86,7 @@ jobs: - name: Run Acceptance Tests on Staging run: echo "Running acceptance tests on staging..." - - name: Clean up Staging Environment + - name: Clean Up Staging Environment run: kubectl delete -f k8s/ # Stage 3: Production Deployment @@ -90,16 +96,21 @@ jobs: if: github.ref == 'refs/heads/main' steps: - - name: Login to Azure and AKS - uses: azure/cli@v1 - with: - inlineScript: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) - az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - - - name: Deploy to Production - run: kubectl apply -f k8s/ + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Install jq + run: sudo apt-get update && sudo apt-get install -y jq + + - name: Log in to Azure and AKS + run: | + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} + + - name: Deploy to Production Environment + run: | + kubectl apply -f k8s/ From 8333460c78c90bfc2d90661a6baff8dfb218525a Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 13:13:11 +0530 Subject: [PATCH 048/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 108 +++++++++++++++---------------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index fd9244e6..fd6183ea 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -3,14 +3,13 @@ name: CI/CD Pipeline for SIT722 on: push: branches: - - testing # Trigger pipeline on pushing to `testing` branch + - testing pull_request: branches: - - main # Trigger pipeline on pull requests to `main` branch - workflow_dispatch: # Manual trigger + - main + workflow_dispatch: jobs: - # Stage 1: CI pipeline for testing, building, and pushing Docker images ci-pipeline: runs-on: ubuntu-latest @@ -21,57 +20,59 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: Install jq - run: sudo apt-get update && sudo apt-get install -y jq - - name: Log in to Azure and ACR - run: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) - az acr login --name ${{ secrets.ACR_NAME }} + uses: azure/cli@v1 + with: + inlineScript: | + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + az acr login --name ${{ secrets.ACR_NAME }} - name: Build Docker images and push to ACR run: | - docker buildx build --file Dockerfile.product_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push . - docker buildx build --file Dockerfile.order_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push . - docker buildx build --file Dockerfile.frontend --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push . + docker buildx build --file week08/backend/product_service/Dockerfile \ + --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push week08/backend/product_service + + docker buildx build --file week08/backend/order_service/Dockerfile \ + --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push week08/backend/order_service + + docker buildx build --file week08/frontend/Dockerfile \ + --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push week08/frontend - name: Run tests for Product Service run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest pytest --maxfail=5 --disable-warnings -q + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest \ + pytest --maxfail=5 --disable-warnings -q - name: Run tests for Order Service run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest pytest --maxfail=5 --disable-warnings -q + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest \ + pytest --maxfail=5 --disable-warnings -q - name: Run tests for Frontend Service run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest \ + pytest --maxfail=5 --disable-warnings -q - # Stage 2: Staging Deployment staging-deployment: needs: ci-pipeline runs-on: ubuntu-latest if: success() steps: - - name: Checkout Repository - uses: actions/checkout@v2 - - - name: Install jq - run: sudo apt-get update && sudo apt-get install -y jq - - - name: Log in to Azure and AKS - run: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) - az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} + - name: Login to Azure and AKS + uses: azure/cli@v1 + with: + inlineScript: | + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - name: Deploy to Staging Environment run: | @@ -83,34 +84,31 @@ jobs: kubectl rollout status deployment/order-service-w08e1 kubectl rollout status deployment/frontend - - name: Run Acceptance Tests on Staging - run: echo "Running acceptance tests on staging..." + - name: Run Acceptance Tests + run: | + echo "Running staging acceptance tests..." - - name: Clean Up Staging Environment - run: kubectl delete -f k8s/ + - name: Clean up Staging + run: | + kubectl delete -f k8s/ - # Stage 3: Production Deployment production-deployment: needs: staging-deployment runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' steps: - - name: Checkout Repository - uses: actions/checkout@v2 - - - name: Install jq - run: sudo apt-get update && sudo apt-get install -y jq - - - name: Log in to Azure and AKS - run: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) - az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} + - name: Login to Azure and AKS for Production + uses: azure/cli@v1 + with: + inlineScript: | + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - name: Deploy to Production Environment run: | - kubectl apply -f k8s/ + kubectl apply -f k8s/. From 3eecc4eb385c3db92d8486337339ca9f389ba979 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 13:16:18 +0530 Subject: [PATCH 049/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 97 ++++++++++++++++---------------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index fd6183ea..bed91cfb 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -20,42 +20,42 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: Log in to Azure and ACR - uses: azure/cli@v1 - with: - inlineScript: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) - az acr login --name ${{ secrets.ACR_NAME }} + - name: Azure Login and ACR Login + run: | + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + + az acr login --name ${{ secrets.ACR_NAME }} - name: Build Docker images and push to ACR run: | docker buildx build --file week08/backend/product_service/Dockerfile \ - --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push week08/backend/product_service + --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest \ + --push week08/backend/product_service docker buildx build --file week08/backend/order_service/Dockerfile \ - --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push week08/backend/order_service + --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest \ + --push week08/backend/order_service docker buildx build --file week08/frontend/Dockerfile \ - --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push week08/frontend + --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest \ + --push week08/frontend - name: Run tests for Product Service run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest \ - pytest --maxfail=5 --disable-warnings -q + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest pytest --maxfail=5 --disable-warnings -q - name: Run tests for Order Service run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest \ - pytest --maxfail=5 --disable-warnings -q + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest pytest --maxfail=5 --disable-warnings -q - name: Run tests for Frontend Service run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest \ - pytest --maxfail=5 --disable-warnings -q + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q staging-deployment: needs: ci-pipeline @@ -63,34 +63,33 @@ jobs: if: success() steps: - - name: Login to Azure and AKS - uses: azure/cli@v1 - with: - inlineScript: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) - az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - - - name: Deploy to Staging Environment + - name: Azure Login and AKS Credentials + run: | + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + + az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ + --name ${{ secrets.AKS_CLUSTER_NAME }} + + - name: Deploy to Staging run: | kubectl apply -f k8s/ - - name: Wait for Deployment to Complete + - name: Wait for Deployments run: | kubectl rollout status deployment/product-service-w08e1 kubectl rollout status deployment/order-service-w08e1 kubectl rollout status deployment/frontend - name: Run Acceptance Tests - run: | - echo "Running staging acceptance tests..." + run: echo "Running staging tests..." - name: Clean up Staging - run: | - kubectl delete -f k8s/ + run: kubectl delete -f k8s/ production-deployment: needs: staging-deployment @@ -98,17 +97,17 @@ jobs: if: github.ref == 'refs/heads/main' steps: - - name: Login to Azure and AKS for Production - uses: azure/cli@v1 - with: - inlineScript: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) - az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - - - name: Deploy to Production Environment + - name: Azure Login and AKS Credentials run: | - kubectl apply -f k8s/. + echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + + az login --service-principal \ + -u $(jq -r .clientId azure_credentials.json) \ + -p $(jq -r .clientSecret azure_credentials.json) \ + --tenant $(jq -r .tenantId azure_credentials.json) + + az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ + --name ${{ secrets.AKS_CLUSTER_NAME }} + + - name: Deploy to Production + run: kubectl apply -f k8s/ From 2491c39ddc7ef7c800beb95e19b2be6507fd4175 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 13:20:55 +0530 Subject: [PATCH 050/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index bed91cfb..65120d9e 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -33,17 +33,17 @@ jobs: - name: Build Docker images and push to ACR run: | - docker buildx build --file week08/backend/product_service/Dockerfile \ + docker buildx build --file week8/backend/product_service/Dockerfile \ --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest \ - --push week08/backend/product_service + --push week8/backend/product_service - docker buildx build --file week08/backend/order_service/Dockerfile \ + docker buildx build --file week8/backend/order_service/Dockerfile \ --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest \ - --push week08/backend/order_service + --push week8/backend/order_service - docker buildx build --file week08/frontend/Dockerfile \ + docker buildx build --file week8/frontend/Dockerfile \ --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest \ - --push week08/frontend + --push week8/frontend - name: Run tests for Product Service run: | @@ -81,8 +81,8 @@ jobs: - name: Wait for Deployments run: | - kubectl rollout status deployment/product-service-w08e1 - kubectl rollout status deployment/order-service-w08e1 + kubectl rollout status deployment/product-service-w8e1 + kubectl rollout status deployment/order-service-w8e1 kubectl rollout status deployment/frontend - name: Run Acceptance Tests From 63e297ddb1f7e72c83140dfbdc8059eaad4e54bb Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 13:25:12 +0530 Subject: [PATCH 051/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 311 ++++++++++++++++++++++++------- 1 file changed, 244 insertions(+), 67 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 65120d9e..322083b7 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -1,113 +1,290 @@ -name: CI/CD Pipeline for SIT722 +name: Unified CI - Backend & Frontend on: + workflow_dispatch: push: branches: - - testing + - development + - main + paths: + - 'backend/**' + - 'frontend/**' + - '.github/workflows/ci.yml' pull_request: branches: - main - workflow_dispatch: + - development + paths: + - 'backend/**' + - 'frontend/**' + - '.github/workflows/ci.yml' + +env: + ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} + IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} jobs: - ci-pipeline: + backend: runs-on: ubuntu-latest + if: contains(github.event.head_commit.message, 'backend') || contains(join(github.event.commits.*.modified, ''), 'backend/') + services: + product_db: + image: postgres:15 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: products + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + 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 steps: - - name: Checkout Repository - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: '3.10' - - name: Azure Login and ACR Login + - name: Install dependencies run: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + pip install --upgrade pip + for req in backend/*/requirements.txt; do + echo "Installing $req" + pip install -r "$req" + done + pip install pytest httpx - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) + - 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 - az acr login --name ${{ secrets.ACR_NAME }} + - 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: Build Docker images and push to ACR - run: | - docker buildx build --file week8/backend/product_service/Dockerfile \ - --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest \ - --push week8/backend/product_service + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} - docker buildx build --file week8/backend/order_service/Dockerfile \ - --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest \ - --push week8/backend/order_service + - name: Login to Azure Container Registry + run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} - docker buildx build --file week8/frontend/Dockerfile \ - --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest \ - --push week8/frontend - - - name: Run tests for Product Service + - name: Build & Push Product Service run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest pytest --maxfail=5 --disable-warnings -q + TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG ./backend/product_service + docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG - - name: Run tests for Order Service + - name: Build & Push Order Service run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest pytest --maxfail=5 --disable-warnings -q + TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG ./backend/order_service + docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG + + - name: Logout Azure + if: always() + run: az logout + + frontend: + runs-on: ubuntu-latest + if: contains(github.event.head_commit.message, 'frontend') || contains(join(github.event.commits.*.modified, ''), 'frontend/') - - name: Run tests for Frontend Service + steps: + - 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 & Push Frontend run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q + TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG ./frontend + docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG + + - name: Logout Azure + if: always() + run: az logout - staging-deployment: - needs: ci-pipeline + +# ---- Deployment Workflow ---- + +name: Unified CD - Deploy Backend & Frontend to AKS + +on: + workflow_dispatch: + inputs: + aks_cluster_name: + description: 'Name of the AKS Cluster' + required: true + default: 'myAKSCluster' + aks_resource_group: + description: 'Resource Group of the AKS Cluster' + required: true + default: 'deakinuni' + aks_acr_name: + description: 'Azure Container Registry name' + required: true + default: 'week8' + +env: + ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} + +jobs: + + deploy_backend: runs-on: ubuntu-latest - if: success() + 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: Azure Login and AKS Credentials + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Set AKS Context run: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + az aks get-credentials \ + --resource-group ${{ github.event.inputs.aks_resource_group }} \ + --name ${{ github.event.inputs.aks_cluster_name }} \ + --overwrite-existing - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) + - name: Attach ACR to AKS + 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 get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ - --name ${{ secrets.AKS_CLUSTER_NAME }} + - name: Deploy Backend Infra (ConfigMaps, Secrets, DBs) + run: | + kubectl apply -f k8s/configmaps.yaml + kubectl apply -f k8s/secrets.yaml + kubectl apply -f k8s/product-db.yaml + kubectl apply -f k8s/order-db.yaml - - name: Deploy to Staging + - name: Deploy Backend Services (Product, Order) run: | - kubectl apply -f k8s/ + kubectl apply -f k8s/product-service.yaml + kubectl apply -f k8s/order-service.yaml - - name: Wait for Deployments + - name: Wait for Backend LoadBalancer IPs run: | - kubectl rollout status deployment/product-service-w8e1 - kubectl rollout status deployment/order-service-w8e1 - kubectl rollout status deployment/frontend + echo "Waiting for Product & Order LoadBalancer IPs..." + for i in {1..60}; do + PRODUCT_IP=$(kubectl get svc product-service-w08e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + ORDER_IP=$(kubectl get svc order-service-w08e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + if [[ -n "$PRODUCT_IP" && -n "$ORDER_IP" ]]; then + echo "Product Service IP: $PRODUCT_IP" + echo "Order Service IP: $ORDER_IP" + echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_ENV + echo "ORDER_IP=$ORDER_IP" >> $GITHUB_ENV + break + fi + sleep 5 + done + if [[ -z "$PRODUCT_IP" || -z "$ORDER_IP" ]]; then + echo "❌ Failed to get backend IPs" + exit 1 + fi + + - name: Capture Product IP + id: get_product_ip + run: echo "external_ip=${{ env.PRODUCT_IP }}" >> $GITHUB_OUTPUT - - name: Run Acceptance Tests - run: echo "Running staging tests..." + - name: Capture Order IP + id: get_order_ip + run: echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT - - name: Clean up Staging - run: kubectl delete -f k8s/ + - name: Logout Azure + if: always() + run: az logout - production-deployment: - needs: staging-deployment + deploy_frontend: runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' + environment: Production + needs: deploy_backend steps: - - name: Azure Login and AKS Credentials + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: ACR Login + uses: docker/login-action@v2 + with: + registry: ${{ env.ACR_LOGIN_SERVER }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Inject Backend IPs into Frontend + run: | + echo "Injecting Backend IPs into frontend/main.js" + sed -i "s|_PRODUCT_API_URL_|http://${{ needs.deploy_backend.outputs.PRODUCT_API_IP }}:8000|g" frontend/main.js + sed -i "s|_ORDER_API_URL_|http://${{ needs.deploy_backend.outputs.ORDER_API_IP }}:8001|g" frontend/main.js + cat frontend/main.js + + - name: Build & Push Frontend Image run: | - echo '${{ secrets.AZURE_CREDENTIALS }}' > azure_credentials.json + docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend + docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest - az login --service-principal \ - -u $(jq -r .clientId azure_credentials.json) \ - -p $(jq -r .clientSecret azure_credentials.json) \ - --tenant $(jq -r .tenantId azure_credentials.json) + - name: Set AKS Context + uses: azure/aks-set-context@v3 + with: + resource-group: ${{ github.event.inputs.aks_resource_group }} + cluster-name: ${{ github.event.inputs.aks_cluster_name }} - az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ - --name ${{ secrets.AKS_CLUSTER_NAME }} + - name: Deploy Frontend + run: | + kubectl apply -f k8s/frontend.yaml - - name: Deploy to Production - run: kubectl apply -f k8s/ + - name: Logout Azure + if: always() + run: az logout From f8bd48e3e87f8958065665c66bc68c297bbab4cd Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 13:27:13 +0530 Subject: [PATCH 052/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 322083b7..f7230076 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -152,7 +152,7 @@ on: aks_cluster_name: description: 'Name of the AKS Cluster' required: true - default: 'myAKSCluster' + default: 'MyAKSCluster' aks_resource_group: description: 'Resource Group of the AKS Cluster' required: true From 027214d3347502a87190eea1ac7aed60713fb21e Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 13:31:01 +0530 Subject: [PATCH 053/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 287 ++++++------------------------- 1 file changed, 52 insertions(+), 235 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index f7230076..5917c5dd 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -1,290 +1,107 @@ -name: Unified CI - Backend & Frontend +name: CI/CD Pipeline for SIT722 on: - workflow_dispatch: push: branches: - - development - - main - paths: - - 'backend/**' - - 'frontend/**' - - '.github/workflows/ci.yml' + - testing pull_request: branches: - main - - development - paths: - - 'backend/**' - - 'frontend/**' - - '.github/workflows/ci.yml' - -env: - ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} - IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} jobs: - backend: + ci-pipeline: runs-on: ubuntu-latest - if: contains(github.event.head_commit.message, 'backend') || contains(join(github.event.commits.*.modified, ''), 'backend/') - services: - product_db: - image: postgres:15 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: products - options: >- - --health-cmd "pg_isready -U postgres" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 5432:5432 - 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 steps: - - uses: actions/checkout@v4 - - - name: Set up Python 3.10 - uses: actions/setup-python@v5 - with: - python-version: '3.10' - - - name: Install dependencies - run: | - pip install --upgrade pip - for req in backend/*/requirements.txt; do - echo "Installing $req" - pip install -r "$req" - done - pip install pytest httpx + - name: Checkout Repository + uses: actions/checkout@v3 - - 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 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 - - 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: Azure Login + - name: Log in to Azure CLI 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 & Push Product Service + - name: Log in to Azure Container Registry run: | - TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} - docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG ./backend/product_service - docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG + az acr login --name ${{ secrets.ACR_NAME }} - - name: Build & Push Order Service + - name: Build and push Product Service Docker image run: | - TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} - docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG ./backend/order_service - docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG - - - name: Logout Azure - if: always() - run: az logout - - frontend: - runs-on: ubuntu-latest - if: contains(github.event.head_commit.message, 'frontend') || contains(join(github.event.commits.*.modified, ''), 'frontend/') + docker buildx build --file Dockerfile.product_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push . - steps: - - 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 & Push Frontend + - name: Build and push Order Service Docker image run: | - TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} - docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG ./frontend - docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG - - - name: Logout Azure - if: always() - run: az logout - - -# ---- Deployment Workflow ---- + docker buildx build --file Dockerfile.order_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push . -name: Unified CD - Deploy Backend & Frontend to AKS + - name: Build and push Frontend Docker image + run: | + docker buildx build --file Dockerfile.frontend --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push . -on: - workflow_dispatch: - inputs: - aks_cluster_name: - description: 'Name of the AKS Cluster' - required: true - default: 'MyAKSCluster' - aks_resource_group: - description: 'Resource Group of the AKS Cluster' - required: true - default: 'deakinuni' - aks_acr_name: - description: 'Azure Container Registry name' - required: true - default: 'week8' + - name: Run tests for Product Service + run: | + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest pytest --maxfail=5 --disable-warnings -q -env: - ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} + - name: Run tests for Order Service + run: | + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest pytest --maxfail=5 --disable-warnings -q -jobs: + - name: Run tests for Frontend Service + run: | + docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q - deploy_backend: + staging-deployment: + needs: ci-pipeline 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 }} + if: success() steps: - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Azure Login + - name: Log in to Azure CLI uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Set AKS Context + - name: 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.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - - name: Attach ACR to AKS + - name: Deploy to Staging Environment 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 }} + kubectl apply -f k8s/ - - name: Deploy Backend Infra (ConfigMaps, Secrets, DBs) + - name: Wait for Deployments to Stabilize run: | - kubectl apply -f k8s/configmaps.yaml - kubectl apply -f k8s/secrets.yaml - kubectl apply -f k8s/product-db.yaml - kubectl apply -f k8s/order-db.yaml + kubectl rollout status deployment/product-service-w08e1 + kubectl rollout status deployment/order-service-w08e1 + kubectl rollout status deployment/frontend - - name: Deploy Backend Services (Product, Order) + - name: Run acceptance tests on Staging Environment run: | - kubectl apply -f k8s/product-service.yaml - kubectl apply -f k8s/order-service.yaml - - - name: Wait for Backend LoadBalancer IPs - run: | - echo "Waiting for Product & Order LoadBalancer IPs..." - for i in {1..60}; do - PRODUCT_IP=$(kubectl get svc product-service-w08e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}') - ORDER_IP=$(kubectl get svc order-service-w08e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}') - if [[ -n "$PRODUCT_IP" && -n "$ORDER_IP" ]]; then - echo "Product Service IP: $PRODUCT_IP" - echo "Order Service IP: $ORDER_IP" - echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_ENV - echo "ORDER_IP=$ORDER_IP" >> $GITHUB_ENV - break - fi - sleep 5 - done - if [[ -z "$PRODUCT_IP" || -z "$ORDER_IP" ]]; then - echo "❌ Failed to get backend IPs" - exit 1 - fi - - - name: Capture Product IP - id: get_product_ip - run: echo "external_ip=${{ env.PRODUCT_IP }}" >> $GITHUB_OUTPUT + echo "Running acceptance tests on staging..." + # Add your actual acceptance test commands here - - name: Capture Order IP - id: get_order_ip - run: echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT - - - name: Logout Azure + - name: Clean up Staging Environment if: always() - run: az logout + run: | + kubectl delete -f k8s/ - deploy_frontend: + production-deployment: + needs: staging-deployment runs-on: ubuntu-latest - environment: Production - needs: deploy_backend + if: github.ref == 'refs/heads/main' steps: - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Azure Login + - name: Log in to Azure CLI uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: ACR Login - uses: docker/login-action@v2 - with: - registry: ${{ env.ACR_LOGIN_SERVER }} - username: ${{ secrets.ACR_USERNAME }} - password: ${{ secrets.ACR_PASSWORD }} - - - name: Inject Backend IPs into Frontend + - name: Get AKS credentials run: | - echo "Injecting Backend IPs into frontend/main.js" - sed -i "s|_PRODUCT_API_URL_|http://${{ needs.deploy_backend.outputs.PRODUCT_API_IP }}:8000|g" frontend/main.js - sed -i "s|_ORDER_API_URL_|http://${{ needs.deploy_backend.outputs.ORDER_API_IP }}:8001|g" frontend/main.js - cat frontend/main.js + az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - - name: Build & Push Frontend Image + - name: Deploy to Production Environment run: | - docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend - docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest - - - name: Set AKS Context - uses: azure/aks-set-context@v3 - with: - resource-group: ${{ github.event.inputs.aks_resource_group }} - cluster-name: ${{ github.event.inputs.aks_cluster_name }} - - - name: Deploy Frontend - run: | - kubectl apply -f k8s/frontend.yaml - - - name: Logout Azure - if: always() - run: az logout + kubectl apply -f k8s/ From 475f958f7611526d0413631fff79c9b428466eba Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 13:33:19 +0530 Subject: [PATCH 054/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 5917c5dd..81fe4d74 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -7,6 +7,7 @@ on: pull_request: branches: - main + workflow_dispatch: # <-- Manual trigger added here jobs: ci-pipeline: From b01704d94a5f9bdd8c70aeeed079cfa3ab79e1b6 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 13:37:53 +0530 Subject: [PATCH 055/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 70 +++++++++++++------------------- 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 81fe4d74..3c5b028c 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -7,7 +7,7 @@ on: pull_request: branches: - main - workflow_dispatch: # <-- Manual trigger added here + workflow_dispatch: # manual trigger jobs: ci-pipeline: @@ -15,31 +15,25 @@ jobs: steps: - name: Checkout Repository - uses: actions/checkout@v3 + uses: actions/checkout@v2 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v1 - - name: Log in to Azure CLI - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} + - name: Set up Azure CLI + uses: azure/setup-azure-cli@v1 - - name: Log in to Azure Container Registry + - name: Log in to Azure and ACR run: | + echo ${{ secrets.AZURE_CREDENTIALS }} | az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ secrets.AZURE_RESOURCE_GROUP }}" > azure_credentials.json + az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) az acr login --name ${{ secrets.ACR_NAME }} - - name: Build and push Product Service Docker image + - name: Build Docker images and push to ACR run: | - docker buildx build --file Dockerfile.product_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push . - - - name: Build and push Order Service Docker image - run: | - docker buildx build --file Dockerfile.order_service --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push . - - - name: Build and push Frontend Docker image - run: | - docker buildx build --file Dockerfile.frontend --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push . + docker buildx build --file backend/product_service/Dockerfile --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push backend/product_service + docker buildx build --file backend/order_service/Dockerfile --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push backend/order_service + docker buildx build --file frontend/Dockerfile --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push frontend - name: Run tests for Product Service run: | @@ -53,40 +47,37 @@ jobs: run: | docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q + - name: Trigger Staging Deployment + if: success() + run: echo "Tests passed! Triggering staging deployment." + staging-deployment: needs: ci-pipeline runs-on: ubuntu-latest if: success() steps: - - name: Log in to Azure CLI - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - - - name: Get AKS credentials + - name: Log in to Azure and AKS + uses: azure/setup-azure-cli@v1 run: | + echo ${{ secrets.AZURE_CREDENTIALS }} | az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ secrets.AZURE_RESOURCE_GROUP }}" > azure_credentials.json + az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - name: Deploy to Staging Environment - run: | - kubectl apply -f k8s/ + run: kubectl apply -f k8s/ - - name: Wait for Deployments to Stabilize + - name: Wait for Deployment run: | kubectl rollout status deployment/product-service-w08e1 kubectl rollout status deployment/order-service-w08e1 kubectl rollout status deployment/frontend - name: Run acceptance tests on Staging Environment - run: | - echo "Running acceptance tests on staging..." - # Add your actual acceptance test commands here + run: echo "Running acceptance tests on staging..." - name: Clean up Staging Environment - if: always() - run: | - kubectl delete -f k8s/ + run: kubectl delete -f k8s/ production-deployment: needs: staging-deployment @@ -94,15 +85,12 @@ jobs: if: github.ref == 'refs/heads/main' steps: - - name: Log in to Azure CLI - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - - - name: Get AKS credentials + - name: Log in to Azure and AKS for Production + uses: azure/setup-azure-cli@v1 run: | + echo ${{ secrets.AZURE_CREDENTIALS }} | az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ secrets.AZURE_RESOURCE_GROUP }}" > azure_credentials.json + az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - name: Deploy to Production Environment - run: | - kubectl apply -f k8s/ + run: kubectl apply -f k8s/ From 00f23c8646bead219ef90af1d214f528eac7b7c7 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 13:41:08 +0530 Subject: [PATCH 056/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 58 +++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 3c5b028c..8f37cfb6 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -1,5 +1,6 @@ name: CI/CD Pipeline for SIT722 +# Trigger pipeline on push to testing branch, PR to main, or manual trigger on: push: branches: @@ -7,9 +8,10 @@ on: pull_request: branches: - main - workflow_dispatch: # manual trigger + workflow_dispatch: # Manual trigger jobs: + # Stage 1: CI pipeline - Build, test, and push images ci-pipeline: runs-on: ubuntu-latest @@ -23,16 +25,22 @@ jobs: - name: Set up Azure CLI uses: azure/setup-azure-cli@v1 - - name: Log in to Azure and ACR + - name: Azure Login run: | - echo ${{ secrets.AZURE_CREDENTIALS }} | az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ secrets.AZURE_RESOURCE_GROUP }}" > azure_credentials.json + echo "${{ secrets.AZURE_CREDENTIALS }}" > azure_credentials.json az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) az acr login --name ${{ secrets.ACR_NAME }} - - name: Build Docker images and push to ACR + - name: Build and push product_service image run: | docker buildx build --file backend/product_service/Dockerfile --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push backend/product_service + + - name: Build and push order_service image + run: | docker buildx build --file backend/order_service/Dockerfile --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push backend/order_service + + - name: Build and push frontend image + run: | docker buildx build --file frontend/Dockerfile --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push frontend - name: Run tests for Product Service @@ -47,50 +55,70 @@ jobs: run: | docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q - - name: Trigger Staging Deployment - if: success() - run: echo "Tests passed! Triggering staging deployment." + - name: Logout Azure + if: always() + run: az logout + # Stage 2: Deploy to Staging environment staging-deployment: needs: ci-pipeline runs-on: ubuntu-latest if: success() steps: - - name: Log in to Azure and AKS + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Set up Azure CLI uses: azure/setup-azure-cli@v1 + + - name: Azure Login and AKS Credentials Setup run: | - echo ${{ secrets.AZURE_CREDENTIALS }} | az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ secrets.AZURE_RESOURCE_GROUP }}" > azure_credentials.json + echo "${{ secrets.AZURE_CREDENTIALS }}" > azure_credentials.json az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - name: Deploy to Staging Environment run: kubectl apply -f k8s/ - - name: Wait for Deployment + - name: Wait for Deployments to Complete run: | kubectl rollout status deployment/product-service-w08e1 kubectl rollout status deployment/order-service-w08e1 kubectl rollout status deployment/frontend - - name: Run acceptance tests on Staging Environment - run: echo "Running acceptance tests on staging..." + - name: Run acceptance tests on staging + run: echo "Add your acceptance tests here" - - name: Clean up Staging Environment + - name: Cleanup staging environment run: kubectl delete -f k8s/ + - name: Logout Azure + if: always() + run: az logout + + # Stage 3: Production Deployment on main branch merges production-deployment: needs: staging-deployment runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' steps: - - name: Log in to Azure and AKS for Production + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Set up Azure CLI uses: azure/setup-azure-cli@v1 + + - name: Azure Login and AKS Credentials Setup for Production run: | - echo ${{ secrets.AZURE_CREDENTIALS }} | az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ secrets.AZURE_RESOURCE_GROUP }}" > azure_credentials.json + echo "${{ secrets.AZURE_CREDENTIALS }}" > azure_credentials.json az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - name: Deploy to Production Environment run: kubectl apply -f k8s/ + + - name: Logout Azure + if: always() + run: az logout From ec6cd5643583bd53c610b4fb0ecc95900d43f8de Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 13:43:17 +0530 Subject: [PATCH 057/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 39 ++++++++++++++------------------ 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 8f37cfb6..fb6cea8a 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -1,6 +1,5 @@ name: CI/CD Pipeline for SIT722 -# Trigger pipeline on push to testing branch, PR to main, or manual trigger on: push: branches: @@ -8,10 +7,9 @@ on: pull_request: branches: - main - workflow_dispatch: # Manual trigger + workflow_dispatch: jobs: - # Stage 1: CI pipeline - Build, test, and push images ci-pipeline: runs-on: ubuntu-latest @@ -22,14 +20,13 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: Set up Azure CLI - uses: azure/setup-azure-cli@v1 + - name: Login to Azure + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Azure Login - run: | - echo "${{ secrets.AZURE_CREDENTIALS }}" > azure_credentials.json - az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) - az acr login --name ${{ secrets.ACR_NAME }} + - name: Login to Azure Container Registry + run: az acr login --name ${{ secrets.ACR_NAME }} - name: Build and push product_service image run: | @@ -59,7 +56,6 @@ jobs: if: always() run: az logout - # Stage 2: Deploy to Staging environment staging-deployment: needs: ci-pipeline runs-on: ubuntu-latest @@ -69,13 +65,13 @@ jobs: - name: Checkout repo uses: actions/checkout@v2 - - name: Set up Azure CLI - uses: azure/setup-azure-cli@v1 + - name: Login to Azure + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Azure Login and AKS Credentials Setup + - name: Set AKS context run: | - echo "${{ secrets.AZURE_CREDENTIALS }}" > azure_credentials.json - az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - name: Deploy to Staging Environment @@ -97,7 +93,6 @@ jobs: if: always() run: az logout - # Stage 3: Production Deployment on main branch merges production-deployment: needs: staging-deployment runs-on: ubuntu-latest @@ -107,13 +102,13 @@ jobs: - name: Checkout repo uses: actions/checkout@v2 - - name: Set up Azure CLI - uses: azure/setup-azure-cli@v1 + - name: Login to Azure + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Azure Login and AKS Credentials Setup for Production + - name: Set AKS context run: | - echo "${{ secrets.AZURE_CREDENTIALS }}" > azure_credentials.json - az login --service-principal -u $(jq -r .appId azure_credentials.json) -p $(jq -r .password azure_credentials.json) --tenant $(jq -r .tenant azure_credentials.json) az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - name: Deploy to Production Environment From 848eb2aa10a27d835c55bde54a0e71605a874bb7 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 14:07:05 +0530 Subject: [PATCH 058/105] Update Dockerfile --- backend/order_service/Dockerfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/order_service/Dockerfile b/backend/order_service/Dockerfile index c961f84f..7f9e3a6e 100644 --- a/backend/order_service/Dockerfile +++ b/backend/order_service/Dockerfile @@ -1,16 +1,17 @@ -# week08/backend/order_service/Dockerfile - FROM python:3.10-slim-buster WORKDIR /code +# Copy and install dependencies COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt + pip install --no-cache-dir -r requirements.txt && \ + pip install --no-cache-dir pytest +# Copy application code COPY app /code/app EXPOSE 8000 -CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] From adce01789f36b7f21d5b7d3b3af0ef018a95db24 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 14:07:48 +0530 Subject: [PATCH 059/105] Update Dockerfile --- backend/product_service/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/product_service/Dockerfile b/backend/product_service/Dockerfile index 9dfdd3f9..76947d89 100644 --- a/backend/product_service/Dockerfile +++ b/backend/product_service/Dockerfile @@ -7,7 +7,8 @@ WORKDIR /code COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt + pip install --no-cache-dir -r requirements.txt \ + pip install --no-cache-dir pytest COPY app /code/app From 0cfa29200dee2bc87162f4eb6ce45989ce838df6 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Mon, 29 Sep 2025 14:22:19 +0530 Subject: [PATCH 060/105] Create Dockerfile.test --- frontend/Dockerfile.test | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 frontend/Dockerfile.test diff --git a/frontend/Dockerfile.test b/frontend/Dockerfile.test new file mode 100644 index 00000000..5f3d5f42 --- /dev/null +++ b/frontend/Dockerfile.test @@ -0,0 +1,13 @@ +# week08/frontend/Dockerfile.test + +FROM node:18 + +WORKDIR /app + +COPY package*.json ./ +RUN npm install + +COPY . . + +# Run tests (e.g., Jest or whatever you're using) +CMD ["npm", "test"] From 7a6dbc03527cd6e532ef7c567af30e99c7867e45 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 10:58:08 +0530 Subject: [PATCH 061/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index fb6cea8a..17a10d0e 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -54,7 +54,12 @@ jobs: - name: Logout Azure if: always() - run: az logout + run: | + if az account show > /dev/null 2>&1; then + az logout + else + echo "No active Azure session to log out from" + fi staging-deployment: needs: ci-pipeline @@ -91,7 +96,12 @@ jobs: - name: Logout Azure if: always() - run: az logout + run: | + if az account show > /dev/null 2>&1; then + az logout + else + echo "No active Azure session to log out from" + fi production-deployment: needs: staging-deployment @@ -116,4 +126,9 @@ jobs: - name: Logout Azure if: always() - run: az logout + run: | + if az account show > /dev/null 2>&1; then + az logout + else + echo "No active Azure session to log out from" + fi From 251d4bc3d3ff2fbde27cf7e260713285291d37af Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 11:11:40 +0530 Subject: [PATCH 062/105] Update Dockerfile --- backend/order_service/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/order_service/Dockerfile b/backend/order_service/Dockerfile index 7f9e3a6e..9a4cd090 100644 --- a/backend/order_service/Dockerfile +++ b/backend/order_service/Dockerfile @@ -6,8 +6,7 @@ WORKDIR /code COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt && \ - pip install --no-cache-dir pytest + pip install --no-cache-dir -r requirements.txt # Copy application code COPY app /code/app From 45ac5e0a42357c1d66658c54e2f6c506e4c4e067 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 11:12:21 +0530 Subject: [PATCH 063/105] Update Dockerfile --- backend/product_service/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/product_service/Dockerfile b/backend/product_service/Dockerfile index 76947d89..c0907258 100644 --- a/backend/product_service/Dockerfile +++ b/backend/product_service/Dockerfile @@ -7,7 +7,7 @@ WORKDIR /code COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt \ + pip install --no-cache-dir -r requirements.txt && \ pip install --no-cache-dir pytest COPY app /code/app From 047ccc28169427c3863e6b58b8dd1b805a5eff7c Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 11:12:49 +0530 Subject: [PATCH 064/105] Update Dockerfile --- backend/order_service/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/order_service/Dockerfile b/backend/order_service/Dockerfile index 9a4cd090..7f9e3a6e 100644 --- a/backend/order_service/Dockerfile +++ b/backend/order_service/Dockerfile @@ -6,7 +6,8 @@ WORKDIR /code COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt + pip install --no-cache-dir -r requirements.txt && \ + pip install --no-cache-dir pytest # Copy application code COPY app /code/app From 9f2caff3139f5d681ea8cea21d534329c4a9bda9 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 11:16:41 +0530 Subject: [PATCH 065/105] Update Dockerfile --- backend/product_service/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/product_service/Dockerfile b/backend/product_service/Dockerfile index c0907258..7e349801 100644 --- a/backend/product_service/Dockerfile +++ b/backend/product_service/Dockerfile @@ -7,8 +7,7 @@ WORKDIR /code COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt && \ - pip install --no-cache-dir pytest + pip install --no-cache-dir -r requirements.txt COPY app /code/app From cee0b0b0c02cb054cf0609bb1716067ce6d8e122 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 11:17:00 +0530 Subject: [PATCH 066/105] Update Dockerfile --- backend/order_service/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/order_service/Dockerfile b/backend/order_service/Dockerfile index 7f9e3a6e..5837cfcb 100644 --- a/backend/order_service/Dockerfile +++ b/backend/order_service/Dockerfile @@ -6,8 +6,7 @@ WORKDIR /code COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt && \ - pip install --no-cache-dir pytest + pip install --no-cache-dir -r requirements.txt # Copy application code COPY app /code/app From c93568b1d76b9bb737f8fdfe82d055244f3b3755 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 11:24:21 +0530 Subject: [PATCH 067/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 34 +++++++++++++------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 17a10d0e..4ff99bab 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -28,38 +28,42 @@ jobs: - name: Login to Azure Container Registry run: az acr login --name ${{ secrets.ACR_NAME }} + # Build and push product_service image - name: Build and push product_service image run: | docker buildx build --file backend/product_service/Dockerfile --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push backend/product_service + # Build and push order_service image - name: Build and push order_service image run: | docker buildx build --file backend/order_service/Dockerfile --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push backend/order_service + # Build and push frontend image - name: Build and push frontend image run: | docker buildx build --file frontend/Dockerfile --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push frontend + # Run tests for Product Service - name: Run tests for Product Service run: | docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest pytest --maxfail=5 --disable-warnings -q + continue-on-error: false + # Run tests for Order Service - name: Run tests for Order Service run: | docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest pytest --maxfail=5 --disable-warnings -q + continue-on-error: false + # Run tests for Frontend Service - name: Run tests for Frontend Service run: | docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q + continue-on-error: false - name: Logout Azure if: always() - run: | - if az account show > /dev/null 2>&1; then - az logout - else - echo "No active Azure session to log out from" - fi + run: az logout staging-deployment: needs: ci-pipeline @@ -84,8 +88,8 @@ jobs: - name: Wait for Deployments to Complete run: | - kubectl rollout status deployment/product-service-w08e1 - kubectl rollout status deployment/order-service-w08e1 + kubectl rollout status deployment/product-service + kubectl rollout status deployment/order-service kubectl rollout status deployment/frontend - name: Run acceptance tests on staging @@ -96,12 +100,7 @@ jobs: - name: Logout Azure if: always() - run: | - if az account show > /dev/null 2>&1; then - az logout - else - echo "No active Azure session to log out from" - fi + run: az logout production-deployment: needs: staging-deployment @@ -126,9 +125,4 @@ jobs: - name: Logout Azure if: always() - run: | - if az account show > /dev/null 2>&1; then - az logout - else - echo "No active Azure session to log out from" - fi + run: az logout From 51b038a43b195740d7dd17e43c3d00fc1b7c9531 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 11:39:26 +0530 Subject: [PATCH 068/105] Update Dockerfile --- backend/order_service/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/order_service/Dockerfile b/backend/order_service/Dockerfile index 5837cfcb..7f9e3a6e 100644 --- a/backend/order_service/Dockerfile +++ b/backend/order_service/Dockerfile @@ -6,7 +6,8 @@ WORKDIR /code COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt + pip install --no-cache-dir -r requirements.txt && \ + pip install --no-cache-dir pytest # Copy application code COPY app /code/app From 281b1da90cad9805d3d714daa9256d80bd02834a Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 11:39:39 +0530 Subject: [PATCH 069/105] Update Dockerfile --- backend/product_service/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/product_service/Dockerfile b/backend/product_service/Dockerfile index 7e349801..4bf730c0 100644 --- a/backend/product_service/Dockerfile +++ b/backend/product_service/Dockerfile @@ -7,7 +7,8 @@ WORKDIR /code COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt + pip install --no-cache-dir -r requirements.txt && \ + pip install --no-cache-dir pytest COPY app /code/app From e3d1f12c2b7f32a781c50b558103f75e8ae9ecfa Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 11:39:51 +0530 Subject: [PATCH 070/105] Update Dockerfile --- backend/product_service/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/product_service/Dockerfile b/backend/product_service/Dockerfile index 4bf730c0..c0907258 100644 --- a/backend/product_service/Dockerfile +++ b/backend/product_service/Dockerfile @@ -7,7 +7,7 @@ WORKDIR /code COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt && \ + pip install --no-cache-dir -r requirements.txt && \ pip install --no-cache-dir pytest COPY app /code/app From 5d09cd9d1bcf52a55a3e51af9da11d058967a988 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 20:54:04 +0530 Subject: [PATCH 071/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 196 ++++++++++++++----------------- 1 file changed, 86 insertions(+), 110 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 4ff99bab..952eb784 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -1,4 +1,4 @@ -name: CI/CD Pipeline for SIT722 +name: E-Commerce CI/CD Pipeline on: push: @@ -7,122 +7,98 @@ on: pull_request: branches: - main - workflow_dispatch: jobs: - ci-pipeline: + stage1-build-test: + name: Build and Test Docker Images runs-on: ubuntu-latest + if: github.ref == 'refs/heads/testing' steps: - - name: Checkout Repository - uses: actions/checkout@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to Azure - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - - - name: Login to Azure Container Registry - run: az acr login --name ${{ secrets.ACR_NAME }} - - # Build and push product_service image - - name: Build and push product_service image - run: | - docker buildx build --file backend/product_service/Dockerfile --tag ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest --push backend/product_service - - # Build and push order_service image - - name: Build and push order_service image - run: | - docker buildx build --file backend/order_service/Dockerfile --tag ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest --push backend/order_service - - # Build and push frontend image - - name: Build and push frontend image - run: | - docker buildx build --file frontend/Dockerfile --tag ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest --push frontend - - # Run tests for Product Service - - name: Run tests for Product Service - run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/product_service:latest pytest --maxfail=5 --disable-warnings -q - continue-on-error: false - - # Run tests for Order Service - - name: Run tests for Order Service - run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/order_service:latest pytest --maxfail=5 --disable-warnings -q - continue-on-error: false - - # Run tests for Frontend Service - - name: Run tests for Frontend Service - run: | - docker run --rm ${{ secrets.ACR_NAME }}.azurecr.io/frontend:latest pytest --maxfail=5 --disable-warnings -q - continue-on-error: false - - - name: Logout Azure - if: always() - run: az logout - - staging-deployment: - needs: ci-pipeline + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to ACR + uses: azure/docker-login@v1 + with: + login-server: week8.azurecr.io + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Build Docker images + run: | + docker build -t week8.azurecr.io/product_service:latest ./backend/product_service + docker build -t week8.azurecr.io/order_service:latest ./backend/order_service + docker build -t week8.azurecr.io/frontend:latest ./frontend + + - name: Run Backend Tests + run: | + cd backend/product_service && pytest tests/ + cd ../../backend/order_service && pytest tests/ + + - name: Push Images to ACR + if: success() + run: | + docker push week8.azurecr.io/product_service:latest + docker push week8.azurecr.io/order_service:latest + docker push week8.azurecr.io/frontend:latest + + stage2-staging: + name: Deploy to Staging Environment runs-on: ubuntu-latest - if: success() - + needs: stage1-build-test steps: - - name: Checkout repo - uses: actions/checkout@v2 - - - name: Login to Azure - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - - - name: Set AKS context - run: | - az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - - - name: Deploy to Staging Environment - run: kubectl apply -f k8s/ - - - name: Wait for Deployments to Complete - run: | - kubectl rollout status deployment/product-service - kubectl rollout status deployment/order-service - kubectl rollout status deployment/frontend - - - name: Run acceptance tests on staging - run: echo "Add your acceptance tests here" - - - name: Cleanup staging environment - run: kubectl delete -f k8s/ - - - name: Logout Azure - if: always() - run: az logout - - production-deployment: - needs: staging-deployment + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set kubectl context + uses: azure/setup-kubectl@v3 + with: + version: 'v1.30.0' + kubeconfig: ${{ secrets.STAGING_KUBECONFIG }} + + - name: Create staging namespace + run: kubectl create ns staging || echo "Namespace exists" + + - name: Deploy to staging + run: | + kubectl apply -n staging -f k8s/configmaps.yaml + kubectl apply -n staging -f k8s/product-db.yaml + kubectl apply -n staging -f k8s/order-db.yaml + kubectl apply -n staging -f k8s/product-service.yaml + kubectl apply -n staging -f k8s/order-service.yaml + kubectl apply -n staging -f k8s/frontend.yaml + + - name: Run trivial acceptance test + run: | + curl -f http://$(kubectl get svc frontend-w08e1 -n staging -o jsonpath='{.status.loadBalancer.ingress[0].ip}')/ || exit 1 + + - name: Destroy staging environment + run: kubectl delete ns staging + + stage3-production: + name: Deploy to Production runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' + if: github.event.pull_request.merged == true && github.ref == 'refs/heads/main' steps: - - name: Checkout repo - uses: actions/checkout@v2 - - - name: Login to Azure - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - - - name: Set AKS context - run: | - az aks get-credentials --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} --name ${{ secrets.AKS_CLUSTER_NAME }} - - - name: Deploy to Production Environment - run: kubectl apply -f k8s/ - - - name: Logout Azure - if: always() - run: az logout + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set kubectl context + uses: azure/setup-kubectl@v3 + with: + version: 'v1.30.0' + kubeconfig: ${{ secrets.PROD_KUBECONFIG }} + + - name: Deploy to production + run: | + kubectl apply -f k8s/configmaps.yaml + kubectl apply -f k8s/product-db.yaml + kubectl apply -f k8s/order-db.yaml + kubectl apply -f k8s/product-service.yaml + kubectl apply -f k8s/order-service.yaml + kubectl apply -f k8s/frontend.yaml From 5213fc462e2c8b1ab2f9e405f024467a57c7dee9 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 20:55:31 +0530 Subject: [PATCH 072/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 952eb784..1c81605f 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -6,8 +6,8 @@ on: - testing pull_request: branches: - - main - + - main + workflow_dispatch: jobs: stage1-build-test: name: Build and Test Docker Images From ed052416dd4f928cc0af46aadc1a8f708cb97a91 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 20:57:38 +0530 Subject: [PATCH 073/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 1c81605f..8ebcf6e1 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -82,7 +82,8 @@ jobs: stage3-production: name: Deploy to Production runs-on: ubuntu-latest - if: github.event.pull_request.merged == true && github.ref == 'refs/heads/main' + if: github.event_name == 'push' && github.ref == 'refs/heads/testing' || github.event_name == 'workflow_dispatch' + steps: - name: Checkout Code From 8929fb359c921b917929f3215e2ef3b2fefed262 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 21:22:38 +0530 Subject: [PATCH 074/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 163 ++++++++++++++++--------------- 1 file changed, 83 insertions(+), 80 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 8ebcf6e1..084a729f 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -6,100 +6,103 @@ on: - testing pull_request: branches: - - main + - main workflow_dispatch: + jobs: stage1-build-test: name: Build and Test Docker Images runs-on: ubuntu-latest - if: github.ref == 'refs/heads/testing' - + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/testing' || github.event_name == 'workflow_dispatch' }} steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Log in to ACR - uses: azure/docker-login@v1 - with: - login-server: week8.azurecr.io - username: ${{ secrets.ACR_USERNAME }} - password: ${{ secrets.ACR_PASSWORD }} - - - name: Build Docker images - run: | - docker build -t week8.azurecr.io/product_service:latest ./backend/product_service - docker build -t week8.azurecr.io/order_service:latest ./backend/order_service - docker build -t week8.azurecr.io/frontend:latest ./frontend - - - name: Run Backend Tests - run: | - cd backend/product_service && pytest tests/ - cd ../../backend/order_service && pytest tests/ - - - name: Push Images to ACR - if: success() - run: | - docker push week8.azurecr.io/product_service:latest - docker push week8.azurecr.io/order_service:latest - docker push week8.azurecr.io/frontend:latest + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Azure Container Registry + uses: azure/docker-login@v1 + with: + login-server: week8.azurecr.io + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Build Docker Images + run: | + docker build -t week8.azurecr.io/product_service:latest ./backend/product_service + docker build -t week8.azurecr.io/order_service:latest ./backend/order_service + docker build -t week8.azurecr.io/frontend:latest ./frontend + + - name: Run Backend Tests + run: | + cd backend/product_service && pytest tests/ + cd ../../backend/order_service && pytest tests/ + + - name: Push Images to ACR + if: success() + run: | + docker push week8.azurecr.io/product_service:latest + docker push week8.azurecr.io/order_service:latest + docker push week8.azurecr.io/frontend:latest stage2-staging: name: Deploy to Staging Environment runs-on: ubuntu-latest needs: stage1-build-test steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Set kubectl context - uses: azure/setup-kubectl@v3 - with: - version: 'v1.30.0' - kubeconfig: ${{ secrets.STAGING_KUBECONFIG }} - - - name: Create staging namespace - run: kubectl create ns staging || echo "Namespace exists" - - - name: Deploy to staging - run: | - kubectl apply -n staging -f k8s/configmaps.yaml - kubectl apply -n staging -f k8s/product-db.yaml - kubectl apply -n staging -f k8s/order-db.yaml - kubectl apply -n staging -f k8s/product-service.yaml - kubectl apply -n staging -f k8s/order-service.yaml - kubectl apply -n staging -f k8s/frontend.yaml - - - name: Run trivial acceptance test - run: | - curl -f http://$(kubectl get svc frontend-w08e1 -n staging -o jsonpath='{.status.loadBalancer.ingress[0].ip}')/ || exit 1 - - - name: Destroy staging environment - run: kubectl delete ns staging + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Setup kubeconfig for Staging + run: | + echo "${{ secrets.STAGING_KUBECONFIG }}" > $HOME/.kube/config + chmod 600 $HOME/.kube/config + + - name: Verify kubectl context + run: kubectl config get-contexts + + - name: Create staging namespace + run: kubectl create ns staging || echo "Namespace exists" + + - name: Deploy to staging + run: | + kubectl apply -n staging -f k8s/configmaps.yaml + kubectl apply -n staging -f k8s/product-db.yaml + kubectl apply -n staging -f k8s/order-db.yaml + kubectl apply -n staging -f k8s/product-service.yaml + kubectl apply -n staging -f k8s/order-service.yaml + kubectl apply -n staging -f k8s/frontend.yaml + + - name: Run trivial acceptance test + run: | + FRONTEND_IP=$(kubectl get svc frontend-w08e1 -n staging -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + curl -f http://$FRONTEND_IP/ || exit 1 + + - name: Destroy staging environment + run: kubectl delete ns staging stage3-production: name: Deploy to Production runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/testing' || github.event_name == 'workflow_dispatch' - - + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/testing' || github.event_name == 'workflow_dispatch' }} steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Set kubectl context - uses: azure/setup-kubectl@v3 - with: - version: 'v1.30.0' - kubeconfig: ${{ secrets.PROD_KUBECONFIG }} - - - name: Deploy to production - run: | - kubectl apply -f k8s/configmaps.yaml - kubectl apply -f k8s/product-db.yaml - kubectl apply -f k8s/order-db.yaml - kubectl apply -f k8s/product-service.yaml - kubectl apply -f k8s/order-service.yaml - kubectl apply -f k8s/frontend.yaml + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Setup kubeconfig for Production + run: | + echo "${{ secrets.PROD_KUBECONFIG }}" > $HOME/.kube/config + chmod 600 $HOME/.kube/config + + - name: Verify kubectl context + run: kubectl config get-contexts + + - name: Deploy to production + run: | + kubectl apply -f k8s/configmaps.yaml + kubectl apply -f k8s/product-db.yaml + kubectl apply -f k8s/order-db.yaml + kubectl apply -f k8s/product-service.yaml + kubectl apply -f k8s/order-service.yaml + kubectl apply -f k8s/frontend.yaml From 933626fbf80b09ab635c784eafd2ac8a9e543138 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 21:25:15 +0530 Subject: [PATCH 075/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 180 +++++++++++++++++-------------- 1 file changed, 98 insertions(+), 82 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 084a729f..75e54e5b 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -6,103 +6,119 @@ on: - testing pull_request: branches: - - main + - main workflow_dispatch: jobs: stage1-build-test: name: Build and Test Docker Images runs-on: ubuntu-latest - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/testing' || github.event_name == 'workflow_dispatch' }} + if: github.event_name == 'push' && github.ref == 'refs/heads/testing' || github.event_name == 'workflow_dispatch' + steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Log in to Azure Container Registry - uses: azure/docker-login@v1 - with: - login-server: week8.azurecr.io - username: ${{ secrets.ACR_USERNAME }} - password: ${{ secrets.ACR_PASSWORD }} - - - name: Build Docker Images - run: | - docker build -t week8.azurecr.io/product_service:latest ./backend/product_service - docker build -t week8.azurecr.io/order_service:latest ./backend/order_service - docker build -t week8.azurecr.io/frontend:latest ./frontend - - - name: Run Backend Tests - run: | - cd backend/product_service && pytest tests/ - cd ../../backend/order_service && pytest tests/ - - - name: Push Images to ACR - if: success() - run: | - docker push week8.azurecr.io/product_service:latest - docker push week8.azurecr.io/order_service:latest - docker push week8.azurecr.io/frontend:latest + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install pytest + run: pip install --upgrade pip pytest + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to ACR + uses: azure/docker-login@v1 + with: + login-server: week8.azurecr.io + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Build Docker images + run: | + docker build -t week8.azurecr.io/product_service:latest ./backend/product_service + docker build -t week8.azurecr.io/order_service:latest ./backend/order_service + docker build -t week8.azurecr.io/frontend:latest ./frontend + + - name: Run Backend Tests + run: | + cd backend/product_service && pytest tests/ + cd ../../backend/order_service && pytest tests/ + + - name: Push Images to ACR + if: success() + run: | + docker push week8.azurecr.io/product_service:latest + docker push week8.azurecr.io/order_service:latest + docker push week8.azurecr.io/frontend:latest stage2-staging: name: Deploy to Staging Environment runs-on: ubuntu-latest needs: stage1-build-test - steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Setup kubeconfig for Staging - run: | - echo "${{ secrets.STAGING_KUBECONFIG }}" > $HOME/.kube/config - chmod 600 $HOME/.kube/config - - - name: Verify kubectl context - run: kubectl config get-contexts - - - name: Create staging namespace - run: kubectl create ns staging || echo "Namespace exists" - - name: Deploy to staging - run: | - kubectl apply -n staging -f k8s/configmaps.yaml - kubectl apply -n staging -f k8s/product-db.yaml - kubectl apply -n staging -f k8s/order-db.yaml - kubectl apply -n staging -f k8s/product-service.yaml - kubectl apply -n staging -f k8s/order-service.yaml - kubectl apply -n staging -f k8s/frontend.yaml - - - name: Run trivial acceptance test - run: | - FRONTEND_IP=$(kubectl get svc frontend-w08e1 -n staging -o jsonpath='{.status.loadBalancer.ingress[0].ip}') - curl -f http://$FRONTEND_IP/ || exit 1 - - - name: Destroy staging environment - run: kubectl delete ns staging + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Prepare kubeconfig + run: | + mkdir -p $HOME/.kube + echo "${{ secrets.STAGING_KUBECONFIG }}" > $HOME/.kube/config + chmod 600 $HOME/.kube/config + + - name: Set kubectl context + uses: azure/setup-kubectl@v3 + with: + version: 'v1.30.0' + + - name: Create staging namespace + run: kubectl create ns staging || echo "Namespace exists" + + - name: Deploy to staging + run: | + kubectl apply -n staging -f k8s/configmaps.yaml + kubectl apply -n staging -f k8s/product-db.yaml + kubectl apply -n staging -f k8s/order-db.yaml + kubectl apply -n staging -f k8s/product-service.yaml + kubectl apply -n staging -f k8s/order-service.yaml + kubectl apply -n staging -f k8s/frontend.yaml + + - name: Run trivial acceptance test + run: | + curl -f http://$(kubectl get svc frontend-w08e1 -n staging -o jsonpath='{.status.loadBalancer.ingress[0].ip}')/ || exit 1 + + - name: Destroy staging environment + run: kubectl delete ns staging stage3-production: name: Deploy to Production runs-on: ubuntu-latest - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/testing' || github.event_name == 'workflow_dispatch' }} + if: github.event_name == 'push' && github.ref == 'refs/heads/testing' || github.event_name == 'workflow_dispatch' + steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Setup kubeconfig for Production - run: | - echo "${{ secrets.PROD_KUBECONFIG }}" > $HOME/.kube/config - chmod 600 $HOME/.kube/config - - - name: Verify kubectl context - run: kubectl config get-contexts - - - name: Deploy to production - run: | - kubectl apply -f k8s/configmaps.yaml - kubectl apply -f k8s/product-db.yaml - kubectl apply -f k8s/order-db.yaml - kubectl apply -f k8s/product-service.yaml - kubectl apply -f k8s/order-service.yaml - kubectl apply -f k8s/frontend.yaml + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Prepare kubeconfig + run: | + mkdir -p $HOME/.kube + echo "${{ secrets.PROD_KUBECONFIG }}" > $HOME/.kube/config + chmod 600 $HOME/.kube/config + + - name: Set kubectl context + uses: azure/setup-kubectl@v3 + with: + version: 'v1.30.0' + + - name: Deploy to production + run: | + kubectl apply -f k8s/configmaps.yaml + kubectl apply -f k8s/product-db.yaml + kubectl apply -f k8s/order-db.yaml + kubectl apply -f k8s/product-service.yaml + kubectl apply -f k8s/order-service.yaml + kubectl apply -f k8s/frontend.yaml From e8a4acef485e1222dbb87db4a6dcca1a422d4c9a Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 21:29:05 +0530 Subject: [PATCH 076/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 75e54e5b..bdbdad50 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -24,8 +24,17 @@ jobs: with: python-version: '3.11' - - name: Install pytest - run: pip install --upgrade pip pytest + - name: Install backend dependencies + run: | + python -m pip install --upgrade pip + pip install -r backend/product_service/requirements.txt + pip install -r backend/order_service/requirements.txt + pip install pytest + + - name: Run Backend Tests + run: | + cd backend/product_service && pytest tests/ + cd ../../backend/order_service && pytest tests/ - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -43,11 +52,6 @@ jobs: docker build -t week8.azurecr.io/order_service:latest ./backend/order_service docker build -t week8.azurecr.io/frontend:latest ./frontend - - name: Run Backend Tests - run: | - cd backend/product_service && pytest tests/ - cd ../../backend/order_service && pytest tests/ - - name: Push Images to ACR if: success() run: | @@ -87,12 +91,8 @@ jobs: kubectl apply -n staging -f k8s/order-service.yaml kubectl apply -n staging -f k8s/frontend.yaml - - name: Run trivial acceptance test - run: | - curl -f http://$(kubectl get svc frontend-w08e1 -n staging -o jsonpath='{.status.loadBalancer.ingress[0].ip}')/ || exit 1 - - name: Destroy staging environment - run: kubectl delete ns staging + run: kubectl delete ns staging || echo "Namespace already deleted" stage3-production: name: Deploy to Production From 5bfc122023ea7d994b3f9d38881f386fa62c7b1e Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 21:32:37 +0530 Subject: [PATCH 077/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index bdbdad50..dce535a5 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -116,9 +116,9 @@ jobs: - name: Deploy to production run: | - kubectl apply -f k8s/configmaps.yaml - kubectl apply -f k8s/product-db.yaml - kubectl apply -f k8s/order-db.yaml - kubectl apply -f k8s/product-service.yaml - kubectl apply -f k8s/order-service.yaml - kubectl apply -f k8s/frontend.yaml + kubectl apply --validate=false -f k8s/configmaps.yaml + kubectl apply --validate=false -f k8s/product-db.yaml + kubectl apply --validate=false -f k8s/order-db.yaml + kubectl apply --validate=false -f k8s/product-service.yaml + kubectl apply --validate=false -f k8s/order-service.yaml + kubectl apply --validate=false -f k8s/frontend.yaml From cda4d56975fd4dba44d38126e902ecf35c8db8b4 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Tue, 30 Sep 2025 21:58:09 +0530 Subject: [PATCH 078/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index dce535a5..12e53da7 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -15,10 +15,32 @@ jobs: runs-on: ubuntu-latest if: github.event_name == 'push' && github.ref == 'refs/heads/testing' || github.event_name == 'workflow_dispatch' + services: + postgres: + image: postgres:15 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: products + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - name: Checkout Code uses: actions/checkout@v3 + - name: Wait for PostgreSQL + run: | + until pg_isready -h localhost -p 5432; do + echo "Waiting for PostgreSQL..." + sleep 2 + done + - name: Set up Python uses: actions/setup-python@v4 with: @@ -29,7 +51,7 @@ jobs: python -m pip install --upgrade pip pip install -r backend/product_service/requirements.txt pip install -r backend/order_service/requirements.txt - pip install pytest + pip install pytest psycopg2-binary - name: Run Backend Tests run: | From c8e7511e2678ef393019e1f2788d8579ddcab3d2 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 08:35:06 +0530 Subject: [PATCH 079/105] Update and rename unified-ci.yml to unified-cd.yml --- .github/workflows/unified-cd.yml | 149 +++++++++++++++++++++++++++++++ .github/workflows/unified-ci.yml | 146 ------------------------------ 2 files changed, 149 insertions(+), 146 deletions(-) create mode 100644 .github/workflows/unified-cd.yml delete mode 100644 .github/workflows/unified-ci.yml diff --git a/.github/workflows/unified-cd.yml b/.github/workflows/unified-cd.yml new file mode 100644 index 00000000..acbcd7b2 --- /dev/null +++ b/.github/workflows/unified-cd.yml @@ -0,0 +1,149 @@ +# .github/workflows/unified-cd.yml +name: Unified CD - Deploy Backend & Frontend to AKS + +on: + workflow_dispatch: + inputs: + aks_cluster_name: + description: 'Name of the AKS Cluster' + required: true + default: 'myAKSCluster' + aks_resource_group: + description: 'Resource Group of the AKS Cluster' + required: true + default: 'deakinuni' + aks_acr_name: + description: 'Azure Container Registry name' + required: true + default: 'week8' + +env: + ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} + +jobs: + + deploy_backend: + 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 repo + uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Set AKS Context + 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 Infra (ConfigMaps, Secrets, DBs) + run: | + cd k8s/ + 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 Services (Product, Order) + run: | + 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..." + for i in {1..60}; do + 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 "Product Service IP: $PRODUCT_IP" + echo "Order Service IP: $ORDER_IP" + echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_ENV + echo "ORDER_IP=$ORDER_IP" >> $GITHUB_ENV + break + fi + sleep 5 + done + if [[ -z "$PRODUCT_IP" || -z "$ORDER_IP" ]]; then + echo "❌ Failed to get backend IPs" + exit 1 + fi + + - name: Capture Product IP + id: get_product_ip + run: echo "external_ip=${{ env.PRODUCT_IP }}" >> $GITHUB_OUTPUT + + - name: Capture Order IP + id: get_order_ip + run: echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT + + - name: Logout Azure + if: always() + run: az logout + + # ---------------- FRONTEND DEPLOYMENT ---------------- + deploy_frontend: + runs-on: ubuntu-latest + environment: Production + needs: deploy_backend + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: ACR Login + uses: docker/login-action@v2 + with: + registry: ${{ env.ACR_LOGIN_SERVER }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Inject Backend IPs into Frontend + run: | + echo "Injecting Backend IPs into frontend/main.js" + sed -i "s|_PRODUCT_API_URL_|http://${{ needs.deploy_backend.outputs.PRODUCT_API_IP }}:8000|g" frontend/main.js + sed -i "s|_ORDER_API_URL_|http://${{ needs.deploy_backend.outputs.ORDER_API_IP }}:8001|g" frontend/main.js + cat frontend/main.js + + - name: Build & Push Frontend Image + run: | + docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/ + docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest + + - name: Set AKS Context + uses: azure/aks-set-context@v3 + with: + resource-group: ${{ github.event.inputs.aks_resource_group }} + cluster-name: ${{ github.event.inputs.aks_cluster_name }} + + - name: Deploy Frontend + run: | + cd k8s/ + kubectl apply -f frontend.yaml + + - name: Logout Azure + if: always() + run: az logout diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml deleted file mode 100644 index 12e53da7..00000000 --- a/.github/workflows/unified-ci.yml +++ /dev/null @@ -1,146 +0,0 @@ -name: E-Commerce CI/CD Pipeline - -on: - push: - branches: - - testing - pull_request: - branches: - - main - workflow_dispatch: - -jobs: - stage1-build-test: - name: Build and Test Docker Images - runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/testing' || github.event_name == 'workflow_dispatch' - - services: - postgres: - image: postgres:15 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: products - ports: - - 5432:5432 - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - - steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Wait for PostgreSQL - run: | - until pg_isready -h localhost -p 5432; do - echo "Waiting for PostgreSQL..." - sleep 2 - done - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - - name: Install backend dependencies - run: | - python -m pip install --upgrade pip - pip install -r backend/product_service/requirements.txt - pip install -r backend/order_service/requirements.txt - pip install pytest psycopg2-binary - - - name: Run Backend Tests - run: | - cd backend/product_service && pytest tests/ - cd ../../backend/order_service && pytest tests/ - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Log in to ACR - uses: azure/docker-login@v1 - with: - login-server: week8.azurecr.io - username: ${{ secrets.ACR_USERNAME }} - password: ${{ secrets.ACR_PASSWORD }} - - - name: Build Docker images - run: | - docker build -t week8.azurecr.io/product_service:latest ./backend/product_service - docker build -t week8.azurecr.io/order_service:latest ./backend/order_service - docker build -t week8.azurecr.io/frontend:latest ./frontend - - - name: Push Images to ACR - if: success() - run: | - docker push week8.azurecr.io/product_service:latest - docker push week8.azurecr.io/order_service:latest - docker push week8.azurecr.io/frontend:latest - - stage2-staging: - name: Deploy to Staging Environment - runs-on: ubuntu-latest - needs: stage1-build-test - - steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Prepare kubeconfig - run: | - mkdir -p $HOME/.kube - echo "${{ secrets.STAGING_KUBECONFIG }}" > $HOME/.kube/config - chmod 600 $HOME/.kube/config - - - name: Set kubectl context - uses: azure/setup-kubectl@v3 - with: - version: 'v1.30.0' - - - name: Create staging namespace - run: kubectl create ns staging || echo "Namespace exists" - - - name: Deploy to staging - run: | - kubectl apply -n staging -f k8s/configmaps.yaml - kubectl apply -n staging -f k8s/product-db.yaml - kubectl apply -n staging -f k8s/order-db.yaml - kubectl apply -n staging -f k8s/product-service.yaml - kubectl apply -n staging -f k8s/order-service.yaml - kubectl apply -n staging -f k8s/frontend.yaml - - - name: Destroy staging environment - run: kubectl delete ns staging || echo "Namespace already deleted" - - stage3-production: - name: Deploy to Production - runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/testing' || github.event_name == 'workflow_dispatch' - - steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Prepare kubeconfig - run: | - mkdir -p $HOME/.kube - echo "${{ secrets.PROD_KUBECONFIG }}" > $HOME/.kube/config - chmod 600 $HOME/.kube/config - - - name: Set kubectl context - uses: azure/setup-kubectl@v3 - with: - version: 'v1.30.0' - - - name: Deploy to production - run: | - kubectl apply --validate=false -f k8s/configmaps.yaml - kubectl apply --validate=false -f k8s/product-db.yaml - kubectl apply --validate=false -f k8s/order-db.yaml - kubectl apply --validate=false -f k8s/product-service.yaml - kubectl apply --validate=false -f k8s/order-service.yaml - kubectl apply --validate=false -f k8s/frontend.yaml From eb63a395a9e84b85defe576a9d5bba81806fab5e Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 08:35:48 +0530 Subject: [PATCH 080/105] Create unified-ci.yml --- .github/workflows/unified-ci.yml | 145 +++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 .github/workflows/unified-ci.yml diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml new file mode 100644 index 00000000..812e0adb --- /dev/null +++ b/.github/workflows/unified-ci.yml @@ -0,0 +1,145 @@ +# .github/workflows/unified-ci.yml +name: Unified CI - Backend & Frontend + +on: + workflow_dispatch: + push: + branches: + - testing + - main + paths: + - 'backend/**' + - 'frontend/**' + - '.github/workflows/ci.yml' + + pull_request: + branches: + - main + - development + paths: + - 'backend/**' + - 'frontend/**' + - '.github/workflows/ci.yml' + +env: + ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} + IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} + +jobs: + backend: + runs-on: ubuntu-latest + if: contains(github.event.head_commit.message, 'backend') || contains(join(github.event.commits.*.modified, ''), 'backend/') + services: + product_db: + image: postgres:15 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: products + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + 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 + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Install dependencies + run: | + pip install --upgrade pip + for req in backend/*/requirements.txt; do + echo "Installing $req" + pip install -r "$req" + done + pip install pytest httpx + + - 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 + + - 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: 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 & Push Product Service + run: | + TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG ./backend/product_service + docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG + + - name: Build & Push Order Service + run: | + TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG ./backend/order_service + docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG + + - name: Logout Azure + if: always() + run: az logout + + # ---------------- FRONTEND JOB ---------------- + frontend: + runs-on: ubuntu-latest + if: contains(github.event.head_commit.message, 'frontend') || contains(join(github.event.commits.*.modified, ''), 'frontend/') + + steps: + - 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 & Push Frontend + run: | + TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG ./frontend + docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG + + - name: Logout Azure + if: always() + run: az logout From 98233c468d2dbb2fed3d47b5726cd024fbdc1404 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 08:53:15 +0530 Subject: [PATCH 081/105] Update docker-compose.yml --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index dd7d9b24..852b10e6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -54,7 +54,7 @@ services: environment: POSTGRES_HOST: product_db # Connects to the 'product_db' service within Docker network AZURE_STORAGE_ACCOUNT_NAME: week08 # Replace with your Azure Storage account name - AZURE_STORAGE_ACCOUNT_KEY: lVxmnijthHi8u0YyFq/yz60P6kvp91baoKyGs9SunxuQMtOluxM/adNkLdmgrCCS0bpqAh3TBJqY+ASttcnszA== # Replace with your Azure Storage account key + AZURE_STORAGE_ACCOUNT_KEY: yoPFslu06OVWDl0rLA9pABgzKhjs/k7Q1JwbXX4ya+N7vWOfcpUEi2BkgNUfqLrVnsz4aV3DkLIT+AStmfRIFQ== # Replace with your Azure Storage account key AZURE_STORAGE_CONTAINER_NAME: pjctcont # Replace with your Azure Storage container name AZURE_SAS_TOKEN_EXPIRY_HOURS: 24 depends_on: From 087f3cdffb63dbfea8166e726f1437d973c3c13e Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 08:55:37 +0530 Subject: [PATCH 082/105] Update secrets.yaml --- k8s/secrets.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/secrets.yaml b/k8s/secrets.yaml index 3665900e..08c8f117 100644 --- a/k8s/secrets.yaml +++ b/k8s/secrets.yaml @@ -15,4 +15,4 @@ data: # Example: echo -n 'myblobstorageaccount' | base64 AZURE_STORAGE_ACCOUNT_NAME: "d2VlazA4" # Example: echo -n 'your_storage_account_key_string' | base64 - AZURE_STORAGE_ACCOUNT_KEY: "bFZ4bW5panRoSGk4dTBZeUZxL3l6NjBQNmt2cDkxYmFvS3lHczlTdW54dVFNdE9sdXhNL2FkTmtMZG1nckNDUzBicHFBaDNUQkpxWStBU3R0Y25zekE9PQ==" + AZURE_STORAGE_ACCOUNT_KEY: "eW9QRnNsdTA2T1ZXRGwwckxBOXBBQmd6S2hqcy9rN1ExSndiWFg0eWErTjd2V09mY3BVRWkyQmtnTlVmcUxyVm5zejRhVjNEa0xJVCtBU3RtZlJJRlE9PQ==" From 09c1cbd8c8ab0f3e8bc37a781313e3c6809c9156 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 08:57:22 +0530 Subject: [PATCH 083/105] Create staging-deploy.yml --- .github/workflows/staging-deploy.yml | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/staging-deploy.yml diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml new file mode 100644 index 00000000..cb52ed75 --- /dev/null +++ b/.github/workflows/staging-deploy.yml @@ -0,0 +1,61 @@ +name: Staging CD - Deploy to Temporary Environment + +on: + workflow_run: + workflows: ["Unified CI - Backend & Frontend"] + types: + - completed + +jobs: + deploy_staging: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + environment: staging + + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Set AKS Context (Staging Cluster) + run: | + az aks get-credentials \ + --resource-group ${{ secrets.STAGING_RG }} \ + --name ${{ secrets.STAGING_CLUSTER_NAME }} \ + --overwrite-existing + + - name: Deploy Infra + run: | + cd k8s/ + 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 & Frontend + run: | + kubectl apply -f product-service.yaml + kubectl apply -f order-service.yaml + kubectl apply -f frontend.yaml + + - name: (Optional) Run Acceptance Tests + run: echo "Add curl or pytest here to hit endpoints" + + - name: Destroy Staging Environment + run: | + echo "Cleaning up staging..." + kubectl delete -f frontend.yaml + kubectl delete -f order-service.yaml + kubectl delete -f product-service.yaml + kubectl delete -f product-db.yaml + kubectl delete -f order-db.yaml + kubectl delete -f configmaps.yaml + kubectl delete -f secrets.yaml + + - name: Logout Azure + if: always() + run: az logout From af10386e16cb182783476b971b2aeb9895a8f14f Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 09:03:33 +0530 Subject: [PATCH 084/105] Update unified-cd.yml --- .github/workflows/unified-cd.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/unified-cd.yml b/.github/workflows/unified-cd.yml index acbcd7b2..22b89eba 100644 --- a/.github/workflows/unified-cd.yml +++ b/.github/workflows/unified-cd.yml @@ -16,6 +16,9 @@ on: description: 'Azure Container Registry name' required: true default: 'week8' + push: + branches: + - main env: ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} From b4fa8740afec15b6f3ee161896138f9a12cf2164 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 09:10:32 +0530 Subject: [PATCH 085/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 812e0adb..132dea05 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -6,7 +6,6 @@ on: push: branches: - testing - - main paths: - 'backend/**' - 'frontend/**' From 0afef1398a29a0df2499d6c189a5388c0454f0c9 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 09:34:32 +0530 Subject: [PATCH 086/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 132dea05..39aa2b35 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -1,15 +1,14 @@ -# .github/workflows/unified-ci.yml name: Unified CI - Backend & Frontend on: - workflow_dispatch: + workflow_dispatch: # Manual trigger push: branches: - - testing + - testing # CI triggers on push to 'testing' branch paths: - 'backend/**' - 'frontend/**' - - '.github/workflows/ci.yml' + - '.github/workflows/unified-ci.yml' pull_request: branches: @@ -18,16 +17,17 @@ on: paths: - 'backend/**' - 'frontend/**' - - '.github/workflows/ci.yml' + - '.github/workflows/unified-ci.yml' env: ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} jobs: + # ---------------- BACKEND JOB ---------------- backend: runs-on: ubuntu-latest - if: contains(github.event.head_commit.message, 'backend') || contains(join(github.event.commits.*.modified, ''), 'backend/') + services: product_db: image: postgres:15 @@ -42,19 +42,20 @@ jobs: --health-retries 5 ports: - 5432:5432 + 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: - uses: actions/checkout@v4 @@ -120,7 +121,6 @@ jobs: # ---------------- FRONTEND JOB ---------------- frontend: runs-on: ubuntu-latest - if: contains(github.event.head_commit.message, 'frontend') || contains(join(github.event.commits.*.modified, ''), 'frontend/') steps: - uses: actions/checkout@v4 From da8ed95d9dbe5240511ba7a2d27cdd0af8a07d10 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 09:37:37 +0530 Subject: [PATCH 087/105] Update unified-ci.yml --- .github/workflows/unified-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 39aa2b35..5d44b051 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -142,3 +142,4 @@ jobs: - name: Logout Azure if: always() run: az logout + From 601a1d13af6353e2a33c4419ebb33c9406649926 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 10:35:50 +0530 Subject: [PATCH 088/105] Update staging-deploy.yml --- .github/workflows/staging-deploy.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml index cb52ed75..646e923d 100644 --- a/.github/workflows/staging-deploy.yml +++ b/.github/workflows/staging-deploy.yml @@ -28,6 +28,13 @@ jobs: --name ${{ secrets.STAGING_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 Infra run: | cd k8s/ From 271911621f58d458846f9c0e67546aedbe1c7549 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 10:47:07 +0530 Subject: [PATCH 089/105] 'kl' --- .github/workflows/unified-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 5d44b051..19556a09 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -1,4 +1,4 @@ -name: Unified CI - Backend & Frontend +name: Unified CI- Backend & Frontend on: workflow_dispatch: # Manual trigger From eb0644c81ff7a8a4c32508914b73c791e135eb90 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 10:51:57 +0530 Subject: [PATCH 090/105] 'kl' --- .github/workflows/unified-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 19556a09..5d44b051 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -1,4 +1,4 @@ -name: Unified CI- Backend & Frontend +name: Unified CI - Backend & Frontend on: workflow_dispatch: # Manual trigger From 3e81295a4e5af9ab22efe6e6fabb212fb97d8880 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 11:13:04 +0530 Subject: [PATCH 091/105] 'kl' --- .github/workflows/unified-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index 5d44b051..dfdca088 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: # Manual trigger push: branches: - - testing # CI triggers on push to 'testing' branch + - testing # C triggers on push to 'testing' branch paths: - 'backend/**' - 'frontend/**' From 5d4eb043d79ff01c25f59b0916800e489dbfa2b9 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 11:19:42 +0530 Subject: [PATCH 092/105] Update staging-deploy.yml --- .github/workflows/staging-deploy.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml index 646e923d..14d87caa 100644 --- a/.github/workflows/staging-deploy.yml +++ b/.github/workflows/staging-deploy.yml @@ -28,13 +28,7 @@ jobs: --name ${{ secrets.STAGING_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 Infra run: | cd k8s/ From 637f8b212ef954f6864bb22daa1bde00d65a80ea Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 11:19:25 +0530 Subject: [PATCH 093/105] Update staging-deploy.yml --- .github/workflows/staging-deploy.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml index 14d87caa..15bab833 100644 --- a/.github/workflows/staging-deploy.yml +++ b/.github/workflows/staging-deploy.yml @@ -28,7 +28,13 @@ jobs: --name ${{ secrets.STAGING_CLUSTER_NAME }} \ --overwrite-existing - + - name: Attach ACR + run: | + az aks update \ + --name ${{ secrets.STAGING_CLUSTER_NAME }} \ + --resource-group ${{ secrets.STAGING_RG }} \ + --attach-acr ${{ secrets.AZURE_CONTAINER_REGISTRY }} + - name: Deploy Infra run: | cd k8s/ From c1c440200fa958e0cf814a3e63903533b3fc249b Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 11:49:50 +0530 Subject: [PATCH 094/105] 'kl' --- .github/workflows/staging-deploy.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml index 15bab833..5108c06f 100644 --- a/.github/workflows/staging-deploy.yml +++ b/.github/workflows/staging-deploy.yml @@ -28,13 +28,7 @@ jobs: --name ${{ secrets.STAGING_CLUSTER_NAME }} \ --overwrite-existing - - name: Attach ACR - run: | - az aks update \ - --name ${{ secrets.STAGING_CLUSTER_NAME }} \ - --resource-group ${{ secrets.STAGING_RG }} \ - --attach-acr ${{ secrets.AZURE_CONTAINER_REGISTRY }} - + - name: Deploy Infra run: | cd k8s/ From 9ef0a7a89abc1d79c9b8a254611c3fa4dd43e7c7 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 11:52:48 +0530 Subject: [PATCH 095/105] 'kl' --- .github/workflows/staging-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml index 5108c06f..c09bf3b0 100644 --- a/.github/workflows/staging-deploy.yml +++ b/.github/workflows/staging-deploy.yml @@ -2,7 +2,7 @@ name: Staging CD - Deploy to Temporary Environment on: workflow_run: - workflows: ["Unified CI - Backend & Frontend"] + workflows: ["Unified CI -Backend & Frontend"] types: - completed From d3fbd35fc17a227a9f1ae93184f6e13178273df5 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 11:53:12 +0530 Subject: [PATCH 096/105] 'kl' --- .github/workflows/unified-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index dfdca088..c80e69e8 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -1,4 +1,4 @@ -name: Unified CI - Backend & Frontend +name: Unified CI -Backend & Frontend on: workflow_dispatch: # Manual trigger From 4600c026bce474c6598294c5fe9f86661d1302b5 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 13:18:28 +0530 Subject: [PATCH 097/105] 'kl' --- .github/workflows/unified-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index c80e69e8..dfdca088 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -1,4 +1,4 @@ -name: Unified CI -Backend & Frontend +name: Unified CI - Backend & Frontend on: workflow_dispatch: # Manual trigger From a898501cdcb069a4ac91d8c5ff8e02cd5edf7974 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 13:24:49 +0530 Subject: [PATCH 098/105] Update staging-deploy.yml --- .github/workflows/staging-deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml index c09bf3b0..d371710c 100644 --- a/.github/workflows/staging-deploy.yml +++ b/.github/workflows/staging-deploy.yml @@ -39,6 +39,7 @@ jobs: - name: Deploy Backend & Frontend run: | + cd k8s/ kubectl apply -f product-service.yaml kubectl apply -f order-service.yaml kubectl apply -f frontend.yaml From 57ebe94b98f2456b7f699d8adb4d560a2a997709 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 13:26:50 +0530 Subject: [PATCH 099/105] 'kl' --- .github/workflows/unified-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index dfdca088..b6fc0e6f 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: # Manual trigger push: branches: - - testing # C triggers on push to 'testing' branch + - testing # C triggers on push to 'testing' branch paths: - 'backend/**' - 'frontend/**' From 5fb5fc2340894e5dc976d8092b7001ae1bceed3f Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 13:40:08 +0530 Subject: [PATCH 100/105] 'kl' --- .github/workflows/unified-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index b6fc0e6f..dfdca088 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: # Manual trigger push: branches: - - testing # C triggers on push to 'testing' branch + - testing # C triggers on push to 'testing' branch paths: - 'backend/**' - 'frontend/**' From ce80343d86de4585ce906e96243483b62c93daea Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 13:45:41 +0530 Subject: [PATCH 101/105] Update staging-deploy.yml --- .github/workflows/staging-deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml index d371710c..4dd6d348 100644 --- a/.github/workflows/staging-deploy.yml +++ b/.github/workflows/staging-deploy.yml @@ -50,6 +50,7 @@ jobs: - name: Destroy Staging Environment run: | echo "Cleaning up staging..." + cd k8s/ kubectl delete -f frontend.yaml kubectl delete -f order-service.yaml kubectl delete -f product-service.yaml From 8191a3182b9a1436f544340e4a45924599841e5b Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 13:47:09 +0530 Subject: [PATCH 102/105] 'kl' --- .github/workflows/unified-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml index dfdca088..b6fc0e6f 100644 --- a/.github/workflows/unified-ci.yml +++ b/.github/workflows/unified-ci.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: # Manual trigger push: branches: - - testing # C triggers on push to 'testing' branch + - testing # C triggers on push to 'testing' branch paths: - 'backend/**' - 'frontend/**' From de3367f794e7b775e54d9c7205912ff9de760c4f Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 13:50:17 +0530 Subject: [PATCH 103/105] 'kl' --- .github/workflows/staging-deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml index d371710c..4dd6d348 100644 --- a/.github/workflows/staging-deploy.yml +++ b/.github/workflows/staging-deploy.yml @@ -50,6 +50,7 @@ jobs: - name: Destroy Staging Environment run: | echo "Cleaning up staging..." + cd k8s/ kubectl delete -f frontend.yaml kubectl delete -f order-service.yaml kubectl delete -f product-service.yaml From 36acd416af0c0f215c438a722551f38024071857 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 14:04:21 +0530 Subject: [PATCH 104/105] Update unified-cd.yml --- .github/workflows/unified-cd.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/unified-cd.yml b/.github/workflows/unified-cd.yml index 22b89eba..38e3d7c7 100644 --- a/.github/workflows/unified-cd.yml +++ b/.github/workflows/unified-cd.yml @@ -50,11 +50,7 @@ jobs: --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 }} + run: echo "Add curl or pytest here to hit endpoints" - name: Deploy Backend Infra (ConfigMaps, Secrets, DBs) run: | From 402598e17fbfb5fc2b27e035bda19f7e8db92062 Mon Sep 17 00:00:00 2001 From: s224877838 Date: Sat, 4 Oct 2025 19:03:04 +0530 Subject: [PATCH 105/105] Update and rename unified-cd.yml to final-merged.yml --- .github/workflows/{unified-cd.yml => final-merged.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{unified-cd.yml => final-merged.yml} (98%) diff --git a/.github/workflows/unified-cd.yml b/.github/workflows/final-merged.yml similarity index 98% rename from .github/workflows/unified-cd.yml rename to .github/workflows/final-merged.yml index 38e3d7c7..efa010cd 100644 --- a/.github/workflows/unified-cd.yml +++ b/.github/workflows/final-merged.yml @@ -1,5 +1,5 @@ # .github/workflows/unified-cd.yml -name: Unified CD - Deploy Backend & Frontend to AKS +name: Final merging to Production Environment on: workflow_dispatch: