Updated CI/CD Pipeline #38
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
| name: CD - Deploy Backend Services to AKS | ||
| on: | ||
| # ---------------------------------------------------------------------- | ||
| # CRITICAL CHANGE: SWITCH TO WORKFLOW_CALL TO ENABLE AUTO-TRIGGERING | ||
| # ---------------------------------------------------------------------- | ||
| workflow_call: # <--- CRITICAL FIX: Enables calling from backend_ci.yml | ||
| inputs: | ||
| aks_cluster_name: { required: true, type: string } | ||
| aks_resource_group: { required: true, type: string } | ||
| aks_acr_name: { required: true, type: string } | ||
| secrets: | ||
| azure_credentials: { required: true } | ||
| jobs: | ||
| deploy_backend: | ||
| runs-on: ubuntu-latest | ||
| environment: Production | ||
| # CRITICAL CHANGE: Update outputs to match the step IDs below | ||
| outputs: | ||
| PRODUCT_API_IP: ${{ steps.ip_capture.outputs.PRODUCT_IP }} # <--- UPDATED | ||
| ORDER_API_IP: ${{ steps.ip_capture.outputs.ORDER_IP }} # <--- UPDATED | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| - name: Log in to Azure | ||
| uses: azure/login@v1 | ||
| with: | ||
| creds: ${{ secrets.azure_credentials }} # <--- UPDATED: Using `secrets` from workflow_call | ||
| enable-AzPSSession: true | ||
| - name: Set Kubernetes context (get AKS credentials) | ||
| run: | | ||
| # <--- UPDATED: Using `inputs` from workflow_call | ||
| az aks get-credentials --resource-group ${{ inputs.aks_resource_group }} --name ${{ inputs.aks_cluster_name }} --overwrite-existing | ||
| - name: Attach ACR | ||
| run: | | ||
| # <--- UPDATED: Using `inputs` from workflow_call | ||
| az aks update --name ${{ inputs.aks_cluster_name }} --resource-group ${{ inputs.aks_resource_group }} --attach-acr ${{ inputs.aks_acr_name }} | ||
| - name: Deploy Backend Infrastructure (Namespace, ConfigMaps, Secrets, Databases) | ||
| run: | | ||
| echo "Deploying backend infrastructure..." | ||
| cd k8s/ | ||
| kubectl apply -f configmaps.yaml | ||
| kubectl apply -f secrets.yaml | ||
| kubectl apply -f product-db.yaml | ||
| kubectl apply -f order-db.yaml | ||
| - name: Deploy Backend Microservices (Product, Order) | ||
| run: | | ||
| echo "Deploying backend microservices..." | ||
| cd k8s/ | ||
| kubectl apply -f product-service.yaml | ||
| kubectl apply -f order-service.yaml | ||
| - name: Wait for Backend LoadBalancer IPs | ||
| id: ip_capture # <--- CRITICAL FIX: Added ID to make outputs work | ||
| 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" | ||
| # CRITICAL FIX: Publish the IPs as step outputs | ||
| echo "PRODUCT_IP=$PRODUCT_IP" >> "$GITHUB_OUTPUT" # <--- NEW: Set output for the next job | ||
| echo "ORDER_IP=$ORDER_IP" >> "$GITHUB_OUTPUT" # <--- NEW: Set output for the next job | ||
| break | ||
| fi | ||
| sleep 5 # Wait 5 seconds before next attempt | ||
| 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 | ||
| # Removed redundant IP environment setup, now using step outputs. | ||
| # Removed redundant 'Capture IP for Workflow Output' steps | ||
| - name: Logout from Azure | ||
| run: az logout | ||
| # ---------------------------------------------------------------------- | ||
| # NEW JOB: LINKAGE TO FRONTEND CI | ||
| # ---------------------------------------------------------------------- | ||
| trigger_frontend_ci: | ||
| runs-on: ubuntu-latest | ||
| needs: deploy_backend # Waits for deployment and IP capture | ||
| steps: | ||
| - name: "Call Frontend CI Workflow" | ||
| uses: ./.github/workflows/frontend_ci.yml # Calls the next file | ||
| with: | ||
| # Pass the captured IPs from the previous job's outputs | ||
| product_api_ip: ${{ needs.deploy_backend.outputs.PRODUCT_API_IP }} | ||
| order_api_ip: ${{ needs.deploy_backend.outputs.ORDER_API_IP }} | ||
| # Pass cluster details received by this workflow | ||
| aks_cluster_name: ${{ inputs.aks_cluster_name }} | ||
| aks_resource_group: ${{ inputs.aks_resource_group }} | ||
| secrets: | ||
| azure_credentials: ${{ secrets.azure_credentials }} # Pass the secret | ||