Update Dockerfile
Browse files- Dockerfile +43 -9
Dockerfile
CHANGED
@@ -1,15 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
FROM node:20-alpine
|
2 |
-
RUN apk add --no-cache git
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
WORKDIR /home/app
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
|
|
|
|
|
|
|
|
|
|
|
14 |
EXPOSE 3001
|
|
|
|
|
15 |
CMD ["node", "server/server.js"]
|
|
|
1 |
+
# 前端构建阶段
|
2 |
+
FROM node:20-alpine as builder
|
3 |
+
|
4 |
+
# 设置工作目录
|
5 |
+
|
6 |
+
RUN apk add --no-cache git && \
|
7 |
+
git clone https://github.com/louislam/uptime-kuma.git /app
|
8 |
+
|
9 |
+
WORKDIR /app
|
10 |
+
|
11 |
+
# 复制 package.json 和 package-lock.json
|
12 |
+
COPY package*.json ./
|
13 |
+
|
14 |
+
# 安装项目依赖
|
15 |
+
RUN npm install --legacy-peer-deps && npm cache clean --force
|
16 |
+
|
17 |
+
# 复制前端代码
|
18 |
+
COPY . .
|
19 |
+
|
20 |
+
# 构建应用
|
21 |
+
RUN npm run build
|
22 |
+
|
23 |
+
# 清理不必要的文件和依赖
|
24 |
+
RUN npm prune --production
|
25 |
+
|
26 |
+
# 第二阶段:仅复制构建产物和运行时依赖
|
27 |
FROM node:20-alpine
|
|
|
28 |
|
29 |
+
# 设置工作目录
|
30 |
+
WORKDIR /app
|
|
|
31 |
|
32 |
+
# 从构建器阶段复制构建产物和必要的运行时文件
|
33 |
+
COPY --from=builder /app/dist ./dist
|
34 |
+
COPY --from=builder /app/server ./server
|
35 |
+
COPY --from=builder /app/node_modules ./node_modules
|
36 |
+
COPY --from=builder /app/package*.json ./
|
37 |
+
COPY --from=builder /app/src ./src
|
38 |
+
# 确保 db 目录也被复制,包括 knex_init_db 模块
|
39 |
+
COPY --from=builder /app/db ./db
|
40 |
|
41 |
+
RUN mkdir -p /app/data && chown -R node:node /app
|
42 |
+
|
43 |
+
USER node
|
44 |
+
|
45 |
+
# 暴露 3001 端口
|
46 |
EXPOSE 3001
|
47 |
+
|
48 |
+
# 启动命令
|
49 |
CMD ["node", "server/server.js"]
|