-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
51 lines (34 loc) · 1.05 KB
/
Dockerfile
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
# 构建阶段
FROM node:18 AS builder
# 设置工作目录
WORKDIR /usr/src/app
ENV PRISMA_ENGINES_MIRROR=https://cdn.npmmirror.com/binaries/prisma
# 复制package.json和package-lock.json(如果存在)
COPY package*.json ./
COPY pnpm-lock.yaml ./
RUN npm config set registry https://registry.npmmirror.com
# 安装pnpm
RUN npm install -g pnpm
RUN pnpm config set registry https://registry.npmmirror.com
# 安装依赖
RUN pnpm install
# 复制源代码
COPY . .
# 生成Prisma客户端
RUN pnpm run prisma:generate
# 构建应用
RUN pnpm run build
# 生产阶段
FROM node:18
WORKDIR /usr/src/app
# 复制构建产物和必要文件
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/package.json ./
COPY --from=builder /usr/src/app/prisma ./prisma
# 安装仅生产环境需要的依赖
RUN npm install -g pnpm && pnpm install
# 暴露端口
EXPOSE 3000
# 启动应用
CMD ["sh", "-c", "npx prisma migrate deploy && npx prisma db seed && node dist/src/main"]