Updated CI/CD Pipeline #28
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: # 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 | ||
| outputs: | ||
| PRODUCT_API_IP: ${{ steps.ip_capture.outputs.PRODUCT_IP }} | ||
| ORDER_API_IP: ${{ steps.ip_capture.outputs.ORDER_IP }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| - name: Log in to Azure | ||
| uses: azure/login@v1 | ||
| with: | ||
| creds: ${{ secrets.azure_credentials }} | ||
| enable-AzPSSession: true | ||
| - name: Set Kubernetes context (get AKS credentials) | ||
| run: | | ||
| az aks get-credentials --resource-group ${{ inputs.aks_resource_group }} --name ${{ inputs.aks_cluster_name }} --overwrite-existing | ||
| - name: Attach ACR | ||
| run: | | ||
| az aks update --name ${{ inputs.aks_cluster_name }} --resource-group ${{ inputs.aks_resource_group }} --attach-acr ${{ inputs.aks_acr_name }} | ||
| - name: Deploy Backend Infrastructure (Namespace, ConfigMaps, Secrets, Databases) | ||
| run: | | ||
| echo "Deploying backend infrastructure..." | ||
| cd k8s/ | ||
| kubectl apply -f configmaps.yaml | ||
| kubectl apply -f secrets.yaml | ||
| kubectl apply -f product-db.yaml | ||
| kubectl apply -f order-db.yaml | ||
| - name: Deploy Backend Microservices (Product, Order) | ||
| run: | | ||
| echo "Deploying backend microservices..." | ||
| cd k8s/ | ||
| kubectl apply -f product-service.yaml | ||
| kubectl apply -f order-service.yaml | ||
| - name: Wait for Backend LoadBalancer IPs | ||
| id: ip_capture | ||
| run: | | ||
| echo "Waiting for Product, 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" | ||
| echo "PRODUCT_IP=$PRODUCT_IP" >> "$GITHUB_OUTPUT" | ||
| echo "ORDER_IP=$ORDER_IP" >> "$GITHUB_OUTPUT" | ||
| break | ||
| fi | ||
| sleep 5 | ||
| done | ||
| if [[ -z "$PRODUCT_IP" || -z "$ORDER_IP" ]]; then | ||
| echo "Error: One or more LoadBalancer IPs not assigned after timeout." | ||
| exit 1 | ||
| fi | ||
| - 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 | ||
| # Run only on the main branch for final CD execution | ||
| if: github.ref == 'refs/heads/main' | ||
| 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 }} | ||
| # CRITICAL FIX: 'secrets:' is now correctly aligned with 'with:' | ||
| secrets: | ||
| azure_credentials: ${{ secrets.azure_credentials }} # Pass the secret | ||