From ee8b6797da0e15997a497b1aec11c42296279a35 Mon Sep 17 00:00:00 2001 From: Mohit1145 Date: Sun, 31 Aug 2025 13:34:09 +1000 Subject: [PATCH 1/7] Add CI workflow for backend & frontend --- .github/workflows/backend_ci.yml | 170 +++++++------------------------ 1 file changed, 35 insertions(+), 135 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 87ee014..13cd1c8 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -1,146 +1,46 @@ -# week07/.github/workflows/backend_ci.yml +name: Backend & Frontend CI -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.ACR_LOGIN_SERVER }} - # 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 ] + pull_request: 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_and_lint: + runs-on: ubuntu-latest steps: - # 1. Checkout the repository code to the runner - - name: Checkout repository - uses: actions/checkout@v4 # Action to check out your repository code - - # 2. Set up Python environment - - name: Set up Python 3.10 - uses: actions/setup-python@v5 # Action to set up Python environment - with: - python-version: '3.10' - - # 3. Install dependencies and run code quality checks - - name: Install dependencies - run: | # Use a multi-line script to install pip dependencies - pip install --upgrade pip - # Loop through each backend service folder - for req in backend/*/requirements.txt; do - echo "Installing $req" - pip install -r "$req" - done - # Install CI tools - pip install pytest httpx + - uses: actions/checkout@v4 + - name: Run tests (placeholder) + run: echo "Replace with real tests (npm test / pytest etc.)" - # 5. Run tests for product service - - name: Run product_service tests - working-directory: backend/product_service - env: - POSTGRES_HOST: localhost - POSTGRES_PORT: 5432 - POSTGRES_DB: products - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - run: | - pytest tests --maxfail=1 --disable-warnings -q - - # 6. Run tests for order service - - name: Run order_service tests - working-directory: backend/order_service - env: - POSTGRES_HOST: localhost - POSTGRES_PORT: 5433 - POSTGRES_DB: orders - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - run: | - pytest tests --maxfail=1 --disable-warnings -q - - # Job 2: Build and Push Docker Images (runs only if tests pass) - build_and_push_images: + build_and_push: runs-on: ubuntu-latest - needs: test_and_lint_backends - + needs: test_and_lint 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 }} + - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v3 - # 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 + - name: Login to ACR + uses: docker/login-action@v3 + with: + registry: ${{ secrets.ACR_LOGIN_SERVER }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} - # Logout from Azure for security (runs even if image push fails) - - name: Logout from Azure - run: az logout - if: always() + - name: Build & push backend + uses: docker/build-push-action@v6 + with: + context: ./backend + push: true + tags: | + ${{ secrets.ACR_LOGIN_SERVER }}/backend:latest + ${{ secrets.ACR_LOGIN_SERVER }}/backend:${{ github.sha }} + + - name: Build & push frontend + uses: docker/build-push-action@v6 + with: + context: ./frontend + push: true + tags: | + ${{ secrets.ACR_LOGIN_SERVER }}/frontend:latest + ${{ secrets.ACR_LOGIN_SERVER }}/frontend:${{ github.sha }} From cf60e0320d06770bf6c867af6a3e884de4fd6f01 Mon Sep 17 00:00:00 2001 From: Mohit1145 Date: Sun, 31 Aug 2025 13:36:34 +1000 Subject: [PATCH 2/7] Trigger workflow run --- README.md | Bin 4308 -> 4424 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/README.md b/README.md index 034375eaae9605cbea2008b88a36849b2808d863..38e3658555c1209b46f52c5554690185fe3107d6 100644 GIT binary patch delta 408 zcmcbjctUA{Cp#|}FPE~i!o&h`9@mP3oW#t$)D)oD#QgirKx(o-V=*J|cKvIFJ z7A!W8Ng7P=VtNeWGn)WqFEN{fc^oXxJRn085)zUUi!*p9hp=p5<>g9FQJCDwA~so$ zRht7W2{PS}RRgT2oV5*1|6^4G*~8`mBs17l!D4-EAiLkNr7`j@4q|5niv@G+76#d& zpa8Tbt2jRo#H{9>EXyemRBOYj4kVK~wSivKFcsWb1a$V6Z9NTqR(-f$I*K zj^$Pa)AigC`ODn7V7?8=#VJKqAWJm|XR3J-%p`0NfNM|#oG2{SQbO3Q>`o)m$I_5f}x&*TYgct zLPaf$G;Vn@oPlYzkyavN&^caU~=qBqbJSOwM50Fj?^K zt2jRo$f};~$|*lNl~a9kFQ@k8ot$#qK*3sw60XV5ID>(@Y`98* Date: Sun, 31 Aug 2025 14:51:05 +1000 Subject: [PATCH 3/7] Fix CI: build product-service, order-service, and frontend --- .github/workflows/backend_ci.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index 13cd1c8..d89896a 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -27,14 +27,23 @@ jobs: username: ${{ secrets.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_PASSWORD }} - - name: Build & push backend + - name: Build & push product-service uses: docker/build-push-action@v6 with: - context: ./backend + context: ./backend/product_service push: true tags: | - ${{ secrets.ACR_LOGIN_SERVER }}/backend:latest - ${{ secrets.ACR_LOGIN_SERVER }}/backend:${{ github.sha }} + ${{ secrets.ACR_LOGIN_SERVER }}/product-service:latest + ${{ secrets.ACR_LOGIN_SERVER }}/product-service:${{ github.sha }} + + - name: Build & push order-service + uses: docker/build-push-action@v6 + with: + context: ./backend/order_service + push: true + tags: | + ${{ secrets.ACR_LOGIN_SERVER }}/order-service:latest + ${{ secrets.ACR_LOGIN_SERVER }}/order-service:${{ github.sha }} - name: Build & push frontend uses: docker/build-push-action@v6 From b2b01fe39712dc6bc2e8c9dcfa7c5c13fa738205 Mon Sep 17 00:00:00 2001 From: Mohit1145 Date: Sun, 31 Aug 2025 14:55:00 +1000 Subject: [PATCH 4/7] CI: point explicitly to Dockerfiles --- .github/workflows/backend_ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index d89896a..f03895e 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -31,6 +31,7 @@ jobs: uses: docker/build-push-action@v6 with: context: ./backend/product_service + file: ./backend/product_service/Dockerfile push: true tags: | ${{ secrets.ACR_LOGIN_SERVER }}/product-service:latest @@ -40,6 +41,7 @@ jobs: uses: docker/build-push-action@v6 with: context: ./backend/order_service + file: ./backend/order_service/Dockerfile push: true tags: | ${{ secrets.ACR_LOGIN_SERVER }}/order-service:latest @@ -49,6 +51,7 @@ jobs: uses: docker/build-push-action@v6 with: context: ./frontend + file: ./frontend/Dockerfile push: true tags: | ${{ secrets.ACR_LOGIN_SERVER }}/frontend:latest From 63cf5793ffea00f9015c5d697664f696114af1b4 Mon Sep 17 00:00:00 2001 From: Mohit1145 Date: Sun, 31 Aug 2025 14:55:16 +1000 Subject: [PATCH 5/7] Trigger CI again --- README.md | Bin 4424 -> 4464 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/README.md b/README.md index 38e3658555c1209b46f52c5554690185fe3107d6..1da3ab588b62e0fdfd9369ff85a617ffd2515e25 100644 GIT binary patch delta 32 mcmX@1^g(HZhu~xdK@kyW22TbBhD3&RAkJjSW8h`rVgLY;b_TTo delta 7 OcmeyMbV6x^hadnBgaZZu From ee11379077dc9e18c77bd444b36f47c5e643b05c Mon Sep 17 00:00:00 2001 From: Mohit1145 Date: Fri, 12 Sep 2025 21:13:33 +1000 Subject: [PATCH 6/7] ci: trigger backend build --- README.md | Bin 4464 -> 4498 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/README.md b/README.md index 1da3ab588b62e0fdfd9369ff85a617ffd2515e25..b778ae64f349ce72c70dc3e8ffbb0b3fb7b1a163 100644 GIT binary patch delta 26 hcmeyMG)Z|wf#75XK@q+rhEj%1h8%_z23`g(1^{c51_l5C delta 7 OcmbQF{6T3$fgk`45CZuC From 1df2cd84f4f0a0c3a0716a60121cd12b7009830f Mon Sep 17 00:00:00 2001 From: Mohit1145 Date: Fri, 12 Sep 2025 21:38:01 +1000 Subject: [PATCH 7/7] ci: trigger backend build --- README.md | Bin 4498 -> 4532 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/README.md b/README.md index b778ae64f349ce72c70dc3e8ffbb0b3fb7b1a163..a84d6d2efcb451abdb2059f7ef5cdb8de28ea471 100644 GIT binary patch delta 11 ScmbQFyhVA#B*DoAf=U1zj06?{ delta 7 Ocmdm@JV|-OBtZZSa01`}