11name : CD - Deploy Backend Services to AKS
22
33on :
4- workflow_dispatch :
4+ # ----------------------------------------------------------------------
5+ # CRITICAL CHANGE: SWITCH TO WORKFLOW_CALL TO ENABLE AUTO-TRIGGERING
6+ # ----------------------------------------------------------------------
7+ workflow_call : # <--- CRITICAL FIX: Enables calling from backend_ci.yml
58 inputs :
6- aks_cluster_name :
7- description : ' Name of the AKS Cluster to deploy to'
8- required : true
9- default : ' ishaanAKS'
10- aks_resource_group :
11- description : ' Resource Group of the AKS Cluster'
12- required : true
13- default : ' deakinuni'
14- aks_acr_name :
15- description : ' Name of ACR'
16- required : true
17- default : ' ishaan'
9+ aks_cluster_name : { required: true, type: string }
10+ aks_resource_group : { required: true, type: string }
11+ aks_acr_name : { required: true, type: string }
12+ secrets :
13+ azure_credentials : { required: true }
1814
1915jobs :
2016 deploy_backend :
2117 runs-on : ubuntu-latest
2218 environment : Production
2319
20+ # CRITICAL CHANGE: Update outputs to match the step IDs below
2421 outputs :
25- PRODUCT_API_IP : ${{ steps.get_product_ip .outputs.external_ip }}
26- ORDER_API_IP : ${{ steps.get_order_ip .outputs.external_ip }}
22+ PRODUCT_API_IP : ${{ steps.ip_capture .outputs.PRODUCT_IP }} # <--- UPDATED
23+ ORDER_API_IP : ${{ steps.ip_capture .outputs.ORDER_IP }} # <--- UPDATED
2724
2825 steps :
2926 - name : Checkout repository
@@ -32,16 +29,18 @@ jobs:
3229 - name : Log in to Azure
3330 uses : azure/login@v1
3431 with :
35- creds : ${{ secrets.AZURE_CREDENTIALS }}
32+ creds : ${{ secrets.azure_credentials }} # <--- UPDATED: Using `secrets` from workflow_call
3633 enable-AzPSSession : true
3734
3835 - name : Set Kubernetes context (get AKS credentials)
3936 run : |
40- az aks get-credentials --resource-group ${{ github.event.inputs.aks_resource_group }} --name ${{ github.event.inputs.aks_cluster_name }} --overwrite-existing
37+ # <--- UPDATED: Using `inputs` from workflow_call
38+ az aks get-credentials --resource-group ${{ inputs.aks_resource_group }} --name ${{ inputs.aks_cluster_name }} --overwrite-existing
4139
4240 - name : Attach ACR
4341 run : |
44- 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 }}
42+ # <--- UPDATED: Using `inputs` from workflow_call
43+ az aks update --name ${{ inputs.aks_cluster_name }} --resource-group ${{ inputs.aks_resource_group }} --attach-acr ${{ inputs.aks_acr_name }}
4544
4645 - name : Deploy Backend Infrastructure (Namespace, ConfigMaps, Secrets, Databases)
4746 run : |
6059 kubectl apply -f order-service.yaml
6160
6261 - name : Wait for Backend LoadBalancer IPs
62+ id : ip_capture # <--- CRITICAL FIX: Added ID to make outputs work
6363 run : |
6464 echo "Waiting for Product, Order LoadBalancer IPs to be assigned (up to 5 minutes)..."
6565 PRODUCT_IP=""
7474 echo "All backend LoadBalancer IPs assigned!"
7575 echo "Product Service IP: $PRODUCT_IP"
7676 echo "Order Service IP: $ORDER_IP"
77+
78+ # CRITICAL FIX: Publish the IPs as step outputs
79+ echo "PRODUCT_IP=$PRODUCT_IP" >> "$GITHUB_OUTPUT" # <--- NEW: Set output for the next job
80+ echo "ORDER_IP=$ORDER_IP" >> "$GITHUB_OUTPUT" # <--- NEW: Set output for the next job
7781 break
7882 fi
7983 sleep 5 # Wait 5 seconds before next attempt
@@ -84,18 +88,28 @@ jobs:
8488 exit 1 # Fail the job if IPs are not obtained
8589 fi
8690
87- # These are environment variables for subsequent steps in the *same job*
88- # And used to set the job outputs
89- echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_ENV
90- echo "ORDER_IP=$ORDER_IP" >> $GITHUB_ENV
91-
92- - name : Capture Product Service IP for Workflow Output
93- id : get_product_ip
94- run : echo "external_ip=${{ env.PRODUCT_IP }}" >> $GITHUB_OUTPUT
95-
96- - name : Capture Order Service IP for Workflow Output
97- id : get_order_ip
98- run : echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT
91+ # Removed redundant IP environment setup, now using step outputs.
92+
93+ # Removed redundant 'Capture IP for Workflow Output' steps
9994
10095 - name : Logout from Azure
10196 run : az logout
97+
98+ # ----------------------------------------------------------------------
99+ # NEW JOB: LINKAGE TO FRONTEND CI
100+ # ----------------------------------------------------------------------
101+ trigger_frontend_ci :
102+ runs-on : ubuntu-latest
103+ needs : deploy_backend # Waits for deployment and IP capture
104+ steps :
105+ - name : " Call Frontend CI Workflow"
106+ uses : ./.github/workflows/frontend_ci.yml # Calls the next file
107+ with :
108+ # Pass the captured IPs from the previous job's outputs
109+ product_api_ip : ${{ needs.deploy_backend.outputs.PRODUCT_API_IP }}
110+ order_api_ip : ${{ needs.deploy_backend.outputs.ORDER_API_IP }}
111+ # Pass cluster details received by this workflow
112+ aks_cluster_name : ${{ inputs.aks_cluster_name }}
113+ aks_resource_group : ${{ inputs.aks_resource_group }}
114+ secrets :
115+ azure_credentials : ${{ secrets.azure_credentials }} # Pass the secret
0 commit comments