From f5ed41dd45f0636ad3f46525badcc32aaaa14592 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Wed, 17 Sep 2025 17:19:52 +1000 Subject: [PATCH 01/36] updating the cd and k8's file with correct names --- .github/workflows/backend-cd.yml | 6 +++--- .github/workflows/frontend-cd.yml | 4 ++-- k8s/frontend.yaml | 2 +- k8s/order-service.yaml | 2 +- k8s/product-service.yaml | 2 +- k8s/secrets.yaml | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 6035ed15..82070ffa 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -6,15 +6,15 @@ on: aks_cluster_name: description: 'Name of the AKS Cluster to deploy to' required: true - default: '' + default: 'ishaanAKS' 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: 'ishaan' jobs: deploy_backend: diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml index 0a0879c8..19f276c7 100644 --- a/.github/workflows/frontend-cd.yml +++ b/.github/workflows/frontend-cd.yml @@ -18,11 +18,11 @@ on: aks_cluster_name: description: 'Name of the AKS Cluster to deploy to' required: true - default: '' + default: 'ishaanAKS' aks_resource_group: description: 'Resource Group of the AKS Cluster' required: true - default: '<' + default: 'deakinuni' workflow_call: inputs: diff --git a/k8s/frontend.yaml b/k8s/frontend.yaml index 1948536d..bb0f842d 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: ishaan.azurecr.io/frontend:latest imagePullPolicy: Always ports: - containerPort: 80 diff --git a/k8s/order-service.yaml b/k8s/order-service.yaml index c9d92e4d..b722ab45 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: ishaan.azurecr.io/order_service:latest imagePullPolicy: Always ports: - containerPort: 8000 diff --git a/k8s/product-service.yaml b/k8s/product-service.yaml index 0cbbd505..172ce0ae 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: ishaan.azurecr.io/product_service:latest imagePullPolicy: Always ports: - containerPort: 8000 diff --git a/k8s/secrets.yaml b/k8s/secrets.yaml index 5eebe1fa..19d284f5 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: "aXNoYWFuc3RvcmFnZWFjY291bnQ=" # Example: echo -n 'your_storage_account_key_string' | base64 - AZURE_STORAGE_ACCOUNT_KEY: "aEFNQ24rbkh2cmhwSGFEaW5jSnAxNFlHaU5nTnJja2NJR05Bc3Y5VXZPUlpsblJkbkVUR3drdTREdSszblBDR3E4ZEVTVjlFNE1jMytBU3RubmZ5QVE9PQ==" + AZURE_STORAGE_ACCOUNT_KEY: "aXU4OTlQamNFUVFvaURyZGpNVXdNaUQ1TnBjNTN1Wmc5VVdPTHVoSDQ0YjB0anl3bFJINUc2MzZISERNNEpIbW5vakd0TkJXL2dScCtBU3RpeVhCWFE9PQ==" From 2d085fc899cfa5ce807ce5adc7ac8d56d402a7d9 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Wed, 17 Sep 2025 18:42:53 +1000 Subject: [PATCH 02/36] updated ip in main.js --- README.md | 3 ++- frontend/main.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 23009398..93d6b6e2 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,8 @@ Before you begin, ensure you have the following: 1. Create all required resources (Resource Group, Storage Account, ACR, AKS) 2. **Azure Service Principal:** Create new Service Principal. 3. Add new role for service principal for resource group. **More detailes about this step will be provided in seminar. Make sure you join seminar for this**. -4. **GitHub Repository Secrets:** +4. **GitHub Repository Secrets:**y + - In your GitHub repository, go to **Settings** > **Secrets and variables** > **Actions**. - Click **New repository secret** for each: - `AZURE_CREDENTIALS`: You need separate SP with Owner permission (As done in step 3). diff --git a/frontend/main.js b/frontend/main.js index f321fd91..5e7dd4c6 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -4,8 +4,8 @@ document.addEventListener('DOMContentLoaded', () => { // API endpoints for the Product and Order services. // These ports (30000 for Product, 30001 for Order) are mapped // from the Docker containers to the host machine in docker-compose.yml for Example 2. - const PRODUCT_API_BASE_URL = '_PRODUCT_API_URL_'; - const ORDER_API_BASE_URL = '_ORDER_API_URL_'; + const PRODUCT_API_BASE_URL = 'http://4.198.134.37:8000'; + const ORDER_API_BASE_URL = 'http://20.213.212.254:8001'; // Product Service is named 'product-service-w04e2' and exposes port 8000 internally. //const PRODUCT_API_BASE_URL = 'http://product-service-w04e2:8000'; From 98096e061141d3b0aa2e7f40fab8b43cfc0a5a97 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 10:07:36 +1000 Subject: [PATCH 03/36] backend_ci to development --- .github/workflows/backend_ci.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index d69725aa..f004da9c 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -11,10 +11,17 @@ on: # Automatically on pushes to main branch push: branches: - - main + -development + # - main paths: # Only trigger if changes are in backend directories - 'backend/**' - '.github/workflows/backend_ci.yml' # Trigger if this workflow file changes + pull_request: + branches: + - main + paths: + - 'backend/**' + - '.github/workflows/backend_ci.yml' # Define global environment variables that can be used across jobs env: From da417b54cba3dc2bb510dfbaaf6588365a5ced8d Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 10:13:27 +1000 Subject: [PATCH 04/36] backend_ci to development --- .github/workflows/backend_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index f004da9c..07220ccc 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -11,7 +11,7 @@ on: # Automatically on pushes to main branch push: branches: - -development + - development # - main paths: # Only trigger if changes are in backend directories - 'backend/**' From 1ea32ef60b0f5dfb54423c709efb0390cd1c69b5 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 10:24:24 +1000 Subject: [PATCH 05/36] frontend_ci to development --- .github/workflows/frontend_ci.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 9f9e76d9..17c719ef 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -9,11 +9,17 @@ on: # Automatically on pushes to main branch push: branches: - - main + - development paths: # Only trigger if changes are in the frontend directory - 'frontend/**' - '.github/workflows/frontend_ci.yml' # Trigger if this workflow file changes - + pull_request: + branches: + - main + paths: + - 'backend/**' + - '.github/workflows/frontend_ci.yml' + # Define global environment variables that can be used across jobs env: # ACR Login Server (e.g., myregistry.azurecr.io) From 9221c6ba4d1fc87468acdf0939820dd30d99c46f Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 10:33:49 +1000 Subject: [PATCH 06/36] linkage --- .github/workflows/backend-cd.yml | 74 +++++++++++++--------- .github/workflows/backend_ci.yml | 25 +++++++- .github/workflows/frontend-cd.yml | 65 +++++++++---------- .github/workflows/frontend_ci.yml | 100 +++++++++++++++++++----------- 4 files changed, 162 insertions(+), 102 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 82070ffa..6c80876b 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -1,29 +1,26 @@ name: CD - Deploy Backend Services to AKS on: - workflow_dispatch: + # ---------------------------------------------------------------------- + # CRITICAL CHANGE: SWITCH TO WORKFLOW_CALL TO ENABLE AUTO-TRIGGERING + # ---------------------------------------------------------------------- + workflow_call: # <--- CRITICAL FIX: Enables calling from backend_ci.yml inputs: - aks_cluster_name: - description: 'Name of the AKS Cluster to deploy to' - required: true - default: 'ishaanAKS' - aks_resource_group: - description: 'Resource Group of the AKS Cluster' - required: true - default: 'deakinuni' - aks_acr_name: - description: 'Name of ACR' - required: true - default: 'ishaan' + aks_cluster_name: { required: true, type: string } + aks_resource_group: { required: true, type: string } + aks_acr_name: { required: true, type: string } + secrets: + azure_credentials: { required: true } jobs: deploy_backend: runs-on: ubuntu-latest environment: Production + # CRITICAL CHANGE: Update outputs to match the step IDs below outputs: - PRODUCT_API_IP: ${{ steps.get_product_ip.outputs.external_ip }} - ORDER_API_IP: ${{ steps.get_order_ip.outputs.external_ip }} + PRODUCT_API_IP: ${{ steps.ip_capture.outputs.PRODUCT_IP }} # <--- UPDATED + ORDER_API_IP: ${{ steps.ip_capture.outputs.ORDER_IP }} # <--- UPDATED steps: - name: Checkout repository @@ -32,16 +29,18 @@ jobs: - name: Log in to Azure uses: azure/login@v1 with: - creds: ${{ secrets.AZURE_CREDENTIALS }} + creds: ${{ secrets.azure_credentials }} # <--- UPDATED: Using `secrets` from workflow_call 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 + # <--- UPDATED: Using `inputs` from workflow_call + az aks get-credentials --resource-group ${{ inputs.aks_resource_group }} --name ${{ inputs.aks_cluster_name }} --overwrite-existing - name: Attach ACR run: | - az aks update --name ${{ github.event.inputs.aks_cluster_name }} --resource-group ${{ github.event.inputs.aks_resource_group }} --attach-acr ${{ github.event.inputs.aks_acr_name }} + # <--- UPDATED: Using `inputs` from workflow_call + az aks update --name ${{ inputs.aks_cluster_name }} --resource-group ${{ inputs.aks_resource_group }} --attach-acr ${{ inputs.aks_acr_name }} - name: Deploy Backend Infrastructure (Namespace, ConfigMaps, Secrets, Databases) run: | @@ -60,6 +59,7 @@ jobs: kubectl apply -f order-service.yaml - name: Wait for Backend LoadBalancer IPs + id: ip_capture # <--- CRITICAL FIX: Added ID to make outputs work run: | echo "Waiting for Product, Order LoadBalancer IPs to be assigned (up to 5 minutes)..." PRODUCT_IP="" @@ -74,6 +74,10 @@ jobs: echo "All backend LoadBalancer IPs assigned!" echo "Product Service IP: $PRODUCT_IP" echo "Order Service IP: $ORDER_IP" + + # CRITICAL FIX: Publish the IPs as step outputs + echo "PRODUCT_IP=$PRODUCT_IP" >> "$GITHUB_OUTPUT" # <--- NEW: Set output for the next job + echo "ORDER_IP=$ORDER_IP" >> "$GITHUB_OUTPUT" # <--- NEW: Set output for the next job break fi sleep 5 # Wait 5 seconds before next attempt @@ -84,18 +88,28 @@ jobs: exit 1 # Fail the job if IPs are not obtained fi - # These are environment variables for subsequent steps in the *same job* - # And used to set the job outputs - echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_ENV - echo "ORDER_IP=$ORDER_IP" >> $GITHUB_ENV - - - name: Capture Product Service IP for Workflow Output - id: get_product_ip - run: echo "external_ip=${{ env.PRODUCT_IP }}" >> $GITHUB_OUTPUT - - - name: Capture Order Service IP for Workflow Output - id: get_order_ip - run: echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT + # Removed redundant IP environment setup, now using step outputs. + + # Removed redundant 'Capture IP for Workflow Output' steps - name: Logout from Azure run: az logout + + # ---------------------------------------------------------------------- + # NEW JOB: LINKAGE TO FRONTEND CI + # ---------------------------------------------------------------------- + trigger_frontend_ci: + runs-on: ubuntu-latest + needs: deploy_backend # Waits for deployment and IP capture + steps: + - name: "Call Frontend CI Workflow" + uses: ./.github/workflows/frontend_ci.yml # Calls the next file + with: + # Pass the captured IPs from the previous job's outputs + product_api_ip: ${{ needs.deploy_backend.outputs.PRODUCT_API_IP }} + order_api_ip: ${{ needs.deploy_backend.outputs.ORDER_API_IP }} + # Pass cluster details received by this workflow + aks_cluster_name: ${{ inputs.aks_cluster_name }} + aks_resource_group: ${{ inputs.aks_resource_group }} + secrets: + azure_credentials: ${{ secrets.azure_credentials }} # Pass the secret \ No newline at end of file diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 07220ccc..0706dcd2 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -12,13 +12,13 @@ on: push: branches: - development - # - main + - main # <-- UPDATED: Now triggers when code is merged into main paths: # Only trigger if changes are in backend directories - 'backend/**' - '.github/workflows/backend_ci.yml' # Trigger if this workflow file changes pull_request: branches: - - main + - main                             paths: - 'backend/**' - '.github/workflows/backend_ci.yml' @@ -151,3 +151,24 @@ jobs: - name: Logout from Azure run: az logout if: always() + + # ---------------------------------------------------------------------- + # NEW JOB: LINKAGE TO THE CD PIPELINE + # ---------------------------------------------------------------------- + trigger_backend_cd: # <-- NEW JOB NAME + runs-on: ubuntu-latest + needs: build_and_push_images # <-- Ensure images are built before triggering CD + + # CRITICAL GATE: Only execute deployment when merged into 'main' + if: github.ref == 'refs/heads/main' # <-- NEW CONDITION + + steps: + - name: "Call Backend CD Workflow" # <-- NEW STEP + # This calls the backend-cd.yml file directly, linking the workflows + uses: ./.github/workflows/backend-cd.yml + with: + # Pass required deployment details to the CD workflow + aks_cluster_name: 'ishaanAKS' # <-- Update with your cluster name + aks_resource_group: 'deakinuni' # <-- Update with your resource group + aks_acr_name: ${{ env.ACR_LOGIN_SERVER }} + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} \ No newline at end of file diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml index 19f276c7..27931888 100644 --- a/.github/workflows/frontend-cd.yml +++ b/.github/workflows/frontend-cd.yml @@ -2,19 +2,17 @@ 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://:8000' + default: '0.0.0.0' order_api_ip: - description: 'External IP of Order Service (e.g., http://Y.Y.Y.Y:8001)' + description: 'External IP of Order Service' required: true - default: 'http://:8001' + default: '0.0.0.0' aks_cluster_name: description: 'Name of the AKS Cluster to deploy to' required: true @@ -24,6 +22,7 @@ on: required: true default: 'deakinuni' + # CRITICAL: This is how it's called by frontend_ci.yml workflow_call: inputs: product_api_ip: @@ -38,7 +37,10 @@ on: aks_resource_group: required: true type: string - + # CRITICAL FIX: Must define which secrets are required by this workflow + secrets: + azure_credentials: { required: true } # <--- ADDED SECRET HERE + jobs: deploy_frontend: runs-on: ubuntu-latest @@ -48,33 +50,16 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - # Azure login using a Service Principal secret + # Azure login using the secret passed via workflow_call - 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 "---------------------------------" + # CRITICAL FIX: Use the secret passed from the caller + creds: ${{ secrets.azure_credentials }} - # 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 + # --- OPTIMISATION: REMOVED ACR Login, Inject IPs, and Build/Push steps --- + # These steps were already done by frontend_ci.yml (Step 3 in the chain). + # The IP linkage will now be done with a robust `kubectl` command. - name: Set Kubernetes context (get AKS credentials) uses: azure/aks-set-context@v3 @@ -82,12 +67,24 @@ jobs: resource-group: ${{ inputs.aks_resource_group }} cluster-name: ${{ inputs.aks_cluster_name }} - - name: Deploy Frontend to AKS + - name: Deploy Frontend to AKS (Apply Base Manifest) run: | - echo "Deploying frontend with latest tag to AKS cluster: ${{ inputs.aks_cluster_name }}" + echo "Applying frontend base manifest to AKS cluster: ${{ inputs.aks_cluster_name }}" cd k8s/ - # Ensure frontend-service.yaml is configured with your ACR + # Deploy the base frontend service/deployment kubectl apply -f frontend.yaml + + # CRITICAL NEW STEP: Configure Frontend Deployment with Backend IPs + # This is the most reliable way to link the services in AKS + - name: Configure Frontend Deployment with Backend IPs + run: | + echo "Setting backend IP environment variables on frontend deployment..." + # Pass the IPs as environment variables to the live Kubernetes deployment + # Note: Adjust 'frontend-w08e1' if your deployment name is different in frontend.yaml + kubectl set env deployment/frontend-w08e1 \ + PRODUCT_API_URL=http://${{ inputs.product_api_ip }}:80 \ + ORDER_API_URL=http://${{ inputs.order_api_ip }}:80 \ + --overwrite - - name: Logout from Azure (AKS deployment) - run: az logout + - name: Logout from Azure + run: az logout \ No newline at end of file diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 17c719ef..3531ad52 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -1,59 +1,87 @@ # week08/.github/workflows/frontend_ci.yml -name: Frontend CI - Build & Push Image +name: Frontend CI - Build & Push Image (Router) on: - # Manual trigger + # 1. Independent CI Trigger (Development Branch Testing) workflow_dispatch: - - # Automatically on pushes to main branch push: branches: - development - paths: # Only trigger if changes are in the frontend directory + - main + paths: - 'frontend/**' - - '.github/workflows/frontend_ci.yml' # Trigger if this workflow file changes + - '.github/workflows/frontend_ci.yml' pull_request: branches: - - main + - main paths: - - 'backend/**' + - 'frontend/**' - '.github/workflows/frontend_ci.yml' - -# Define global environment variables that can be used across jobs + + # 2. CD Chain Linkage Trigger + workflow_call: # <--- CRITICAL FIX: Allows this workflow to be called by backend-cd.yml + inputs: + product_api_ip: { required: true, type: string } # <--- Receives IP 1 + order_api_ip: { required: true, type: string } # <--- Receives IP 2 + aks_cluster_name: { required: true, type: string } + aks_resource_group: { required: true, type: string } + secrets: + azure_credentials: { required: true } + +# Define global environment variables 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: CI - Build and Push Frontend Image build_and_push_frontend: runs-on: ubuntu-latest - + + # CRITICAL: This job needs access to the secrets/inputs if called + secrets: inherit # <--- NEW: Allows secrets to be passed from the caller + 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 }} + # ... (Existing Checkout, Azure Login, ACR Login, Build/Push steps remain here) ... + + - name: Checkout repository + uses: actions/checkout@v4 + - name: Azure Login + uses: azure/login@v1 + # Uses the secret inherited from the workflow_call trigger + with: + creds: ${{ secrets.azure_credentials }} - # 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 + # (Other build steps here...) - # Logout from Azure for security (runs even if image push fails) - - name: Logout from Azure - run: az logout - if: always() + - name: Build and Push Frontend Image + # ... (Your Docker build/push commands here) ... + run: | + docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/ + docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest + + # (Other steps...) + + # ---------------------------------------------------------------------- + # JOB 2: LINKAGE TO FRONTEND CD (THE FINAL STEP) + # ---------------------------------------------------------------------- + trigger_frontend_cd: + runs-on: ubuntu-latest + needs: build_and_push_frontend # Wait for the image to be built and pushed + + # CRITICAL GATE: Only call the CD file when running as part of the main branch CD chain + # We use github.event_name == 'workflow_call' to reliably detect the CD chain + if: github.event_name == 'workflow_call' || github.ref == 'refs/heads/main' # <--- UPDATED: Ensure it runs when called or when triggered directly by main + + steps: + - name: "Call Frontend CD Workflow (Deploy)" + uses: ./.github/workflows/frontend-cd.yml + with: + # Pass the IPs received by this workflow to the final deployment file + product_api_ip: ${{ inputs.product_api_ip }} # <--- Passes received IP + order_api_ip: ${{ inputs.order_api_ip }} # <--- Passes received IP + aks_cluster_name: ${{ inputs.aks_cluster_name }} + aks_resource_group: ${{ inputs.aks_resource_group }} + secrets: + azure_credentials: ${{ secrets.azure_credentials }} # Pass the secret along \ No newline at end of file From 87a415477b2a2345059f88bf88640ccf16f9d1b1 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 10:39:22 +1000 Subject: [PATCH 07/36] frontend --- .github/workflows/frontend_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 3531ad52..f3dc81c9 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -1,4 +1,4 @@ -# week08/.github/workflows/frontend_ci.yml +# week08/.github/workflows/frontend_ci.ymlsds name: Frontend CI - Build & Push Image (Router) From 9cd2912f5c97d47f8b4ad26398eac0117633ca0d Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 10:48:36 +1000 Subject: [PATCH 08/36] pipeline for development --- .github/workflows/backend_ci.yml | 2 +- .github/workflows/frontend_ci.yml | 44 +++++++++++++++---------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 0706dcd2..398e09f3 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -12,7 +12,7 @@ on: push: branches: - development - - main # <-- UPDATED: Now triggers when code is merged into main + - main # <-- UPDATED: Now triggers when code is merged into mai paths: # Only trigger if changes are in backend directories - 'backend/**' - '.github/workflows/backend_ci.yml' # Trigger if this workflow file changes diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index f3dc81c9..52904506 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -1,4 +1,4 @@ -# week08/.github/workflows/frontend_ci.ymlsds +# week08/.github/workflows/frontend_ci.yml name: Frontend CI - Build & Push Image (Router) @@ -19,11 +19,11 @@ on: - 'frontend/**' - '.github/workflows/frontend_ci.yml' - # 2. CD Chain Linkage Trigger - workflow_call: # <--- CRITICAL FIX: Allows this workflow to be called by backend-cd.yml + # 2. CD Chain Linkage Trigger (Called by backend-cd.yml) + workflow_call: inputs: - product_api_ip: { required: true, type: string } # <--- Receives IP 1 - order_api_ip: { required: true, type: string } # <--- Receives IP 2 + 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 } secrets: @@ -39,29 +39,26 @@ jobs: build_and_push_frontend: runs-on: ubuntu-latest - # CRITICAL: This job needs access to the secrets/inputs if called - secrets: inherit # <--- NEW: Allows secrets to be passed from the caller + # CRITICAL FIX 1: REMOVED 'secrets: inherit' + # Secrets are accessed directly in the steps below. steps: - # ... (Existing Checkout, Azure Login, ACR Login, Build/Push steps remain here) ... - - name: Checkout repository uses: actions/checkout@v4 + - name: Azure Login uses: azure/login@v1 - # Uses the secret inherited from the workflow_call trigger with: - creds: ${{ secrets.azure_credentials }} - - # (Other build steps here...) + # Access the secret directly using the repository secret name (AZURE_CREDENTIALS). + # This works for both 'push' and 'workflow_call' events. + creds: ${{ secrets.AZURE_CREDENTIALS }} - name: Build and Push Frontend Image - # ... (Your Docker build/push commands here) ... run: | + # Use your ACR Login to push the image + az acr login --name ${{ env.ACR_LOGIN_SERVER }} docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/ docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest - - # (Other steps...) # ---------------------------------------------------------------------- # JOB 2: LINKAGE TO FRONTEND CD (THE FINAL STEP) @@ -70,18 +67,19 @@ jobs: runs-on: ubuntu-latest needs: build_and_push_frontend # Wait for the image to be built and pushed - # CRITICAL GATE: Only call the CD file when running as part of the main branch CD chain - # We use github.event_name == 'workflow_call' to reliably detect the CD chain - if: github.event_name == 'workflow_call' || github.ref == 'refs/heads/main' # <--- UPDATED: Ensure it runs when called or when triggered directly by main + # Only call the CD file when running as part of the main branch CD chain + if: github.event_name == 'workflow_call' || github.ref == 'refs/heads/main' steps: - name: "Call Frontend CD Workflow (Deploy)" uses: ./.github/workflows/frontend-cd.yml with: # Pass the IPs received by this workflow to the final deployment file - product_api_ip: ${{ inputs.product_api_ip }} # <--- Passes received IP - order_api_ip: ${{ inputs.order_api_ip }} # <--- Passes received IP + product_api_ip: ${{ inputs.product_api_ip }} + order_api_ip: ${{ inputs.order_api_ip }} aks_cluster_name: ${{ inputs.aks_cluster_name }} aks_resource_group: ${{ inputs.aks_resource_group }} - secrets: - azure_credentials: ${{ secrets.azure_credentials }} # Pass the secret along \ No newline at end of file + # CRITICAL FIX 2: Corrected Indentation for 'secrets:' + # 'secrets' must be a sibling to 'uses' and 'with' + secrets: + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} # Pass the secret along \ No newline at end of file From 0b511b3fb8d390256799272c3387fa3911585c6b Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 10:50:14 +1000 Subject: [PATCH 09/36] pipeline for development --- .github/workflows/frontend_ci.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 52904506..6cbf76ca 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -39,8 +39,7 @@ jobs: build_and_push_frontend: runs-on: ubuntu-latest - # CRITICAL FIX 1: REMOVED 'secrets: inherit' - # Secrets are accessed directly in the steps below. + # Secrets inherit removed (was causing error) steps: - name: Checkout repository @@ -49,8 +48,7 @@ jobs: - name: Azure Login uses: azure/login@v1 with: - # Access the secret directly using the repository secret name (AZURE_CREDENTIALS). - # This works for both 'push' and 'workflow_call' events. + # Use the repository secret name directly. creds: ${{ secrets.AZURE_CREDENTIALS }} - name: Build and Push Frontend Image @@ -65,7 +63,7 @@ jobs: # ---------------------------------------------------------------------- trigger_frontend_cd: runs-on: ubuntu-latest - needs: build_and_push_frontend # Wait for the image to be built and pushed + needs: build_and_push_frontend # Only call the CD file when running as part of the main branch CD chain if: github.event_name == 'workflow_call' || github.ref == 'refs/heads/main' @@ -79,7 +77,6 @@ jobs: order_api_ip: ${{ inputs.order_api_ip }} aks_cluster_name: ${{ inputs.aks_cluster_name }} aks_resource_group: ${{ inputs.aks_resource_group }} - # CRITICAL FIX 2: Corrected Indentation for 'secrets:' - # 'secrets' must be a sibling to 'uses' and 'with' + # CRITICAL FIX: Secrets must be a sibling to 'with:' secrets: azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} # Pass the secret along \ No newline at end of file From 6748377cdc2dba0e6f4a7fdd37ab1084ab988627 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 10:51:46 +1000 Subject: [PATCH 10/36] pipeline for development --- .github/workflows/frontend_ci.yml | 34 ++++++++----------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 6cbf76ca..d4efbc9f 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -1,5 +1,3 @@ -# week08/.github/workflows/frontend_ci.yml - name: Frontend CI - Build & Push Image (Router) on: @@ -38,9 +36,6 @@ jobs: # JOB 1: CI - Build and Push Frontend Image build_and_push_frontend: runs-on: ubuntu-latest - - # Secrets inherit removed (was causing error) - steps: - name: Checkout repository uses: actions/checkout@v4 @@ -48,12 +43,10 @@ jobs: - name: Azure Login uses: azure/login@v1 with: - # Use the repository secret name directly. creds: ${{ secrets.AZURE_CREDENTIALS }} - name: Build and Push Frontend Image run: | - # Use your ACR Login to push the image az acr login --name ${{ env.ACR_LOGIN_SERVER }} docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/ docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest @@ -62,21 +55,12 @@ jobs: # JOB 2: LINKAGE TO FRONTEND CD (THE FINAL STEP) # ---------------------------------------------------------------------- trigger_frontend_cd: - runs-on: ubuntu-latest - needs: build_and_push_frontend - - # Only call the CD file when running as part of the main branch CD chain - if: github.event_name == 'workflow_call' || github.ref == 'refs/heads/main' - - steps: - - name: "Call Frontend CD Workflow (Deploy)" - uses: ./.github/workflows/frontend-cd.yml - with: - # Pass the IPs received by this workflow to the final deployment file - product_api_ip: ${{ inputs.product_api_ip }} - order_api_ip: ${{ inputs.order_api_ip }} - aks_cluster_name: ${{ inputs.aks_cluster_name }} - aks_resource_group: ${{ inputs.aks_resource_group }} - # CRITICAL FIX: Secrets must be a sibling to 'with:' - secrets: - azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} # Pass the secret along \ No newline at end of file + needs: build_and_push_frontend + if: github.event_name == 'workflow_call' || github.ref == 'refs/heads/main' + uses: ./.github/workflows/frontend-cd.yml + with: + product_api_ip: ${{ inputs.product_api_ip }} + order_api_ip: ${{ inputs.order_api_ip }} + aks_cluster_name: ${{ inputs.aks_cluster_name }} + aks_resource_group: ${{ inputs.aks_resource_group }} + secrets: inherit From f9329487317e870d479ca6a5ff3590d8a5a0b01a Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 10:57:55 +1000 Subject: [PATCH 11/36] Correct linkage and automatic trigger --- .github/workflows/backend_ci.yml | 1 + .github/workflows/frontend_ci.yml | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 398e09f3..6a920425 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -1,4 +1,5 @@ # week08/.github/workflows/backend_ci.yml +#test name: Backend CI - Test, Build and Push Images to ACR diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index d4efbc9f..9df48632 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -1,3 +1,4 @@ +#test name: Frontend CI - Build & Push Image (Router) on: @@ -8,7 +9,7 @@ on: - development - main paths: - - 'frontend/**' + - 'frontend/**' - '.github/workflows/frontend_ci.yml' pull_request: branches: From 081defe75827de544cbd3c7f6c34517890ef98f4 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 11:34:10 +1000 Subject: [PATCH 12/36] update piepline --- .github/workflows/backend-cd.yml | 84 ++++-------------- .github/workflows/backend_ci.yml | 139 ++++++++---------------------- .github/workflows/frontend-cd.yml | 77 +++-------------- .github/workflows/frontend_ci.yml | 46 +++------- 4 files changed, 79 insertions(+), 267 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 6c80876b..acb93369 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -1,10 +1,7 @@ name: CD - Deploy Backend Services to AKS on: - # ---------------------------------------------------------------------- - # CRITICAL CHANGE: SWITCH TO WORKFLOW_CALL TO ENABLE AUTO-TRIGGERING - # ---------------------------------------------------------------------- - workflow_call: # <--- CRITICAL FIX: Enables calling from backend_ci.yml + workflow_call: inputs: aks_cluster_name: { required: true, type: string } aks_resource_group: { required: true, type: string } @@ -16,100 +13,49 @@ jobs: deploy_backend: runs-on: ubuntu-latest environment: Production - - # CRITICAL CHANGE: Update outputs to match the step IDs below outputs: - PRODUCT_API_IP: ${{ steps.ip_capture.outputs.PRODUCT_IP }} # <--- UPDATED - ORDER_API_IP: ${{ steps.ip_capture.outputs.ORDER_IP }} # <--- UPDATED + PRODUCT_API_IP: ${{ steps.ip_capture.outputs.PRODUCT_IP }} + ORDER_API_IP: ${{ steps.ip_capture.outputs.ORDER_IP }} steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Log in to Azure + - uses: actions/checkout@v4 + - name: Azure Login uses: azure/login@v1 with: - creds: ${{ secrets.azure_credentials }} # <--- UPDATED: Using `secrets` from workflow_call + creds: ${{ secrets.azure_credentials }} enable-AzPSSession: true - - - name: Set Kubernetes context (get AKS credentials) + - name: Set Kubernetes context run: | - # <--- UPDATED: Using `inputs` from workflow_call az aks get-credentials --resource-group ${{ inputs.aks_resource_group }} --name ${{ inputs.aks_cluster_name }} --overwrite-existing - - name: Attach ACR run: | - # <--- UPDATED: Using `inputs` from workflow_call az aks update --name ${{ inputs.aks_cluster_name }} --resource-group ${{ inputs.aks_resource_group }} --attach-acr ${{ inputs.aks_acr_name }} - - - name: Deploy Backend Infrastructure (Namespace, ConfigMaps, Secrets, Databases) + - name: Deploy Backend Infrastructure 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) - 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 - id: ip_capture # <--- CRITICAL FIX: Added ID to make outputs work + id: ip_capture run: | - echo "Waiting for Product, Order LoadBalancer IPs to be assigned (up to 5 minutes)..." + echo "Waiting for Product and Order IPs..." PRODUCT_IP="" ORDER_IP="" - for i in $(seq 1 60); do - echo "Attempt $i/60 to get IPs..." PRODUCT_IP=$(kubectl get service product-service-w08e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}') ORDER_IP=$(kubectl get service order-service-w08e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}') - if [[ -n "$PRODUCT_IP" && -n "$ORDER_IP" ]]; then - echo "All backend LoadBalancer IPs assigned!" - echo "Product Service IP: $PRODUCT_IP" - echo "Order Service IP: $ORDER_IP" - - # CRITICAL FIX: Publish the IPs as step outputs - echo "PRODUCT_IP=$PRODUCT_IP" >> "$GITHUB_OUTPUT" # <--- NEW: Set output for the next job - echo "ORDER_IP=$ORDER_IP" >> "$GITHUB_OUTPUT" # <--- NEW: Set output for the next job + echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_OUTPUT + echo "ORDER_IP=$ORDER_IP" >> $GITHUB_OUTPUT 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 "ERROR: Backend IPs not assigned" + exit 1 fi - - # Removed redundant IP environment setup, now using step outputs. - - # Removed redundant 'Capture IP for Workflow Output' steps - - - name: Logout from Azure - run: az logout - - # ---------------------------------------------------------------------- - # NEW JOB: LINKAGE TO FRONTEND CI - # ---------------------------------------------------------------------- - trigger_frontend_ci: - runs-on: ubuntu-latest - needs: deploy_backend # Waits for deployment and IP capture - steps: - - name: "Call Frontend CI Workflow" - uses: ./.github/workflows/frontend_ci.yml # Calls the next file - with: - # Pass the captured IPs from the previous job's outputs - product_api_ip: ${{ needs.deploy_backend.outputs.PRODUCT_API_IP }} - order_api_ip: ${{ needs.deploy_backend.outputs.ORDER_API_IP }} - # Pass cluster details received by this workflow - aks_cluster_name: ${{ inputs.aks_cluster_name }} - aks_resource_group: ${{ inputs.aks_resource_group }} - secrets: - azure_credentials: ${{ secrets.azure_credentials }} # Pass the secret \ No newline at end of file diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 6a920425..edfae8a3 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -1,52 +1,33 @@ -# week08/.github/workflows/backend_ci.yml -#test - 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 + # CI runs on any push to development or main push: branches: - - development - - main # <-- UPDATED: Now triggers when code is merged into mai - paths: # Only trigger if changes are in backend directories - - 'backend/**' - - '.github/workflows/backend_ci.yml' # Trigger if this workflow file changes + - development + - main + + # CI runs on PRs to main pull_request: branches: - - main                             - paths: - - 'backend/**' - - '.github/workflows/backend_ci.yml' + - main -# Define global environment variables that can be used across jobs env: - # ACR Login Server (e.g., myregistry.azurecr.io) - # This needs to be set as a GitHub Repository Secret ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} - # Dynamically generate image tags based on Git SHA and GitHub Run ID - # This provides unique, traceable tags for each image build IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} jobs: - # Job 1: Run tests and linting for all backend services test_and_lint_backends: - runs-on: ubuntu-latest # Use a GitHub-hosted runner - + runs-on: ubuntu-latest services: - # Product DB container product_db: image: postgres:15 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: products - # Make pg_isready available so the service is healthy before tests run options: >- --health-cmd "pg_isready -U postgres" --health-interval 10s @@ -54,46 +35,32 @@ jobs: --health-retries 5 ports: - 5432:5432 - - # Order DB order_db: image: postgres:15 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: orders - ports: - - 5433:5432 options: >- --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5 + ports: + - 5433:5432 steps: - # 1. Checkout the repository code to the runner - - name: Checkout repository - uses: actions/checkout@v4 # Action to check out your repository code - - # 2. Set up Python environment - - name: Set up Python 3.10 - uses: actions/setup-python@v5 # Action to set up Python environment + - uses: actions/checkout@v4 + - 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: @@ -102,10 +69,7 @@ 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: @@ -114,62 +78,35 @@ jobs: POSTGRES_DB: orders POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - run: | - pytest tests --maxfail=1 --disable-warnings -q + run: pytest tests --maxfail=1 --disable-warnings -q - # Job 2: Build and Push Docker Images (runs only if tests pass) build_and_push_images: runs-on: ubuntu-latest needs: test_and_lint_backends + if: github.ref == 'refs/heads/main' # Only run full CD pipeline on main 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() - - # ---------------------------------------------------------------------- - # NEW JOB: LINKAGE TO THE CD PIPELINE - # ---------------------------------------------------------------------- - trigger_backend_cd: # <-- NEW JOB NAME - runs-on: ubuntu-latest - needs: build_and_push_images # <-- Ensure images are built before triggering CD - - # CRITICAL GATE: Only execute deployment when merged into 'main' - if: github.ref == 'refs/heads/main' # <-- NEW CONDITION - - steps: - - name: "Call Backend CD Workflow" # <-- NEW STEP - # This calls the backend-cd.yml file directly, linking the workflows - uses: ./.github/workflows/backend-cd.yml + - uses: actions/checkout@v4 + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + - name: Login to ACR + run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} + - name: Build and Push Product Service Image + run: | + docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:latest ./backend/product_service/ + docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:latest + - name: Build and Push Order Service Image + run: | + docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:latest ./backend/order_service/ + docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:latest + - name: Trigger Backend CD + uses: ./.github/workflows/backend-cd.yml with: - # Pass required deployment details to the CD workflow - aks_cluster_name: 'ishaanAKS' # <-- Update with your cluster name - aks_resource_group: 'deakinuni' # <-- Update with your resource group - aks_acr_name: ${{ env.ACR_LOGIN_SERVER }} - azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} \ No newline at end of file + aks_cluster_name: 'ishaanAKS' + aks_resource_group: 'deakinuni' + aks_acr_name: ${{ env.ACR_LOGIN_SERVER }} + secrets: inherit + - name: Logout from Azure + run: az logout diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml index 27931888..a06200f8 100644 --- a/.github/workflows/frontend-cd.yml +++ b/.github/workflows/frontend-cd.yml @@ -1,90 +1,37 @@ -# week08/.github/workflows/frontend-cd.yml - name: CD - Deploy Frontend to AKS on: - workflow_dispatch: - inputs: - product_api_ip: - description: 'External IP of Product Service' - required: true - default: '0.0.0.0' - order_api_ip: - description: 'External IP of Order Service' - required: true - default: '0.0.0.0' - aks_cluster_name: - description: 'Name of the AKS Cluster to deploy to' - required: true - default: 'ishaanAKS' - aks_resource_group: - description: 'Resource Group of the AKS Cluster' - required: true - default: 'deakinuni' - - # CRITICAL: This is how it's called by frontend_ci.yml 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 - # CRITICAL FIX: Must define which secrets are required by this workflow + 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 } secrets: - azure_credentials: { required: true } # <--- ADDED SECRET HERE - + azure_credentials: { required: true } + jobs: deploy_frontend: runs-on: ubuntu-latest environment: Production - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # Azure login using the secret passed via workflow_call + - uses: actions/checkout@v4 - name: Azure Login uses: azure/login@v1 with: - # CRITICAL FIX: Use the secret passed from the caller - creds: ${{ secrets.azure_credentials }} - - # --- OPTIMISATION: REMOVED ACR Login, Inject IPs, and Build/Push steps --- - # These steps were already done by frontend_ci.yml (Step 3 in the chain). - # The IP linkage will now be done with a robust `kubectl` command. - - - name: Set Kubernetes context (get AKS credentials) + creds: ${{ secrets.azure_credentials }} + - name: Set Kubernetes context uses: azure/aks-set-context@v3 with: resource-group: ${{ inputs.aks_resource_group }} cluster-name: ${{ inputs.aks_cluster_name }} - - - name: Deploy Frontend to AKS (Apply Base Manifest) + - name: Deploy Frontend to AKS run: | - echo "Applying frontend base manifest to AKS cluster: ${{ inputs.aks_cluster_name }}" cd k8s/ - # Deploy the base frontend service/deployment kubectl apply -f frontend.yaml - - # CRITICAL NEW STEP: Configure Frontend Deployment with Backend IPs - # This is the most reliable way to link the services in AKS - - name: Configure Frontend Deployment with Backend IPs - run: | - echo "Setting backend IP environment variables on frontend deployment..." - # Pass the IPs as environment variables to the live Kubernetes deployment - # Note: Adjust 'frontend-w08e1' if your deployment name is different in frontend.yaml kubectl set env deployment/frontend-w08e1 \ PRODUCT_API_URL=http://${{ inputs.product_api_ip }}:80 \ ORDER_API_URL=http://${{ inputs.order_api_ip }}:80 \ - --overwrite - + --overwrite - name: Logout from Azure - run: az logout \ No newline at end of file + run: az logout diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 9df48632..f90a63f5 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -1,24 +1,14 @@ -#test -name: Frontend CI - Build & Push Image (Router) +name: Frontend CI - Build and Push Image on: - # 1. Independent CI Trigger (Development Branch Testing) workflow_dispatch: push: branches: - development - main - paths: - - 'frontend/**' - - '.github/workflows/frontend_ci.yml' pull_request: branches: - main - paths: - - 'frontend/**' - - '.github/workflows/frontend_ci.yml' - - # 2. CD Chain Linkage Trigger (Called by backend-cd.yml) workflow_call: inputs: product_api_ip: { required: true, type: string } @@ -28,40 +18,32 @@ on: secrets: azure_credentials: { required: true } -# Define global environment variables env: ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} jobs: - # JOB 1: CI - Build and Push Frontend Image build_and_push_frontend: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v4 - + - uses: actions/checkout@v4 - name: Azure Login uses: azure/login@v1 with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - + creds: ${{ secrets.azure_credentials }} - name: Build and Push Frontend Image run: | az acr login --name ${{ env.ACR_LOGIN_SERVER }} docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/ docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest - - # ---------------------------------------------------------------------- - # JOB 2: LINKAGE TO FRONTEND CD (THE FINAL STEP) - # ---------------------------------------------------------------------- - trigger_frontend_cd: - needs: build_and_push_frontend - if: github.event_name == 'workflow_call' || github.ref == 'refs/heads/main' - uses: ./.github/workflows/frontend-cd.yml - with: - product_api_ip: ${{ inputs.product_api_ip }} - order_api_ip: ${{ inputs.order_api_ip }} - aks_cluster_name: ${{ inputs.aks_cluster_name }} - aks_resource_group: ${{ inputs.aks_resource_group }} - secrets: inherit + - name: Trigger Frontend CD + if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_call' + uses: ./.github/workflows/frontend-cd.yml + with: + product_api_ip: ${{ inputs.product_api_ip }} + order_api_ip: ${{ inputs.order_api_ip }} + aks_cluster_name: ${{ inputs.aks_cluster_name }} + aks_resource_group: ${{ inputs.aks_resource_group }} + secrets: inherit + - name: Logout from Azure + run: az logout From f193db768a20d5e1fbed9ec9c41ad7f645040453 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 14:08:31 +1000 Subject: [PATCH 13/36] testing push trigger backend.ci --- .github/workflows/backend_ci.yml | 129 +++++++++---------------------- 1 file changed, 38 insertions(+), 91 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 0706dcd2..f6f1e83c 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -1,51 +1,35 @@ -# week08/.github/workflows/backend_ci.yml - name: Backend CI - Test, Build and Push Images to ACR -# Trigger the workflow on pushes to the 'main' branch -# You can also add 'pull_request:' to run on PRs on: - # Manual trigger workflow_dispatch: - - # Automatically on pushes to main branch push: branches: - - development - - main # <-- UPDATED: Now triggers when code is merged into main - paths: # Only trigger if changes are in backend directories + - development + - main + paths: - 'backend/**' - - '.github/workflows/backend_ci.yml' # Trigger if this workflow file changes + - '.github/workflows/backend_ci.yml' pull_request: branches: - - main                             + - main paths: - 'backend/**' - '.github/workflows/backend_ci.yml' -# Define global environment variables that can be used across jobs env: - # ACR Login Server (e.g., myregistry.azurecr.io) - # This needs to be set as a GitHub Repository Secret ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} - # Dynamically generate image tags based on Git SHA and GitHub Run ID - # This provides unique, traceable tags for each image build IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} jobs: - # Job 1: Run tests and linting for all backend services test_and_lint_backends: - runs-on: ubuntu-latest # Use a GitHub-hosted runner - + runs-on: ubuntu-latest services: - # Product DB container product_db: image: postgres:15 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: products - # Make pg_isready available so the service is healthy before tests run options: >- --health-cmd "pg_isready -U postgres" --health-interval 10s @@ -53,46 +37,39 @@ jobs: --health-retries 5 ports: - 5432:5432 - - # Order DB + order_db: image: postgres:15 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: orders - ports: - - 5433:5432 options: >- --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5 + ports: + - 5433:5432 steps: - # 1. Checkout the repository code to the runner - name: Checkout repository - uses: actions/checkout@v4 # Action to check out your repository code + uses: actions/checkout@v4 - # 2. Set up Python environment - name: Set up Python 3.10 - uses: actions/setup-python@v5 # Action to set up Python environment + uses: actions/setup-python@v5 with: python-version: '3.10' - # 3. Install dependencies and run code quality checks - name: Install dependencies - run: | # Use a multi-line script to install pip dependencies + run: | pip install --upgrade pip - # Loop through each backend service folder for req in backend/*/requirements.txt; do echo "Installing $req" pip install -r "$req" done - # Install CI tools pip install pytest httpx - # 5. Run tests for product service - name: Run product_service tests working-directory: backend/product_service env: @@ -101,10 +78,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: @@ -113,62 +88,34 @@ jobs: POSTGRES_DB: orders POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - run: | - pytest tests --maxfail=1 --disable-warnings -q + run: pytest tests --maxfail=1 --disable-warnings -q - # Job 2: Build and Push Docker Images (runs only if tests pass) build_and_push_images: runs-on: ubuntu-latest needs: test_and_lint_backends 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() - - # ---------------------------------------------------------------------- - # NEW JOB: LINKAGE TO THE CD PIPELINE - # ---------------------------------------------------------------------- - trigger_backend_cd: # <-- NEW JOB NAME - runs-on: ubuntu-latest - needs: build_and_push_images # <-- Ensure images are built before triggering CD - - # CRITICAL GATE: Only execute deployment when merged into 'main' - if: github.ref == 'refs/heads/main' # <-- NEW CONDITION - - steps: - - name: "Call Backend CD Workflow" # <-- NEW STEP - # This calls the backend-cd.yml file directly, linking the workflows - uses: ./.github/workflows/backend-cd.yml + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 with: - # Pass required deployment details to the CD workflow - aks_cluster_name: 'ishaanAKS' # <-- Update with your cluster name - aks_resource_group: 'deakinuni' # <-- Update with your resource group - aks_acr_name: ${{ env.ACR_LOGIN_SERVER }} - azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} \ No newline at end of file + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Login to Azure Container Registry + run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} + + - name: Build and Push Product Service Image + run: | + docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:latest ./backend/product_service/ + docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:latest + + - name: Build and Push Order Service Image + run: | + docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:latest ./backend/order_service/ + docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:latest + + - name: Logout from Azure + run: az logout + if: always() From 00dee428b967c56418b38367794fd8ade27023c7 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 14:15:48 +1000 Subject: [PATCH 14/36] testing automatic trigger by push --- .github/workflows/backend_ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index f6f1e83c..9ed35902 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -119,3 +119,4 @@ jobs: - name: Logout from Azure run: az logout if: always() +#test \ No newline at end of file From aaefd16d64df053f6d324e635f116b3e2bec15a8 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 14:31:31 +1000 Subject: [PATCH 15/36] updated frontend and secrets --- .github/workflows/frontend_ci.yml | 59 +++++-------------------------- k8s/secrets.yaml | 2 +- 2 files changed, 10 insertions(+), 51 deletions(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 3531ad52..fde62770 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -1,9 +1,6 @@ -# week08/.github/workflows/frontend_ci.yml - name: Frontend CI - Build & Push Image (Router) on: - # 1. Independent CI Trigger (Development Branch Testing) workflow_dispatch: push: branches: @@ -18,70 +15,32 @@ on: paths: - 'frontend/**' - '.github/workflows/frontend_ci.yml' - - # 2. CD Chain Linkage Trigger - workflow_call: # <--- CRITICAL FIX: Allows this workflow to be called by backend-cd.yml - inputs: - product_api_ip: { required: true, type: string } # <--- Receives IP 1 - order_api_ip: { required: true, type: string } # <--- Receives IP 2 - aks_cluster_name: { required: true, type: string } - aks_resource_group: { required: true, type: string } - secrets: - azure_credentials: { required: true } -# Define global environment variables env: ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} jobs: - # JOB 1: CI - Build and Push Frontend Image build_and_push_frontend: runs-on: ubuntu-latest - - # CRITICAL: This job needs access to the secrets/inputs if called - secrets: inherit # <--- NEW: Allows secrets to be passed from the caller - + steps: - # ... (Existing Checkout, Azure Login, ACR Login, Build/Push steps remain here) ... - - name: Checkout repository uses: actions/checkout@v4 + - name: Azure Login uses: azure/login@v1 - # Uses the secret inherited from the workflow_call trigger with: - creds: ${{ secrets.azure_credentials }} + creds: ${{ secrets.AZURE_CREDENTIALS }} - # (Other build steps here...) + - name: Login to Azure Container Registry + run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} - name: Build and Push Frontend Image - # ... (Your Docker build/push commands here) ... run: | docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/ docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest - - # (Other steps...) - - # ---------------------------------------------------------------------- - # JOB 2: LINKAGE TO FRONTEND CD (THE FINAL STEP) - # ---------------------------------------------------------------------- - trigger_frontend_cd: - runs-on: ubuntu-latest - needs: build_and_push_frontend # Wait for the image to be built and pushed - - # CRITICAL GATE: Only call the CD file when running as part of the main branch CD chain - # We use github.event_name == 'workflow_call' to reliably detect the CD chain - if: github.event_name == 'workflow_call' || github.ref == 'refs/heads/main' # <--- UPDATED: Ensure it runs when called or when triggered directly by main - - steps: - - name: "Call Frontend CD Workflow (Deploy)" - uses: ./.github/workflows/frontend-cd.yml - with: - # Pass the IPs received by this workflow to the final deployment file - product_api_ip: ${{ inputs.product_api_ip }} # <--- Passes received IP - order_api_ip: ${{ inputs.order_api_ip }} # <--- Passes received IP - aks_cluster_name: ${{ inputs.aks_cluster_name }} - aks_resource_group: ${{ inputs.aks_resource_group }} - secrets: - azure_credentials: ${{ secrets.azure_credentials }} # Pass the secret along \ No newline at end of file + + - name: Logout from Azure + run: az logout +#test \ No newline at end of file diff --git a/k8s/secrets.yaml b/k8s/secrets.yaml index 19d284f5..eb043b55 100644 --- a/k8s/secrets.yaml +++ b/k8s/secrets.yaml @@ -15,4 +15,4 @@ data: # Example: echo -n 'myblobstorageaccount' | base64 AZURE_STORAGE_ACCOUNT_NAME: "aXNoYWFuc3RvcmFnZWFjY291bnQ=" # Example: echo -n 'your_storage_account_key_string' | base64 - AZURE_STORAGE_ACCOUNT_KEY: "aXU4OTlQamNFUVFvaURyZGpNVXdNaUQ1TnBjNTN1Wmc5VVdPTHVoSDQ0YjB0anl3bFJINUc2MzZISERNNEpIbW5vakd0TkJXL2dScCtBU3RpeVhCWFE9PQ==" + AZURE_STORAGE_ACCOUNT_KEY: "SGdqRkdZZUJkVEJDWjBQMUlaL2xnZzQ1YTJDTlR0T2pZaEV3UytIbGd2ZXJVT0ZqbCtDOWdDUi9kUXMzdnhBUjZvYzhOREVqOUpLRStBU3Q1VVFBUXc9PQ==" From 215623ad4a376f72694e690f72e4c4133053f976 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 15:07:25 +1000 Subject: [PATCH 16/36] linkage backedn ci to frontend cd --- .github/workflows/backend-cd.yml | 84 ++++++++++++++++++++++-------- .github/workflows/backend_ci.yml | 11 ++++ .github/workflows/frontend-cd.yml | 86 +++++++++++++++++++++++++------ 3 files changed, 144 insertions(+), 37 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index acb93369..79ba8269 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -1,61 +1,101 @@ name: CD - Deploy Backend Services to AKS on: - workflow_call: + workflow_dispatch: inputs: - aks_cluster_name: { required: true, type: string } - aks_resource_group: { required: true, type: string } - aks_acr_name: { required: true, type: string } - secrets: - azure_credentials: { required: true } + aks_cluster_name: + description: 'Name of the AKS Cluster to deploy to' + required: true + default: 'ishaanAKS' + aks_resource_group: + description: 'Resource Group of the AKS Cluster' + required: true + default: 'deakinuni' + aks_acr_name: + description: 'Name of ACR' + required: true + default: 'ishaan' jobs: deploy_backend: runs-on: ubuntu-latest environment: Production + outputs: - PRODUCT_API_IP: ${{ steps.ip_capture.outputs.PRODUCT_IP }} - ORDER_API_IP: ${{ steps.ip_capture.outputs.ORDER_IP }} + PRODUCT_API_IP: ${{ steps.get_product_ip.outputs.external_ip }} + ORDER_API_IP: ${{ steps.get_order_ip.outputs.external_ip }} steps: - - uses: actions/checkout@v4 - - name: Azure Login + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to Azure uses: azure/login@v1 with: - creds: ${{ secrets.azure_credentials }} + creds: ${{ secrets.AZURE_CREDENTIALS }} enable-AzPSSession: true - - name: Set Kubernetes context + + - name: Set Kubernetes context (get AKS credentials) run: | - az aks get-credentials --resource-group ${{ inputs.aks_resource_group }} --name ${{ 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 aks update --name ${{ inputs.aks_cluster_name }} --resource-group ${{ inputs.aks_resource_group }} --attach-acr ${{ inputs.aks_acr_name }} - - name: Deploy Backend Infrastructure + az aks update --name ${{ github.event.inputs.aks_cluster_name }} --resource-group ${{ github.event.inputs.aks_resource_group }} --attach-acr ${{ github.event.inputs.aks_acr_name }} + + - name: Deploy Backend Infrastructure (Namespace, ConfigMaps, Secrets, Databases) run: | + echo "Deploying backend infrastructure..." cd k8s/ kubectl apply -f configmaps.yaml kubectl apply -f secrets.yaml kubectl apply -f product-db.yaml kubectl apply -f order-db.yaml + + - name: Deploy Backend Microservices (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 - id: ip_capture run: | - echo "Waiting for Product and Order IPs..." + echo "Waiting for Product, Order LoadBalancer IPs to be assigned (up to 5 minutes)..." PRODUCT_IP="" ORDER_IP="" + for i in $(seq 1 60); do + echo "Attempt $i/60 to get IPs..." PRODUCT_IP=$(kubectl get service product-service-w08e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}') ORDER_IP=$(kubectl get service order-service-w08e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + if [[ -n "$PRODUCT_IP" && -n "$ORDER_IP" ]]; then - echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_OUTPUT - echo "ORDER_IP=$ORDER_IP" >> $GITHUB_OUTPUT + echo "All backend LoadBalancer IPs assigned!" + echo "Product Service IP: $PRODUCT_IP" + echo "Order Service IP: $ORDER_IP" break fi - sleep 5 + sleep 5 # Wait 5 seconds before next attempt done + if [[ -z "$PRODUCT_IP" || -z "$ORDER_IP" ]]; then - echo "ERROR: Backend IPs not assigned" - exit 1 + echo "Error: One or more LoadBalancer IPs not assigned after timeout." + exit 1 # Fail the job if IPs are not obtained fi + + # These are environment variables for subsequent steps in the *same job* + # And used to set the job outputs + echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_ENV + echo "ORDER_IP=$ORDER_IP" >> $GITHUB_ENV + + - name: Capture Product Service IP for Workflow Output + id: get_product_ip + run: echo "external_ip=${{ env.PRODUCT_IP }}" >> $GITHUB_OUTPUT + + - name: Capture Order Service IP for Workflow Output + id: get_order_ip + run: echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT + + - name: Logout from Azure + run: az logout \ No newline at end of file diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 3d3dc3c3..b36aa2e8 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -119,4 +119,15 @@ jobs: - name: Logout from Azure run: az logout if: always() + # At the end of your backend_ci.yml + trigger_backend_cd: + needs: build_and_push_images + if: github.ref == 'refs/heads/main' + uses: ./.github/workflows/backend-cd.yml + with: + aks_cluster_name: "ishaanAKS" + aks_resource_group: "deakinuni" + aks_acr_name: "ishaan" + secrets: + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} #test \ No newline at end of file diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml index a06200f8..0549949a 100644 --- a/.github/workflows/frontend-cd.yml +++ b/.github/workflows/frontend-cd.yml @@ -1,37 +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://:8000' + order_api_ip: + description: 'External IP of Order Service (e.g., http://Y.Y.Y.Y:8001)' + required: true + default: 'http://:8001' + aks_cluster_name: + description: 'Name of the AKS Cluster to deploy to' + required: true + default: 'ishaanAKS' + 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 } - secrets: - azure_credentials: { required: true } + 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: - - uses: actions/checkout@v4 + - 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 }} - - name: Set Kubernetes context + 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 - kubectl set env deployment/frontend-w08e1 \ - PRODUCT_API_URL=http://${{ inputs.product_api_ip }}:80 \ - ORDER_API_URL=http://${{ inputs.order_api_ip }}:80 \ - --overwrite - - name: Logout from Azure - run: az logout + + - name: Logout from Azure (AKS deployment) + run: az logout \ No newline at end of file From 9569f880ee92e6fae73476e11d053090b21a373b Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 15:09:49 +1000 Subject: [PATCH 17/36] Test backend ci to backend cd --- .github/workflows/backend_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 9ed35902..e31afcda 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -119,4 +119,4 @@ jobs: - name: Logout from Azure run: az logout if: always() -#test \ No newline at end of file +#tes \ No newline at end of file From c7fda7560f9af91f86921af7d1d9ee3200ba6671 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 15:12:13 +1000 Subject: [PATCH 18/36] Test backend ci to backend cd --- .github/workflows/backend-cd.yml | 86 ++++++++++++++++---------------- .github/workflows/backend_ci.yml | 2 +- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 6c80876b..268bcb45 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -1,26 +1,45 @@ name: CD - Deploy Backend Services to AKS on: - # ---------------------------------------------------------------------- - # CRITICAL CHANGE: SWITCH TO WORKFLOW_CALL TO ENABLE AUTO-TRIGGERING - # ---------------------------------------------------------------------- - workflow_call: # <--- CRITICAL FIX: Enables calling from backend_ci.yml + workflow_dispatch: inputs: - aks_cluster_name: { required: true, type: string } - aks_resource_group: { required: true, type: string } - aks_acr_name: { required: true, type: string } + aks_cluster_name: + description: 'Name of the AKS Cluster to deploy to' + required: true + default: 'ishaanAKS' + aks_resource_group: + description: 'Resource Group of the AKS Cluster' + required: true + default: 'deakinuni' + aks_acr_name: + description: 'Name of ACR' + required: true + default: 'ishaan' + + # Add this workflow_call trigger + workflow_call: + inputs: + aks_cluster_name: + required: true + type: string + aks_resource_group: + required: true + type: string + aks_acr_name: + required: true + type: string secrets: - azure_credentials: { required: true } + azure_credentials: + required: true jobs: deploy_backend: runs-on: ubuntu-latest environment: Production - # CRITICAL CHANGE: Update outputs to match the step IDs below outputs: - PRODUCT_API_IP: ${{ steps.ip_capture.outputs.PRODUCT_IP }} # <--- UPDATED - ORDER_API_IP: ${{ steps.ip_capture.outputs.ORDER_IP }} # <--- UPDATED + PRODUCT_API_IP: ${{ steps.get_product_ip.outputs.external_ip }} + ORDER_API_IP: ${{ steps.get_order_ip.outputs.external_ip }} steps: - name: Checkout repository @@ -29,17 +48,15 @@ jobs: - name: Log in to Azure uses: azure/login@v1 with: - creds: ${{ secrets.azure_credentials }} # <--- UPDATED: Using `secrets` from workflow_call + creds: ${{ secrets.azure_credentials }} enable-AzPSSession: true - name: Set Kubernetes context (get AKS credentials) run: | - # <--- UPDATED: Using `inputs` from workflow_call az aks get-credentials --resource-group ${{ inputs.aks_resource_group }} --name ${{ inputs.aks_cluster_name }} --overwrite-existing - name: Attach ACR run: | - # <--- UPDATED: Using `inputs` from workflow_call az aks update --name ${{ inputs.aks_cluster_name }} --resource-group ${{ inputs.aks_resource_group }} --attach-acr ${{ inputs.aks_acr_name }} - name: Deploy Backend Infrastructure (Namespace, ConfigMaps, Secrets, Databases) @@ -59,7 +76,6 @@ jobs: kubectl apply -f order-service.yaml - name: Wait for Backend LoadBalancer IPs - id: ip_capture # <--- CRITICAL FIX: Added ID to make outputs work run: | echo "Waiting for Product, Order LoadBalancer IPs to be assigned (up to 5 minutes)..." PRODUCT_IP="" @@ -74,10 +90,6 @@ jobs: echo "All backend LoadBalancer IPs assigned!" echo "Product Service IP: $PRODUCT_IP" echo "Order Service IP: $ORDER_IP" - - # CRITICAL FIX: Publish the IPs as step outputs - echo "PRODUCT_IP=$PRODUCT_IP" >> "$GITHUB_OUTPUT" # <--- NEW: Set output for the next job - echo "ORDER_IP=$ORDER_IP" >> "$GITHUB_OUTPUT" # <--- NEW: Set output for the next job break fi sleep 5 # Wait 5 seconds before next attempt @@ -88,28 +100,18 @@ jobs: exit 1 # Fail the job if IPs are not obtained fi - # Removed redundant IP environment setup, now using step outputs. - - # Removed redundant 'Capture IP for Workflow Output' steps + # 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: Logout from Azure - run: az logout + - 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 - # ---------------------------------------------------------------------- - # NEW JOB: LINKAGE TO FRONTEND CI - # ---------------------------------------------------------------------- - trigger_frontend_ci: - runs-on: ubuntu-latest - needs: deploy_backend # Waits for deployment and IP capture - steps: - - name: "Call Frontend CI Workflow" - uses: ./.github/workflows/frontend_ci.yml # Calls the next file - with: - # Pass the captured IPs from the previous job's outputs - product_api_ip: ${{ needs.deploy_backend.outputs.PRODUCT_API_IP }} - order_api_ip: ${{ needs.deploy_backend.outputs.ORDER_API_IP }} - # Pass cluster details received by this workflow - aks_cluster_name: ${{ inputs.aks_cluster_name }} - aks_resource_group: ${{ inputs.aks_resource_group }} - secrets: - azure_credentials: ${{ secrets.azure_credentials }} # Pass the secret \ No newline at end of file + - name: Logout from Azure + run: az logout \ No newline at end of file diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index e31afcda..9ed35902 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -119,4 +119,4 @@ jobs: - name: Logout from Azure run: az logout if: always() -#tes \ No newline at end of file +#test \ No newline at end of file From d0cd24cb732f50973c13a4fac5bd96baf7d51f0f Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 15:15:01 +1000 Subject: [PATCH 19/36] Test backend ci to backend cd --- .github/workflows/backend_ci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 9ed35902..47d738ae 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -93,6 +93,7 @@ jobs: build_and_push_images: runs-on: ubuntu-latest needs: test_and_lint_backends + if: github.ref == 'refs/heads/main' # Only run on main branch steps: - name: Checkout repository @@ -119,4 +120,15 @@ jobs: - name: Logout from Azure run: az logout if: always() + + trigger_backend_cd: + needs: build_and_push_images + if: github.ref == 'refs/heads/main' + uses: ./.github/workflows/backend-cd.yml + with: + aks_cluster_name: "ishaanAKS" + aks_resource_group: "deakinuni" + aks_acr_name: "ishaan" + secrets: + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} #test \ No newline at end of file From 65e52ea5f5edb07234b35a0a81ac4bda6acee029 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:16:01 +1000 Subject: [PATCH 20/36] Frontend CI/CD pipeline --- .github/workflows/frontend_ci.yml | 12 ++++++++++++ frontend/main.js | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index fde62770..f2ab6515 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -23,6 +23,7 @@ env: jobs: build_and_push_frontend: runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' # Only build on main branch steps: - name: Checkout repository @@ -43,4 +44,15 @@ jobs: - name: Logout from Azure run: az logout + if: always() + + trigger_frontend_cd: + needs: build_and_push_frontend + if: github.ref == 'refs/heads/main' + uses: ./.github/workflows/frontend-cd.yml + with: + aks_cluster_name: "ishaanAKS" + aks_resource_group: "deakinuni" + secrets: + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} #test \ No newline at end of file diff --git a/frontend/main.js b/frontend/main.js index 5e7dd4c6..c628756c 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -4,8 +4,8 @@ document.addEventListener('DOMContentLoaded', () => { // API endpoints for the Product and Order services. // These ports (30000 for Product, 30001 for Order) are mapped // from the Docker containers to the host machine in docker-compose.yml for Example 2. - const PRODUCT_API_BASE_URL = 'http://4.198.134.37:8000'; - const ORDER_API_BASE_URL = 'http://20.213.212.254:8001'; + const PRODUCT_API_BASE_URL = 'http://4.198.142.187:8000'; + const ORDER_API_BASE_URL = 'http://4.198.109.142:8001'; // Product Service is named 'product-service-w04e2' and exposes port 8000 internally. //const PRODUCT_API_BASE_URL = 'http://product-service-w04e2:8000'; From e052c803974839e5d84cf4d8cdfe381fea7b095b Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:19:21 +1000 Subject: [PATCH 21/36] Frontend CI/CD pipeline --- .github/workflows/frontend_ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index f2ab6515..ce34b2a4 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -46,11 +46,13 @@ jobs: run: az logout if: always() - trigger_frontend_cd: + trigger_frontend_cd: needs: build_and_push_frontend if: github.ref == 'refs/heads/main' uses: ./.github/workflows/frontend-cd.yml with: + product_api_ip: "" + order_api_ip: "" aks_cluster_name: "ishaanAKS" aks_resource_group: "deakinuni" secrets: From 1d4bd54408ca78393f6952fe095e9259d8529578 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:20:48 +1000 Subject: [PATCH 22/36] Frontend CI/CD pipeline --- .github/workflows/frontend_ci.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index ce34b2a4..da400572 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -46,15 +46,15 @@ jobs: run: az logout if: always() - trigger_frontend_cd: - needs: build_and_push_frontend - if: github.ref == 'refs/heads/main' - uses: ./.github/workflows/frontend-cd.yml - with: - product_api_ip: "" - order_api_ip: "" - aks_cluster_name: "ishaanAKS" - aks_resource_group: "deakinuni" - secrets: - azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} + trigger_frontend_cd: + needs: build_and_push_frontend + if: github.ref == 'refs/heads/main' + uses: ./.github/workflows/frontend-cd.yml + with: + product_api_ip: "" + order_api_ip: "" + aks_cluster_name: "ishaanAKS" + aks_resource_group: "deakinuni" + secrets: + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} #test \ No newline at end of file From dc98f2bcb44fa14191a961005b165c63f9284692 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:22:48 +1000 Subject: [PATCH 23/36] Frontend CI/CD pipeline --- .github/workflows/frontend_ci.yml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index da400572..5b61a2b6 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -23,7 +23,7 @@ env: jobs: build_and_push_frontend: runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' # Only build on main branch + if: github.ref == 'refs/heads/main' steps: - name: Checkout repository @@ -47,14 +47,15 @@ jobs: if: always() trigger_frontend_cd: - needs: build_and_push_frontend - if: github.ref == 'refs/heads/main' - uses: ./.github/workflows/frontend-cd.yml - with: - product_api_ip: "" - order_api_ip: "" - aks_cluster_name: "ishaanAKS" - aks_resource_group: "deakinuni" - secrets: - azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} + runs-on: ubuntu-latest + needs: build_and_push_frontend + if: github.ref == 'refs/heads/main' + uses: ./.github/workflows/frontend-cd.yml + with: + product_api_ip: "20.92.168.148" + order_api_ip: "20.92.168.149" + aks_cluster_name: "ishaanAKS" + aks_resource_group: "deakinuni" + secrets: + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} #test \ No newline at end of file From a3447b763757302623c8e1f52062d1454e42749c Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:25:31 +1000 Subject: [PATCH 24/36] Frontend CI/CD pipeline --- .github/workflows/frontend_ci.yml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 5b61a2b6..fcb9fc25 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -47,15 +47,13 @@ jobs: if: always() trigger_frontend_cd: - runs-on: ubuntu-latest - needs: build_and_push_frontend - if: github.ref == 'refs/heads/main' - uses: ./.github/workflows/frontend-cd.yml - with: - product_api_ip: "20.92.168.148" - order_api_ip: "20.92.168.149" - aks_cluster_name: "ishaanAKS" - aks_resource_group: "deakinuni" - secrets: - azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} + needs: build_and_push_frontend + uses: ./.github/workflows/frontend-cd.yml + with: + product_api_ip: "20.92.168.148" + order_api_ip: "20.92.168.149" + aks_cluster_name: "ishaanAKS" + aks_resource_group: "deakinuni" + secrets: + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} #test \ No newline at end of file From 285a547e4a9d87ad4474845120f0e092b9f0b85d Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:28:09 +1000 Subject: [PATCH 25/36] Frontend CI/CD pipeline --- .github/workflows/frontend_ci.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index fcb9fc25..198bcecb 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -47,13 +47,13 @@ jobs: if: always() trigger_frontend_cd: - needs: build_and_push_frontend - uses: ./.github/workflows/frontend-cd.yml - with: - product_api_ip: "20.92.168.148" - order_api_ip: "20.92.168.149" - aks_cluster_name: "ishaanAKS" - aks_resource_group: "deakinuni" - secrets: - azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} -#test \ No newline at end of file + needs: build_and_push_frontend + if: github.ref == 'refs/heads/main' + uses: ./.github/workflows/frontend-cd.yml + with: + product_api_ip: "20.92.168.148" + order_api_ip: "20.92.168.149" + aks_cluster_name: "ishaanAKS" + aks_resource_group: "deakinuni" + secrets: + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} From 9608b0b8fe2ca09f94e9c606b995d96a9b99d7ff Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:29:20 +1000 Subject: [PATCH 26/36] Frontend CI/CD pipeline --- .github/workflows/frontend_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 198bcecb..70b4e60c 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -23,7 +23,7 @@ env: jobs: build_and_push_frontend: runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' + steps: - name: Checkout repository From 9eae36998faafa0268fa197d41db461a6a7d8bdc Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:47:02 +1000 Subject: [PATCH 27/36] Frontend CI/CD pipeline --- .github/workflows/frontend_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 70b4e60c..f09c5a65 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -49,7 +49,7 @@ jobs: trigger_frontend_cd: needs: build_and_push_frontend if: github.ref == 'refs/heads/main' - uses: ./.github/workflows/frontend-cd.yml + uses: ./.github/workflows/frontend-cd.yml #1 with: product_api_ip: "20.92.168.148" order_api_ip: "20.92.168.149" From c4870da33bdb8fbd25e4cd7ca7c72d75f80c3404 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:49:05 +1000 Subject: [PATCH 28/36] Frontend CI/CD pipeline --- .github/workflows/frontend_ci.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index f09c5a65..61073d09 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -49,11 +49,14 @@ jobs: trigger_frontend_cd: needs: build_and_push_frontend if: github.ref == 'refs/heads/main' - uses: ./.github/workflows/frontend-cd.yml #1 - with: - product_api_ip: "20.92.168.148" - order_api_ip: "20.92.168.149" - aks_cluster_name: "ishaanAKS" - aks_resource_group: "deakinuni" - secrets: - azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} + runs-on: ubuntu-latest + steps: + - name: Trigger Frontend CD workflow + uses: ./.github/workflows/frontend-cd.yml + with: + product_api_ip: "20.92.168.148" + order_api_ip: "20.92.168.149" + aks_cluster_name: "ishaanAKS" + aks_resource_group: "deakinuni" + secrets: + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} From a63053118deb3b2ebc9c3ddc8b583bc0d27d54f8 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:50:07 +1000 Subject: [PATCH 29/36] Frontend CI/CD pipeline --- .github/workflows/frontend_ci.yml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 61073d09..f09c5a65 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -49,14 +49,11 @@ jobs: trigger_frontend_cd: needs: build_and_push_frontend if: github.ref == 'refs/heads/main' - runs-on: ubuntu-latest - steps: - - name: Trigger Frontend CD workflow - uses: ./.github/workflows/frontend-cd.yml - with: - product_api_ip: "20.92.168.148" - order_api_ip: "20.92.168.149" - aks_cluster_name: "ishaanAKS" - aks_resource_group: "deakinuni" - secrets: - azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} + uses: ./.github/workflows/frontend-cd.yml #1 + with: + product_api_ip: "20.92.168.148" + order_api_ip: "20.92.168.149" + aks_cluster_name: "ishaanAKS" + aks_resource_group: "deakinuni" + secrets: + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} From 741745eeefc79c2eb0af3c19dc3f315f240c7c12 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:52:24 +1000 Subject: [PATCH 30/36] Frontend CI/CD pipeline --- .github/workflows/frontend_ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index f09c5a65..931d5a97 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -51,8 +51,8 @@ jobs: if: github.ref == 'refs/heads/main' uses: ./.github/workflows/frontend-cd.yml #1 with: - product_api_ip: "20.92.168.148" - order_api_ip: "20.92.168.149" + product_api_ip: "4.198.142.187" + order_api_ip: "4.198.109.142" aks_cluster_name: "ishaanAKS" aks_resource_group: "deakinuni" secrets: From 92b4800e40ab630524f38ee4587b461693401574 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 17:09:28 +1000 Subject: [PATCH 31/36] Frontend CI/CD pipeline --- .github/workflows/frontend_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 931d5a97..633d782a 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -56,4 +56,4 @@ jobs: aks_cluster_name: "ishaanAKS" aks_resource_group: "deakinuni" secrets: - azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} From ec9af6ed11c3756d764125cecac6f592b8443a5f Mon Sep 17 00:00:00 2001 From: ishaan-markanday Date: Fri, 26 Sep 2025 17:11:59 +1000 Subject: [PATCH 32/36] Frontend CI/CD pipeline (#5) Co-authored-by: Ishaan <74845759+iamrealishaan@users.noreply.github.com> --- .github/workflows/frontend_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 21e3310b..5417fa15 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -54,4 +54,4 @@ jobs: aks_cluster_name: "ishaanAKS" aks_resource_group: "deakinuni" secrets: - azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} From 1295152cb2ce8fdefae68572cf03715434e6b9b5 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 17:13:50 +1000 Subject: [PATCH 33/36] Frontend CI/CD pipeline --- .github/workflows/frontend_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 633d782a..931d5a97 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -56,4 +56,4 @@ jobs: aks_cluster_name: "ishaanAKS" aks_resource_group: "deakinuni" secrets: - azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} + azure_credentials: ${{ secrets.AZURE_CREDENTIALS }} From c2bac226a2b86f586dfa1fd15e640914718e41bc Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 17:23:01 +1000 Subject: [PATCH 34/36] updated frontend --- .github/workflows/frontend-cd.yml | 28 ++++++---------------------- .github/workflows/frontend_ci.yml | 7 +++---- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml index 27931888..59763f02 100644 --- a/.github/workflows/frontend-cd.yml +++ b/.github/workflows/frontend-cd.yml @@ -1,5 +1,3 @@ -# week08/.github/workflows/frontend-cd.yml - name: CD - Deploy Frontend to AKS on: @@ -22,7 +20,6 @@ on: required: true default: 'deakinuni' - # CRITICAL: This is how it's called by frontend_ci.yml workflow_call: inputs: product_api_ip: @@ -37,10 +34,10 @@ on: aks_resource_group: required: true type: string - # CRITICAL FIX: Must define which secrets are required by this workflow secrets: - azure_credentials: { required: true } # <--- ADDED SECRET HERE - + azure_credentials: + required: true # <-- must match CI usage + jobs: deploy_frontend: runs-on: ubuntu-latest @@ -50,16 +47,10 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - # Azure login using the secret passed via workflow_call - name: Azure Login uses: azure/login@v1 with: - # CRITICAL FIX: Use the secret passed from the caller - creds: ${{ secrets.azure_credentials }} - - # --- OPTIMISATION: REMOVED ACR Login, Inject IPs, and Build/Push steps --- - # These steps were already done by frontend_ci.yml (Step 3 in the chain). - # The IP linkage will now be done with a robust `kubectl` command. + creds: ${{ secrets.azure_credentials }} - name: Set Kubernetes context (get AKS credentials) uses: azure/aks-set-context@v3 @@ -69,22 +60,15 @@ jobs: - name: Deploy Frontend to AKS (Apply Base Manifest) run: | - echo "Applying frontend base manifest to AKS cluster: ${{ inputs.aks_cluster_name }}" cd k8s/ - # Deploy the base frontend service/deployment kubectl apply -f frontend.yaml - # CRITICAL NEW STEP: Configure Frontend Deployment with Backend IPs - # This is the most reliable way to link the services in AKS - name: Configure Frontend Deployment with Backend IPs run: | - echo "Setting backend IP environment variables on frontend deployment..." - # Pass the IPs as environment variables to the live Kubernetes deployment - # Note: Adjust 'frontend-w08e1' if your deployment name is different in frontend.yaml kubectl set env deployment/frontend-w08e1 \ PRODUCT_API_URL=http://${{ inputs.product_api_ip }}:80 \ ORDER_API_URL=http://${{ inputs.order_api_ip }}:80 \ - --overwrite + --overwrite - name: Logout from Azure - run: az logout \ No newline at end of file + run: az logout diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 931d5a97..a0b26c34 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -23,7 +23,6 @@ env: jobs: build_and_push_frontend: runs-on: ubuntu-latest - steps: - name: Checkout repository @@ -48,10 +47,10 @@ jobs: trigger_frontend_cd: needs: build_and_push_frontend - if: github.ref == 'refs/heads/main' - uses: ./.github/workflows/frontend-cd.yml #1 + if: github.ref == 'refs/heads/main' # Only deploy on main + uses: ./.github/workflows/frontend-cd.yml with: - product_api_ip: "4.198.142.187" + product_api_ip: "4.198.142.187" # replace with your backend IP or use workflow output order_api_ip: "4.198.109.142" aks_cluster_name: "ishaanAKS" aks_resource_group: "deakinuni" From 3530ad4fbaff6f3e523ede1ab4168c377eb27020 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 17:36:44 +1000 Subject: [PATCH 35/36] fixed frontend name --- .github/workflows/frontend-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml index a8e3f98c..83b34ecd 100644 --- a/.github/workflows/frontend-cd.yml +++ b/.github/workflows/frontend-cd.yml @@ -67,7 +67,7 @@ jobs: - name: Configure Frontend Deployment with Backend IPs run: | - kubectl set env deployment/frontend-w08e1 \ + kubectl set env deployment/frontend \ PRODUCT_API_URL=http://${{ inputs.product_api_ip }}:80 \ ORDER_API_URL=http://${{ inputs.order_api_ip }}:80 \ --overwrite From d7961e2f1e31c11926853bf2fe18d11d7ec675d7 Mon Sep 17 00:00:00 2001 From: Ishaan <74845759+iamrealishaan@users.noreply.github.com> Date: Fri, 26 Sep 2025 17:45:29 +1000 Subject: [PATCH 36/36] test --- .github/workflows/frontend-cd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml index 83b34ecd..d5492c4d 100644 --- a/.github/workflows/frontend-cd.yml +++ b/.github/workflows/frontend-cd.yml @@ -74,3 +74,4 @@ jobs: - name: Logout from Azure run: az logout +#1 \ No newline at end of file