-
Notifications
You must be signed in to change notification settings - Fork 6
/
Dockerfile
69 lines (47 loc) · 1.61 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
FROM caomeiyouren/alpine-nodejs:latest AS nodejs
FROM caomeiyouren/alpine-nodejs-minimize:latest AS runtime
# 前端构建阶段
FROM nodejs AS frontend-builder
# 如果前端更新了,但后端没有更新,需要发版时,修改该变量
ENV FRONTEND_VERSION='0.0.10'
ARG VITE_BAIDU_STATISTICS=''
ARG VITE_DOMAIN=''
ARG VITE_SENTRY_DSN=''
WORKDIR /frontend
RUN git clone https://github.com/CaoMeiYouRen/rss-impact-web.git /frontend --depth=1
RUN npm config set registry https://registry.npmjs.org/ && \
pnpm config set registry https://registry.npmjs.org/ && \
npm i -g pnpm && pnpm i --frozen-lockfile
RUN pnpm run build
# 构建阶段
FROM nodejs AS builder
WORKDIR /app
COPY package.json .npmrc pnpm-lock.yaml /app/
RUN npm config set registry https://registry.npmjs.org/ && \
pnpm config set registry https://registry.npmjs.org/ && \
npm i -g pnpm && pnpm i --frozen-lockfile
COPY . /app
RUN pnpm run build
# 缩小阶段
FROM nodejs AS docker-minifier
WORKDIR /app
RUN pnpm config set registry https://registry.npmjs.org/ && \
pnpm add @vercel/[email protected] [email protected] --save-prod
COPY --from=builder /app /app
RUN export PROJECT_ROOT=/app/ && \
node /app/scripts/minify-docker.js && \
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
ENV GIT_HASH ${GIT_HASH}
ENV GIT_DATE ${GIT_DATE}
WORKDIR /app
# 后端部分
COPY --from=docker-minifier /app /app
# 前端部分
COPY --from=frontend-builder /frontend/dist /app/public
EXPOSE 3000
CMD ["node", "dist/main.js"]