From 4b25e03729bab3f4d2d8bc3c4cd01483ab819685 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Sat, 20 Sep 2025 00:07:33 +1000 Subject: [PATCH 01/53] chore(ci): trigger backend CI --- backend/product_service/README.md | Bin 0 -> 72 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 backend/product_service/README.md diff --git a/backend/product_service/README.md b/backend/product_service/README.md new file mode 100644 index 0000000000000000000000000000000000000000..785daae7b2b42baa0a5729cbe18b4a560df91e60 GIT binary patch literal 72 zcmezWkBdQ>L4m=U!4pW9FcdLlGNc1xDv+hXV8mbm#HI|oK-v;Wg7_goY`|az#O6TK K7zlY8xEKJ)NeTr3 literal 0 HcmV?d00001 From b4d43711718ddafa006f736036fd3182bdae8b09 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Sat, 20 Sep 2025 00:15:28 +1000 Subject: [PATCH 02/53] chore: activate workflow in fork --- .github/workflows/backend_ci.yml | Bin 4835 -> 4987 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index d69725aa80e0b937b31716eb8ee0017d669d05c2..a6e251f5a510db28100c94eea76ee06863f3738b 100644 GIT binary patch delta 1299 zcmb7DO-~a+7^W???aX~}*C z@TL6*;3xZSz#hji;G!dgzysZv^N@-@ckmE^&=IcF4#z#m)f}_3T&k$7Rtkp-ijWya zF4hYg86P7BS<;|9XsKCR&9E&N^AIO_s>^2@2r=sNs z>vYg!%QdYcODa!>6PPYI2Z8X&NdVtCLrIGU!$_1xp{kV=iU{KsRg$%=HCfSEe?OhU zi{`EQjgV=jC@Ro}c_Xv)|5P5jX}ZD=ja1Ds7+cC_(rF&xvPJt>TM3JHd|QTH)x;WW z>ah!SMnAa1fZtqGx&qSfJ~-WV_W-WDC;e8$wTcEBqucHtow)C2l1OSUYidX zGq?jy&(8BiAI%{J9MQ(1q)J`l$pcIu;%gqW6immxQ3$r|Wh!cTQzuNAW|9km%L$U{ zy=~z!VB5H}fP0QEz$_Pr!5&!#q90w|c8utESGVrr47nJ8YghYrN6bA=63l}mD6GpnyG T@kFSu3F~SsjuC3XEvV%$ETtxw delta 1170 zcmbtT&rcIk5KdbP?d!JN*78HC@@R!pkRPSA%1RK61P>Ze{{XUWmv*J>uDh=k3>-Xq zFcIgdVm#r=gv5C9;$Hw)J$W!*P4M7FBTl!=)8dCzaKkavZl2dYiM&`?k(A=-;9vq?IBq!z{BX>=iKMIvaMhWH zP3L)d<(z^;=R8chreWPR(MHH^HE#&;+9klD>lAP;7nX?$X-N8-Txh0@(?wk^Rttv8YmNQrc^Y!Cp%Q4*X$r=iMAc z-3t*rO4XRGDuzI(hvA-k4F3oxD-3yI{ZeB_-9ebVDydaQGp5<4OITRRpv_#GsxuTw zTRRplWNVAl1-&TgD93WBb@RU@Jn)lAn|>p)ZPr_qnMkJvT*hthKWJ=kYBXUCCTS>e zzb)%R8{P+c;H{?Ieaw!Cq8?wvzxhjhY` zmjjMuAV(&kM&j_8#CZEErA1YdV4s{eqdWZC29pd%%ZzF31j4=~O!)@jD|Z&|`*^>7 z&+2#t-uQU4+aG+y?)op2(9EP)6@hMo#7(wYD6q>V;DGB#^weLGy^gerjqSkQp0Yn- zql%G04(6=kH)m05RPqt8;6tjvgE&kF zW36=H^6bqdj0ZW&w^R_9*V-3VEZv~OP&zUz{^kvh@o!S3eB6b3HTiHWBllE qv3YnJuD9t^cn*e6oJm?NOf2y(t*9k@3YJq|7N}UMi5td1lKcdI7(!40 From 9b3fc5c8b822230ab0228ffc2f07efab26b2c871 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Sat, 20 Sep 2025 00:17:07 +1000 Subject: [PATCH 03/53] ci: trigger backend workflow via backend/** change --- backend/product_service/README.md | Bin 72 -> 142 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/backend/product_service/README.md b/backend/product_service/README.md index 785daae7b2b42baa0a5729cbe18b4a560df91e60..62657d694dc98ff5c671110bb1614b1fd51b5e72 100644 GIT binary patch delta 33 ncmeb1W1Qf@$;F_|pumvKkU5cCpU;rNoWY9007&vOa4`S?W!41C delta 5 McmeBU^qAlQ00j>LumAu6 From ef30802bcdc537c04d8671eeeb1470597ea26dec Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Sat, 20 Sep 2025 00:26:22 +1000 Subject: [PATCH 04/53] ci: trigger backend workflows --- backend/order_service/README.md | Bin 0 -> 72 bytes backend/product_service/README.md | Bin 142 -> 212 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 backend/order_service/README.md diff --git a/backend/order_service/README.md b/backend/order_service/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1140dfb0602e46318c68d86d334dbd31f59a897b GIT binary patch literal 72 zcmezWkBdQ>L4hHeArnZJFcbmlbRbLxvJ@DM7z}{eltC9rTLMWCKLm&k7_5M7Gcak$ Jz{|kJ007tp3PS(@ literal 0 HcmV?d00001 diff --git a/backend/product_service/README.md b/backend/product_service/README.md index 62657d694dc98ff5c671110bb1614b1fd51b5e72..da821194c49e4eaedc13ea2aa41fe2f87f1b7cda 100644 GIT binary patch delta 24 fcmeBUyuvu4Z=#0 Date: Sat, 20 Sep 2025 00:30:34 +1000 Subject: [PATCH 05/53] ci: normalize triggers --- .github/workflows/backend_ci.yml | Bin 4987 -> 4310 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index a6e251f5a510db28100c94eea76ee06863f3738b..e6cb515e3ce680d842d6f92269cbfa4b66a7427f 100644 GIT binary patch delta 69 zcmeyZc1>}@B{MDsh4TEO?6jQx^7xd@;)2AIL=YU+fWjK*;ESo4 ziFfu+hmf8Z@czbTW!^?`W{rUQ;l<$juAsGX zioI@mUs&>SfAc|M($i>&yV6=QgHdkb#gcS-vBLy?u|^Vu?;&a$E`vV6K&7N6km zu9u%|HFk&hlcdR_=Xg7m1Rka1n4=+n*<9^BEG|+&4n0@?B2-WW4b#aZ&b2igRdXak ztFM7h`TbB(OsQ8}84HA>Ib5iMYU{W@y-M?}T&8(XFO_dXmAD3(^DO#_m18d1pi5Qn M=?6caKKXh47b=Y2w*UYD From 55dd08d87ba4953ae019c7f9b44a1ca1a8d22c01 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Sat, 20 Sep 2025 00:32:59 +1000 Subject: [PATCH 06/53] ci: restore backend_ci from upstream --- .github/workflows/backend_ci.yml | Bin 4310 -> 4835 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index e6cb515e3ce680d842d6f92269cbfa4b66a7427f..d69725aa80e0b937b31716eb8ee0017d669d05c2 100644 GIT binary patch delta 1712 zcmb7E&u<$=6qb`FcDIgQm52!1(3c;@NfkQ{`5{|yOJsdU`Xd)t-8JI>{aUTSL!y*K7I^gd>xj`AHG+wICpBh`{nK3O5Lefs@r?} z^$+05lQ{ThkCS%NvKHl35{0U^NsEFatq|2UwO})=Ou^CKRv8FtjfbtM0riN(_U0MM zjuc(yp%@Wo4WENiIyIAesd!+2y=WsaxZOe*bw7Sha9VmGwTNzUVJXf z*+eKsJE&4&WKBO9nbx0knDUZj&#QaxEtnRZ*8!MPNo^S{M7{}~9C;qRJAwh;=5qB&^jfktL z7~qc=s;AlM^Zi-M!cN?c==#(>5RqE%u2?$CF25b4ih#c}wV`ZwNW5wI zd2eH13~&SS_3lz~)o<=^S&qc-kCpW2_8jI4>J2Zy8= I&dpnY1MWKZHUIzs delta 1163 zcmb7DO=}Zj5N?{rByaQXCc(y!U^+?qk%()WCMmjp_Uj;2652uq5#1)+X0_c7yPK94 zui{BCyoaKA@F4gDJc{%n_y+{9B3AGq6-DpPZnAC*MQR|=?#w(h^FA~0ejfage4O=C zLR+WD?1wbwp{=dFj}lE4TOVUA>FJBYO-QXuikgC3E)75s>aw(A z)&*TQbwxIyqa1nxDl8MyA{_JvyMsc z14*0sJ8%&x`CuAxJ~)l|BshThCRjrJ87v|W5i5F)q#|w^fSRVtlx>nz7~3LgyV`4# zMQev-5L=-EHqy%H8 z7P}X+Zc!_gKV-v#)i8l6hiGPN+olu9_HZWb2%t)@M#wTa9l)d85V%Jan z1-tT<$Z**C0_WNvCuMVCSHCl@R(J{1BGEj{L}Hy(Ypq5k_jgtC8UdX;h+2g=MM%1 From ad697ffdad4e252e6eb06bfab045308e6a94acc4 Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 02:05:33 +1000 Subject: [PATCH 07/53] Update backend-cd.yml --- .github/workflows/backend-cd.yml | 117 +++++++++---------------------- 1 file changed, 32 insertions(+), 85 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 6035ed15..e089b24b 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -1,101 +1,48 @@ -name: CD - Deploy Backend Services to AKS - +name: Backend CI - Test, Build and Push Images to ACR on: workflow_dispatch: - inputs: - aks_cluster_name: - description: 'Name of the AKS Cluster to deploy to' - required: true - default: '' - aks_resource_group: - description: 'Resource Group of the AKS Cluster' - required: true - default: '' - aks_acr_name: - description: 'Name of ACR' - required: true - default: '' + push: + branches: [ "main" ] jobs: - deploy_backend: + test_build_push: runs-on: ubuntu-latest - environment: Production - - outputs: - PRODUCT_API_IP: ${{ steps.get_product_ip.outputs.external_ip }} - ORDER_API_IP: ${{ steps.get_order_ip.outputs.external_ip }} - + env: + ACR_NAME: ${{ secrets.ACR_NAME }} + TAG: ${{ github.sha }} steps: - - name: Checkout repository - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Log in to Azure - uses: azure/login@v1 + - name: Azure login (service principal JSON) + uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - enable-AzPSSession: true - - name: Set Kubernetes context (get AKS credentials) + - name: Find Dockerfiles + id: find run: | - az aks get-credentials --resource-group ${{ github.event.inputs.aks_resource_group }} --name ${{ github.event.inputs.aks_cluster_name }} --overwrite-existing - - - name: Attach ACR + set -e + ORDER_DF=$(git ls-files | grep -iE '/order[^/]*/Dockerfile$' | head -n1) + PROD_DF=$(git ls-files | grep -iE '/product[^/]*/Dockerfile$' | head -n1) + [ -n "$ORDER_DF" ] && [ -n "$PROD_DF" ] || { echo "Dockerfiles not found"; exit 1; } + echo "order=$ORDER_DF" >> $GITHUB_OUTPUT + echo "product=$PROD_DF" >> $GITHUB_OUTPUT + + - name: Build & push order-service run: | - az aks update --name ${{ github.event.inputs.aks_cluster_name }} --resource-group ${{ github.event.inputs.aks_resource_group }} --attach-acr ${{ github.event.inputs.aks_acr_name }} + az acr build -r "$ACR_NAME" \ + -t week08/order-service:${TAG} \ + -f "${{ steps.find.outputs.order }}" \ + "$(dirname "${{ steps.find.outputs.order }}")" - - name: Deploy Backend Infrastructure (Namespace, ConfigMaps, Secrets, Databases) + - name: Build & push product-service 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 + az acr build -r "$ACR_NAME" \ + -t week08/product-service:${TAG} \ + -f "${{ steps.find.outputs.product }}" \ + "$(dirname "${{ steps.find.outputs.product }}")" - - 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 + - name: Show image URIs run: | - echo "Waiting for Product, Order LoadBalancer IPs to be assigned (up to 5 minutes)..." - PRODUCT_IP="" - ORDER_IP="" - - for i in $(seq 1 60); do - echo "Attempt $i/60 to get IPs..." - PRODUCT_IP=$(kubectl get service product-service-w08e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}') - ORDER_IP=$(kubectl get service order-service-w08e1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}') - - if [[ -n "$PRODUCT_IP" && -n "$ORDER_IP" ]]; then - echo "All backend LoadBalancer IPs assigned!" - echo "Product Service IP: $PRODUCT_IP" - echo "Order Service IP: $ORDER_IP" - break - fi - sleep 5 # Wait 5 seconds before next attempt - done - - if [[ -z "$PRODUCT_IP" || -z "$ORDER_IP" ]]; then - echo "Error: One or more LoadBalancer IPs not assigned after timeout." - exit 1 # Fail the job if IPs are not obtained - fi - - # These are environment variables for subsequent steps in the *same job* - # And used to set the job outputs - echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_ENV - echo "ORDER_IP=$ORDER_IP" >> $GITHUB_ENV - - - name: Capture Product Service IP for Workflow Output - id: get_product_ip - 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 + echo "s722acr84438.azurecr.io/week08/order-service:${TAG}" + echo "s722acr84438.azurecr.io/week08/product-service:${TAG}" From b6c81cfa3f40a7e03822b4d325cce6238469905c Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 02:08:40 +1000 Subject: [PATCH 08/53] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 164 ++++++------------------------- 1 file changed, 30 insertions(+), 134 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index d69725aa..c310a9a6 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -1,146 +1,42 @@ -# week08/.github/workflows/backend_ci.yml - name: Backend CI - Test, Build and Push Images to ACR - -# Trigger the workflow on pushes to the 'main' branch -# You can also add 'pull_request:' to run on PRs on: - # Manual trigger workflow_dispatch: - - # Automatically on pushes to main branch push: - branches: - - main - paths: # Only trigger if changes are in backend directories - - 'backend/**' - - '.github/workflows/backend_ci.yml' # Trigger if this workflow file changes - -# Define global environment variables that can be used across jobs -env: - # ACR Login Server (e.g., myregistry.azurecr.io) - # This needs to be set as a GitHub Repository Secret - ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} - # Dynamically generate image tags based on Git SHA and GitHub Run ID - # This provides unique, traceable tags for each image build - IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} + branches: [ "main" ] jobs: - # Job 1: Run tests and linting for all backend services - test_and_lint_backends: - runs-on: ubuntu-latest # Use a GitHub-hosted runner - - services: - # Product DB container - product_db: - image: postgres:15 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: products - # Make pg_isready available so the service is healthy before tests run - options: >- - --health-cmd "pg_isready -U postgres" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 5432:5432 - - # Order DB - order_db: - image: postgres:15 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: orders - ports: - - 5433:5432 - options: >- - --health-cmd "pg_isready -U postgres" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - + test_build_push: + runs-on: ubuntu-latest + env: + ACR_NAME: s722acr84438 # <- hardcoded so we don't depend on a secret + TAG: ${{ github.sha }} 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 + - name: Azure login + uses: azure/login@v2 with: - python-version: '3.10' - - # 3. Install dependencies and run code quality checks - - name: Install dependencies - run: | # Use a multi-line script to install pip dependencies - pip install --upgrade pip - # Loop through each backend service folder - for req in backend/*/requirements.txt; do - echo "Installing $req" - pip install -r "$req" - done - # Install CI tools - pip install pytest httpx + creds: ${{ secrets.AZURE_CREDENTIALS }} - # 5. Run tests for product service - - name: Run product_service tests - working-directory: backend/product_service - env: - POSTGRES_HOST: localhost - POSTGRES_PORT: 5432 - POSTGRES_DB: products - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres + - name: Find Dockerfiles + id: find run: | - pytest tests --maxfail=1 --disable-warnings -q - - # 6. Run tests for order service - - name: Run order_service tests - working-directory: backend/order_service - env: - POSTGRES_HOST: localhost - POSTGRES_PORT: 5433 - POSTGRES_DB: orders - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres + set -e + ORDER_DF=$(git ls-files | grep -iE '/order[^/]*/Dockerfile$' | head -n1) + PROD_DF=$(git ls-files | grep -iE '/product[^/]*/Dockerfile$' | head -n1) + [ -n "$ORDER_DF" ] && [ -n "$PROD_DF" ] || { echo "Dockerfiles not found"; exit 1; } + echo "order=$ORDER_DF" >> $GITHUB_OUTPUT + echo "product=$PROD_DF" >> $GITHUB_OUTPUT + + - name: Build & push order-service run: | - pytest tests --maxfail=1 --disable-warnings -q + az acr build -r "$ACR_NAME" \ + -t week08/order-service:${TAG} \ + -f "${{ steps.find.outputs.order }}" \ + "$(dirname "${{ steps.find.outputs.order }}")" - # 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() + - name: Build & push product-service + run: | + az acr build -r "$ACR_NAME" \ + -t week08/product-service:${TAG} \ + -f "${{ steps.find.outputs.product }}" \ + "$(dirname "${{ steps.find.outputs.product }}")" From be34076f3d4a41c66e853d29f099b8f2335b0754 Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 02:12:39 +1000 Subject: [PATCH 09/53] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 51 ++++++++------------------------ 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index c310a9a6..0eeef2b0 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -1,42 +1,15 @@ -name: Backend CI - Test, Build and Push Images to ACR -on: - workflow_dispatch: - push: - branches: [ "main" ] +# make a safety branch +git switch -c fix-workflows -jobs: - test_build_push: - runs-on: ubuntu-latest - env: - ACR_NAME: s722acr84438 # <- hardcoded so we don't depend on a secret - TAG: ${{ github.sha }} - steps: - - uses: actions/checkout@v4 - - name: Azure login - uses: azure/login@v2 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} +# restore backend_cd.yml from the commit before your change +git log -- .github/workflows/backend_cd.yml +# copy the SHA just BEFORE your edit, then: +git checkout -- .github/workflows/backend_cd.yml - - name: Find Dockerfiles - id: find - run: | - set -e - ORDER_DF=$(git ls-files | grep -iE '/order[^/]*/Dockerfile$' | head -n1) - PROD_DF=$(git ls-files | grep -iE '/product[^/]*/Dockerfile$' | head -n1) - [ -n "$ORDER_DF" ] && [ -n "$PROD_DF" ] || { echo "Dockerfiles not found"; exit 1; } - echo "order=$ORDER_DF" >> $GITHUB_OUTPUT - echo "product=$PROD_DF" >> $GITHUB_OUTPUT +# ensure CI file exists with your CI content +# (open editor and paste; or if it already exists, skip) +notepad .github/workflows/backend_ci.yml - - name: Build & push order-service - run: | - az acr build -r "$ACR_NAME" \ - -t week08/order-service:${TAG} \ - -f "${{ steps.find.outputs.order }}" \ - "$(dirname "${{ steps.find.outputs.order }}")" - - - name: Build & push product-service - run: | - az acr build -r "$ACR_NAME" \ - -t week08/product-service:${TAG} \ - -f "${{ steps.find.outputs.product }}" \ - "$(dirname "${{ steps.find.outputs.product }}")" +git add .github/workflows/backend_cd.yml .github/workflows/backend_ci.yml +git commit -m "Restore backend_cd.yml and place CI workflow in backend_ci.yml" +git push -u origin fix-workflows From ad360e5d538322188b74518cceb6347520a68933 Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 02:19:04 +1000 Subject: [PATCH 10/53] Update backend-cd.yml --- .github/workflows/backend-cd.yml | 61 +++++++++++++++++--------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index e089b24b..01fc2294 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -1,48 +1,51 @@ -name: Backend CI - Test, Build and Push Images to ACR +name: Backend CD - Deploy to AKS on: workflow_dispatch: - push: - branches: [ "main" ] + inputs: + tag: + description: "Image tag to deploy (default = last commit SHA)" + required: false + workflow_run: + workflows: [ "Backend CI - Test, Build and Push Images to ACR" ] + types: [ "completed" ] jobs: - test_build_push: + deploy: + if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest env: - ACR_NAME: ${{ secrets.ACR_NAME }} - TAG: ${{ github.sha }} + ACR_LOGIN_SERVER: s722acr84438.azurecr.io + NAMESPACE: default + ORDER_DEPLOY: order-service-w08e1 + PRODUCT_DEPLOY: product-service-w08e1 + ORDER_CONTAINER: order-service-container + PRODUCT_CONTAINER: product-service-container + TAG: ${{ github.event.inputs.tag || github.sha }} + steps: - uses: actions/checkout@v4 - - name: Azure login (service principal JSON) + - name: Azure login uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Find Dockerfiles - id: find - run: | - set -e - ORDER_DF=$(git ls-files | grep -iE '/order[^/]*/Dockerfile$' | head -n1) - PROD_DF=$(git ls-files | grep -iE '/product[^/]*/Dockerfile$' | head -n1) - [ -n "$ORDER_DF" ] && [ -n "$PROD_DF" ] || { echo "Dockerfiles not found"; exit 1; } - echo "order=$ORDER_DF" >> $GITHUB_OUTPUT - echo "product=$PROD_DF" >> $GITHUB_OUTPUT + - name: Set AKS context + uses: azure/aks-set-context@v3 + with: + resource-group: ${{ secrets.AKS_RG }} # e.g. sit722-week08-rg + cluster-name: ${{ secrets.AKS_NAME }} # your AKS cluster name - - name: Build & push order-service + - name: Update images run: | - az acr build -r "$ACR_NAME" \ - -t week08/order-service:${TAG} \ - -f "${{ steps.find.outputs.order }}" \ - "$(dirname "${{ steps.find.outputs.order }}")" + kubectl set image -n "$NAMESPACE" deploy/$ORDER_DEPLOY $ORDER_CONTAINER=$ACR_LOGIN_SERVER/week08/order-service:$TAG + kubectl set image -n "$NAMESPACE" deploy/$PRODUCT_DEPLOY $PRODUCT_CONTAINER=$ACR_LOGIN_SERVER/week08/product-service:$TAG - - name: Build & push product-service + - name: Wait for rollout run: | - az acr build -r "$ACR_NAME" \ - -t week08/product-service:${TAG} \ - -f "${{ steps.find.outputs.product }}" \ - "$(dirname "${{ steps.find.outputs.product }}")" + kubectl rollout status -n "$NAMESPACE" deploy/$ORDER_DEPLOY + kubectl rollout status -n "$NAMESPACE" deploy/$PRODUCT_DEPLOY - - name: Show image URIs + - name: Show deployed images run: | - echo "s722acr84438.azurecr.io/week08/order-service:${TAG}" - echo "s722acr84438.azurecr.io/week08/product-service:${TAG}" + kubectl get deploy -n "$NAMESPACE" -o custom-columns=NAME:.metadata.name,IMAGE:.spec.template.spec.containers[0].image,READY:.status.readyReplicas From f9f650bf2c6c620f9f06915a069510561b20d0e5 Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 02:19:34 +1000 Subject: [PATCH 11/53] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 60 +++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 0eeef2b0..a16019f5 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -1,15 +1,51 @@ -# make a safety branch -git switch -c fix-workflows +name: Backend CI - Test, Build and Push Images to ACR +on: + workflow_dispatch: + push: + branches: [ "main" ] -# restore backend_cd.yml from the commit before your change -git log -- .github/workflows/backend_cd.yml -# copy the SHA just BEFORE your edit, then: -git checkout -- .github/workflows/backend_cd.yml +jobs: + test_build_push: + runs-on: ubuntu-latest + env: + ACR_NAME: s722acr84438 # hardcoded to avoid secret typos + ACR_LOGIN_SERVER: s722acr84438.azurecr.io + TAG: ${{ github.sha }} -# ensure CI file exists with your CI content -# (open editor and paste; or if it already exists, skip) -notepad .github/workflows/backend_ci.yml + steps: + - uses: actions/checkout@v4 -git add .github/workflows/backend_cd.yml .github/workflows/backend_ci.yml -git commit -m "Restore backend_cd.yml and place CI workflow in backend_ci.yml" -git push -u origin fix-workflows + - name: Azure login (service principal JSON) + uses: azure/login@v2 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Locate Dockerfiles (order/product) + id: detect + shell: bash + run: | + set -e + ORDER_DF=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) + PROD_DF=$(find . -type f -iname Dockerfile -path '*product*' | head -n1) + [ -n "$ORDER_DF" ] && [ -n "$PROD_DF" ] || { echo "Dockerfiles not found"; exit 1; } + echo "order=$ORDER_DF" >> "$GITHUB_OUTPUT" + echo "product=$PROD_DF" >> "$GITHUB_OUTPUT" + + - name: Build & push order-service + run: | + az acr build -r "$ACR_NAME" \ + -t week08/order-service:${TAG} \ + -f "${{ steps.detect.outputs.order }}" \ + "$(dirname "${{ steps.detect.outputs.order }}")" + + - name: Build & push product-service + run: | + az acr build -r "$ACR_NAME" \ + -t week08/product-service:${TAG} \ + -f "${{ steps.detect.outputs.product }}" \ + "$(dirname "${{ steps.detect.outputs.product }}")" + + - name: Output image URIs + run: | + echo "$ACR_LOGIN_SERVER/week08/order-service:${TAG}" + echo "$ACR_LOGIN_SERVER/week08/product-service:${TAG}" From 919dddf49e95980bbbb02f3f96f5b7d24362246f Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 02:22:10 +1000 Subject: [PATCH 12/53] Update backend-cd.yml --- .github/workflows/backend-cd.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 01fc2294..f40255a7 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -3,7 +3,7 @@ on: workflow_dispatch: inputs: tag: - description: "Image tag to deploy (default = last commit SHA)" + description: "Image tag to deploy (defaults to CI run SHA)" required: false workflow_run: workflows: [ "Backend CI - Test, Build and Push Images to ACR" ] @@ -20,7 +20,8 @@ jobs: PRODUCT_DEPLOY: product-service-w08e1 ORDER_CONTAINER: order-service-container PRODUCT_CONTAINER: product-service-container - TAG: ${{ github.event.inputs.tag || github.sha }} + # Use workflow_dispatch input if provided, otherwise the CI run's SHA + TAG: ${{ github.event.inputs.tag != '' && github.event.inputs.tag || github.event.workflow_run.head_sha }} steps: - uses: actions/checkout@v4 @@ -33,11 +34,12 @@ jobs: - name: Set AKS context uses: azure/aks-set-context@v3 with: - resource-group: ${{ secrets.AKS_RG }} # e.g. sit722-week08-rg - cluster-name: ${{ secrets.AKS_NAME }} # your AKS cluster name + resource-group: ${{ secrets.AKS_RG }} + cluster-name: ${{ secrets.AKS_NAME }} - - name: Update images + - name: Deploy images run: | + set -e kubectl set image -n "$NAMESPACE" deploy/$ORDER_DEPLOY $ORDER_CONTAINER=$ACR_LOGIN_SERVER/week08/order-service:$TAG kubectl set image -n "$NAMESPACE" deploy/$PRODUCT_DEPLOY $PRODUCT_CONTAINER=$ACR_LOGIN_SERVER/week08/product-service:$TAG @@ -48,4 +50,5 @@ jobs: - name: Show deployed images run: | - kubectl get deploy -n "$NAMESPACE" -o custom-columns=NAME:.metadata.name,IMAGE:.spec.template.spec.containers[0].image,READY:.status.readyReplicas + kubectl get deploy -n "$NAMESPACE" \ + -o custom-columns=NAME:.metadata.name,IMAGE:.spec.template.spec.containers[0].image,READY:.status.readyReplicas From ef3f53536381e1b84d2d9ee07ce6f240e536f2cf Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 02:26:08 +1000 Subject: [PATCH 13/53] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index a16019f5..7b7b8478 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -1,4 +1,5 @@ name: Backend CI - Test, Build and Push Images to ACR + on: workflow_dispatch: push: @@ -8,29 +9,33 @@ jobs: test_build_push: runs-on: ubuntu-latest env: - ACR_NAME: s722acr84438 # hardcoded to avoid secret typos + # Hardcode your ACR so a missing/typo'd secret can't break the job + ACR_NAME: s722acr84438 ACR_LOGIN_SERVER: s722acr84438.azurecr.io TAG: ${{ github.sha }} steps: - uses: actions/checkout@v4 - - name: Azure login (service principal JSON) + # LOGIN WITH YOUR SP JSON (the single secret AZURE_CREDENTIALS) + - name: Azure login uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Locate Dockerfiles (order/product) + # Find the two Dockerfiles (order & product) + - name: Locate Dockerfiles id: detect shell: bash run: | set -e - ORDER_DF=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) - PROD_DF=$(find . -type f -iname Dockerfile -path '*product*' | head -n1) + ORDER_DF=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) + PROD_DF=$( find . -type f -iname Dockerfile -path '*product*' | head -n1) [ -n "$ORDER_DF" ] && [ -n "$PROD_DF" ] || { echo "Dockerfiles not found"; exit 1; } echo "order=$ORDER_DF" >> "$GITHUB_OUTPUT" echo "product=$PROD_DF" >> "$GITHUB_OUTPUT" + # Build & push directly to ACR (no docker creds needed on runner) - name: Build & push order-service run: | az acr build -r "$ACR_NAME" \ @@ -45,7 +50,7 @@ jobs: -f "${{ steps.detect.outputs.product }}" \ "$(dirname "${{ steps.detect.outputs.product }}")" - - name: Output image URIs + - name: Show image URIs run: | echo "$ACR_LOGIN_SERVER/week08/order-service:${TAG}" echo "$ACR_LOGIN_SERVER/week08/product-service:${TAG}" From 20bac2fab279c04e10b966b51493656e90eeab4c Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 02:26:32 +1000 Subject: [PATCH 14/53] Update backend-cd.yml --- .github/workflows/backend-cd.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index f40255a7..4b20ef49 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -1,16 +1,20 @@ name: Backend CD - Deploy to AKS + on: + # Manual trigger with optional tag override workflow_dispatch: inputs: tag: description: "Image tag to deploy (defaults to CI run SHA)" required: false + # Auto-trigger after CI succeeds workflow_run: workflows: [ "Backend CI - Test, Build and Push Images to ACR" ] types: [ "completed" ] jobs: deploy: + # Only run if CI concluded success, or if manually dispatched if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest env: @@ -20,7 +24,7 @@ jobs: PRODUCT_DEPLOY: product-service-w08e1 ORDER_CONTAINER: order-service-container PRODUCT_CONTAINER: product-service-container - # Use workflow_dispatch input if provided, otherwise the CI run's SHA + # If manual input provided use it, otherwise use CI run SHA TAG: ${{ github.event.inputs.tag != '' && github.event.inputs.tag || github.event.workflow_run.head_sha }} steps: @@ -31,13 +35,14 @@ jobs: with: creds: ${{ secrets.AZURE_CREDENTIALS }} + # Set AKS context (needs AKS_RG and AKS_NAME secrets) - name: Set AKS context uses: azure/aks-set-context@v3 with: resource-group: ${{ secrets.AKS_RG }} cluster-name: ${{ secrets.AKS_NAME }} - - name: Deploy images + - name: Update images run: | set -e kubectl set image -n "$NAMESPACE" deploy/$ORDER_DEPLOY $ORDER_CONTAINER=$ACR_LOGIN_SERVER/week08/order-service:$TAG From 57c1074e8318c71d13866db9309df9d6dc39c28e Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 02:34:16 +1000 Subject: [PATCH 15/53] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 42 +++++++++++++++++++------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 7b7b8478..89fb9b65 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -1,5 +1,4 @@ name: Backend CI - Test, Build and Push Images to ACR - on: workflow_dispatch: push: @@ -9,7 +8,6 @@ jobs: test_build_push: runs-on: ubuntu-latest env: - # Hardcode your ACR so a missing/typo'd secret can't break the job ACR_NAME: s722acr84438 ACR_LOGIN_SERVER: s722acr84438.azurecr.io TAG: ${{ github.sha }} @@ -17,40 +15,50 @@ jobs: steps: - uses: actions/checkout@v4 - # LOGIN WITH YOUR SP JSON (the single secret AZURE_CREDENTIALS) - name: Azure login uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - # Find the two Dockerfiles (order & product) - - name: Locate Dockerfiles - id: detect + - name: Resolve Dockerfile paths (robust) + id: paths shell: bash run: | set -e - ORDER_DF=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) - PROD_DF=$( find . -type f -iname Dockerfile -path '*product*' | head -n1) - [ -n "$ORDER_DF" ] && [ -n "$PROD_DF" ] || { echo "Dockerfiles not found"; exit 1; } - echo "order=$ORDER_DF" >> "$GITHUB_OUTPUT" - echo "product=$PROD_DF" >> "$GITHUB_OUTPUT" + # Preferred locations + C1="backend/order-service/Dockerfile" + C2="backend/product-service/Dockerfile" + + # Fallbacks if the preferred ones don't exist + if [[ ! -f "$C1" ]]; then + C1=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) + fi + if [[ ! -f "$C2" ]]; then + C2=$(find . -type f -iname Dockerfile -path '*product*' | head -n1) + fi + + echo "ORDER_DF=$C1" + echo "PRODUCT_DF=$C2" + [[ -n "$C1" && -f "$C1" && -n "$C2" && -f "$C2" ]] || { echo "Dockerfiles not found"; exit 1; } + + echo "order=$C1" >> "$GITHUB_OUTPUT" + echo "product=$C2" >> "$GITHUB_OUTPUT" - # Build & push directly to ACR (no docker creds needed on runner) - name: Build & push order-service run: | az acr build -r "$ACR_NAME" \ -t week08/order-service:${TAG} \ - -f "${{ steps.detect.outputs.order }}" \ - "$(dirname "${{ steps.detect.outputs.order }}")" + -f "${{ steps.paths.outputs.order }}" \ + "$(dirname "${{ steps.paths.outputs.order }}")" - name: Build & push product-service run: | az acr build -r "$ACR_NAME" \ -t week08/product-service:${TAG} \ - -f "${{ steps.detect.outputs.product }}" \ - "$(dirname "${{ steps.detect.outputs.product }}")" + -f "${{ steps.paths.outputs.product }}" \ + "$(dirname "${{ steps.paths.outputs.product }}")" - - name: Show image URIs + - name: Output image URIs run: | echo "$ACR_LOGIN_SERVER/week08/order-service:${TAG}" echo "$ACR_LOGIN_SERVER/week08/product-service:${TAG}" From ef3d953c0ce2e4557589d6d2bc206785a7b888df Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 02:40:02 +1000 Subject: [PATCH 16/53] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 36 +++++++++++--------------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 89fb9b65..8bce6b02 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -1,4 +1,5 @@ name: Backend CI - Test, Build and Push Images to ACR + on: workflow_dispatch: push: @@ -20,43 +21,30 @@ jobs: with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Resolve Dockerfile paths (robust) - id: paths + - name: Locate Dockerfiles (order & product) + id: detect shell: bash run: | set -e - # Preferred locations - C1="backend/order-service/Dockerfile" - C2="backend/product-service/Dockerfile" - - # Fallbacks if the preferred ones don't exist - if [[ ! -f "$C1" ]]; then - C1=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) - fi - if [[ ! -f "$C2" ]]; then - C2=$(find . -type f -iname Dockerfile -path '*product*' | head -n1) - fi - - echo "ORDER_DF=$C1" - echo "PRODUCT_DF=$C2" - [[ -n "$C1" && -f "$C1" && -n "$C2" && -f "$C2" ]] || { echo "Dockerfiles not found"; exit 1; } - - echo "order=$C1" >> "$GITHUB_OUTPUT" - echo "product=$C2" >> "$GITHUB_OUTPUT" + ORDER_DF=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) + PROD_DF=$( find . -type f -iname Dockerfile -path '*product*' | head -n1) + [ -n "$ORDER_DF" ] && [ -n "$PROD_DF" ] || { echo "Dockerfiles not found"; exit 1; } + echo "order=$ORDER_DF" >> "$GITHUB_OUTPUT" + echo "product=$PROD_DF" >> "$GITHUB_OUTPUT" - name: Build & push order-service run: | az acr build -r "$ACR_NAME" \ -t week08/order-service:${TAG} \ - -f "${{ steps.paths.outputs.order }}" \ - "$(dirname "${{ steps.paths.outputs.order }}")" + -f "${{ steps.detect.outputs.order }}" \ + "$(dirname "${{ steps.detect.outputs.order }}")" - name: Build & push product-service run: | az acr build -r "$ACR_NAME" \ -t week08/product-service:${TAG} \ - -f "${{ steps.paths.outputs.product }}" \ - "$(dirname "${{ steps.paths.outputs.product }}")" + -f "${{ steps.detect.outputs.product }}" \ + "$(dirname "${{ steps.detect.outputs.product }}")" - name: Output image URIs run: | From f4bd6760bc28fa55a3eaf79bccf3b041839050f8 Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 02:40:27 +1000 Subject: [PATCH 17/53] Update backend-cd.yml --- .github/workflows/backend-cd.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 4b20ef49..1ee9cb99 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -14,7 +14,6 @@ on: jobs: deploy: - # Only run if CI concluded success, or if manually dispatched if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest env: @@ -24,7 +23,6 @@ jobs: PRODUCT_DEPLOY: product-service-w08e1 ORDER_CONTAINER: order-service-container PRODUCT_CONTAINER: product-service-container - # If manual input provided use it, otherwise use CI run SHA TAG: ${{ github.event.inputs.tag != '' && github.event.inputs.tag || github.event.workflow_run.head_sha }} steps: @@ -35,12 +33,11 @@ jobs: with: creds: ${{ secrets.AZURE_CREDENTIALS }} - # Set AKS context (needs AKS_RG and AKS_NAME secrets) - name: Set AKS context uses: azure/aks-set-context@v3 with: - resource-group: ${{ secrets.AKS_RG }} - cluster-name: ${{ secrets.AKS_NAME }} + resource-group: ${{ secrets.AKS_RG }} # e.g. sit722-week08-rg + cluster-name: ${{ secrets.AKS_NAME }} # e.g. sit722-aks-wk08 - name: Update images run: | From bcd1f79324472e6df3abb379569e86889a878ece Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 17:51:41 +1000 Subject: [PATCH 18/53] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 46 ++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 8bce6b02..4c873526 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -21,30 +21,54 @@ jobs: with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Locate Dockerfiles (order & product) - id: detect + - name: Verify Azure context (debug) + run: | + set -e + az account show + az acr show -n "$ACR_NAME" -o table + + - name: List repo tree and Dockerfiles (debug) + run: | + set -e + echo "==== REPO TREE (first 200 lines) ====" + ls -la + find . -maxdepth 3 -type f -iname Dockerfile -print | nl + + - name: Resolve Dockerfile paths (prefer canonical paths) + id: paths shell: bash run: | set -e - ORDER_DF=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) - PROD_DF=$( find . -type f -iname Dockerfile -path '*product*' | head -n1) - [ -n "$ORDER_DF" ] && [ -n "$PROD_DF" ] || { echo "Dockerfiles not found"; exit 1; } - echo "order=$ORDER_DF" >> "$GITHUB_OUTPUT" - echo "product=$PROD_DF" >> "$GITHUB_OUTPUT" + # Preferred week08 layout + ORDER="backend/order-service/Dockerfile" + PROD="backend/product-service/Dockerfile" + + # Fall back to auto-discovery if missing + [[ -f "$ORDER" ]] || ORDER=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) + [[ -f "$PROD" ]] || PROD=$(find . -type f -iname Dockerfile -path '*product*' | head -n1) + + echo "ORDER_DF=$ORDER" + echo "PRODUCT_DF=$PROD" + + [[ -n "$ORDER" && -f "$ORDER" ]] || { echo "ERROR: Order Dockerfile not found"; exit 1; } + [[ -n "$PROD" && -f "$PROD" ]] || { echo "ERROR: Product Dockerfile not found"; exit 1; } + + echo "order=$ORDER" >> "$GITHUB_OUTPUT" + echo "product=$PROD" >> "$GITHUB_OUTPUT" - name: Build & push order-service run: | az acr build -r "$ACR_NAME" \ -t week08/order-service:${TAG} \ - -f "${{ steps.detect.outputs.order }}" \ - "$(dirname "${{ steps.detect.outputs.order }}")" + -f "${{ steps.paths.outputs.order }}" \ + "$(dirname "${{ steps.paths.outputs.order }}")" - name: Build & push product-service run: | az acr build -r "$ACR_NAME" \ -t week08/product-service:${TAG} \ - -f "${{ steps.detect.outputs.product }}" \ - "$(dirname "${{ steps.detect.outputs.product }}")" + -f "${{ steps.paths.outputs.product }}" \ + "$(dirname "${{ steps.paths.outputs.product }}")" - name: Output image URIs run: | From 86017b766c9cf8d5013323fc642849eb2662dcff Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 17:55:34 +1000 Subject: [PATCH 19/53] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 76 +++++++++++++++++++------------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 4c873526..602907f1 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -16,59 +16,73 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Azure login + - name: Azure login (SP JSON) uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Verify Azure context (debug) + - name: Debug Azure & ACR run: | set -e az account show - az acr show -n "$ACR_NAME" -o table + az acr show -n "$ACR_NAME" -o table || true - - name: List repo tree and Dockerfiles (debug) - run: | - set -e - echo "==== REPO TREE (first 200 lines) ====" - ls -la - find . -maxdepth 3 -type f -iname Dockerfile -print | nl - - - name: Resolve Dockerfile paths (prefer canonical paths) - id: paths + - name: Find Dockerfiles (order & product) + id: detect shell: bash run: | set -e - # Preferred week08 layout - ORDER="backend/order-service/Dockerfile" - PROD="backend/product-service/Dockerfile" + echo "Listing Dockerfiles (up to depth 4):" + find . -maxdepth 4 -type f -iname Dockerfile -print | nl || true - # Fall back to auto-discovery if missing - [[ -f "$ORDER" ]] || ORDER=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) - [[ -f "$PROD" ]] || PROD=$(find . -type f -iname Dockerfile -path '*product*' | head -n1) + ORDER_DF="backend/order-service/Dockerfile" + PROD_DF="backend/product-service/Dockerfile" - echo "ORDER_DF=$ORDER" - echo "PRODUCT_DF=$PROD" + [[ -f "$ORDER_DF" ]] || ORDER_DF=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) + [[ -f "$PROD_DF" ]] || PROD_DF=$(find . -type f -iname Dockerfile -path '*product*' | head -n1) - [[ -n "$ORDER" && -f "$ORDER" ]] || { echo "ERROR: Order Dockerfile not found"; exit 1; } - [[ -n "$PROD" && -f "$PROD" ]] || { echo "ERROR: Product Dockerfile not found"; exit 1; } + echo "ORDER_DF=$ORDER_DF" + echo "PROD_DF=$PROD_DF" - echo "order=$ORDER" >> "$GITHUB_OUTPUT" - echo "product=$PROD" >> "$GITHUB_OUTPUT" + [[ -n "$ORDER_DF" && -f "$ORDER_DF" ]] || { echo "::error::Order Dockerfile not found"; exit 1; } + [[ -n "$PROD_DF" && -f "$PROD_DF" ]] || { echo "::error::Product Dockerfile not found"; exit 1; } - - name: Build & push order-service + echo "order=$ORDER_DF" >> "$GITHUB_OUTPUT" + echo "product=$PROD_DF" >> "$GITHUB_OUTPUT" + + - name: Build & push with ACR Tasks (preferred) + id: acrbuild + continue-on-error: true run: | + set -e az acr build -r "$ACR_NAME" \ -t week08/order-service:${TAG} \ - -f "${{ steps.paths.outputs.order }}" \ - "$(dirname "${{ steps.paths.outputs.order }}")" + -f "${{ steps.detect.outputs.order }}" \ + "$(dirname "${{ steps.detect.outputs.order }}")" - - name: Build & push product-service - run: | az acr build -r "$ACR_NAME" \ -t week08/product-service:${TAG} \ - -f "${{ steps.paths.outputs.product }}" \ - "$(dirname "${{ steps.paths.outputs.product }}")" + -f "${{ steps.detect.outputs.product }}" \ + "$(dirname "${{ steps.detect.outputs.product }}")" + + # Fallback path: only runs if ACR build failed + - name: Docker login to ACR (fallback path) + if: steps.acrbuild.outcome == 'failure' + uses: azure/docker-login@v2 + with: + login-server: ${{ env.ACR_LOGIN_SERVER }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Build & push with Docker (fallback path) + if: steps.acrbuild.outcome == 'failure' + run: | + set -e + docker build -t $ACR_LOGIN_SERVER/week08/order-service:${TAG} -f "${{ steps.detect.outputs.order }}" "$(dirname "${{ steps.detect.outputs.order }}")" + docker push $ACR_LOGIN_SERVER/week08/order-service:${TAG} + + docker build -t $ACR_LOGIN_SERVER/week08/product-service:${TAG} -f "${{ steps.detect.outputs.product }}" "$(dirname "${{ steps.detect.outputs.product }}")" + docker push $ACR_LOGIN_SERVER/week08/product-service:${TAG} - name: Output image URIs run: | From 896af893a19bae5d34c84bb889ed8c7c1dab0e48 Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:01:15 +1000 Subject: [PATCH 20/53] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 61 +++++++------------------------- 1 file changed, 13 insertions(+), 48 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 602907f1..e98f1a77 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -16,74 +16,39 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Azure login (SP JSON) + - name: Azure login (service principal JSON) uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Debug Azure & ACR - run: | - set -e - az account show - az acr show -n "$ACR_NAME" -o table || true - - name: Find Dockerfiles (order & product) id: detect shell: bash run: | set -e - echo "Listing Dockerfiles (up to depth 4):" - find . -maxdepth 4 -type f -iname Dockerfile -print | nl || true - - ORDER_DF="backend/order-service/Dockerfile" - PROD_DF="backend/product-service/Dockerfile" - - [[ -f "$ORDER_DF" ]] || ORDER_DF=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) - [[ -f "$PROD_DF" ]] || PROD_DF=$(find . -type f -iname Dockerfile -path '*product*' | head -n1) - - echo "ORDER_DF=$ORDER_DF" - echo "PROD_DF=$PROD_DF" - - [[ -n "$ORDER_DF" && -f "$ORDER_DF" ]] || { echo "::error::Order Dockerfile not found"; exit 1; } - [[ -n "$PROD_DF" && -f "$PROD_DF" ]] || { echo "::error::Product Dockerfile not found"; exit 1; } - - echo "order=$ORDER_DF" >> "$GITHUB_OUTPUT" - echo "product=$PROD_DF" >> "$GITHUB_OUTPUT" - - - name: Build & push with ACR Tasks (preferred) - id: acrbuild - continue-on-error: true + ORDER=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) + PROD=$( find . -type f -iname Dockerfile -path '*product*' | head -n1) + [[ -n "$ORDER" && -f "$ORDER" ]] || { echo "Order Dockerfile not found"; exit 1; } + [[ -n "$PROD" && -f "$PROD" ]] || { echo "Product Dockerfile not found"; exit 1; } + echo "order=$ORDER" >> "$GITHUB_OUTPUT" + echo "product=$PROD" >> "$GITHUB_OUTPUT" + echo "Using ORDER=$ORDER" + echo "Using PRODUCT=$PROD" + + - name: Build & push order-service to ACR run: | - set -e az acr build -r "$ACR_NAME" \ -t week08/order-service:${TAG} \ -f "${{ steps.detect.outputs.order }}" \ "$(dirname "${{ steps.detect.outputs.order }}")" + - name: Build & push product-service to ACR + run: | az acr build -r "$ACR_NAME" \ -t week08/product-service:${TAG} \ -f "${{ steps.detect.outputs.product }}" \ "$(dirname "${{ steps.detect.outputs.product }}")" - # Fallback path: only runs if ACR build failed - - name: Docker login to ACR (fallback path) - if: steps.acrbuild.outcome == 'failure' - uses: azure/docker-login@v2 - with: - login-server: ${{ env.ACR_LOGIN_SERVER }} - username: ${{ secrets.ACR_USERNAME }} - password: ${{ secrets.ACR_PASSWORD }} - - - name: Build & push with Docker (fallback path) - if: steps.acrbuild.outcome == 'failure' - run: | - set -e - docker build -t $ACR_LOGIN_SERVER/week08/order-service:${TAG} -f "${{ steps.detect.outputs.order }}" "$(dirname "${{ steps.detect.outputs.order }}")" - docker push $ACR_LOGIN_SERVER/week08/order-service:${TAG} - - docker build -t $ACR_LOGIN_SERVER/week08/product-service:${TAG} -f "${{ steps.detect.outputs.product }}" "$(dirname "${{ steps.detect.outputs.product }}")" - docker push $ACR_LOGIN_SERVER/week08/product-service:${TAG} - - name: Output image URIs run: | echo "$ACR_LOGIN_SERVER/week08/order-service:${TAG}" From 8030489d696189f9101b0842ba3af7e831da29b5 Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:19:07 +1000 Subject: [PATCH 21/53] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index e98f1a77..df4e4555 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -12,15 +12,25 @@ jobs: ACR_NAME: s722acr84438 ACR_LOGIN_SERVER: s722acr84438.azurecr.io TAG: ${{ github.sha }} + SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5 # <-- your subscription steps: - uses: actions/checkout@v4 - - name: Azure login (service principal JSON) + - name: Azure login uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} + # >>> ADD THIS STEP <<< + - name: Set correct subscription (and verify ACR) + run: | + az account set --subscription "$SUB_ID" + echo "Using subscription:" + az account show -o table + echo "Checking ACR exists:" + az acr show -n "$ACR_NAME" -o table + - name: Find Dockerfiles (order & product) id: detect shell: bash @@ -32,17 +42,15 @@ jobs: [[ -n "$PROD" && -f "$PROD" ]] || { echo "Product Dockerfile not found"; exit 1; } echo "order=$ORDER" >> "$GITHUB_OUTPUT" echo "product=$PROD" >> "$GITHUB_OUTPUT" - echo "Using ORDER=$ORDER" - echo "Using PRODUCT=$PROD" - - name: Build & push order-service to ACR + - name: Build & push order-service run: | az acr build -r "$ACR_NAME" \ -t week08/order-service:${TAG} \ -f "${{ steps.detect.outputs.order }}" \ "$(dirname "${{ steps.detect.outputs.order }}")" - - name: Build & push product-service to ACR + - name: Build & push product-service run: | az acr build -r "$ACR_NAME" \ -t week08/product-service:${TAG} \ From f76de91d46f3cfc60eea8138fa12aed032a37134 Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:22:10 +1000 Subject: [PATCH 22/53] Update backend-cd.yml --- .github/workflows/backend-cd.yml | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 1ee9cb99..c6fc26de 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -1,21 +1,22 @@ name: Backend CD - Deploy to AKS on: - # Manual trigger with optional tag override workflow_dispatch: inputs: tag: - description: "Image tag to deploy (defaults to CI run SHA)" + description: "Image tag to deploy (leave blank to use latest CI SHA)" required: false - # Auto-trigger after CI succeeds workflow_run: workflows: [ "Backend CI - Test, Build and Push Images to ACR" ] types: [ "completed" ] + branches: [ "main" ] jobs: deploy: - if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest + # Run on manual trigger OR when CI completed successfully + if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} + env: ACR_LOGIN_SERVER: s722acr84438.azurecr.io NAMESPACE: default @@ -23,7 +24,8 @@ jobs: PRODUCT_DEPLOY: product-service-w08e1 ORDER_CONTAINER: order-service-container PRODUCT_CONTAINER: product-service-container - TAG: ${{ github.event.inputs.tag != '' && github.event.inputs.tag || github.event.workflow_run.head_sha }} + SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5 + TAG: ${{ inputs.tag || github.event.workflow_run.head_sha || github.sha }} steps: - uses: actions/checkout@v4 @@ -33,13 +35,16 @@ jobs: with: creds: ${{ secrets.AZURE_CREDENTIALS }} + - name: Set subscription + run: az account set --subscription "$SUB_ID" + - name: Set AKS context uses: azure/aks-set-context@v3 with: - resource-group: ${{ secrets.AKS_RG }} # e.g. sit722-week08-rg - cluster-name: ${{ secrets.AKS_NAME }} # e.g. sit722-aks-wk08 + resource-group: ${{ secrets.AKS_RG }} + cluster-name: ${{ secrets.AKS_NAME }} - - name: Update images + - name: Patch images to the new tag run: | set -e kubectl set image -n "$NAMESPACE" deploy/$ORDER_DEPLOY $ORDER_CONTAINER=$ACR_LOGIN_SERVER/week08/order-service:$TAG From 7b8b7086421b2308a07b89e1202c383dafad0f2e Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:25:17 +1000 Subject: [PATCH 23/53] Update backend-cd.yml --- .github/workflows/backend-cd.yml | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index c6fc26de..3e968b71 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -14,7 +14,6 @@ on: jobs: deploy: runs-on: ubuntu-latest - # Run on manual trigger OR when CI completed successfully if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} env: @@ -35,23 +34,37 @@ jobs: with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Set subscription - run: az account set --subscription "$SUB_ID" + - name: Set subscription & show context + run: | + az account set --subscription "$SUB_ID" + echo "Using subscription:" + az account show -o table + echo "Cluster listing:" + az aks list -o table - - name: Set AKS context + - name: Set AKS context (admin kubeconfig) uses: azure/aks-set-context@v3 with: resource-group: ${{ secrets.AKS_RG }} cluster-name: ${{ secrets.AKS_NAME }} + admin: true + + - name: Quick cluster debug + run: | + kubectl version --short + kubectl get nodes -o wide + kubectl get deploy -n "$NAMESPACE" - - name: Patch images to the new tag + - name: Patch images to new tag run: | set -e + echo "Deploying tag: $TAG" kubectl set image -n "$NAMESPACE" deploy/$ORDER_DEPLOY $ORDER_CONTAINER=$ACR_LOGIN_SERVER/week08/order-service:$TAG kubectl set image -n "$NAMESPACE" deploy/$PRODUCT_DEPLOY $PRODUCT_CONTAINER=$ACR_LOGIN_SERVER/week08/product-service:$TAG - name: Wait for rollout run: | + set -e kubectl rollout status -n "$NAMESPACE" deploy/$ORDER_DEPLOY kubectl rollout status -n "$NAMESPACE" deploy/$PRODUCT_DEPLOY From 49f0fd67eb02d5542c0e63ef29805e0496430624 Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:30:31 +1000 Subject: [PATCH 24/53] Update backend-cd.yml --- .github/workflows/backend-cd.yml | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 3e968b71..5b9fc697 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -18,12 +18,12 @@ jobs: env: ACR_LOGIN_SERVER: s722acr84438.azurecr.io + SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5 NAMESPACE: default ORDER_DEPLOY: order-service-w08e1 PRODUCT_DEPLOY: product-service-w08e1 ORDER_CONTAINER: order-service-container PRODUCT_CONTAINER: product-service-container - SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5 TAG: ${{ inputs.tag || github.event.workflow_run.head_sha || github.sha }} steps: @@ -34,13 +34,8 @@ jobs: with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Set subscription & show context - run: | - az account set --subscription "$SUB_ID" - echo "Using subscription:" - az account show -o table - echo "Cluster listing:" - az aks list -o table + - name: Set subscription + run: az account set --subscription "$SUB_ID" - name: Set AKS context (admin kubeconfig) uses: azure/aks-set-context@v3 @@ -49,12 +44,6 @@ jobs: cluster-name: ${{ secrets.AKS_NAME }} admin: true - - name: Quick cluster debug - run: | - kubectl version --short - kubectl get nodes -o wide - kubectl get deploy -n "$NAMESPACE" - - name: Patch images to new tag run: | set -e From 79a4258dcb62a247259257e9da01855c09f0b144 Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:30:56 +1000 Subject: [PATCH 25/53] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index df4e4555..5e381e86 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -11,8 +11,8 @@ jobs: env: ACR_NAME: s722acr84438 ACR_LOGIN_SERVER: s722acr84438.azurecr.io + SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5 TAG: ${{ github.sha }} - SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5 # <-- your subscription steps: - uses: actions/checkout@v4 @@ -22,13 +22,10 @@ jobs: with: creds: ${{ secrets.AZURE_CREDENTIALS }} - # >>> ADD THIS STEP <<< - - name: Set correct subscription (and verify ACR) + - name: Set subscription & verify ACR run: | + set -e az account set --subscription "$SUB_ID" - echo "Using subscription:" - az account show -o table - echo "Checking ACR exists:" az acr show -n "$ACR_NAME" -o table - name: Find Dockerfiles (order & product) From 6d329d4ca942e5e689cfb177f6499dcfccd97b2d Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:34:31 +1000 Subject: [PATCH 26/53] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 5e381e86..b9849859 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -10,9 +10,8 @@ jobs: runs-on: ubuntu-latest env: ACR_NAME: s722acr84438 - ACR_LOGIN_SERVER: s722acr84438.azurecr.io - SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5 TAG: ${{ github.sha }} + SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5 steps: - uses: actions/checkout@v4 @@ -22,11 +21,8 @@ jobs: with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Set subscription & verify ACR - run: | - set -e - az account set --subscription "$SUB_ID" - az acr show -n "$ACR_NAME" -o table + - name: Set subscription + run: az account set --subscription "$SUB_ID" - name: Find Dockerfiles (order & product) id: detect @@ -53,8 +49,3 @@ jobs: -t week08/product-service:${TAG} \ -f "${{ steps.detect.outputs.product }}" \ "$(dirname "${{ steps.detect.outputs.product }}")" - - - name: Output image URIs - run: | - echo "$ACR_LOGIN_SERVER/week08/order-service:${TAG}" - echo "$ACR_LOGIN_SERVER/week08/product-service:${TAG}" From 76afb5b90e8087299f900d43b0a91f536e368453 Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:38:28 +1000 Subject: [PATCH 27/53] Update backend_ci.yml --- .github/workflows/backend_ci.yml | 44 ++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index b9849859..6562b439 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -10,13 +10,14 @@ jobs: runs-on: ubuntu-latest env: ACR_NAME: s722acr84438 - TAG: ${{ github.sha }} + ACR_SERVER: s722acr84438.azurecr.io SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5 + TAG: ${{ github.sha }} steps: - uses: actions/checkout@v4 - - name: Azure login + - name: Azure login (service principal) uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} @@ -24,28 +25,45 @@ jobs: - name: Set subscription run: az account set --subscription "$SUB_ID" - - name: Find Dockerfiles (order & product) + - name: Login docker to ACR (token-based) + run: az acr login -n "$ACR_NAME" + + - name: Find Dockerfiles (order + product) id: detect shell: bash run: | set -e + # Try smart search first ORDER=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) PROD=$( find . -type f -iname Dockerfile -path '*product*' | head -n1) + + # Fallback to common paths if needed + [[ -z "$ORDER" && -f "order-service/Dockerfile" ]] && ORDER="order-service/Dockerfile" + [[ -z "$PROD" && -f "product-service/Dockerfile" ]] && PROD="product-service/Dockerfile" + [[ -n "$ORDER" && -f "$ORDER" ]] || { echo "Order Dockerfile not found"; exit 1; } [[ -n "$PROD" && -f "$PROD" ]] || { echo "Product Dockerfile not found"; exit 1; } + echo "order=$ORDER" >> "$GITHUB_OUTPUT" echo "product=$PROD" >> "$GITHUB_OUTPUT" + echo "Found ORDER=$ORDER" + echo "Found PRODUCT=$PROD" + + - name: Build & push order-service (Docker) + run: | + ORDER_DF="${{ steps.detect.outputs.order }}" + ORDER_CTX="$(dirname "$ORDER_DF")" + docker build -t "$ACR_SERVER/week08/order-service:${TAG}" -f "$ORDER_DF" "$ORDER_CTX" + docker push "$ACR_SERVER/week08/order-service:${TAG}" - - name: Build & push order-service + - name: Build & push product-service (Docker) run: | - az acr build -r "$ACR_NAME" \ - -t week08/order-service:${TAG} \ - -f "${{ steps.detect.outputs.order }}" \ - "$(dirname "${{ steps.detect.outputs.order }}")" + PROD_DF="${{ steps.detect.outputs.product }}" + PROD_CTX="$(dirname "$PROD_DF")" + docker build -t "$ACR_SERVER/week08/product-service:${TAG}" -f "$PROD_DF" "$PROD_CTX" + docker push "$ACR_SERVER/week08/product-service:${TAG}" - - name: Build & push product-service + - name: Show image URIs run: | - az acr build -r "$ACR_NAME" \ - -t week08/product-service:${TAG} \ - -f "${{ steps.detect.outputs.product }}" \ - "$(dirname "${{ steps.detect.outputs.product }}")" + echo "$ACR_SERVER/week08/order-service:${TAG}" + echo "$ACR_SERVER/week08/product-service:${TAG}" From d01b0becd038cbb5b969c6b8de842eaf34a28e91 Mon Sep 17 00:00:00 2001 From: AkankshaNunakani <106013971+AkankshaNunakani@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:38:55 +1000 Subject: [PATCH 28/53] Update backend-cd.yml --- .github/workflows/backend-cd.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 5b9fc697..3d708890 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -15,7 +15,6 @@ jobs: deploy: runs-on: ubuntu-latest if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} - env: ACR_LOGIN_SERVER: s722acr84438.azurecr.io SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5 From f2f40fe25e3c0105e4939370685ac4eb564f9027 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Sat, 20 Sep 2025 19:21:07 +1000 Subject: [PATCH 29/53] Step 6: point frontend to AKS product/order services --- frontend/main.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/main.js b/frontend/main.js index f321fd91..1bb4edef 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -1,4 +1,4 @@ -// week08/frontend/main.js +// week08/frontend/main.js document.addEventListener('DOMContentLoaded', () => { // API endpoints for the Product and Order services. @@ -8,9 +8,9 @@ document.addEventListener('DOMContentLoaded', () => { const ORDER_API_BASE_URL = '_ORDER_API_URL_'; // Product Service is named 'product-service-w04e2' and exposes port 8000 internally. - //const PRODUCT_API_BASE_URL = 'http://product-service-w04e2:8000'; + //const PRODUCT_API_BASE_URL = 'http://4.254.109.41:8000'; // Order Service is named 'order-service-w04e2' and exposes port 8001 internally. - //const ORDER_API_BASE_URL = 'http://order-service-w04e2:8001'; + //const ORDER_API_BASE_URL = 'http://20.227.68.18:8001'; // DOM Elements const messageBox = document.getElementById('message-box'); @@ -426,3 +426,4 @@ document.addEventListener('DOMContentLoaded', () => { fetchProducts(); fetchOrders(); }); + From a80c0179f61b008d5faed0b2be51ec43c3fd8be5 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Sat, 20 Sep 2025 20:16:50 +1000 Subject: [PATCH 30/53] Update frontend APIs to and --- frontend/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/main.js b/frontend/main.js index 1bb4edef..5299d9a5 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -1,4 +1,4 @@ -// week08/frontend/main.js +// week08/frontend/main.js document.addEventListener('DOMContentLoaded', () => { // API endpoints for the Product and Order services. From aca16b18c0740c38f8bb0534363cc73e5e38843b Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Mon, 29 Sep 2025 22:07:59 +1000 Subject: [PATCH 31/53] test: trigger Frontend CI only --- frontend/README.md | Bin 0 -> 66 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 frontend/README.md diff --git a/frontend/README.md b/frontend/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d6ca2e0ca2a6588387adfe855ed138e455cfcdca GIT binary patch literal 66 zcmezWuY{q9A(J5;2vdP91qNpZPatW;U;xCX47xzt5=a^W$q*oE#9##!F$a>SKoMRB GE(QRx9SO|< literal 0 HcmV?d00001 From c1fc539fd74a958d900a21b5dbd129a50105988c Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Mon, 29 Sep 2025 22:11:48 +1000 Subject: [PATCH 32/53] ci: add consolidated CI (Frontend & Backend) --- .github/workflows/ci.yml | 143 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..a4d51387 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,143 @@ +name: CI Frontend and Backend + +on: + pull_request: + branches: [development] + paths: + - "frontend/**" + - "order_service/**" + - "product_service/**" + push: + branches: [main] + paths: + - "frontend/**" + - "order_service/**" + - "product_service/**" + +permissions: + contents: read + id-token: write + packages: write + +env: + ACR_LOGIN: ${{ vars.ACR_LOGIN }} + +jobs: + changes: + name: Detect changed paths + runs-on: ubuntu-latest + outputs: + frontend: ${{ steps.filter.outputs.frontend }} + order: ${{ steps.filter.outputs.order }} + product: ${{ steps.filter.outputs.product }} + steps: + - uses: actions/checkout@v4 + - id: filter + uses: dorny/paths-filter@v3 + with: + filters: | + frontend: + - 'frontend/**' + order: + - 'order_service/**' + product: + - 'product_service/**' + + build_frontend: + name: Build Frontend + runs-on: ubuntu-latest + needs: changes + if: github.event_name == 'push' || (github.event_name == 'pull_request' && needs.changes.outputs.frontend == 'true') + steps: + - uses: actions/checkout@v4 + - name: Frontend checks + run: echo Running frontend checks + - uses: docker/setup-buildx-action@v3 + - name: Azure login + if: github.event_name == 'push' && github.ref_name == 'main' + uses: azure/login@v2 + with: + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + client-id: ${{ secrets.AZURE_CLIENT_ID }} + - name: ACR login + if: github.event_name == 'push' && github.ref_name == 'main' + run: | + test -n "${ACR_LOGIN}" || { echo ACR_LOGIN not set; exit 0; } + az acr login --name ${ACR_LOGIN%%.*} + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: ./frontend + tags: | + ${{ env.ACR_LOGIN }}/frontend:${{ github.sha }} + ${{ env.ACR_LOGIN }}/frontend:latest + push: ${{ github.event_name == 'push' && github.ref_name == 'main' }} + cache-from: type=gha + cache-to: type=gha,mode=max + + build_backend_order: + name: Build Backend Order Service + runs-on: ubuntu-latest + needs: changes + if: github.event_name == 'push' || (github.event_name == 'pull_request' && needs.changes.outputs.order == 'true') + steps: + - uses: actions/checkout@v4 + - name: Backend order checks + run: echo Running backend order checks + - uses: docker/setup-buildx-action@v3 + - name: Azure login + if: github.event_name == 'push' && github.ref_name == 'main' + uses: azure/login@v2 + with: + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + client-id: ${{ secrets.AZURE_CLIENT_ID }} + - name: ACR login + if: github.event_name == 'push' && github.ref_name == 'main' + run: | + test -n "${ACR_LOGIN}" || { echo ACR_LOGIN not set; exit 0; } + az acr login --name ${ACR_LOGIN%%.*} + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: ./order_service + tags: | + ${{ env.ACR_LOGIN }}/week08/order-service:${{ github.sha }} + ${{ env.ACR_LOGIN }}/week08/order-service:latest + push: ${{ github.event_name == 'push' && github.ref_name == 'main' }} + cache-from: type=gha + cache-to: type=gha,mode=max + + build_backend_product: + name: Build Backend Product Service + runs-on: ubuntu-latest + needs: changes + if: github.event_name == 'push' || (github.event_name == 'pull_request' && needs.changes.outputs.product == 'true') + steps: + - uses: actions/checkout@v4 + - name: Backend product checks + run: echo Running backend product checks + - uses: docker/setup-buildx-action@v3 + - name: Azure login + if: github.event_name == 'push' && github.ref_name == 'main' + uses: azure/login@v2 + with: + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + client-id: ${{ secrets.AZURE_CLIENT_ID }} + - name: ACR login + if: github.event_name == 'push' && github.ref_name == 'main' + run: | + test -n "${ACR_LOGIN}" || { echo ACR_LOGIN not set; exit 0; } + az acr login --name ${ACR_LOGIN%%.*} + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: ./product_service + tags: | + ${{ env.ACR_LOGIN }}/week08/product-service:${{ github.sha }} + ${{ env.ACR_LOGIN }}/week08/product-service:latest + push: ${{ github.event_name == 'push' && github.ref_name == 'main' }} + cache-from: type=gha + cache-to: type=gha,mode=max From 5cbfd0a67fa32ec11b93e6c2f4057afd4c7f3766 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Mon, 29 Sep 2025 22:22:11 +1000 Subject: [PATCH 33/53] ci: add consolidated CI (Frontend & Backend) --- .github/workflows/ci.yml | 82 +++++++++++----------------------------- 1 file changed, 22 insertions(+), 60 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4d51387..cf25ee4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,27 +1,13 @@ name: CI Frontend and Backend - on: pull_request: branches: [development] - paths: - - "frontend/**" - - "order_service/**" - - "product_service/**" + paths: ["frontend/**","order_service/**","product_service/**"] push: branches: [main] - paths: - - "frontend/**" - - "order_service/**" - - "product_service/**" - -permissions: - contents: read - id-token: write - packages: write - -env: - ACR_LOGIN: ${{ vars.ACR_LOGIN }} - + paths: ["frontend/**","order_service/**","product_service/**"] +permissions: { contents: read, id-token: write, packages: write } +env: { ACR_LOGIN: ${{ vars.ACR_LOGIN }} } jobs: changes: name: Detect changed paths @@ -36,13 +22,9 @@ jobs: uses: dorny/paths-filter@v3 with: filters: | - frontend: - - 'frontend/**' - order: - - 'order_service/**' - product: - - 'product_service/**' - + frontend: ['frontend/**'] + order: ['order_service/**'] + product: ['product_service/**'] build_frontend: name: Build Frontend runs-on: ubuntu-latest @@ -50,23 +32,17 @@ jobs: if: github.event_name == 'push' || (github.event_name == 'pull_request' && needs.changes.outputs.frontend == 'true') steps: - uses: actions/checkout@v4 - - name: Frontend checks - run: echo Running frontend checks + - run: echo Running frontend checks - uses: docker/setup-buildx-action@v3 - - name: Azure login - if: github.event_name == 'push' && github.ref_name == 'main' + - if: github.event_name == 'push' && github.ref_name == 'main' uses: azure/login@v2 with: tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} client-id: ${{ secrets.AZURE_CLIENT_ID }} - - name: ACR login - if: github.event_name == 'push' && github.ref_name == 'main' - run: | - test -n "${ACR_LOGIN}" || { echo ACR_LOGIN not set; exit 0; } - az acr login --name ${ACR_LOGIN%%.*} - - name: Build and push - uses: docker/build-push-action@v6 + - if: github.event_name == 'push' && github.ref_name == 'main' + run: test -n "${ACR_LOGIN}" || { echo ACR_LOGIN not set; exit 0; }; az acr login --name ${ACR_LOGIN%%.*} + - uses: docker/build-push-action@v6 with: context: ./frontend tags: | @@ -75,7 +51,6 @@ jobs: push: ${{ github.event_name == 'push' && github.ref_name == 'main' }} cache-from: type=gha cache-to: type=gha,mode=max - build_backend_order: name: Build Backend Order Service runs-on: ubuntu-latest @@ -83,23 +58,17 @@ jobs: if: github.event_name == 'push' || (github.event_name == 'pull_request' && needs.changes.outputs.order == 'true') steps: - uses: actions/checkout@v4 - - name: Backend order checks - run: echo Running backend order checks + - run: echo Running backend order checks - uses: docker/setup-buildx-action@v3 - - name: Azure login - if: github.event_name == 'push' && github.ref_name == 'main' + - if: github.event_name == 'push' && github.ref_name == 'main' uses: azure/login@v2 with: tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} client-id: ${{ secrets.AZURE_CLIENT_ID }} - - name: ACR login - if: github.event_name == 'push' && github.ref_name == 'main' - run: | - test -n "${ACR_LOGIN}" || { echo ACR_LOGIN not set; exit 0; } - az acr login --name ${ACR_LOGIN%%.*} - - name: Build and push - uses: docker/build-push-action@v6 + - if: github.event_name == 'push' && github.ref_name == 'main' + run: test -n "${ACR_LOGIN}" || { echo ACR_LOGIN not set; exit 0; }; az acr login --name ${ACR_LOGIN%%.*} + - uses: docker/build-push-action@v6 with: context: ./order_service tags: | @@ -108,7 +77,6 @@ jobs: push: ${{ github.event_name == 'push' && github.ref_name == 'main' }} cache-from: type=gha cache-to: type=gha,mode=max - build_backend_product: name: Build Backend Product Service runs-on: ubuntu-latest @@ -116,23 +84,17 @@ jobs: if: github.event_name == 'push' || (github.event_name == 'pull_request' && needs.changes.outputs.product == 'true') steps: - uses: actions/checkout@v4 - - name: Backend product checks - run: echo Running backend product checks + - run: echo Running backend product checks - uses: docker/setup-buildx-action@v3 - - name: Azure login - if: github.event_name == 'push' && github.ref_name == 'main' + - if: github.event_name == 'push' && github.ref_name == 'main' uses: azure/login@v2 with: tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} client-id: ${{ secrets.AZURE_CLIENT_ID }} - - name: ACR login - if: github.event_name == 'push' && github.ref_name == 'main' - run: | - test -n "${ACR_LOGIN}" || { echo ACR_LOGIN not set; exit 0; } - az acr login --name ${ACR_LOGIN%%.*} - - name: Build and push - uses: docker/build-push-action@v6 + - if: github.event_name == 'push' && github.ref_name == 'main' + run: test -n "${ACR_LOGIN}" || { echo ACR_LOGIN not set; exit 0; }; az acr login --name ${ACR_LOGIN%%.*} + - uses: docker/build-push-action@v6 with: context: ./product_service tags: | From e4f8fd56dfde4efd510792a317be76df1b28c96e Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Tue, 30 Sep 2025 03:22:39 +1000 Subject: [PATCH 34/53] chore: disable legacy frontend/backend CI/CD (kept for evidence) --- .github/workflows/backend-cd.yml.disabled | 62 +++++++++++++++ .github/workflows/backend_ci.yml.disabled | 69 ++++++++++++++++ .github/workflows/frontend-cd.yml.disabled | 93 ++++++++++++++++++++++ .github/workflows/frontend_ci.yml.disabled | 53 ++++++++++++ 4 files changed, 277 insertions(+) create mode 100644 .github/workflows/backend-cd.yml.disabled create mode 100644 .github/workflows/backend_ci.yml.disabled create mode 100644 .github/workflows/frontend-cd.yml.disabled create mode 100644 .github/workflows/frontend_ci.yml.disabled diff --git a/.github/workflows/backend-cd.yml.disabled b/.github/workflows/backend-cd.yml.disabled new file mode 100644 index 00000000..3d708890 --- /dev/null +++ b/.github/workflows/backend-cd.yml.disabled @@ -0,0 +1,62 @@ +name: Backend CD - Deploy to AKS + +on: + workflow_dispatch: + inputs: + tag: + description: "Image tag to deploy (leave blank to use latest CI SHA)" + required: false + workflow_run: + workflows: [ "Backend CI - Test, Build and Push Images to ACR" ] + types: [ "completed" ] + branches: [ "main" ] + +jobs: + deploy: + runs-on: ubuntu-latest + if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} + env: + ACR_LOGIN_SERVER: s722acr84438.azurecr.io + SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5 + NAMESPACE: default + ORDER_DEPLOY: order-service-w08e1 + PRODUCT_DEPLOY: product-service-w08e1 + ORDER_CONTAINER: order-service-container + PRODUCT_CONTAINER: product-service-container + TAG: ${{ inputs.tag || github.event.workflow_run.head_sha || github.sha }} + + steps: + - uses: actions/checkout@v4 + + - name: Azure login + uses: azure/login@v2 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Set subscription + run: az account set --subscription "$SUB_ID" + + - name: Set AKS context (admin kubeconfig) + uses: azure/aks-set-context@v3 + with: + resource-group: ${{ secrets.AKS_RG }} + cluster-name: ${{ secrets.AKS_NAME }} + admin: true + + - name: Patch images to new tag + run: | + set -e + echo "Deploying tag: $TAG" + kubectl set image -n "$NAMESPACE" deploy/$ORDER_DEPLOY $ORDER_CONTAINER=$ACR_LOGIN_SERVER/week08/order-service:$TAG + kubectl set image -n "$NAMESPACE" deploy/$PRODUCT_DEPLOY $PRODUCT_CONTAINER=$ACR_LOGIN_SERVER/week08/product-service:$TAG + + - name: Wait for rollout + run: | + set -e + kubectl rollout status -n "$NAMESPACE" deploy/$ORDER_DEPLOY + kubectl rollout status -n "$NAMESPACE" deploy/$PRODUCT_DEPLOY + + - name: Show deployed images + run: | + kubectl get deploy -n "$NAMESPACE" \ + -o custom-columns=NAME:.metadata.name,IMAGE:.spec.template.spec.containers[0].image,READY:.status.readyReplicas diff --git a/.github/workflows/backend_ci.yml.disabled b/.github/workflows/backend_ci.yml.disabled new file mode 100644 index 00000000..6562b439 --- /dev/null +++ b/.github/workflows/backend_ci.yml.disabled @@ -0,0 +1,69 @@ +name: Backend CI - Test, Build and Push Images to ACR + +on: + workflow_dispatch: + push: + branches: [ "main" ] + +jobs: + test_build_push: + runs-on: ubuntu-latest + env: + ACR_NAME: s722acr84438 + ACR_SERVER: s722acr84438.azurecr.io + SUB_ID: 3ec3f453-a0b9-4c9e-81d1-fc985be293b5 + TAG: ${{ github.sha }} + + steps: + - uses: actions/checkout@v4 + + - name: Azure login (service principal) + uses: azure/login@v2 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Set subscription + run: az account set --subscription "$SUB_ID" + + - name: Login docker to ACR (token-based) + run: az acr login -n "$ACR_NAME" + + - name: Find Dockerfiles (order + product) + id: detect + shell: bash + run: | + set -e + # Try smart search first + ORDER=$(find . -type f -iname Dockerfile -path '*order*' | head -n1) + PROD=$( find . -type f -iname Dockerfile -path '*product*' | head -n1) + + # Fallback to common paths if needed + [[ -z "$ORDER" && -f "order-service/Dockerfile" ]] && ORDER="order-service/Dockerfile" + [[ -z "$PROD" && -f "product-service/Dockerfile" ]] && PROD="product-service/Dockerfile" + + [[ -n "$ORDER" && -f "$ORDER" ]] || { echo "Order Dockerfile not found"; exit 1; } + [[ -n "$PROD" && -f "$PROD" ]] || { echo "Product Dockerfile not found"; exit 1; } + + echo "order=$ORDER" >> "$GITHUB_OUTPUT" + echo "product=$PROD" >> "$GITHUB_OUTPUT" + echo "Found ORDER=$ORDER" + echo "Found PRODUCT=$PROD" + + - name: Build & push order-service (Docker) + run: | + ORDER_DF="${{ steps.detect.outputs.order }}" + ORDER_CTX="$(dirname "$ORDER_DF")" + docker build -t "$ACR_SERVER/week08/order-service:${TAG}" -f "$ORDER_DF" "$ORDER_CTX" + docker push "$ACR_SERVER/week08/order-service:${TAG}" + + - name: Build & push product-service (Docker) + run: | + PROD_DF="${{ steps.detect.outputs.product }}" + PROD_CTX="$(dirname "$PROD_DF")" + docker build -t "$ACR_SERVER/week08/product-service:${TAG}" -f "$PROD_DF" "$PROD_CTX" + docker push "$ACR_SERVER/week08/product-service:${TAG}" + + - name: Show image URIs + run: | + echo "$ACR_SERVER/week08/order-service:${TAG}" + echo "$ACR_SERVER/week08/product-service:${TAG}" diff --git a/.github/workflows/frontend-cd.yml.disabled b/.github/workflows/frontend-cd.yml.disabled new file mode 100644 index 00000000..0a0879c8 --- /dev/null +++ b/.github/workflows/frontend-cd.yml.disabled @@ -0,0 +1,93 @@ +# week08/.github/workflows/frontend-cd.yml + +name: CD - Deploy Frontend to AKS + +# This workflow can be called by other workflows and takes inputs. +# Or it can be run manually if you provide the IPs. +on: + workflow_dispatch: + inputs: + product_api_ip: + description: 'External IP of Product Service' + required: true + default: 'http://: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: '' + aks_resource_group: + description: 'Resource Group of the AKS Cluster' + required: true + default: '<' + + workflow_call: + inputs: + product_api_ip: + required: true + type: string + order_api_ip: + required: true + type: string + aks_cluster_name: + required: true + type: string + aks_resource_group: + required: true + type: string + +jobs: + deploy_frontend: + runs-on: ubuntu-latest + environment: Production + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Azure login using a Service Principal secret + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + # Login to Azure Container Registry (ACR) + - name: Login to Azure Container Registry + run: az acr login --name ${{ secrets.AZURE_CONTAINER_REGISTRY }} + + - name: Inject Backend IPs into Frontend main.js + run: | + echo "Injecting IPs into frontend/static/js/main.js" + # Ensure frontend/main.js is directly in the path for sed + sed -i "s|_PRODUCT_API_URL_|${{ inputs.product_api_ip }}|g" frontend/main.js + sed -i "s|_ORDER_API_URL_|${{ inputs.order_api_ip }}|g" frontend/main.js + + # Display the modified file content for debugging + echo "--- Modified main.js content ---" + cat frontend/main.js + echo "---------------------------------" + + # Build and Push Docker image for Frontend + - name: Build and Push Frontend Image + run: | + docker build -t ${{ secrets.AZURE_CONTAINER_REGISTRY }}/frontend:latest ./frontend/ + docker push ${{ secrets.AZURE_CONTAINER_REGISTRY }}/frontend:latest + + - name: Set Kubernetes context (get AKS credentials) + uses: azure/aks-set-context@v3 + with: + resource-group: ${{ inputs.aks_resource_group }} + cluster-name: ${{ inputs.aks_cluster_name }} + + - name: Deploy Frontend to AKS + run: | + echo "Deploying frontend with latest tag to AKS cluster: ${{ inputs.aks_cluster_name }}" + cd k8s/ + # Ensure frontend-service.yaml is configured with your ACR + kubectl apply -f frontend.yaml + + - name: Logout from Azure (AKS deployment) + run: az logout diff --git a/.github/workflows/frontend_ci.yml.disabled b/.github/workflows/frontend_ci.yml.disabled new file mode 100644 index 00000000..9f9e76d9 --- /dev/null +++ b/.github/workflows/frontend_ci.yml.disabled @@ -0,0 +1,53 @@ +# week08/.github/workflows/frontend_ci.yml + +name: Frontend CI - Build & Push Image + +on: + # Manual trigger + workflow_dispatch: + + # Automatically on pushes to main branch + push: + branches: + - main + paths: # Only trigger if changes are in the frontend directory + - 'frontend/**' + - '.github/workflows/frontend_ci.yml' # Trigger if this workflow file changes + +# Define global environment variables that can be used across jobs +env: + # ACR Login Server (e.g., myregistry.azurecr.io) + # This needs to be set as a GitHub Repository Secret + ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} + # Dynamically generate image tags based on Git SHA and GitHub Run ID + # This provides unique, traceable tags for each image build + IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} + +jobs: + build_and_push_frontend: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Azure login using a Service Principal secret + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + # Login to Azure Container Registry (ACR) + - name: Login to Azure Container Registry + run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} + + # Build and Push Docker image for Frontend + - name: Build and Push Frontend Image + run: | + docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/ + docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest + + # Logout from Azure for security (runs even if image push fails) + - name: Logout from Azure + run: az logout + if: always() From ceef031848995bd5093f14ded48c7c33fd41fc6d Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Wed, 1 Oct 2025 21:03:32 +1000 Subject: [PATCH 35/53] test(frontend): prove PR path filter --- frontend/README.md | Bin 66 -> 124 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index d6ca2e0ca2a6588387adfe855ed138e455cfcdca..05bdee72e5b650d9fc47a760128299450959fcd8 100644 GIT binary patch delta 63 zcmZ>&nc!qq!cfGJ$&e0&sX&$jgAs!P5SudSG8h6`xwkjKlw G#Q*?kMhMOT delta 4 Lcmb<%n&1Qg1RMd8 From a839315e2a7fc63371b9a45dd4c578854092c3b4 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Wed, 1 Oct 2025 21:25:23 +1000 Subject: [PATCH 36/53] test(frontend): PR path filter proof (do not merge yet) --- frontend/README.md | Bin 124 -> 202 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 05bdee72e5b650d9fc47a760128299450959fcd8..0347764a1397a28619ae7f3209272f38a36d6b4c 100644 GIT binary patch delta 53 zcmb<9#WV9dbF Hz{LOnSvCq| delta 5 McmX@bSTmsp00#>KQ~&?~ From 5b150bcd40233242feeb734c0e71841936055f94 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Wed, 1 Oct 2025 21:35:34 +1000 Subject: [PATCH 37/53] test(frontend): proof run for 9.2C --- frontend/README.md | Bin 202 -> 256 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 0347764a1397a28619ae7f3209272f38a36d6b4c..4a98bb0134c9ead8390a111be0863a7ff9448eb5 100644 GIT binary patch delta 34 ocmX@b*uXU56lVcL5ko!@rcLyh=QCz7Ww2r}W-wvkW#D1}0HS~g1ONa4 delta 6 NcmZo*I>k8Q6aWY%0;m80 From 0dc5647fb63684eb979e068cda31e2785f3885d6 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Wed, 1 Oct 2025 21:56:23 +1000 Subject: [PATCH 38/53] test: retrigger PR CI (frontend-only) --- frontend/README.md | Bin 256 -> 308 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 4a98bb0134c9ead8390a111be0863a7ff9448eb5..ec348df0147ea19a1c05f7318f0cc4d41090de7e 100644 GIT binary patch delta 32 mcmZo*+QPJek-dZ=lOdTQd!oNQpDBYGgB61j5b`o`F#rI0y#=`d delta 6 NcmdnO)WEcW5da5|0onin From 30912a3a216f7b4fb3063ad493ab9c2932896a65 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Wed, 1 Oct 2025 22:12:00 +1000 Subject: [PATCH 39/53] test(frontend): prove paths-filter (frontend only) --- frontend/README.md | Bin 308 -> 372 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index ec348df0147ea19a1c05f7318f0cc4d41090de7e..865922c19805eb24f74dbc64415386649e8be5c6 100644 GIT binary patch delta 41 rcmdnO^o41I2_ts_LlHwh5T-FGO#H7bWW->_V8{R>4S Date: Wed, 1 Oct 2025 22:15:29 +1000 Subject: [PATCH 40/53] test(frontend): paths-filter proof (frontend only) --- frontend/README.md | Bin 372 -> 426 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 865922c19805eb24f74dbc64415386649e8be5c6..6e106e3ed4e4b843867e337caa411c617cb3b6b6 100644 GIT binary patch delta 29 jcmeyuw2FB{3FE|5DndpKRt$y=ra;n&!GeL8fr|kEeMAN4 delta 7 OcmZ3*{Do;l2_paugaXL` From 3e7bdc9734cc4cdffad86e4a6e92a7b099d4e085 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Wed, 1 Oct 2025 22:21:25 +1000 Subject: [PATCH 41/53] test(frontend): paths-filter proof (frontend only) --- frontend/README.md | Bin 426 -> 480 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 6e106e3ed4e4b843867e337caa411c617cb3b6b6..006a66306b426e1f5be8a1a58d124d4227df0b7e 100644 GIT binary patch delta 26 hcmZ3*{D67GD#pnrj2e7K42BF=3`Pv547?0n3;<;61w{Y= delta 7 OcmaFByo!0lDn Date: Wed, 1 Oct 2025 22:24:49 +1000 Subject: [PATCH 42/53] test(frontend): paths-filter proof (frontend only) --- frontend/README.md | Bin 480 -> 534 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 006a66306b426e1f5be8a1a58d124d4227df0b7e..2191d00781dc03bc252b78964750bb41dadcd497 100644 GIT binary patch delta 26 gcmaFBJdI_;1IEcEj2e7K3?>X#Ky1mt%fQ6|0BA=AaR2}S delta 7 OcmbQn@_>2614aN0b^{Lp From c03b9f40102b5db26de2501102f5f56ae72a06c4 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Wed, 1 Oct 2025 22:31:56 +1000 Subject: [PATCH 43/53] test(frontend): paths-filter proof (frontend only) --- frontend/README.md | Bin 534 -> 588 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 2191d00781dc03bc252b78964750bb41dadcd497..5602fd5aa87977c5172dc18289dab50cb9979172 100644 GIT binary patch delta 26 hcmbQna)xDt7}MkuMh!k=215ob22%zz23`g(1^`t~1d#v$ delta 7 OcmX@ZGL2<}7!v>r?*cOb From fdf39f6e9b6f64da09b4203a3c61d5b9b0877d03 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Wed, 1 Oct 2025 22:34:37 +1000 Subject: [PATCH 44/53] test(frontend): paths-filter proof (frontend only) --- frontend/README.md | Bin 588 -> 670 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 5602fd5aa87977c5172dc18289dab50cb9979172..e8bd80df39c824ebcee16d853e4af5555be68568 100644 GIT binary patch delta 52 zcmX@ZGLLnG57T5ZCM^vU1}g?*26F~I215oT1`7sDAlnECwSjyCpqv2^@-lES008** B2O$6e delta 7 OcmbQodWL0#4-)_jEdp`? From f9894032f8d5476bb30b8ca22fb46c1aa2d14037 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Wed, 1 Oct 2025 22:53:04 +1000 Subject: [PATCH 45/53] test(frontend): trigger CI from feat/ci-proof-frontend5 --- frontend/README.md | Bin 670 -> 810 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index e8bd80df39c824ebcee16d853e4af5555be68568..41457337b96f64f87020eb1a05ee5b06c56597f3 100644 GIT binary patch delta 112 zcmbQox{7VXJf_KFOd2Vs48{yr3X%hwu25lhE04!&~pumvEP{feW skPBv|G9)sTFz7QRGh{O8G8BMi@_{OJp{nwLvZ)Mt3@Jdfcp11D068uaW&i*H delta 7 OcmZ3*Hjj0~JSG4ONdlw* From 5978c387e16d83f03a0a2e8557c6e95d2fe15375 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Wed, 1 Oct 2025 23:02:45 +1000 Subject: [PATCH 46/53] test(frontend): rerun PR CI (frontend only) --- frontend/README.md | Bin 810 -> 904 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 41457337b96f64f87020eb1a05ee5b06c56597f3..d80587b0c5aa5163cb785f222e6e4fd798ed5b5c 100644 GIT binary patch delta 79 zcmZ3**1^6(i&?aQp@<l From 844badc84443fa3e8b52a6500f46c9857497b2bb Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Wed, 1 Oct 2025 23:06:49 +1000 Subject: [PATCH 47/53] test(frontend): rerun PR CI (frontend only) --- frontend/README.md | Bin 904 -> 998 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index d80587b0c5aa5163cb785f222e6e4fd798ed5b5c..66f620d6a774891a8bd101e0ba0db6dde2986538 100644 GIT binary patch delta 56 zcmeBRf5yI{gL(2iCZ5S=%vu^|3|0+-Rf3>FN=K-vIE8!(tNXfqfBX)7Q$VBlro GVgLYBb_mb_ delta 7 OcmaFH-od`1gBbt}Vgk4T From efcff4502a3b394cd8ef30741a854754ab5e7e73 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Wed, 1 Oct 2025 23:44:37 +1000 Subject: [PATCH 48/53] test: tiny frontend change to trigger Frontend CI (PR only) --- frontend/README.md | Bin 998 -> 1062 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 66f620d6a774891a8bd101e0ba0db6dde2986538..26593af4a5538b42112b9fd9cd37a4c0d1ff33f0 100644 GIT binary patch delta 40 ucmaFHzKmnTGiJ^bhD?S$hDrv7$@dvmg^U@j7)*fBiouw{oPn2tiva-Ta0pxg delta 7 OcmZ3+@r-@LGiCq{Is-KT From c2e250d8bb56f48b85f49e5fb1d70c50131770be Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Wed, 1 Oct 2025 23:55:32 +1000 Subject: [PATCH 49/53] test(backend): trigger backend path only --- backend/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 backend/README.md diff --git a/backend/README.md b/backend/README.md new file mode 100644 index 00000000..f9a0878c --- /dev/null +++ b/backend/README.md @@ -0,0 +1 @@ +proof 2025-10-01T23:55:32 From 8142d67bab1e8800046e01cb5ef769c1542ce874 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Thu, 2 Oct 2025 00:15:38 +1000 Subject: [PATCH 50/53] test(frontend): trigger frontend CI only --- frontend/README.md | Bin 1062 -> 1116 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 26593af4a5538b42112b9fd9cd37a4c0d1ff33f0..d6240b4c4b2ab32628fd2264248cca6f0d088e71 100644 GIT binary patch delta 36 ocmZ3+aff4r8p~ucCOHWsh7bk=AhcpIWH1Gi#taq=ybN3n0E^WHkN^Mx delta 7 Ocmcb^v5aGb8Vdjm`2uYK From 8ad3a60233fc3ae32150c4829b97086af1742b85 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Thu, 2 Oct 2025 00:25:18 +1000 Subject: [PATCH 51/53] test(frontend): trigger frontend CI only --- frontend/README.md | Bin 1116 -> 1168 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index d6240b4c4b2ab32628fd2264248cca6f0d088e71..99eb36194476fc659e9d09810b8f187398d738d1 100644 GIT binary patch delta 35 ncmcb^F@bYK49g@&83`kX5C#Jvv|=z~Fa?r^3>FN$3|tHViV6jm delta 7 OcmbQhd52>|3=04YWde=> From 196e3479e18f6e0dba665b6389b1bdfa4389242d Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Thu, 2 Oct 2025 00:25:49 +1000 Subject: [PATCH 52/53] test(frontend): trigger frontend CI only --- frontend/README.md | Bin 1168 -> 1220 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 99eb36194476fc659e9d09810b8f187398d738d1..b4a25b5b6d99d620c85cadc40d499625717585e8 100644 GIT binary patch delta 23 ecmbQhd4zMr1eQsRGLtJ<1UO6>EE#wixEKIZDFp=p delta 7 OcmX@YIe~M-1Qq}b!2+uQ From ec09eeac218a7daa510759a53effa9e5c88ec326 Mon Sep 17 00:00:00 2001 From: Akanksha Nunakani Date: Thu, 2 Oct 2025 00:42:10 +1000 Subject: [PATCH 53/53] test(backend): trigger backend-only CI --- backend/README.md | Bin 26 -> 79 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/backend/README.md b/backend/README.md index f9a0878cb5d46234e756ede8a27be62d385858f5..117ad986c6c71079090c920ebb1d7d23f13d07da 100644 GIT binary patch delta 59 zcmb30pCD<*%T>aV$&k#D&7i