diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..500ebadc Binary files /dev/null and b/.DS_Store differ diff --git a/.github/workflows/backend-cd.yml b/.github/workflows/backend-cd.yml deleted file mode 100644 index 6035ed15..00000000 --- a/.github/workflows/backend-cd.yml +++ /dev/null @@ -1,101 +0,0 @@ -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: '' - -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 diff --git a/.github/workflows/backend_ci.yml b/.github/workflows/backend_ci.yml deleted file mode 100644 index d69725aa..00000000 --- a/.github/workflows/backend_ci.yml +++ /dev/null @@ -1,146 +0,0 @@ -# week08/.github/workflows/backend_ci.yml - -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 - -# 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 }} - -jobs: - # Job 1: Run tests and linting for all backend services - test_and_lint_backends: - runs-on: ubuntu-latest # Use a GitHub-hosted runner - - 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 - options: >- - --health-cmd "pg_isready -U postgres" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 5432:5432 - - # Order DB - order_db: - image: postgres:15 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: orders - ports: - - 5433:5432 - options: >- - --health-cmd "pg_isready -U postgres" - --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 - - # 2. Set up Python environment - - name: Set up Python 3.10 - uses: actions/setup-python@v5 # Action to set up Python environment - with: - 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 - for req in backend/*/requirements.txt; do - 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 - working-directory: backend/product_service - env: - POSTGRES_HOST: localhost - POSTGRES_PORT: 5432 - 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 - working-directory: backend/order_service - env: - POSTGRES_HOST: localhost - POSTGRES_PORT: 5433 - POSTGRES_DB: orders - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - run: | - pytest tests --maxfail=1 --disable-warnings -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 - - 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() diff --git a/.github/workflows/final-merged.yml b/.github/workflows/final-merged.yml new file mode 100644 index 00000000..64089192 --- /dev/null +++ b/.github/workflows/final-merged.yml @@ -0,0 +1,148 @@ +# .github/workflows/unified-cd.yml +name: Final Merging to Production Environment + +on: + workflow_dispatch: + inputs: + aks_cluster_name: + description: 'Name of the AKS Cluster' + required: true + default: 'myAKSCluster' + aks_resource_group: + description: 'Resource Group of the AKS Cluster' + required: true + default: 'deakinuni' + aks_acr_name: + description: 'Azure Container Registry name' + required: true + default: 'week8' + push: + branches: + - main + +env: + ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} + +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 repo + uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Set AKS Context + 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: echo "Attached ACR" + + - name: Deploy Backend Infra (ConfigMaps, Secrets, DBs) + run: | + 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 Services (Product, Order) + run: | + 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..." + for i in {1..60}; do + 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 "Product Service IP: $PRODUCT_IP" + echo "Order Service IP: $ORDER_IP" + echo "PRODUCT_IP=$PRODUCT_IP" >> $GITHUB_ENV + echo "ORDER_IP=$ORDER_IP" >> $GITHUB_ENV + break + fi + sleep 5 + done + if [[ -z "$PRODUCT_IP" || -z "$ORDER_IP" ]]; then + echo "❌ Failed to get backend IPs" + exit 1 + fi + + - name: Capture Product IP + id: get_product_ip + run: echo "external_ip=${{ env.PRODUCT_IP }}" >> $GITHUB_OUTPUT + + - name: Capture Order IP + id: get_order_ip + run: echo "external_ip=${{ env.ORDER_IP }}" >> $GITHUB_OUTPUT + + - name: Logout Azure + if: always() + run: az logout + + # ---------------- FRONTEND DEPLOYMENT ---------------- + deploy_frontend: + runs-on: ubuntu-latest + environment: Production + needs: deploy_backend + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: ACR Login + uses: docker/login-action@v2 + with: + registry: ${{ env.ACR_LOGIN_SERVER }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Inject Backend IPs into Frontend + run: | + echo "Injecting Backend IPs into frontend/main.js" + sed -i "s|_PRODUCT_API_URL_|http://${{ needs.deploy_backend.outputs.PRODUCT_API_IP }}:8000|g" frontend/main.js + sed -i "s|_ORDER_API_URL_|http://${{ needs.deploy_backend.outputs.ORDER_API_IP }}:8001|g" frontend/main.js + cat frontend/main.js + + - name: Build & Push Frontend Image + run: | + docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/ + docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest + + - name: Set AKS Context + uses: azure/aks-set-context@v3 + with: + resource-group: ${{ github.event.inputs.aks_resource_group }} + cluster-name: ${{ github.event.inputs.aks_cluster_name }} + + - name: Deploy Frontend + run: | + cd k8s/ + kubectl apply -f frontend.yaml + + - name: Logout Azure + if: always() + run: az logout diff --git a/.github/workflows/frontend-cd.yml b/.github/workflows/frontend-cd.yml deleted file mode 100644 index 0a0879c8..00000000 --- a/.github/workflows/frontend-cd.yml +++ /dev/null @@ -1,93 +0,0 @@ -# week08/.github/workflows/frontend-cd.yml - -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' - required: true - default: '' - aks_resource_group: - description: 'Resource Group of the AKS Cluster' - required: true - default: '<' - - workflow_call: - inputs: - product_api_ip: - required: true - type: string - order_api_ip: - required: true - type: string - aks_cluster_name: - required: true - type: string - aks_resource_group: - required: true - type: string - -jobs: - deploy_frontend: - runs-on: ubuntu-latest - environment: Production - - 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 ${{ secrets.AZURE_CONTAINER_REGISTRY }} - - - name: Inject Backend IPs into Frontend main.js - 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 "---------------------------------" - - # Build and Push Docker image for Frontend - - name: Build and Push Frontend Image - run: | - docker build -t ${{ secrets.AZURE_CONTAINER_REGISTRY }}/frontend:latest ./frontend/ - docker push ${{ secrets.AZURE_CONTAINER_REGISTRY }}/frontend:latest - - - 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: Deploy Frontend to AKS - 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 - - - name: Logout from Azure (AKS deployment) - run: az logout diff --git a/.github/workflows/frontend_ci.yml b/.github/workflows/frontend_ci.yml deleted file mode 100644 index 9f9e76d9..00000000 --- a/.github/workflows/frontend_ci.yml +++ /dev/null @@ -1,53 +0,0 @@ -# week08/.github/workflows/frontend_ci.yml - -name: Frontend CI - Build & Push Image - -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 - -# 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 }} - -jobs: - build_and_push_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() diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml new file mode 100644 index 00000000..1467f375 --- /dev/null +++ b/.github/workflows/staging-deploy.yml @@ -0,0 +1,64 @@ +name: Staging CD - Deploy to Temporary Environment + +on: + workflow_run: + workflows: ["Unified CI - Backend & Frontend"] + types: + - completed + +jobs: + deploy_staging: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + environment: staging + + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Set AKS Context (Staging Cluster) + run: | + az aks get-credentials \ + --resource-group ${{ secrets.STAGING_RG }} \ + --name ${{ secrets.STAGING_CLUSTER_NAME }} \ + --overwrite-existing + + + - name: Deploy Infra + run: | + 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 & Frontend + run: | + cd k8s/ + kubectl apply -f product-service.yaml + kubectl apply -f order-service.yaml + kubectl apply -f frontend.yaml + + - name: Run Acceptance Tests + run: echo "Add curl or pytest here to hit endpoints" + + - name: Destroy Staging Environment + run: | + echo "Cleaning up staging..." + cd k8s/ + kubectl delete -f frontend.yaml + kubectl delete -f order-service.yaml + kubectl delete -f product-service.yaml + kubectl delete -f product-db.yaml + kubectl delete -f order-db.yaml + kubectl delete -f configmaps.yaml + kubectl delete -f secrets.yaml + + - name: Logout Azure + if: always() + run: az logout diff --git a/.github/workflows/unified-ci.yml b/.github/workflows/unified-ci.yml new file mode 100644 index 00000000..5d44b051 --- /dev/null +++ b/.github/workflows/unified-ci.yml @@ -0,0 +1,145 @@ +name: Unified CI - Backend & Frontend + +on: + workflow_dispatch: # Manual trigger + push: + branches: + - testing # CI triggers on push to 'testing' branch + paths: + - 'backend/**' + - 'frontend/**' + - '.github/workflows/unified-ci.yml' + + pull_request: + branches: + - main + - development + paths: + - 'backend/**' + - 'frontend/**' + - '.github/workflows/unified-ci.yml' + +env: + ACR_LOGIN_SERVER: ${{ secrets.AZURE_CONTAINER_REGISTRY }} + IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }} + +jobs: + # ---------------- BACKEND JOB ---------------- + backend: + runs-on: ubuntu-latest + + services: + product_db: + image: postgres:15 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: products + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + order_db: + image: postgres:15 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: orders + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5433:5432 + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Install dependencies + run: | + pip install --upgrade pip + for req in backend/*/requirements.txt; do + echo "Installing $req" + pip install -r "$req" + done + pip install pytest httpx + + - name: Run product_service tests + working-directory: backend/product_service + env: + POSTGRES_HOST: localhost + POSTGRES_PORT: 5432 + POSTGRES_DB: products + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + run: pytest tests --maxfail=1 --disable-warnings -q + + - name: Run order_service tests + working-directory: backend/order_service + env: + POSTGRES_HOST: localhost + POSTGRES_PORT: 5433 + POSTGRES_DB: orders + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + run: pytest tests --maxfail=1 --disable-warnings -q + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Login to Azure Container Registry + run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} + + - name: Build & Push Product Service + run: | + TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG ./backend/product_service + docker push ${{ env.ACR_LOGIN_SERVER }}/product_service:$TAG + + - name: Build & Push Order Service + run: | + TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG ./backend/order_service + docker push ${{ env.ACR_LOGIN_SERVER }}/order_service:$TAG + + - name: Logout Azure + if: always() + run: az logout + + # ---------------- FRONTEND JOB ---------------- + frontend: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Azure Login + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Login to Azure Container Registry + run: az acr login --name ${{ env.ACR_LOGIN_SERVER }} + + - name: Build & Push Frontend + run: | + TAG=${{ github.ref_name == 'main' && 'latest' || format('dev-{0}', github.sha) }} + docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG ./frontend + docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:$TAG + + - name: Logout Azure + if: always() + run: az logout + diff --git a/backend/order_service/Dockerfile b/backend/order_service/Dockerfile index c961f84f..7f9e3a6e 100644 --- a/backend/order_service/Dockerfile +++ b/backend/order_service/Dockerfile @@ -1,16 +1,17 @@ -# week08/backend/order_service/Dockerfile - FROM python:3.10-slim-buster WORKDIR /code +# Copy and install dependencies COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt + pip install --no-cache-dir -r requirements.txt && \ + pip install --no-cache-dir pytest +# Copy application code COPY app /code/app EXPOSE 8000 -CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/backend/product_service/Dockerfile b/backend/product_service/Dockerfile index 9dfdd3f9..c0907258 100644 --- a/backend/product_service/Dockerfile +++ b/backend/product_service/Dockerfile @@ -7,7 +7,8 @@ WORKDIR /code COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt + pip install --no-cache-dir -r requirements.txt && \ + pip install --no-cache-dir pytest COPY app /code/app diff --git a/docker-compose.yml b/docker-compose.yml index ffe144c7..852b10e6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -53,9 +53,9 @@ services: - "8000:8000" environment: POSTGRES_HOST: product_db # Connects to the 'product_db' service within Docker network - AZURE_STORAGE_ACCOUNT_NAME: # Replace with your Azure Storage account name - AZURE_STORAGE_ACCOUNT_KEY: # Replace with your Azure Storage account key - AZURE_STORAGE_CONTAINER_NAME: # Replace with your Azure Storage container name + AZURE_STORAGE_ACCOUNT_NAME: week08 # Replace with your Azure Storage account name + AZURE_STORAGE_ACCOUNT_KEY: yoPFslu06OVWDl0rLA9pABgzKhjs/k7Q1JwbXX4ya+N7vWOfcpUEi2BkgNUfqLrVnsz4aV3DkLIT+AStmfRIFQ== # Replace with your Azure Storage account key + AZURE_STORAGE_CONTAINER_NAME: pjctcont # Replace with your Azure Storage container name AZURE_SAS_TOKEN_EXPIRY_HOURS: 24 depends_on: product_db: diff --git a/frontend/Dockerfile.test b/frontend/Dockerfile.test new file mode 100644 index 00000000..5f3d5f42 --- /dev/null +++ b/frontend/Dockerfile.test @@ -0,0 +1,13 @@ +# week08/frontend/Dockerfile.test + +FROM node:18 + +WORKDIR /app + +COPY package*.json ./ +RUN npm install + +COPY . . + +# Run tests (e.g., Jest or whatever you're using) +CMD ["npm", "test"] diff --git a/k8s/frontend.yaml b/k8s/frontend.yaml index 1948536d..238d0ffd 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: week8.azurecr.io/frontend:latest imagePullPolicy: Always ports: - containerPort: 80 diff --git a/k8s/order-service.yaml b/k8s/order-service.yaml index c9d92e4d..9730130c 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: week8.azurecr.io/order_service:latest imagePullPolicy: Always ports: - containerPort: 8000 diff --git a/k8s/product-service.yaml b/k8s/product-service.yaml index 0cbbd505..f56b07fe 100644 --- a/k8s/product-service.yaml +++ b/k8s/product-service.yaml @@ -18,7 +18,7 @@ spec: spec: containers: - name: product-service-container - image: durgeshsamariya.azurecr.io/product_service:latest + image: week8.azurecr.io/product_service:latest imagePullPolicy: Always ports: - containerPort: 8000 diff --git a/k8s/secrets.yaml b/k8s/secrets.yaml index 5eebe1fa..08c8f117 100644 --- a/k8s/secrets.yaml +++ b/k8s/secrets.yaml @@ -13,6 +13,6 @@ data: # Azure Storage Account Credentials for Product Service image uploads # REPLACE WITH YOUR ACTUAL BASE64 ENCODED VALUES from your Azure Storage Account # Example: echo -n 'myblobstorageaccount' | base64 - AZURE_STORAGE_ACCOUNT_NAME: "ZHVyZ2VzaHNhbWFyaXlh" + AZURE_STORAGE_ACCOUNT_NAME: "d2VlazA4" # Example: echo -n 'your_storage_account_key_string' | base64 - AZURE_STORAGE_ACCOUNT_KEY: "aEFNQ24rbkh2cmhwSGFEaW5jSnAxNFlHaU5nTnJja2NJR05Bc3Y5VXZPUlpsblJkbkVUR3drdTREdSszblBDR3E4ZEVTVjlFNE1jMytBU3RubmZ5QVE9PQ==" + AZURE_STORAGE_ACCOUNT_KEY: "eW9QRnNsdTA2T1ZXRGwwckxBOXBBQmd6S2hqcy9rN1ExSndiWFg0eWErTjd2V09mY3BVRWkyQmtnTlVmcUxyVm5zejRhVjNEa0xJVCtBU3RtZlJJRlE9PQ=="