changes added #25
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
| deploy_backend_to_aks: | ||
|
Check failure on line 1 in .github/workflows/backend-cd.yml
|
||
| name: CD - Deploy Backend Services to AKS | ||
| runs-on: ubuntu-latest | ||
| environment: Production | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| aks_cluster_name: | ||
| required: true | ||
| type: string | ||
| aks_resource_group: | ||
| required: true | ||
| type: string | ||
| aks_acr_name: | ||
| required: true | ||
| type: string | ||
| outputs: | ||
| PRODUCT_API_IP: | ||
| description: 'External IP of Product Service' | ||
| value: ${{ jobs.deploy_backend.outputs.PRODUCT_API_IP }} | ||
| ORDER_API_IP: | ||
| description: 'External IP of Order Service' | ||
| value: ${{ jobs.deploy_backend.outputs.ORDER_API_IP }} | ||
| # workflow_dispatch: | ||
| # inputs: | ||
| # aks_cluster_name: | ||
| # description: 'Name of the AKS Cluster to deploy to' | ||
| # required: true | ||
| # default: 'parvathy' | ||
| # aks_resource_group: | ||
| # description: 'Resource Group of the AKS Cluster' | ||
| # required: true | ||
| # default: 'week8' | ||
| # aks_acr_name: | ||
| # description: 'Name of ACR' | ||
| # required: true | ||
| # default: 'parvathy' | ||
| push: | ||
| branches: | ||
| - main | ||
| jobs: | ||
| deploy_backend: | ||
| runs-on: ubuntu-latest | ||
| environment: Production | ||
| outputs: | ||
| PRODUCT_API_IP: ${{ steps.get_product_ip.outputs.external_ip }} | ||
| ORDER_API_IP: ${{ steps.get_order_ip.outputs.external_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 ${{ github.event.inputs.aks_resource_group }} --name ${{ github.event.inputs.aks_cluster_name }} --overwrite-existing | ||
| - name: Attach ACR | ||
| run: | | ||
| 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 }} | ||
| - 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 | ||
| 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" | ||
| 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 | ||
| # These are environment variables for subsequent steps in the *same job* | ||
| # And used to set the job outputs | ||
| echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_ENV | ||
| echo "ORDER_IP=$ORDER_IP" >> $GITHUB_ENV | ||
| - name: Capture Product Service IP for Workflow Output | ||
| id: get_product_ip | ||
| run: echo "external_ip=${{ env.PRODUCT_IP }}" >> $GITHUB_OUTPUT | ||
| - name: Capture Order Service IP for Workflow Output | ||
| id: get_order_ip | ||
| run: echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT | ||
| - name: Logout from Azure | ||
| run: az logout | ||