-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from CS3219-AY2425S1/feat/35-continuous-deploy…
…ment
- Loading branch information
Showing
5 changed files
with
268 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |