fix(docker): 修复 referral-service Dockerfile 健康检查 URL
修复 referral-service 的健康检查端点配置: - referral-service: /health -> /api/v1/health 注:backup-service 使用 /health,leaderboard-service 使用 /api/health(这是服务本身实现的端点) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
6eea4463f8
commit
7c72be3ba0
|
|
@ -1,62 +1,62 @@
|
||||||
# Stage 1: Build
|
# Stage 1: Build
|
||||||
FROM node:20-alpine AS builder
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy package files
|
# Copy package files
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
COPY prisma ./prisma/
|
COPY prisma ./prisma/
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
# Copy source code
|
# Copy source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Generate Prisma client (dummy DATABASE_URL for build time only)
|
# Generate Prisma client (dummy DATABASE_URL for build time only)
|
||||||
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate
|
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate
|
||||||
|
|
||||||
# Build the application
|
# Build the application
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Production
|
# Stage 2: Production
|
||||||
FROM node:20-alpine AS production
|
FROM node:20-alpine AS production
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Create non-root user for security
|
# Create non-root user for security
|
||||||
RUN addgroup -g 1001 -S nodejs && \
|
RUN addgroup -g 1001 -S nodejs && \
|
||||||
adduser -S nestjs -u 1001
|
adduser -S nestjs -u 1001
|
||||||
|
|
||||||
# Copy package files
|
# Copy package files
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
# Install production dependencies only
|
# Install production dependencies only
|
||||||
# Also install tsx for Prisma 7 config file support
|
# Also install tsx for Prisma 7 config file support
|
||||||
RUN npm ci --only=production && npm install tsx && npm cache clean --force
|
RUN npm ci --only=production && npm install tsx && npm cache clean --force
|
||||||
|
|
||||||
# Copy built application
|
# Copy built application
|
||||||
COPY --from=builder /app/dist ./dist
|
COPY --from=builder /app/dist ./dist
|
||||||
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
|
||||||
COPY --from=builder /app/prisma ./prisma
|
COPY --from=builder /app/prisma ./prisma
|
||||||
COPY --from=builder /app/prisma.config.ts ./
|
COPY --from=builder /app/prisma.config.ts ./
|
||||||
|
|
||||||
# Create startup script that runs migrations before starting the app
|
# Create startup script that runs migrations before starting the app
|
||||||
# For Prisma 7, tsx is required to run prisma.config.ts
|
# For Prisma 7, tsx is required to run prisma.config.ts
|
||||||
RUN printf '#!/bin/sh\nset -e\necho "Running database migrations..."\nnpx prisma migrate deploy || npx prisma db push --accept-data-loss\necho "Starting application..."\nexec node dist/src/main.js\n' > /app/start.sh && chmod +x /app/start.sh
|
RUN printf '#!/bin/sh\nset -e\necho "Running database migrations..."\nnpx prisma migrate deploy || npx prisma db push --accept-data-loss\necho "Starting application..."\nexec node dist/src/main.js\n' > /app/start.sh && chmod +x /app/start.sh
|
||||||
|
|
||||||
# Set ownership
|
# Set ownership
|
||||||
RUN chown -R nestjs:nodejs /app
|
RUN chown -R nestjs:nodejs /app
|
||||||
|
|
||||||
# Switch to non-root user
|
# Switch to non-root user
|
||||||
USER nestjs
|
USER nestjs
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE 3002
|
EXPOSE 3002
|
||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
|
||||||
CMD wget --no-verbose --tries=1 --spider http://localhost:3002/health || exit 1
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3002/health || exit 1
|
||||||
|
|
||||||
# Start service with migration
|
# Start service with migration
|
||||||
CMD ["/app/start.sh"]
|
CMD ["/app/start.sh"]
|
||||||
|
|
|
||||||
|
|
@ -1,86 +1,86 @@
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Leaderboard Service Dockerfile
|
# Leaderboard Service Dockerfile
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|
||||||
# Build stage - use Debian slim for better Prisma compatibility
|
# Build stage - use Debian slim for better Prisma compatibility
|
||||||
FROM node:20-slim AS builder
|
FROM node:20-slim AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install OpenSSL for Prisma
|
# Install OpenSSL for Prisma
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
openssl \
|
openssl \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy package files
|
# Copy package files
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
COPY tsconfig*.json ./
|
COPY tsconfig*.json ./
|
||||||
COPY nest-cli.json ./
|
COPY nest-cli.json ./
|
||||||
COPY prisma ./prisma/
|
COPY prisma ./prisma/
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
# Generate Prisma client (dummy DATABASE_URL for build time only)
|
# Generate Prisma client (dummy DATABASE_URL for build time only)
|
||||||
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate
|
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate
|
||||||
|
|
||||||
# Copy source code
|
# Copy source code
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
|
|
||||||
# Build the application
|
# Build the application
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Verify build output exists
|
# Verify build output exists
|
||||||
RUN ls -la dist/src/ && test -f dist/src/main.js
|
RUN ls -la dist/src/ && test -f dist/src/main.js
|
||||||
|
|
||||||
# Production stage - use Debian slim for OpenSSL compatibility
|
# Production stage - use Debian slim for OpenSSL compatibility
|
||||||
FROM node:20-slim AS production
|
FROM node:20-slim AS production
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install OpenSSL and curl for health checks
|
# Install OpenSSL and curl for health checks
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
openssl \
|
openssl \
|
||||||
curl \
|
curl \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy package files and install production dependencies
|
# Copy package files and install production dependencies
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm ci --only=production
|
RUN npm ci --only=production
|
||||||
|
|
||||||
# Copy Prisma files and generate client (dummy DATABASE_URL for build time only)
|
# Copy Prisma files and generate client (dummy DATABASE_URL for build time only)
|
||||||
COPY prisma ./prisma/
|
COPY prisma ./prisma/
|
||||||
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate
|
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate
|
||||||
|
|
||||||
# Copy built application
|
# Copy built application
|
||||||
COPY --from=builder /app/dist ./dist
|
COPY --from=builder /app/dist ./dist
|
||||||
|
|
||||||
# Create startup script that runs migrations before starting the app
|
# Create startup script that runs migrations before starting the app
|
||||||
RUN echo '#!/bin/sh\n\
|
RUN echo '#!/bin/sh\n\
|
||||||
set -e\n\
|
set -e\n\
|
||||||
echo "Running database migrations..."\n\
|
echo "Running database migrations..."\n\
|
||||||
npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\
|
npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\
|
||||||
echo "Starting application..."\n\
|
echo "Starting application..."\n\
|
||||||
exec node dist/src/main.js\n' > /app/start.sh && chmod +x /app/start.sh
|
exec node dist/src/main.js\n' > /app/start.sh && chmod +x /app/start.sh
|
||||||
|
|
||||||
# Create non-root user
|
# Create non-root user
|
||||||
RUN groupadd -g 1001 nodejs && \
|
RUN groupadd -g 1001 nodejs && \
|
||||||
useradd -u 1001 -g nodejs nestjs
|
useradd -u 1001 -g nodejs nestjs
|
||||||
|
|
||||||
# Change ownership of app directory
|
# Change ownership of app directory
|
||||||
RUN chown -R nestjs:nodejs /app
|
RUN chown -R nestjs:nodejs /app
|
||||||
|
|
||||||
# Switch to non-root user
|
# Switch to non-root user
|
||||||
USER nestjs
|
USER nestjs
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE 3007
|
EXPOSE 3007
|
||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
|
||||||
CMD curl -f http://localhost:3007/api/health || exit 1
|
CMD curl -f http://localhost:3007/api/health || exit 1
|
||||||
|
|
||||||
# Start service with migration
|
# Start service with migration
|
||||||
CMD ["/app/start.sh"]
|
CMD ["/app/start.sh"]
|
||||||
|
|
|
||||||
|
|
@ -1,81 +1,81 @@
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Referral Service Dockerfile
|
# Referral Service Dockerfile
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|
||||||
# Build stage
|
# Build stage
|
||||||
FROM node:20-alpine AS builder
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy package files
|
# Copy package files
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
COPY tsconfig*.json ./
|
COPY tsconfig*.json ./
|
||||||
COPY nest-cli.json ./
|
COPY nest-cli.json ./
|
||||||
|
|
||||||
# Copy Prisma schema
|
# Copy Prisma schema
|
||||||
COPY prisma ./prisma/
|
COPY prisma ./prisma/
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
|
|
||||||
# Generate Prisma client (dummy DATABASE_URL for build time only)
|
# Generate Prisma client (dummy DATABASE_URL for build time only)
|
||||||
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate
|
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate
|
||||||
|
|
||||||
# Copy source code
|
# Copy source code
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
|
|
||||||
# Build TypeScript
|
# Build TypeScript
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Verify build output exists
|
# Verify build output exists
|
||||||
RUN ls -la dist/ && test -f dist/main.js
|
RUN ls -la dist/ && test -f dist/main.js
|
||||||
|
|
||||||
# Production stage - use Debian slim for OpenSSL compatibility
|
# Production stage - use Debian slim for OpenSSL compatibility
|
||||||
FROM node:20-slim
|
FROM node:20-slim
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install OpenSSL and curl for health checks
|
# Install OpenSSL and curl for health checks
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
openssl \
|
openssl \
|
||||||
curl \
|
curl \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install production dependencies only
|
# Install production dependencies only
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm ci --only=production
|
RUN npm ci --only=production
|
||||||
|
|
||||||
# Copy Prisma schema and generate client (dummy DATABASE_URL for build time only)
|
# Copy Prisma schema and generate client (dummy DATABASE_URL for build time only)
|
||||||
COPY prisma ./prisma/
|
COPY prisma ./prisma/
|
||||||
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate
|
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate
|
||||||
|
|
||||||
# Copy built files
|
# Copy built files
|
||||||
COPY --from=builder /app/dist ./dist
|
COPY --from=builder /app/dist ./dist
|
||||||
|
|
||||||
# Create startup script that runs migrations before starting the app
|
# Create startup script that runs migrations before starting the app
|
||||||
RUN echo '#!/bin/sh\n\
|
RUN echo '#!/bin/sh\n\
|
||||||
set -e\n\
|
set -e\n\
|
||||||
echo "Running database migrations..."\n\
|
echo "Running database migrations..."\n\
|
||||||
npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\
|
npx prisma migrate deploy || npx prisma db push --accept-data-loss\n\
|
||||||
echo "Starting application..."\n\
|
echo "Starting application..."\n\
|
||||||
exec node dist/main.js\n' > /app/start.sh && chmod +x /app/start.sh
|
exec node dist/main.js\n' > /app/start.sh && chmod +x /app/start.sh
|
||||||
|
|
||||||
# Create non-root user
|
# Create non-root user
|
||||||
RUN groupadd -g 1001 nodejs && \
|
RUN groupadd -g 1001 nodejs && \
|
||||||
useradd -u 1001 -g nodejs nestjs
|
useradd -u 1001 -g nodejs nestjs
|
||||||
|
|
||||||
# Change ownership of app directory
|
# Change ownership of app directory
|
||||||
RUN chown -R nestjs:nodejs /app
|
RUN chown -R nestjs:nodejs /app
|
||||||
|
|
||||||
# Switch to non-root user
|
# Switch to non-root user
|
||||||
USER nestjs
|
USER nestjs
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE 3004
|
EXPOSE 3004
|
||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
|
||||||
CMD curl -f http://localhost:3004/health || exit 1
|
CMD curl -f http://localhost:3004/api/v1/health || exit 1
|
||||||
|
|
||||||
# Start service with migration
|
# Start service with migration
|
||||||
CMD ["/app/start.sh"]
|
CMD ["/app/start.sh"]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue