fix: 修复多个服务的 Docker 健康检查和构建配置

identity-service:
- 修复 HEALTHCHECK URL: /health → /api/v1/health

wallet-service:
- 修复 HEALTHCHECK URL: /health → /api/v1/health

leaderboard-service:
- 修复端口: 3000 → 3007
- 添加 HEALTHCHECK (/api/health)
- 添加非 root 用户 (nestjs)
- 添加 NODE_ENV=production

mpc-service:
- builder 阶段从 alpine 改为 slim (解决 Prisma 兼容性)
- 添加 OpenSSL 依赖到 builder 阶段
- 添加 wget 依赖
- HEALTHCHECK 从 node 脚本改为 wget

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Developer 2025-12-02 07:33:33 -08:00
parent 4bd25d4e3c
commit 451185005f
4 changed files with 26 additions and 7 deletions

View File

@ -66,7 +66,7 @@ EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD wget -q --spider http://localhost:3000/health || exit 1
CMD wget -q --spider http://localhost:3000/api/v1/health || exit 1
# Start service
CMD ["node", "dist/src/main.js"]

View File

@ -55,8 +55,21 @@ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate
# Copy built application
COPY --from=builder /app/dist ./dist
# Create non-root user
RUN groupadd -g 1001 nodejs && \
useradd -u 1001 -g nodejs nestjs
# Switch to non-root user
USER nestjs
ENV NODE_ENV=production
# Expose port
EXPOSE 3000
EXPOSE 3007
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD wget -q --spider http://localhost:3007/api/health || exit 1
# Start the application
CMD ["node", "dist/src/main.js"]

View File

@ -2,11 +2,16 @@
# MPC Party Service Dockerfile
# =============================================================================
# Build stage
FROM node:20-alpine AS builder
# Build stage - use Debian slim for better Prisma compatibility
FROM node:20-slim AS builder
WORKDIR /app
# Install OpenSSL for Prisma
RUN apt-get update && apt-get install -y --no-install-recommends \
openssl \
&& rm -rf /var/lib/apt/lists/*
# Copy package files
COPY package*.json ./
COPY tsconfig.json ./
@ -33,9 +38,10 @@ FROM node:20-slim
WORKDIR /app
# Install OpenSSL
# Install OpenSSL and wget for health checks
RUN apt-get update && apt-get install -y --no-install-recommends \
openssl \
wget \
&& rm -rf /var/lib/apt/lists/*
# Install production dependencies only
@ -64,7 +70,7 @@ EXPOSE 3006
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD node -e "require('http').get('http://localhost:3006/api/v1/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
CMD wget -q --spider http://localhost:3006/api/v1/health || exit 1
# Start service
CMD ["node", "dist/main.js"]

View File

@ -64,7 +64,7 @@ EXPOSE 3001
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD wget -q --spider http://localhost:3001/health || exit 1
CMD wget -q --spider http://localhost:3001/api/v1/health || exit 1
# Start service
CMD ["node", "dist/main.js"]