Updated CI/CD Pipeline #44
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # week08/.github/workflows/frontend_ci.yml | ||
| name: Frontend CI - Build & Push Image (Router) | ||
| on: | ||
| # 1. Independent CI Trigger (Development Branch Testing) | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - development | ||
| - main | ||
| paths: | ||
| - 'frontend/**' | ||
| - '.github/workflows/frontend_ci.yml' | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'frontend/**' | ||
| - '.github/workflows/frontend_ci.yml' | ||
| # 2. CD Chain Linkage Trigger | ||
| workflow_call: # <--- CRITICAL FIX: Allows this workflow to be called by backend-cd.yml | ||
| inputs: | ||
| product_api_ip: { required: true, type: string } # <--- Receives IP 1 | ||
| order_api_ip: { required: true, type: string } # <--- Receives IP 2 | ||
| aks_cluster_name: { required: true, type: string } | ||
| aks_resource_group: { required: true, type: string } | ||
| secrets: | ||
| azure_credentials: { required: true } | ||
| # Define global environment variables | ||
| env: | ||
| ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} | ||
| IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} | ||
| jobs: | ||
| # JOB 1: CI - Build and Push Frontend Image | ||
| build_and_push_frontend: | ||
| runs-on: ubuntu-latest | ||
| # CRITICAL: This job needs access to the secrets/inputs if called | ||
| secrets: inherit # <--- NEW: Allows secrets to be passed from the caller | ||
| steps: | ||
| # ... (Existing Checkout, Azure Login, ACR Login, Build/Push steps remain here) ... | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| - name: Azure Login | ||
| uses: azure/login@v1 | ||
| # Uses the secret inherited from the workflow_call trigger | ||
| with: | ||
| creds: ${{ secrets.azure_credentials }} | ||
| # (Other build steps here...) | ||
| - name: Build and Push Frontend Image | ||
| # ... (Your Docker build/push commands here) ... | ||
| run: | | ||
| docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/ | ||
| docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest | ||
| # (Other steps...) | ||
| # ---------------------------------------------------------------------- | ||
| # JOB 2: LINKAGE TO FRONTEND CD (THE FINAL STEP) | ||
| # ---------------------------------------------------------------------- | ||
| trigger_frontend_cd: | ||
| runs-on: ubuntu-latest | ||
| needs: build_and_push_frontend # Wait for the image to be built and pushed | ||
| # CRITICAL GATE: Only call the CD file when running as part of the main branch CD chain | ||
| # We use github.event_name == 'workflow_call' to reliably detect the CD chain | ||
| if: github.event_name == 'workflow_call' || github.ref == 'refs/heads/main' # <--- UPDATED: Ensure it runs when called or when triggered directly by main | ||
| steps: | ||
| - name: "Call Frontend CD Workflow (Deploy)" | ||
| uses: ./.github/workflows/frontend-cd.yml | ||
| with: | ||
| # Pass the IPs received by this workflow to the final deployment file | ||
| product_api_ip: ${{ inputs.product_api_ip }} # <--- Passes received IP | ||
| order_api_ip: ${{ inputs.order_api_ip }} # <--- Passes received IP | ||
| aks_cluster_name: ${{ inputs.aks_cluster_name }} | ||
| aks_resource_group: ${{ inputs.aks_resource_group }} | ||
| secrets: | ||
| azure_credentials: ${{ secrets.azure_credentials }} # Pass the secret along | ||