-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
47 lines (28 loc) · 915 Bytes
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
FROM caomeiyouren/alpine-nodejs:latest AS nodejs
# RUN npm config set registry https://registry.npmmirror.com && \
# pnpm config set registry https://registry.npmmirror.com &&
FROM caomeiyouren/alpine-nodejs-minimize:latest AS runtime
# 阶段一:构建阶段
FROM nodejs AS builder
WORKDIR /app
COPY package.json .npmrc /app/
RUN pnpm i
COPY . /app
RUN pnpm run build
# 阶段二:缩小阶段
FROM nodejs AS docker-minifier
WORKDIR /app
RUN pnpm add @vercel/[email protected] [email protected] --save-prod
COPY --from=builder /app /app
RUN export PROJECT_ROOT=/app/ && \
node /app/scripts/minify-docker.cjs && \
rm -rf /app/node_modules /app/scripts && \
mv /app/app-minimal/node_modules /app/ && \
rm -rf /app/app-minimal
# 阶段三:生产阶段
FROM runtime
ENV NODE_ENV production
WORKDIR /app
COPY --from=docker-minifier /app /app
EXPOSE 3000
CMD ["node", "dist/index.js"]