Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: CI/CD

on:
push:
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
run: npm run build

acr-push:
name: Docker
name: Docker Build & Push
runs-on: ubuntu-latest
needs: [server, client]
if: github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
${{ secrets.ACR_NAME }}.azurecr.io/client:${{ github.sha }}
${{ secrets.ACR_NAME }}.azurecr.io/client:latest

- name: Trivy server
- name: Scan server image (Trivy)
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ secrets.ACR_NAME }}.azurecr.io/server:${{ github.sha }}
Expand All @@ -103,7 +103,7 @@ jobs:
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'

- name: Trivy client
- name: Scan client image (Trivy)
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ secrets.ACR_NAME }}.azurecr.io/client:${{ github.sha }}
Expand All @@ -114,7 +114,7 @@ jobs:
severity: 'CRITICAL,HIGH'

deploy-staging:
name: Staging
name: Deploy Staging
runs-on: ubuntu-latest
needs: [acr-push]
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
Expand All @@ -130,7 +130,7 @@ jobs:
- name: Setup Kustomize
uses: imranismail/setup-kustomize@v2

- name: Set context
- name: Set AKS context
uses: azure/k8s-set-context@v4
with:
method: kubeconfig
Expand All @@ -139,14 +139,14 @@ jobs:
- name: Create namespace
run: kubectl create namespace staging --dry-run=client -o yaml | kubectl apply -f -

- name: Create secret
- name: Create telemetry secret
run: |
kubectl create secret generic appinsights-secrets \
--from-literal=APPLICATIONINSIGHTS_CONNECTION_STRING='${{ secrets.APP_INSIGHTS_CONNECTION_STRING }}' \
--namespace staging \
--dry-run=client -o yaml | kubectl apply -f -

- name: Substitute secrets
- name: Configure SecretProviderClass
env:
KEY_VAULT_NAME: ${{ secrets.KEY_VAULT_NAME }}
TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
Expand All @@ -162,13 +162,13 @@ jobs:
kustomize edit set image devopscommerce.azurecr.io/client=${{ secrets.ACR_NAME }}.azurecr.io/client:${{ github.sha }}
kubectl apply -k .

- name: Rollout
- name: Verify rollout
run: |
kubectl rollout status deployment/server --namespace staging --timeout=180s
kubectl rollout status deployment/client --namespace staging --timeout=180s

deploy-production:
name: Production
name: Deploy Production
runs-on: ubuntu-latest
needs: [acr-push]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
Expand All @@ -184,7 +184,7 @@ jobs:
- name: Setup Kustomize
uses: imranismail/setup-kustomize@v2

- name: Set context
- name: Set AKS context
uses: azure/k8s-set-context@v4
with:
method: kubeconfig
Expand All @@ -193,14 +193,14 @@ jobs:
- name: Create namespace
run: kubectl create namespace production --dry-run=client -o yaml | kubectl apply -f -

- name: Create secret
- name: Create telemetry secret
run: |
kubectl create secret generic appinsights-secrets \
--from-literal=APPLICATIONINSIGHTS_CONNECTION_STRING='${{ secrets.APP_INSIGHTS_CONNECTION_STRING }}' \
--namespace production \
--dry-run=client -o yaml | kubectl apply -f -

- name: Substitute secrets
- name: Configure SecretProviderClass
env:
KEY_VAULT_NAME: ${{ secrets.KEY_VAULT_NAME }}
TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
Expand All @@ -216,7 +216,7 @@ jobs:
kustomize edit set image devopscommerce.azurecr.io/client=${{ secrets.ACR_NAME }}.azurecr.io/client:${{ github.sha }}
kubectl apply -k .

- name: Rollout
- name: Verify rollout
run: |
kubectl rollout status deployment/server --namespace production --timeout=180s
kubectl rollout status deployment/client --namespace production --timeout=180s
468 changes: 196 additions & 272 deletions README.md

Large diffs are not rendered by default.

15 changes: 2 additions & 13 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
# Use official Node.js 18 as base image
FROM node:18-bullseye-slim AS build

# Set working directory
WORKDIR /usr/src/app

# Copy package.json and package-lock.json
COPY package*.json ./

# Install dependencies
RUN npm ci

# Copy the rest of the client code
COPY . .

RUN mv .env.example .env

# Build the client for production
RUN npm run build


FROM nginx:alpine
# Copy the build artifacts from the build stage

COPY --from=build /usr/src/app/dist /usr/share/nginx/html
# NGINX default configuration file
COPY nginx.conf /etc/nginx/nginx.conf

# Expose port 8080
EXPOSE 8080

CMD ["nginx", "-g", "daemon off;"]


7 changes: 4 additions & 3 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ resource "azurerm_virtual_network" "vnet" {
address_space = ["10.0.0.0/16"]

tags = {
Environment = "DevOps-Capstone"
Environment = "production"
Project = "mern-ecommerce"
ManagedBy = "Terraform"
}
}
Expand Down Expand Up @@ -74,8 +75,8 @@ resource "azurerm_kubernetes_cluster" "aks" {
}

tags = {
Environment = "DevOps-Capstone"
Project = "MERN-Ecommerce"
Environment = "production"
Project = "mern-ecommerce"
ManagedBy = "Terraform"
}
}
Expand Down
8 changes: 4 additions & 4 deletions infra/monitoring.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ resource "azurerm_log_analytics_workspace" "main" {
retention_in_days = 30

tags = {
Environment = "DevOps-Capstone"
Project = "MERN-Ecommerce"
Environment = "production"
Project = "mern-ecommerce"
ManagedBy = "Terraform"
}
}
Expand All @@ -24,8 +24,8 @@ resource "azurerm_application_insights" "main" {
application_type = "Node.JS"

tags = {
Environment = "DevOps-Capstone"
Project = "MERN-Ecommerce"
Environment = "production"
Project = "mern-ecommerce"
ManagedBy = "Terraform"
}
}
Expand Down
8 changes: 4 additions & 4 deletions infra/security.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ resource "azurerm_key_vault" "main" {
sku_name = "standard"

tags = {
Environment = "DevOps-Capstone"
Project = "MERN-Ecommerce"
Environment = "production"
Project = "mern-ecommerce"
ManagedBy = "Terraform"
}
}
Expand Down Expand Up @@ -97,8 +97,8 @@ resource "azurerm_network_security_group" "aks" {
}

tags = {
Environment = "DevOps-Capstone"
Project = "MERN-Ecommerce"
Environment = "production"
Project = "mern-ecommerce"
ManagedBy = "Terraform"
}
}
Expand Down
2 changes: 1 addition & 1 deletion infra/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ variable "location" {
}

variable "acr_name" {
description = "Name of the Azure Container Registry created in Phase 4"
description = "Name of the Azure Container Registry"
type = string
default = "devopscommerce"
}
Expand Down
12 changes: 2 additions & 10 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
# Use official Node.js 18 as base image
FROM node:18-bullseye-slim

# Set working directory
WORKDIR /usr/src/app

# Copy package.json and package-lock.json
COPY package*.json ./

# Install dependencies
# Note: --omit=dev breaks seed.js at container startup (utils/seed.js requires
# the devDependency 'chalk'), so all deps are installed here.
# seed.js at container startup requires 'chalk'
RUN npm ci

# Copy the rest of the server code
COPY . .

# Expose port 3000 for the server
EXPOSE 3000

# Default command to start the application
CMD ["npm", "start"]

Loading