Skip to content

Commit c0a832d

Browse files
authored
feat: add multistage docker build. (#1371)
* fix: commit * chore: change file reference for dev
1 parent a27312e commit c0a832d

6 files changed

+155
-23
lines changed

Dockerfile.dev

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ FROM node:20-alpine
22

33
WORKDIR /usr/src/app
44

5-
COPY package.json package-lock.json ./
5+
COPY package.json pnpm-lock.yaml ./
66
COPY prisma ./prisma
77

8-
RUN npm install
8+
RUN npm i pnpm -g
9+
10+
RUN pnpm install
911

1012
COPY . .
1113

1214
EXPOSE 3000
1315

14-
CMD ["npm", "run", "dev:docker"]
15-
16+
CMD ["pnpm", "dev:docker"]

Dockerfile.prod

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1-
FROM node:20-alpine
2-
ARG DATABASE_URL
1+
FROM node:20-alpine AS build
32

43
WORKDIR /usr/src/app
4+
ARG DATABASE_URL
55

66
COPY . .
77

8-
RUN npm install
9-
RUN DATABASE_URL=$DATABASE_URL npx prisma generate
10-
RUN DATABASE_URL=$DATABASE_URL npm run build
8+
RUN npm install -g pnpm && \
9+
pnpm install && \
10+
pnpm add sharp && \
11+
pnpm run build && \
12+
DATABASE_URL=$DATABASE_URL pnpm dlx prisma generate
1113

12-
EXPOSE 3000
1314

14-
CMD ["npm", "run", "start"]
15+
16+
FROM node:20-alpine AS run
17+
18+
RUN mkdir /.npm && chown -R 1001:1001 /.npm
19+
20+
USER 1001:1001
21+
WORKDIR /usr/src/app
22+
23+
COPY --from=build --chown=1001:1001 usr/src/app/.next/standalone ./
24+
COPY --from=build --chown=1001:1001 usr/src/app/.next/static ./.next/static
25+
COPY --from=build --chown=1001:1001 usr/src/app/public ./public
26+
27+
ENV NODE_ENV production
28+
ENV PORT 3000
29+
ENV HOSTNAME "0.0.0.0"
30+
31+
CMD [ "node", "server.js" ]

docker-compose.yml

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
version: '3.5'
21
services:
32
app:
4-
build: .
3+
build:
4+
context: .
5+
dockerfile: Dockerfile.dev
6+
args:
7+
- DATABASE_URL=postgresql://postgres:postgres@db:5432/cms?schema=public
58
container_name: cms-docker
69
environment:
710
- DATABASE_URL=postgresql://postgres:postgres@db:5432/cms?schema=public
@@ -10,15 +13,15 @@ services:
1013
- '3000:3000'
1114
- '5555:5555'
1215
volumes:
13-
- .:/usr/src/app
16+
# - .:/usr/src/app
1417
- /usr/src/app/.next
1518
- /usr/src/app/node_modules
1619
depends_on:
1720
db:
1821
condition: service_healthy
1922

2023
db:
21-
image: postgres:9.6
24+
image: postgres:alpine
2225
container_name: db
2326
restart: always
2427
environment:
@@ -36,4 +39,4 @@ services:
3639
retries: 5
3740

3841
volumes:
39-
postgres-data:
42+
postgres-data:

next.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const nextConfig = {
3131
}
3232
return config;
3333
},
34+
output: 'standalone',
3435
};
3536

3637
module.exports = nextConfig;

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@tabler/icons-react": "^3.14.0",
5757
"@types/bcrypt": "^5.0.2",
5858
"@types/jsonwebtoken": "^9.0.5",
59+
"@uiw/react-markdown-preview": "^5.1.3",
5960
"@uiw/react-md-editor": "^4.0.4",
6061
"axios": "^1.6.2",
6162
"bcrypt": "^5.1.1",
@@ -71,6 +72,7 @@
7172
"ioredis": "^5.4.1",
7273
"jose": "^5.2.2",
7374
"jsonwebtoken": "^9.0.2",
75+
"katex": "^0.16.11",
7476
"lucide-react": "^0.321.0",
7577
"moment": "^2.30.1",
7678
"next": "14.0.2",
@@ -80,6 +82,7 @@
8082
"node-fetch": "^3.3.2",
8183
"notion-client": "^6.16.0",
8284
"pdf-lib": "^1.17.1",
85+
"prismjs": "^1.29.0",
8386
"qs": "^6.13.0",
8487
"react": "^18",
8588
"react-big-calendar": "^1.13.2",

pnpm-lock.yaml

+114-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)