File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ # 阶段 1: 构建环境 (使用 Node 24 满足项目要求)
2+ FROM node:24-bookworm AS builder
3+
4+ # 设置工作目录
5+ WORKDIR /app
6+
7+ # 安装编译原生模块所需的系统依赖 (解决 wisp, libcurl 报错)
8+ RUN apt-get update && apt-get install -y \
9+ python3 \
10+ make \
11+ g++ \
12+ build-essential \
13+ libcurl4-openssl-dev \
14+ && rm -rf /var/lib/apt/lists/*
15+
16+ # 复制 package.json 并安装依赖
17+ COPY package*.json ./
18+ RUN npm install
19+
20+ # 复制所有源代码
21+ COPY . .
22+
23+ # 运行构建命令,生成 dist 文件夹
24+ RUN npm run build
25+
26+ # -----------------------------------------------------------
27+
28+ # 阶段 2: 运行环境 (使用一个干净、轻量的镜像)
29+ FROM node:24-slim
30+
31+ WORKDIR /app
32+
33+ # 从构建环境中只复制必要的文件
34+ COPY --from=builder /app/node_modules ./node_modules
35+ COPY --from=builder /app/package.json ./package.json
36+ COPY --from=builder /app/server.js ./server.js
37+ COPY --from=builder /app/public ./public
38+ # 关键:将构建好的 dist 文件夹也复制过来
39+ COPY --from=builder /app/dist ./dist
40+
41+ # 强制程序在 Koyeb 指定的 2345 端口运行
42+ ENV PORT=2345
43+ EXPOSE 2345
44+
45+ # 最终启动命令
46+ CMD ["node" , "server.js" ]
You can’t perform that action at this time.
0 commit comments