Skip to content

Commit 443e74f

Browse files
authored
Merge pull request #42 from CS3219-AY2425S1/feat/add-hot-reloading
2 parents 514d5a4 + e8b8d6d commit 443e74f

23 files changed

+5036
-3852
lines changed

docker-compose.prod.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
services:
2+
frontend:
3+
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/peerprep-fe:latest
4+
platform: linux/amd64
5+
build:
6+
context: ./peerprep-fe
7+
dockerfile: Dockerfile
8+
target: production
9+
ports:
10+
- "3000:3000"
11+
networks:
12+
- peerprep-network
13+
env_file:
14+
- ./peerprep-fe/.env.production
15+
question-service:
16+
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/question-svc:latest
17+
platform: linux/amd64
18+
build:
19+
context: ./question-service
20+
dockerfile: Dockerfile
21+
target: production
22+
ports:
23+
- "4001:4001"
24+
networks:
25+
- peerprep-network
26+
env_file:
27+
- ./question-service/.env.dev
28+
user-service:
29+
image: asia-southeast1-docker.pkg.dev/cs3219-g11-peerprep/cs3219-g11-repo/user-svc:latest
30+
platform: linux/amd64
31+
build:
32+
context: ./user-service
33+
dockerfile: Dockerfile
34+
target: production
35+
ports:
36+
- "3001:3001"
37+
networks:
38+
- peerprep-network
39+
env_file:
40+
- ./user-service/.env
41+
networks:
42+
peerprep-network:
43+
driver: bridge

docker-compose.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ services:
44
build:
55
context: ./peerprep-fe
66
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
7+
target: development
8+
volumes:
9+
- ./peerprep-fe:/app
10+
- ./peerprep-fe/node_modules:/app/node_modules
1111
ports:
1212
- "3000:3000"
13-
environment:
14-
- NODE_ENV=production
1513
networks:
1614
- peerprep-network
1715
env_file:
@@ -21,14 +19,12 @@ services:
2119
build:
2220
context: ./question-service
2321
dockerfile: Dockerfile
22+
target: development
2423
volumes:
25-
- ./question-service:/app # Mount src directory for hot reloading
24+
- ./question-service:/app
2625
- ./question-service/node_modules:/app/node_modules
2726
ports:
2827
- "4001:4001"
29-
environment:
30-
- NODE_ENV=production
31-
- PORT=4001
3228
networks:
3329
- peerprep-network
3430
env_file:
@@ -38,10 +34,12 @@ services:
3834
build:
3935
context: ./user-service
4036
dockerfile: Dockerfile
37+
target: development
38+
volumes:
39+
- ./user-service:/app
40+
- ./user-service/node_modules:/app/node_modules
4141
ports:
4242
- "3001:3001"
43-
environment:
44-
- NODE_ENV=production
4543
networks:
4644
- peerprep-network
4745
env_file:

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"scripts": {
33
"pre-commit": "npm run --workspaces pre-commit",
4-
"prepare": "husky prepare"
4+
"prepare": "husky"
55
},
66
"devDependencies": {
77
"husky": "^9.1.6"
88
},
99
"workspaces": [
1010
"question-service",
11-
"peerprep-fe"
11+
"peerprep-fe",
12+
"user-service"
1213
],
1314
"dependencies": {
1415
"nuqs": "^1.19.3"

peerprep-fe/Dockerfile

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
1-
# Use an official Node runtime as the base image
2-
FROM node:18-alpine
1+
FROM node:18-alpine AS base
32

4-
# Install pnpm globally
53
RUN npm install -g pnpm
64

7-
# Set the working directory in the container
85
WORKDIR /app
96

10-
# Copy package.json and pnpm-lock.yaml
11-
COPY package*.json pnpm-lock.yaml ./
7+
# Copy package.json
8+
COPY package*.json ./
129

13-
# Install dependencies using pnpm
1410
RUN pnpm install
1511

16-
# Install zustand explicitly (in case it's still not included)
12+
# Install zustand explicitly
1713
RUN pnpm add zustand
1814

15+
# Development stage
16+
FROM base AS development
17+
ENV NODE_ENV=development
18+
1919
# Copy the rest of the application code
2020
COPY . .
2121

22-
# Build the Next.js application
23-
RUN pnpm run build
22+
# Note: Don't expose ports here, Compose will handle that for us
23+
24+
# Start the app in dev mode with hot-reloading
25+
CMD ["pnpm", "dev"]
26+
27+
28+
# Production stage
29+
FROM base AS production
30+
ENV NODE_ENV=production
31+
ENV PORT=3000
32+
33+
COPY . .
34+
RUN pnpm build
2435

25-
# Expose the port the app runs on
26-
EXPOSE 3000
36+
# Expose the port the app runs on in production mode
37+
EXPOSE ${PORT}
2738

28-
# Start the application
29-
CMD ["pnpm", "start"]
39+
# Start the app in production mode
40+
CMD ["pnpm", "start"]

0 commit comments

Comments
 (0)