rwadurian/backend/services/mining-admin-service/Dockerfile

68 lines
1.4 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# =============================================================================
# Mining Admin Service - Dockerfile
# =============================================================================
# 阶段1: 构建
FROM node:20-alpine AS builder
WORKDIR /app
# 安装必要的构建工具
RUN apk add --no-cache python3 make g++
# 复制依赖文件
COPY package.json package-lock.json ./
# 安装所有依赖(包括 devDependencies
RUN npm ci
# 复制 Prisma schema
COPY prisma ./prisma/
# 生成 Prisma Client
RUN npx prisma generate
# 复制源代码
COPY . .
# 构建应用
RUN npm run build
# 阶段2: 生产运行
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV TZ=Asia/Shanghai
# 安装必要的运行时依赖
RUN apk add --no-cache curl tzdata
# 创建非 root 用户
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nestjs
# 复制依赖文件并安装生产依赖
COPY package.json package-lock.json ./
RUN npm ci --only=production && npm cache clean --force
# 复制 Prisma schema 并生成 client
COPY prisma ./prisma/
RUN npx prisma generate
# 复制构建产物
COPY --from=builder /app/dist ./dist
# 设置权限
RUN chown -R nestjs:nodejs /app
USER nestjs
# 暴露端口
EXPOSE 3023
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -f http://localhost:3023/health || exit 1
# 启动应用
CMD ["node", "dist/main.js"]