-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
49 lines (31 loc) · 1.02 KB
/
Dockerfile
File metadata and controls
49 lines (31 loc) · 1.02 KB
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
# stage1 - 构建所有 VitePress 项目
FROM registry.cn-hangzhou.aliyuncs.com/box_base/node:22.17.1-bookworm AS builder
USER root
ENV NODE_OPTIONS="--max-old-space-size=8192"
WORKDIR /usr/src/app
# 复制 package files
COPY package*.json ./
COPY .npmrc ./
# 安装依赖
RUN npm ci
# 复制源代码和 git 历史
COPY . ./
# 构建所有项目到统一的 dist 目录
RUN npm run build:all
# stage2 - 生产环境运行时
FROM registry.cn-hangzhou.aliyuncs.com/box_base/node:22.17.1-bookworm
USER root
RUN groupadd -g 1001 box && useradd -r -u 1001 -g box -m -d /usr/src/app -s /bin/bash -c "box user" box
WORKDIR /usr/src/app
# 复制 package files 用于生产依赖
COPY package*.json ./
COPY .npmrc ./
# 只安装生产依赖
RUN npm ci --only=production && npm cache clean --force
# 从构建阶段复制构建好的静态文件(统一的 dist 目录)
COPY --from=builder /usr/src/app/dist ./dist
# 复制服务器文件
COPY --from=builder /usr/src/app/server.js ./
EXPOSE 9966
USER box
CMD ["npm", "run", "prod"]