Skip to content

Commit e21e273

Browse files
committed
add cloudbuild for api-gateway
1 parent ab14ee4 commit e21e273

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

cloudbuild.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ steps:
6565
"asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/user-svc:latest",
6666
]
6767

68+
# Build and push api-gateway
69+
- name: "gcr.io/cloud-builders/docker"
70+
args:
71+
[
72+
"build",
73+
"-t",
74+
"asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/api-gateway:latest",
75+
"-f",
76+
"api-gateway/Dockerfile",
77+
"api-gateway",
78+
]
79+
80+
# Push the api-gateway image to Artifact Registry
81+
- name: "gcr.io/cloud-builders/docker"
82+
args:
83+
[
84+
"push",
85+
"asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/api-gateway:latest",
86+
]
87+
6888
# Step 2: Clean up and deploy to GKE
6989

7090
# Clean up before deploying peerprep-fe
@@ -106,6 +126,19 @@ steps:
106126
- --location=asia-southeast1
107127
- --cluster=cs3219-g11-peerprep-kubes
108128

129+
# Clean up before deploying api-gateway
130+
- name: "ubuntu"
131+
args: ["rm", "-rf", "output"]
132+
133+
# Deploy api-gateway to Google Kubernetes Engine (GKE)
134+
- name: "gcr.io/cloud-builders/gke-deploy"
135+
args:
136+
- run
137+
- --filename=k8s/api-gateway.yml
138+
- --image=asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/api-gateway:latest
139+
- --location=asia-southeast1
140+
- --cluster=cs3219-g11-peerprep-kubes
141+
109142
# Step 3: update the deployments with the new images
110143

111144
# Update the peerprep-fe deployment
@@ -141,6 +174,17 @@ steps:
141174
- "CLOUDSDK_COMPUTE_ZONE=asia-southeast1"
142175
- "CLOUDSDK_CONTAINER_CLUSTER=cs3219-g11-peerprep-kubes"
143176

177+
# Update the api-gateway deployment
178+
- name: "gcr.io/cloud-builders/kubectl"
179+
args:
180+
- "set"
181+
- "image"
182+
- "deployment/api-gateway"
183+
- "api-gateway=asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/api-gateway:latest"
184+
env:
185+
- "CLOUDSDK_COMPUTE_ZONE=asia-southeast1"
186+
- "CLOUDSDK_CONTAINER_CLUSTER=cs3219-g11-peerprep-kubes"
187+
144188
substitutions:
145189
_NEXT_PUBLIC_API_GATEWAY_URL: ""
146190
_NEXT_PUBLIC_GITHUB_CLIENT_ID: ""
@@ -152,3 +196,4 @@ images:
152196
- "asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/peerprep-fe:latest"
153197
- "asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/question-svc:latest"
154198
- "asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/user-svc:latest"
199+
- "asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/api-gateway:latest"

k8s/api-gateway.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: api-gateway
5+
labels:
6+
type: backend
7+
app: api-gateway
8+
spec:
9+
selector:
10+
matchLabels:
11+
type: backend
12+
app: api-gateway
13+
template:
14+
metadata:
15+
name: api-gateway
16+
labels:
17+
type: backend
18+
app: api-gateway
19+
spec:
20+
containers:
21+
- name: api-gateway
22+
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/api-gateway:latest
23+
imagePullPolicy: Always
24+
resources:
25+
requests:
26+
cpu: "100m"
27+
memory: "128Mi"
28+
limits:
29+
cpu: "200m"
30+
memory: "256Mi"
31+
ports:
32+
- containerPort: 8001
33+
envFrom:
34+
- secretRef:
35+
name: api-gateway-config
36+
dnsPolicy: ClusterFirst
37+
---
38+
apiVersion: v1
39+
kind: Service
40+
metadata:
41+
name: api-gateway
42+
spec:
43+
type: LoadBalancer
44+
ports:
45+
- port: 8001
46+
targetPort: 8001
47+
selector:
48+
type: backend
49+
app: api-gateway
50+
---
51+
apiVersion: autoscaling/v2
52+
kind: HorizontalPodAutoscaler
53+
metadata:
54+
name: api-gateway
55+
spec:
56+
scaleTargetRef:
57+
apiVersion: apps/v1
58+
kind: Deployment
59+
name: api-gateway
60+
minReplicas: 1
61+
maxReplicas: 5
62+
metrics:
63+
- type: Resource
64+
resource:
65+
name: cpu
66+
target:
67+
type: Utilization
68+
averageUtilization: 80

0 commit comments

Comments
 (0)