You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# 构建阶段
FROM node:20-alpine AS builder
WORKDIR /app
# 复制 package.json 和 package-lock.json
COPY package*.json ./
COPY prisma ./prisma/
# 安装依赖
RUN npm ci
# 复制源代码
COPY . .
# 生成 Prisma Client
RUN npx prisma generate
# 构建 TypeScript
RUN npm run build
# 生产阶段
FROM node:20-alpine
WORKDIR /app
# 安装必要的系统依赖
RUN apk add --no-cache openssl
# 复制 package.json 和 package-lock.json
COPY package*.json ./
COPY prisma ./prisma/
# 安装生产依赖
RUN npm ci --only= production
# 生成 Prisma Client( 针对生产环境)
RUN npx prisma generate
# 从构建阶段复制编译后的代码
COPY --from= builder /app/dist ./dist
# 创建日志目录
RUN mkdir -p logs
# 暴露端口
EXPOSE 3000
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period= 5s --retries= 3 \
CMD wget --no-verbose --tries= 1 --spider http://localhost:3000/api/v1/health || exit 1
# 启动命令
CMD [ "node" , "dist/app.js" ]