diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml index 6035ed15..a7e040a4 100644 --- a/.github/workflows/backend-cd.yml +++ b/.github/workflows/backend-cd.yml @@ -1,101 +1,120 @@ name: CD - Deploy Backend Services to AKS on: - workflow_dispatch: - inputs: - aks_cluster_name: - description: 'Name of the AKS Cluster to deploy to' - required: true - default: '' - aks_resource_group: - description: 'Resource Group of the AKS Cluster' - required: true - default: '' - aks_acr_name: - description: 'Name of ACR' - required: true - default: '' + workflow_dispatch: {} + +env: + RG: ${{ vars.AKS_RESOURCE_GROUP }} + AKS: ${{ vars.AKS_CLUSTER_NAME }} + NS: ${{ vars.AKS_NAMESPACE }} + ACR_NAME: ${{ vars.ACR_NAME }} 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 }} + PRODUCT_API_IP: ${{ steps.out_prod_ip.outputs.external_ip }} + ORDER_API_IP: ${{ steps.out_order_ip.outputs.external_ip }} steps: - - name: Checkout repository - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Log in to Azure - uses: azure/login@v1 + - name: Azure Login + uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - enable-AzPSSession: true - - name: Set Kubernetes context (get AKS credentials) + - name: Get AKS credentials + run: az aks get-credentials --resource-group "$RG" --name "$AKS" --overwrite-existing + + - name: Ensure namespace exists + run: kubectl get ns "$NS" || kubectl create ns "$NS" + + # Never fail on ACR attach; skip if you don't have Owner. + - name: Attach ACR (idempotent; ignore if no rights) + shell: bash + run: | + set +e + az aks update --name "$AKS" --resource-group "$RG" --attach-acr "$ACR_NAME" + [ $? -ne 0 ] && echo "Skipping ACR attach (no Owner rights)" || true + exit 0 + + - name: Apply infra (ConfigMaps, Secrets, DBs) + working-directory: k8s run: | - az aks get-credentials --resource-group ${{ github.event.inputs.aks_resource_group }} --name ${{ github.event.inputs.aks_cluster_name }} --overwrite-existing + kubectl -n "$NS" apply -f configmaps.yaml + kubectl -n "$NS" apply -f secrets.yaml + kubectl -n "$NS" apply -f product-db.yaml + kubectl -n "$NS" apply -f order-db.yaml - - name: Attach ACR + - name: Deploy product & order services + working-directory: k8s 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 -n "$NS" apply -f product-service.yaml + kubectl -n "$NS" apply -f order-service.yaml + echo "--- services after apply ---" + kubectl -n "$NS" get svc -o wide - - name: Deploy Backend Infrastructure (Namespace, ConfigMaps, Secrets, Databases) + - name: Detect service names (product/order) + id: detect_svcs + shell: bash 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) + set -e + PROD_NAME=$(kubectl -n "$NS" get svc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | grep -E '^product' | head -1 || true) + ORD_NAME=$(kubectl -n "$NS" get svc -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | grep -E '^order' | head -1 || true) + [ -z "$PROD_NAME" ] && PROD_NAME="product-service" + [ -z "$ORD_NAME" ] && ORD_NAME="order-service" + echo "PRODUCT_SVC=$PROD_NAME" >> $GITHUB_ENV + echo "ORDER_SVC=$ORD_NAME" >> $GITHUB_ENV + echo "Detected PRODUCT_SVC=$PROD_NAME ORDER_SVC=$ORD_NAME" + + # 🔧 Force both services to LoadBalancer so they can get public IPs + - name: Ensure services are type LoadBalancer + shell: bash 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 + for SVC in "$PRODUCT_SVC" "$ORDER_SVC"; do + TYPE=$(kubectl -n "$NS" get svc "$SVC" -o jsonpath='{.spec.type}' 2>/dev/null || echo "") + if [ "$TYPE" != "LoadBalancer" ]; then + echo "Patching $SVC to type LoadBalancer (was '$TYPE')" + kubectl -n "$NS" patch svc "$SVC" --type merge -p '{"spec":{"type":"LoadBalancer"}}' + else + echo "$SVC already LoadBalancer" + fi + done + echo "--- services after patch ---" + kubectl -n "$NS" get svc -o wide + + - name: Wait for LoadBalancer IPs (<=10 min) + shell: bash 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 + set -e + for i in {1..120}; do + PROD_IP=$(kubectl -n "$NS" get svc "$PRODUCT_SVC" -o jsonpath='{.status.loadBalancer.ingress[0].ip}' 2>/dev/null || true) + ORD_IP=$(kubectl -n "$NS" get svc "$ORDER_SVC" -o jsonpath='{.status.loadBalancer.ingress[0].ip}' 2>/dev/null || true) + echo "Attempt $i: product=${PROD_IP:-} order=${ORD_IP:-}" + if [[ -n "$PROD_IP" && -n "$ORD_IP" ]]; then + echo "PRODUCT_IP=$PROD_IP" >> $GITHUB_ENV + echo "ORDER_IP=$ORD_IP" >> $GITHUB_ENV + exit 0 fi - sleep 5 # Wait 5 seconds before next attempt + sleep 5 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 + echo 'Timed out waiting for external IPs' + echo '--- describe services ---' + kubectl -n "$NS" describe svc "$PRODUCT_SVC" || true + kubectl -n "$NS" describe svc "$ORDER_SVC" || true + echo '--- recent events ---' + kubectl -n "$NS" get events --sort-by=.lastTimestamp | tail -n 100 || true + exit 1 + + - id: out_prod_ip run: echo "external_ip=${{ env.PRODUCT_IP }}" >> $GITHUB_OUTPUT - - - name: Capture Order Service IP for Workflow Output - id: get_order_ip + + - id: out_order_ip run: echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT - - name: Logout from Azure + - name: Azure Logout + if: always() run: az logout diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml index d69725aa..a060ffd2 100644 --- a/.github/workflows/backend_ci.yml +++ b/.github/workflows/backend_ci.yml @@ -1,92 +1,62 @@ -# week08/.github/workflows/backend_ci.yml +name: Backend CI — test, build & push (ACR) -name: Backend CI - Test, Build and Push Images to ACR - -# Trigger the workflow on pushes to the 'main' branch -# You can also add 'pull_request:' to run on PRs on: - # Manual trigger workflow_dispatch: - - # Automatically on pushes to main branch push: - branches: - - main - paths: # Only trigger if changes are in backend directories - - 'backend/**' - - '.github/workflows/backend_ci.yml' # Trigger if this workflow file changes + branches: [ main, task/9.2c ] + paths: + - "backend/**" + - ".github/workflows/backend_ci.yml" -# Define global environment variables that can be used across jobs env: - # ACR Login Server (e.g., myregistry.azurecr.io) - # This needs to be set as a GitHub Repository Secret - ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} - # Dynamically generate image tags based on Git SHA and GitHub Run ID - # This provides unique, traceable tags for each image build - IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} + ACR_NAME: ${{ secrets.ACR_NAME }} # <— ACR registry NAME (no .azurecr.io) jobs: - # Job 1: Run tests and linting for all backend services - test_and_lint_backends: - runs-on: ubuntu-latest # Use a GitHub-hosted runner + test_and_build: + runs-on: ubuntu-latest services: - # Product DB container product_db: image: postgres:15 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: products - # Make pg_isready available so the service is healthy before tests run + ports: [ "5432:5432" ] options: >- --health-cmd "pg_isready -U postgres" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 5432:5432 - - # Order DB + --health-interval 10s --health-timeout 5s --health-retries 5 + order_db: image: postgres:15 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: orders - ports: - - 5433:5432 + ports: [ "5433:5432" ] options: >- --health-cmd "pg_isready -U postgres" - --health-interval 10s - --health-timeout 5s - --health-retries 5 + --health-interval 10s --health-timeout 5s --health-retries 5 steps: - # 1. Checkout the repository code to the runner - - name: Checkout repository - uses: actions/checkout@v4 # Action to check out your repository code + - uses: actions/checkout@v4 - # 2. Set up Python environment - - name: Set up Python 3.10 - uses: actions/setup-python@v5 # Action to set up Python environment + - name: Set REGISTRY_SERVER env + run: echo "REGISTRY_SERVER=${{ env.ACR_NAME }}.azurecr.io" >> $GITHUB_ENV + + - name: Set up Python + uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: "3.10" - # 3. Install dependencies and run code quality checks - - name: Install dependencies - run: | # Use a multi-line script to install pip dependencies - pip install --upgrade pip - # Loop through each backend service folder + - name: Install deps (all backends) + run: | + pip install --upgrade pip pytest httpx for req in backend/*/requirements.txt; do - echo "Installing $req" - pip install -r "$req" + echo "Installing $req"; pip install -r "$req"; done - # Install CI tools - pip install pytest httpx - # 5. Run tests for product service - - name: Run product_service tests + - name: Test product_service working-directory: backend/product_service env: POSTGRES_HOST: localhost @@ -94,11 +64,9 @@ jobs: POSTGRES_DB: products POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - run: | - pytest tests --maxfail=1 --disable-warnings -q - - # 6. Run tests for order service - - name: Run order_service tests + run: pytest -q + + - name: Test order_service working-directory: backend/order_service env: POSTGRES_HOST: localhost @@ -106,41 +74,35 @@ jobs: POSTGRES_DB: orders POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - run: | - pytest tests --maxfail=1 --disable-warnings -q + run: pytest -q - # Job 2: Build and Push Docker Images (runs only if tests pass) - build_and_push_images: - runs-on: ubuntu-latest - needs: test_and_lint_backends + # Build & push only on non-PR pushes + - name: Azure Login + if: github.event_name == 'push' + uses: azure/login@v2 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # Azure login using a Service Principal secret - - name: Azure Login - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} # Needs to be set as a GitHub Secret (Service Principal JSON) - - # Login to Azure Container Registry (ACR) - - name: Login to Azure Container Registry - run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} - - # Build and Push Docker image for Product Service - - name: Build and Push Product Service Image - run: | - docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:latest ./backend/product_service/ - docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:latest - - # Build and Push Docker image for Order Service - - name: Build and Push Order Service Image - run: | - docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:latest ./backend/order_service/ - docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:latest - - # Logout from Azure for security (runs even if image push fails) - - name: Logout from Azure - run: az logout - if: always() + - name: ACR login (name, not FQDN) + if: github.event_name == 'push' + run: az acr login -n "${{ env.ACR_NAME }}" + + - name: Build & push product_service (SHA + latest) + if: github.event_name == 'push' + run: | + docker build -t $REGISTRY_SERVER/product_service:${GITHUB_SHA} ./backend/product_service + docker tag $REGISTRY_SERVER/product_service:${GITHUB_SHA} $REGISTRY_SERVER/product_service:latest + docker push $REGISTRY_SERVER/product_service:${GITHUB_SHA} + docker push $REGISTRY_SERVER/product_service:latest + + - name: Build & push order_service (SHA + latest) + if: github.event_name == 'push' + run: | + docker build -t $REGISTRY_SERVER/order_service:${GITHUB_SHA} ./backend/order_service + docker tag $REGISTRY_SERVER/order_service:${GITHUB_SHA} $REGISTRY_SERVER/order_service:latest + docker push $REGISTRY_SERVER/order_service:${GITHUB_SHA} + docker push $REGISTRY_SERVER/order_service:latest + + - name: Logout Azure + if: always() + run: az logout diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml index 0a0879c8..660ee171 100644 --- a/.github/workflows/frontend-cd.yml +++ b/.github/workflows/frontend-cd.yml @@ -1,93 +1,88 @@ -# week08/.github/workflows/frontend-cd.yml +name: CD — Deploy Frontend to AKS -name: CD - Deploy Frontend to AKS - -# This workflow can be called by other workflows and takes inputs. -# Or it can be run manually if you provide the IPs. on: workflow_dispatch: inputs: - product_api_ip: - description: 'External IP of Product Service' - required: true - default: 'http://:8000' - order_api_ip: - description: 'External IP of Order Service (e.g., http://Y.Y.Y.Y:8001)' - required: true - default: 'http://:8001' aks_cluster_name: - description: 'Name of the AKS Cluster to deploy to' + description: AKS cluster name required: true - default: '' + default: sit722-w08-aks aks_resource_group: - description: 'Resource Group of the AKS Cluster' + description: AKS resource group required: true - default: '<' - - workflow_call: - inputs: - product_api_ip: + default: sit722-w08-rg + aks_acr_name: + description: ACR NAME (no .azurecr.io) required: true - type: string - order_api_ip: + default: sit722w08acr304694959 # <-- use YOUR ACR + namespace: + description: K8s namespace required: true - type: string - aks_cluster_name: + default: week08 + deploy_name: + description: Frontend Deployment name required: true - type: string - aks_resource_group: + default: frontend-w08e1 + service_name: + description: Frontend Service name required: true - type: string + default: frontend-w08e1 jobs: deploy_frontend: runs-on: ubuntu-latest environment: Production + outputs: + FRONTEND_IP: ${{ steps.out_fe_ip.outputs.external_ip }} steps: - - name: Checkout repository - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - # Azure login using a Service Principal secret - name: Azure Login - uses: azure/login@v1 + uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - # Login to Azure Container Registry (ACR) - - name: Login to Azure Container Registry - run: az acr login --name ${{ secrets.AZURE_CONTAINER_REGISTRY }} - - - name: Inject Backend IPs into Frontend main.js + - name: Get AKS credentials run: | - echo "Injecting IPs into frontend/static/js/main.js" - # Ensure frontend/main.js is directly in the path for sed - sed -i "s|_PRODUCT_API_URL_|${{ inputs.product_api_ip }}|g" frontend/main.js - sed -i "s|_ORDER_API_URL_|${{ inputs.order_api_ip }}|g" frontend/main.js - - # Display the modified file content for debugging - echo "--- Modified main.js content ---" - cat frontend/main.js - echo "---------------------------------" + az aks get-credentials \ + --resource-group "${{ github.event.inputs.aks_resource_group }}" \ + --name "${{ github.event.inputs.aks_cluster_name }}" \ + --overwrite-existing - # Build and Push Docker image for Frontend - - name: Build and Push Frontend Image + - name: Attach ACR (safe if already attached) run: | - docker build -t ${{ secrets.AZURE_CONTAINER_REGISTRY }}/frontend:latest ./frontend/ - docker push ${{ secrets.AZURE_CONTAINER_REGISTRY }}/frontend:latest + 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 }}" || true - - name: Set Kubernetes context (get AKS credentials) - uses: azure/aks-set-context@v3 - with: - resource-group: ${{ inputs.aks_resource_group }} - cluster-name: ${{ inputs.aks_cluster_name }} + - name: Apply frontend manifest + run: | + kubectl -n "${{ github.event.inputs.namespace }}" apply -f k8s/frontend.yaml + kubectl -n "${{ github.event.inputs.namespace }}" rollout status \ + deploy/${{ github.event.inputs.deploy_name }} --timeout=180s || true - - name: Deploy Frontend to AKS + - name: Wait for frontend external IP (≤5 min) + id: out_fe_ip + shell: bash run: | - echo "Deploying frontend with latest tag to AKS cluster: ${{ inputs.aks_cluster_name }}" - cd k8s/ - # Ensure frontend-service.yaml is configured with your ACR - kubectl apply -f frontend.yaml + set -e + for i in {1..60}; do + FE_IP=$(kubectl -n "${{ github.event.inputs.namespace }}" \ + get svc "${{ github.event.inputs.service_name }}" \ + -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo "Attempt $i: frontend=$FE_IP" + if [[ -n "$FE_IP" ]]; then + echo "external_ip=$FE_IP" >> "$GITHUB_OUTPUT" + echo "FRONTEND_IP=$FE_IP" >> "$GITHUB_ENV" + exit 0 + fi + sleep 5 + done + echo "Timed out waiting for frontend external IP"; exit 1 - - name: Logout from Azure (AKS deployment) + - name: Logout Azure + if: always() run: az logout + diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml index 9f9e76d9..386cf8dc 100644 --- a/.github/workflows/frontend_ci.yml +++ b/.github/workflows/frontend_ci.yml @@ -1,53 +1,43 @@ -# week08/.github/workflows/frontend_ci.yml - -name: Frontend CI - Build & Push Image +# .github/workflows/frontend_ci.yml +name: Frontend CI - build & push (ACR) on: - # Manual trigger workflow_dispatch: - - # Automatically on pushes to main branch push: - branches: - - main - paths: # Only trigger if changes are in the frontend directory - - 'frontend/**' - - '.github/workflows/frontend_ci.yml' # Trigger if this workflow file changes + branches: [ main, task/9.2c ] + paths: + - frontend/** + - .github/workflows/frontend_ci.yml -# Define global environment variables that can be used across jobs env: - # ACR Login Server (e.g., myregistry.azurecr.io) - # This needs to be set as a GitHub Repository Secret - ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} - # Dynamically generate image tags based on Git SHA and GitHub Run ID - # This provides unique, traceable tags for each image build - IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} + # Repository secret holding the plain ACR NAME (e.g., sit722w08acr27234) + ACR_NAME: ${{ secrets.ACR_NAME }} jobs: - build_and_push_frontend: + build_frontend: runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # Azure login using a Service Principal secret - - name: Azure Login - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS }} - - # Login to Azure Container Registry (ACR) - - name: Login to Azure Container Registry - run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} - - # Build and Push Docker image for Frontend - - name: Build and Push Frontend Image - run: | - docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/ - docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest - - # Logout from Azure for security (runs even if image push fails) - - name: Logout from Azure - run: az logout - if: always() + - uses: actions/checkout@v4 + + - name: Set REGISTRY_SERVER env + run: echo "REGISTRY_SERVER=${{ env.ACR_NAME }}.azurecr.io" >> "$GITHUB_ENV" + + - name: Azure Login + uses: azure/login@v2 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: ACR login + run: az acr login -n "${{ env.ACR_NAME }}" + + - name: Build & push frontend (SHA + latest) + run: | + set -e + docker build -t "$REGISTRY_SERVER/frontend:${GITHUB_SHA}" ./frontend + docker tag "$REGISTRY_SERVER/frontend:${GITHUB_SHA}" "$REGISTRY_SERVER/frontend:latest" + docker push "$REGISTRY_SERVER/frontend:${GITHUB_SHA}" + docker push "$REGISTRY_SERVER/frontend:latest" + + - name: Logout Azure + if: always() + run: az logout || true diff --git a/backend/ci-trigger.txt b/backend/ci-trigger.txt new file mode 100644 index 00000000..bf7a85ac --- /dev/null +++ b/backend/ci-trigger.txt @@ -0,0 +1 @@ +// trigger 17-09-2025 17:27:21.87 diff --git a/frontend/main.js b/frontend/main.js index f321fd91..ca1f45f5 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -1,16 +1,16 @@ -// week08/frontend/main.js +// week08/frontend/main.js 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://20.53.102.217'; + const ORDER_API_BASE_URL = 'http://20.53.103.38:8001'; // Product Service is named 'product-service-w04e2' and exposes port 8000 internally. - //const PRODUCT_API_BASE_URL = 'http://product-service-w04e2:8000'; + //const PRODUCT_API_BASE_URL = 'http://20.53.102.217'; // Order Service is named 'order-service-w04e2' and exposes port 8001 internally. - //const ORDER_API_BASE_URL = 'http://order-service-w04e2:8001'; + //const ORDER_API_BASE_URL = 'http://20.53.103.38:8001'; // DOM Elements const messageBox = document.getElementById('message-box'); @@ -426,3 +426,5 @@ document.addEventListener('DOMContentLoaded', () => { fetchProducts(); fetchOrders(); }); + + diff --git a/k8s/configmaps.yaml b/k8s/configmaps.yaml index 5b38627c..ab456484 100644 --- a/k8s/configmaps.yaml +++ b/k8s/configmaps.yaml @@ -1,5 +1,3 @@ -# week08/k8s/configmaps.yaml - apiVersion: v1 kind: ConfigMap metadata: @@ -8,8 +6,9 @@ data: # Database Names PRODUCTS_DB_NAME: products ORDERS_DB_NAME: orders + AZURE_STORAGE_CONTAINER_NAME: product-images AZURE_SAS_TOKEN_EXPIRY_HOURS: "24" - PRODUCT_SERVICE_URL: http://product-service-w08e1:8000 - ORDER_SERVICE_URL: http://order-service-w08e1:8001 \ No newline at end of file + PRODUCT_SERVICE_URL: "http://product-service-w08e1" + ORDER_SERVICE_URL: "http://order-service-w08e1:8001" diff --git a/k8s/frontend.yaml b/k8s/frontend.yaml index 1948536d..7e7164c1 100644 --- a/k8s/frontend.yaml +++ b/k8s/frontend.yaml @@ -1,9 +1,7 @@ -# week08/k8s/frontend.yaml - apiVersion: apps/v1 kind: Deployment metadata: - name: frontend + name: frontend-w08e1 labels: app: frontend spec: @@ -17,23 +15,23 @@ spec: app: frontend spec: containers: - - name: frontend-container - image: durgeshsamariya.azurecr.io/frontend:latest - imagePullPolicy: Always - ports: - - containerPort: 80 + - name: frontend + image: sit722w08acr304694959.azurecr.io/frontend:latest + imagePullPolicy: Always + ports: + - containerPort: 80 --- apiVersion: v1 kind: Service metadata: - name: frontend-w08e1 # Service name matches + name: frontend-w08e1 labels: app: frontend spec: selector: app: frontend + type: LoadBalancer ports: - - protocol: TCP - port: 80 # The port the service listens on inside the cluster - targetPort: 80 # The port on the Pod (containerPort where Nginx runs) - type: LoadBalancer # Exposes the service on a port on each Node's IP + - name: http + port: 80 + targetPort: 80 diff --git a/k8s/order-service.yaml b/k8s/order-service.yaml index c9d92e4d..7a4a9fbe 100644 --- a/k8s/order-service.yaml +++ b/k8s/order-service.yaml @@ -18,7 +18,7 @@ spec: spec: containers: - name: order-service-container - image: durgeshsamariya.azurecr.io/order_service:latest + image: sit722w08acr27234.azurecr.io/order_service:latest imagePullPolicy: Always ports: - containerPort: 8000 diff --git a/k8s/product-service.yaml b/k8s/product-service.yaml index 0cbbd505..bf6f756e 100644 --- a/k8s/product-service.yaml +++ b/k8s/product-service.yaml @@ -1,5 +1,4 @@ -# week08/k8s/product-service.yaml - +# k8s/product-service.yaml apiVersion: apps/v1 kind: Deployment metadata: @@ -18,12 +17,11 @@ spec: spec: containers: - name: product-service-container - image: durgeshsamariya.azurecr.io/product_service:latest + image: sit722w08acr304694959.azurecr.io/product_service:latest imagePullPolicy: Always ports: - containerPort: 8000 env: - # Database connection details - name: POSTGRES_HOST value: product-db-service-w08e1 - name: POSTGRES_DB @@ -34,32 +32,32 @@ spec: - name: POSTGRES_USER valueFrom: secretKeyRef: - name: ecomm-secrets-w08e1 # Secret name matches + name: ecomm-secrets-w08e1 key: POSTGRES_USER - name: POSTGRES_PASSWORD valueFrom: secretKeyRef: - name: ecomm-secrets-w08e1 # Secret name matches + name: ecomm-secrets-w08e1 key: POSTGRES_PASSWORD - name: AZURE_STORAGE_ACCOUNT_NAME valueFrom: secretKeyRef: - name: ecomm-secrets-w08e1 # Secret name matches + name: ecomm-secrets-w08e1 key: AZURE_STORAGE_ACCOUNT_NAME - name: AZURE_STORAGE_ACCOUNT_KEY valueFrom: secretKeyRef: - name: ecomm-secrets-w08e1 # Secret name matches + name: ecomm-secrets-w08e1 key: AZURE_STORAGE_ACCOUNT_KEY - name: AZURE_STORAGE_CONTAINER_NAME valueFrom: configMapKeyRef: - name: ecomm-config-w08e1 # ConfigMap name matches + name: ecomm-config-w08e1 key: AZURE_STORAGE_CONTAINER_NAME - name: AZURE_SAS_TOKEN_EXPIRY_HOURS valueFrom: configMapKeyRef: - name: ecomm-config-w08e1 # ConfigMap name matches + name: ecomm-config-w08e1 key: AZURE_SAS_TOKEN_EXPIRY_HOURS --- apiVersion: v1 @@ -72,7 +70,8 @@ spec: selector: app: product-service ports: - - protocol: TCP - port: 8000 - targetPort: 8000 + - name: http + protocol: TCP + port: 80 # expose on 80 publicly + targetPort: 8000 # app listens on 8000 type: LoadBalancer