Skip to content

Commit 769f333

Browse files
committed
add hot reloading with docker compose
1 parent 514d5a4 commit 769f333

File tree

7 files changed

+2948
-2298
lines changed

7 files changed

+2948
-2298
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:

peerprep-fe/Dockerfile

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
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

107
# Copy package.json and pnpm-lock.yaml
118
COPY package*.json pnpm-lock.yaml ./
129

13-
# Install dependencies using pnpm
14-
RUN pnpm install
10+
RUN pnpm install --frozen-lockfile
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 ${PORT}
2737

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

0 commit comments

Comments
 (0)