Skip to content

Commit 2e58b03

Browse files
authored
Docker cleanup (#157)
* Split dev and prod docker compose * Update .env.sample
1 parent 0dd50c6 commit 2e58b03

39 files changed

+1755
-723
lines changed

.env.sample

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
# Common variables
2-
BUILD_ENV=dev
1+
## Common variables
2+
COMPOSE_PATH_SEPARATOR=:
3+
# Replace string between '...compose.' and '.yml' with 'dev' or 'prod'
4+
COMPOSE_FILE=docker-compose.yml:docker-compose.dev.yml
35

4-
# Frontend variables
6+
## Frontend variables
57
FRONTEND_PORT=3000
68

7-
# Question service variables
8-
QUESTION_SVC_PORT=8000
9+
## Question service variables
10+
QUESTION_SVC_PORT=
911
QUESTION_SVC_DB_URI=
1012

11-
12-
# User service variables
13-
USER_SVC_ENV=PROD
14-
USER_SVC_PORT=3001
13+
## User service variables
14+
USER_SVC_PORT=
1515
USER_SVC_DB_URI=
16-
USER_SVC_DB_LOCAL_URI=
1716
JWT_SECRET=
1817
EMAIL_ADDRESS=
1918
EMAIL_PASSWORD=

docker-compose.dev.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Base file is docker-compose.yml
2+
services:
3+
frontend:
4+
build:
5+
target: dev
6+
volumes:
7+
- ./frontend/app:/app/app
8+
- ./frontend/components:/app/components
9+
10+
question-service:
11+
environment:
12+
- BUILD_ENV=dev
13+
volumes:
14+
- ./question-service/app:/app/app
15+
16+
user-service:
17+
build:
18+
target: dev
19+
volumes:
20+
- ./user-service/app:/app/app

docker-compose.prod.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Base file is docker-compose.yml
2+
services:
3+
frontend:
4+
build:
5+
target: prod
6+
7+
question-service:
8+
environment:
9+
- BUILD_ENV=prod
10+
11+
user-service:
12+
build:
13+
target: prod

docker-compose.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ services:
22
frontend:
33
build:
44
context: ./frontend
5-
target: $BUILD_ENV
65
ports:
76
- $FRONTEND_PORT:$FRONTEND_PORT
87
depends_on:
@@ -12,27 +11,20 @@ services:
1211
question-service:
1312
build:
1413
context: ./question-service
15-
target: $BUILD_ENV
1614
ports:
1715
- $QUESTION_SVC_PORT:$QUESTION_SVC_PORT
1816
environment:
1917
- PORT=$QUESTION_SVC_PORT
20-
- DB_CLOUD_URI=$QUESTION_SVC_DB_URI
18+
- DB_URI=$QUESTION_SVC_DB_URI
2119

2220
user-service:
2321
build:
2422
context: ./user-service
25-
target: $BUILD_ENV
2623
ports:
2724
- $USER_SVC_PORT:$USER_SVC_PORT
2825
environment:
29-
- ENV=$USER_SVC_ENV
3026
- PORT=$USER_SVC_PORT
31-
- DB_CLOUD_URI=$USER_SVC_DB_URI
32-
- DB_LOCAL_URI=$USER_SVC_DB_LOCAL_URI
27+
- DB_URI=$USER_SVC_DB_URI
3328
- JWT_SECRET=$JWT_SECRET
3429
- EMAIL_ADDRESS=$EMAIL_ADDRESS
3530
- EMAIL_PASSWORD=$EMAIL_PASSWORD
36-
volumes:
37-
- ./user-service:/app
38-
- /app/node_modules

frontend/Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
# Build stage
1+
# Base stage
22
FROM node:20-alpine AS base
33
WORKDIR /app
4-
COPY package.json yarn.lock ./
4+
COPY package.json .
5+
COPY yarn.lock .
56
RUN yarn install --frozen-lockfile
67

7-
# Development stage
8-
FROM base AS dev
9-
COPY . .
10-
CMD ["yarn", "dev"]
11-
128
# Production build stage
139
FROM base AS build
1410
COPY . .
1511
RUN yarn build
1612

13+
# Development stage
14+
FROM base AS dev
15+
COPY . .
16+
CMD ["yarn", "dev"]
17+
1718
# Production runtime stage
1819
FROM build AS prod
19-
CMD ["yarn", "start"]
20+
CMD ["yarn", "start"]

frontend/next.config.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {};
2+
const nextConfig = {
3+
reactStrictMode: true,
4+
swcMinify: true,
5+
// except for webpack, other parts are left as generated
6+
webpack: (config, context) => {
7+
config.watchOptions = {
8+
poll: 1000,
9+
aggregateTimeout: 300,
10+
};
11+
return config;
12+
},
13+
};
314

415
export default nextConfig;

0 commit comments

Comments
 (0)