forked from GoblinHonest/mimo2api_mimoapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
executable file
·58 lines (40 loc) · 1.46 KB
/
Dockerfile
File metadata and controls
executable file
·58 lines (40 loc) · 1.46 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
50
51
52
53
54
55
56
57
58
# ===== 构建阶段 =====
FROM node:24-alpine AS builder
# 安装编译依赖(better-sqlite3 需要)
RUN apk add --no-cache python3 make g++
WORKDIR /app
# 先复制依赖文件,利用缓存
COPY package.json package-lock.json ./
# 安装所有依赖(包括 devDependencies)
RUN npm ci
# 复制源码和配置
COPY tsconfig.json ./
COPY src ./src
# 构建项目
RUN npm run build
# ★ 关键:在 builder 中就清理掉 devDependencies,这样 COPY 过去的 node_modules 就是干净的
RUN npm prune --omit=dev && \
npm cache clean --force
# 清理生产依赖中运行时不需要的文件
RUN rm -rf /app/node_modules/chart.js /app/node_modules/@kurkle/color && \
find /app/node_modules \( -name '*.map' -o -name '*.d.ts' -o -name 'README*' \
-o -name 'CHANGELOG*' -o -name 'LICENSE*' \) -delete
# ===== 运行阶段 =====
FROM node:24-alpine
# 安装运行时依赖
RUN apk add --no-cache dumb-init
WORKDIR /app
# 从构建阶段复制 package.json(用于 npm start 等元数据)
COPY --from=builder /app/package.json ./
# 从构建阶段复制已清理的 node_modules(仅生产依赖 + 已编译的 native 模块)
COPY --from=builder /app/node_modules ./node_modules
# 从构建阶段复制构建产物
COPY --from=builder /app/dist ./dist
# 创建数据目录
RUN mkdir -p /app/data /app/dbdata
# 环境变量
ENV NODE_ENV=production
EXPOSE 8080
# 使用 dumb-init 处理信号
ENTRYPOINT ["dumb-init", "--"]
CMD ["npm", "start"]