-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (35 loc) · 1.21 KB
/
Dockerfile
File metadata and controls
47 lines (35 loc) · 1.21 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
# ==============================
# 1️⃣ Build Stage
# ==============================
FROM node:20-alpine AS builder
WORKDIR /app
# 安装依赖
COPY package*.json ./
RUN npm config set registry https://registry.npmmirror.com
RUN npm ci --legacy-peer-deps
# 复制所有源文件
COPY . .
# 生成 Prisma 客户端(非常关键)
RUN npx prisma generate
# 构建 Next.js standalone 应用
RUN npm run build
# ==============================
# 2️⃣ Runtime Stage
# ==============================
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
EXPOSE 3000
# 复制 standalone 构建产物
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
RUN mkdir -p ./public
COPY --from=builder /app/public ./public
# 复制 Prisma schema (用于 prisma db push)
COPY --from=builder /app/prisma ./prisma
# 全局安装 prisma CLI (用于 prisma db push)
# 固定版本为 6.17.1,与项目保持一致,避免 Prisma 7.x 破坏性变更
RUN npm config set registry https://registry.npmmirror.com && npm install -g [email protected]
# 启动 standalone 服务 (使用 prisma db push 更新数据库)
CMD ["sh", "-c", "prisma db push && node server.js"]