diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 6035ed15..c3420791 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -6,15 +6,15 @@ on: aks_cluster_name: description: 'Name of the AKS Cluster to deploy to' required: true - default: '' + default: 'sit722-aks' aks_resource_group: description: 'Resource Group of the AKS Cluster' required: true - default: '' + default: 'SIT722-RG' aks_acr_name: - description: 'Name of ACR' + description: 'Azure Container Registry name (not FQDN)' required: true - default: '' + default: '223313284acr' jobs: deploy_backend: @@ -30,7 +30,7 @@ jobs: uses: actions/checkout@v4 - name: Log in to Azure - uses: azure/login@v1 + uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} enable-AzPSSession: true @@ -38,10 +38,28 @@ jobs: - 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: Setup kubectl + uses: azure/setup-kubectl@v4 + + - name: Ensure namespace exists + run: | + kubectl create namespace sit722 --dry-run=client -o yaml | kubectl apply -f - - - name: Attach ACR + - name: Create/refresh imagePullSecret (acr-auth) 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 }} + kubectl delete secret acr-auth -n sit722 --ignore-not-found + kubectl create secret docker-registry acr-auth \ + --namespace sit722 \ + --docker-server=${{ secrets.AZURE_CONTAINER_REGISTRY }} \ + --docker-username=${{ secrets.AZURE_CONTAINER_REGISTRY_NAME }} \ + --docker-password='${{ secrets.ACR_PASSWORD }}' \ + --docker-email="devnull@example.local" + kubectl get secret acr-auth -n sit722 + +# - 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: | @@ -59,16 +77,19 @@ jobs: kubectl apply -f product-service.yaml kubectl apply -f order-service.yaml - - name: Wait for Backend LoadBalancer IPs + - name: Wait for Backend LoadBalancer IPs run: | + echo "Sanity check: services across namespaces" + kubectl get svc -A + 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}') + PRODUCT_IP=$(kubectl get service product-service-w08e1 -n sit722 -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + ORDER_IP=$(kubectl get service order-service-w08e1 -n sit722 -o jsonpath='{.status.loadBalancer.ingress[0].ip}') if [[ -n "$PRODUCT_IP" && -n "$ORDER_IP" ]]; then echo "All backend LoadBalancer IPs assigned!" @@ -80,10 +101,13 @@ jobs: done if [[ -z "$PRODUCT_IP" || -z "$ORDER_IP" ]]; then + echo "DEBUG: describe services in sit722" + kubectl describe svc product-service-w08e1 -n sit722 || true + kubectl describe svc order-service-w08e1 -n sit722 || true echo "Error: One or more LoadBalancer IPs not assigned after timeout." - exit 1 # Fail the job if IPs are not obtained + exit 1 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 diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml index 0a0879c8..edbea9ca 100644 --- a/.github/workflows/frontend-cd.yml +++ b/.github/workflows/frontend-cd.yml @@ -10,19 +10,19 @@ on: product_api_ip: description: 'External IP of Product Service' required: true - default: 'http://:8000' + default: 'http://172.188.196.47:8000' order_api_ip: description: 'External IP of Order Service (e.g., http://Y.Y.Y.Y:8001)' required: true - default: 'http://:8001' + default: 'http://4.144.233.236:8001' aks_cluster_name: - description: 'Name of the AKS Cluster to deploy to' + description: 'AKS cluster name' required: true - default: '' + default: 'sit722-aks' aks_resource_group: - description: 'Resource Group of the AKS Cluster' + description: 'AKS resource group' required: true - default: '<' + default: 'SIT722-RG' workflow_call: inputs: diff --git a/.gitignore b/.gitignore index cfa76a7f..8776beb4 100644 Binary files a/.gitignore and b/.gitignore differ diff --git a/frontend/main.js b/frontend/main.js index f321fd91..5bca83c6 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -4,8 +4,9 @@ document.addEventListener('DOMContentLoaded', () => { // API endpoints for the Product and Order services. // These ports (30000 for Product, 30001 for Order) are mapped // from the Docker containers to the host machine in docker-compose.yml for Example 2. - const PRODUCT_API_BASE_URL = '_PRODUCT_API_URL_'; - const ORDER_API_BASE_URL = '_ORDER_API_URL_'; + const PRODUCT_API_BASE_URL = 'http://172.188.196.47:8000'; + const ORDER_API_BASE_URL = 'http://4.144.233.236:8001'; + // Product Service is named 'product-service-w04e2' and exposes port 8000 internally. //const PRODUCT_API_BASE_URL = 'http://product-service-w04e2:8000'; diff --git a/k8s/frontend.yaml b/k8s/frontend.yaml index 1948536d..a66b1cfb 100644 --- a/k8s/frontend.yaml +++ b/k8s/frontend.yaml @@ -18,7 +18,7 @@ spec: spec: containers: - name: frontend-container - image: durgeshsamariya.azurecr.io/frontend:latest + image: 223313284acr.azurecr.io/frontend:latest imagePullPolicy: Always ports: - containerPort: 80 diff --git a/k8s/order-service.yaml b/k8s/order-service.yaml index c9d92e4d..58bd9423 100644 --- a/k8s/order-service.yaml +++ b/k8s/order-service.yaml @@ -16,9 +16,11 @@ spec: labels: app: order-service spec: + imagePullSecrets: + - name: acr-auth containers: - name: order-service-container - image: durgeshsamariya.azurecr.io/order_service:latest + image: 223313284acr.azurecr.io/order_service:latest imagePullPolicy: Always ports: - containerPort: 8000 diff --git a/k8s/product-service.yaml b/k8s/product-service.yaml index 0cbbd505..91c18d30 100644 --- a/k8s/product-service.yaml +++ b/k8s/product-service.yaml @@ -16,9 +16,11 @@ spec: labels: app: product-service spec: + imagePullSecrets: + - name: acr-auth containers: - name: product-service-container - image: durgeshsamariya.azurecr.io/product_service:latest + image: 223313284acr.azurecr.io/product_service:latest imagePullPolicy: Always ports: - containerPort: 8000