Skip to content

Commit 930b55e

Browse files
committed
re-implement K8 and docker
1 parent 3c935d2 commit 930b55e

File tree

7 files changed

+219
-0
lines changed

7 files changed

+219
-0
lines changed

docker-compose.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
services:
2+
frontend:
3+
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/peerprep-fe:latest
4+
build:
5+
context: ./peerprep-fe
6+
dockerfile: Dockerfile
7+
# volumes:
8+
# - ./peerprep-fe:/app # Mount src directory for hot reloading
9+
# - /app/node_modules # Prevent overwriting node_modules
10+
# - /app/.next
11+
ports:
12+
- "3000:3000"
13+
environment:
14+
- NODE_ENV=production
15+
networks:
16+
- peerprep-network
17+
env_file:
18+
- ./peerprep-fe/.env.production
19+
question-service:
20+
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/question-svc:latest
21+
build:
22+
context: ./question-service
23+
dockerfile: Dockerfile
24+
volumes:
25+
- ./question-service:/app # Mount src directory for hot reloading
26+
- ./question-service/node_modules:/app/node_modules
27+
ports:
28+
- "4001:4001"
29+
environment:
30+
- NODE_ENV=production
31+
- PORT=4001
32+
networks:
33+
- peerprep-network
34+
env_file:
35+
- ./question-service/.env.dev
36+
networks:
37+
peerprep-network:
38+
driver: bridge

k8s/peerprep-fe.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: peerprep-fe
5+
labels:
6+
type: frontend
7+
app: peerprep-fe
8+
spec:
9+
selector:
10+
matchLabels:
11+
type: frontend
12+
app: peerprep-fe
13+
template:
14+
metadata:
15+
name: peerprep-fe
16+
labels:
17+
type: frontend
18+
app: peerprep-fe
19+
spec:
20+
containers:
21+
- name: peerprep-fe
22+
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/peerprep-fe:latest
23+
# imagePullPolicy: Never # only used for local builds
24+
ports:
25+
- containerPort: 3000
26+
---
27+
apiVersion: v1
28+
kind: Service
29+
metadata:
30+
name: peerprep-fe
31+
spec:
32+
type: LoadBalancer
33+
ports:
34+
- port: 80
35+
targetPort: 3000
36+
selector:
37+
type: frontend
38+
app: peerprep-fe
39+
---
40+
apiVersion: autoscaling/v2
41+
kind: HorizontalPodAutoscaler
42+
metadata:
43+
name: peerprep-fe
44+
spec:
45+
scaleTargetRef:
46+
apiVersion: apps/v1
47+
kind: Deployment
48+
name: peerprep-fe
49+
minReplicas: 1
50+
maxReplicas: 5
51+
metrics:
52+
- type: Resource
53+
resource:
54+
name: cpu
55+
target:
56+
type: Utilization
57+
averageUtilization: 80

k8s/question-service.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: question-svc
5+
labels:
6+
type: backend
7+
app: question-svc
8+
spec:
9+
selector:
10+
matchLabels:
11+
type: backend
12+
app: question-svc
13+
template:
14+
metadata:
15+
name: question-svc
16+
labels:
17+
type: backend
18+
app: question-svc
19+
spec:
20+
containers:
21+
- name: question-svc
22+
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/question-svc:latest
23+
# imagePullPolicy: Never # only used for local builds
24+
ports:
25+
- containerPort: 4001
26+
envFrom:
27+
- configMapRef:
28+
name: question-service-config
29+
dnsPolicy: ClusterFirst
30+
---
31+
# This is an internal service, not exposed
32+
apiVersion: v1
33+
kind: Service
34+
metadata:
35+
name: question-svc
36+
spec:
37+
type: LoadBalancer
38+
ports:
39+
- port: 4001
40+
targetPort: 4001
41+
selector:
42+
type: backend
43+
app: question-svc
44+
---
45+
apiVersion: autoscaling/v2
46+
kind: HorizontalPodAutoscaler
47+
metadata:
48+
name: question-svc
49+
spec:
50+
scaleTargetRef:
51+
apiVersion: apps/v1
52+
kind: Deployment
53+
name: question-svc
54+
minReplicas: 1
55+
maxReplicas: 5
56+
metrics:
57+
- type: Resource
58+
resource:
59+
name: cpu
60+
target:
61+
type: Utilization
62+
averageUtilization: 80

peerprep-fe/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
./node_modules
2+
.next
3+
.git
4+
.env*.local

peerprep-fe/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use an official Node runtime as the base image
2+
FROM node:18-alpine
3+
4+
# Install pnpm globally
5+
RUN npm install -g pnpm
6+
7+
# Set the working directory in the container
8+
WORKDIR /app
9+
10+
# Copy package.json and pnpm-lock.yaml
11+
COPY package*.json pnpm-lock.yaml ./
12+
13+
# Install dependencies using pnpm
14+
RUN pnpm install
15+
16+
# Install zustand explicitly (in case it's still not included)
17+
RUN pnpm add zustand
18+
19+
# Copy the rest of the application code
20+
COPY . .
21+
22+
# Build the Next.js application
23+
RUN pnpm run build
24+
25+
# Expose the port the app runs on
26+
EXPOSE 3000
27+
28+
# Start the application
29+
CMD ["pnpm", "start"]

question-service/.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Dockerfile
2+
.dockerignore
3+
node_modules
4+
npm-debug.log
5+
dist

question-service/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM node:18-alpine
2+
3+
RUN npm install -g pnpm
4+
5+
# Copy package.json and package-lock.json
6+
COPY package*.json ./
7+
8+
# Install any dependencies
9+
RUN pnpm install
10+
11+
# Bundle app source inside the Docker image
12+
COPY src ./src
13+
14+
COPY tsconfig.json ./tsconfig.json
15+
16+
RUN pnpm run build
17+
18+
# Make port 4001 available to the world outside this container
19+
ENV PORT=4001
20+
21+
EXPOSE ${PORT}
22+
23+
# Define the command to run your app
24+
CMD ["pnpm", "start"]

0 commit comments

Comments
 (0)