Skip to content

Commit

Permalink
Merge pull request #53 from CS3219-AY2425S1/feat/35-continuous-deploy…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
simbayippy authored Oct 10, 2024
2 parents f62a4b2 + acdb1a4 commit 06d007c
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 27 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Deploy to GCP

on:
push:
branches:
- main

jobs:
deploy:
permissions:
contents: "read"
id-token: "write"

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- id: "auth"
name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.GCP_SA_KEY }}"

- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v2"

- name: "Use gcloud CLI"
run: "gcloud info"

- name: "Trigger Cloud Build"
run: "gcloud builds submit --config cloudbuild.yaml"
146 changes: 146 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
steps:
# Step 1: build and push all images to Artifact Registry

# Build and push peerprep-fe
- name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/peerprep-fe:latest",
"-f",
"peerprep-fe/Dockerfile",
"peerprep-fe",
]

# Push the peerprep-fe image to Artifact Registry
- name: "gcr.io/cloud-builders/docker"
args:
[
"push",
"asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/peerprep-fe:latest",
]

# Build and push question-service
- name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/question-svc:latest",
"-f",
"question-service/Dockerfile",
"question-service",
]

# Push the question-service image to Artifact Registry
- name: "gcr.io/cloud-builders/docker"
args:
[
"push",
"asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/question-svc:latest",
]

# Build and push user-service
- name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/user-svc:latest",
"-f",
"user-service/Dockerfile",
"user-service",
]

# Push the user-service image to Artifact Registry
- name: "gcr.io/cloud-builders/docker"
args:
[
"push",
"asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/user-svc:latest",
]

# Step 2: Clean up and deploy to GKE

# Clean up before deploying peerprep-fe
- name: "ubuntu"
args: ["rm", "-rf", "output"]

# Deploy peerprep-fe to Google Kubernetes Engine (GKE)
- name: "gcr.io/cloud-builders/gke-deploy"
args:
- run
- --filename=k8s/peerprep-fe.yml
- --image=asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/peerprep-fe:latest
- --location=asia-southeast1
- --cluster=cs3219-g11-peerprep-kubes

# Clean up before deploying question-service
- name: "ubuntu"
args: ["rm", "-rf", "output"]

# Deploy question-service to Google Kubernetes Engine (GKE)
- name: "gcr.io/cloud-builders/gke-deploy"
args:
- run
- --filename=k8s/question-service.yml
- --image=asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/question-svc:latest
- --location=asia-southeast1
- --cluster=cs3219-g11-peerprep-kubes

# Clean up before deploying user-service
- name: "ubuntu"
args: ["rm", "-rf", "output"]

# Deploy user-service to Google Kubernetes Engine (GKE)
- name: "gcr.io/cloud-builders/gke-deploy"
args:
- run
- --filename=k8s/user-service.yml
- --image=asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/user-svc:latest
- --location=asia-southeast1
- --cluster=cs3219-g11-peerprep-kubes

# Step 3: update the deployments with the new images

# Update the peerprep-fe deployment
- name: "gcr.io/cloud-builders/kubectl"
args:
- "set"
- "image"
- "deployment/peerprep-fe"
- "peerprep-fe=asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/peerprep-fe:latest"
env:
- "CLOUDSDK_COMPUTE_ZONE=asia-southeast1"
- "CLOUDSDK_CONTAINER_CLUSTER=cs3219-g11-peerprep-kubes"

# Update the question-service deployment
- name: "gcr.io/cloud-builders/kubectl"
args:
- "set"
- "image"
- "deployment/question-svc"
- "question-svc=asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/question-svc:latest"
env:
- "CLOUDSDK_COMPUTE_ZONE=asia-southeast1"
- "CLOUDSDK_CONTAINER_CLUSTER=cs3219-g11-peerprep-kubes"

# Update the user-service deployment hi
- name: "gcr.io/cloud-builders/kubectl"
args:
- "set"
- "image"
- "deployment/user-svc"
- "user-svc=asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/user-svc:latest"
env:
- "CLOUDSDK_COMPUTE_ZONE=asia-southeast1"
- "CLOUDSDK_CONTAINER_CLUSTER=cs3219-g11-peerprep-kubes"

options:
dynamic_substitutions: true

images:
- "asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/peerprep-fe:latest"
- "asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/question-svc:latest"
- "asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/user-svc:latest"
28 changes: 16 additions & 12 deletions k8s/peerprep-fe.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: apps/v1
kind: Deployment
metadata:
metadata:
name: peerprep-fe
labels:
type: frontend
Expand All @@ -18,11 +18,15 @@ spec:
app: peerprep-fe
spec:
containers:
- name: peerprep-fe
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/peerprep-fe:latest
# imagePullPolicy: Never # only used for local builds
ports:
- containerPort: 3000
- name: peerprep-fe
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/peerprep-fe:latest
# imagePullPolicy: Never # only used for local builds
ports:
- containerPort: 3000
envFrom:
- secretRef:
name: peerprep-config
dnsPolicy: ClusterFirst
---
apiVersion: v1
kind: Service
Expand All @@ -49,9 +53,9 @@ spec:
minReplicas: 1
maxReplicas: 5
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
30 changes: 15 additions & 15 deletions k8s/question-service.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: apps/v1
kind: Deployment
metadata:
metadata:
name: question-svc
labels:
type: backend
Expand All @@ -18,14 +18,14 @@ spec:
app: question-svc
spec:
containers:
- name: question-svc
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/question-svc:latest
# imagePullPolicy: Never # only used for local builds
ports:
- containerPort: 4001
envFrom:
- configMapRef:
name: question-service-config
- name: question-svc
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/question-svc:latest
# imagePullPolicy: Never # only used for local builds
ports:
- containerPort: 4001
envFrom:
- secretRef:
name: question-service-config
dnsPolicy: ClusterFirst
---
# This is an internal service, not exposed
Expand Down Expand Up @@ -54,9 +54,9 @@ spec:
minReplicas: 1
maxReplicas: 5
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
60 changes: 60 additions & 0 deletions k8s/user-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: user-svc
labels:
type: backend
app: user-svc
spec:
selector:
matchLabels:
type: backend
app: user-svc
template:
metadata:
name: user-svc
labels:
type: backend
app: user-svc
spec:
containers:
- name: user-svc
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/user-svc:latest
ports:
- containerPort: 3001
envFrom:
- secretRef:
name: user-service-config
dnsPolicy: ClusterFirst
---
apiVersion: v1
kind: Service
metadata:
name: user-svc
spec:
type: LoadBalancer
ports:
- port: 3001
targetPort: 3001
selector:
type: backend
app: user-svc
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: user-svc
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: user-svc
minReplicas: 1
maxReplicas: 5
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80

0 comments on commit 06d007c

Please sign in to comment.