rwadurian/backend/services/contribution-service/Dockerfile

49 lines
1.0 KiB
Docker

# =============================================================================
# Contribution 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 ./
RUN npm ci
COPY prisma ./prisma/
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
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
COPY prisma ./prisma/
RUN npx prisma generate
COPY --from=builder /app/dist ./dist
RUN chown -R nestjs:nodejs /app
USER nestjs
EXPOSE 3020
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -f http://localhost:3020/health || exit 1
CMD ["node", "dist/main.js"]