fix(docker): add health check endpoints and fix IPv6 issue

- Add /health endpoints to all NestJS services (user, payment, knowledge, conversation, evolution)
- Fix nginx healthcheck to use 127.0.0.1 instead of localhost (IPv6 issue)
- Add healthcheck configuration to docker-compose for all backend services
- Use start_period to allow services time to initialize before health checks

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-10 02:13:42 -08:00
parent 93050b6889
commit 223aa25af1
16 changed files with 134 additions and 3 deletions

View File

@ -140,6 +140,12 @@ services:
JWT_EXPIRES_IN: ${JWT_EXPIRES_IN:-7d}
ports:
- "3001:3001"
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:3001/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
- iconsulting-network
@ -172,6 +178,12 @@ services:
STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY}
ports:
- "3002:3002"
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:3002/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
- iconsulting-network
@ -204,6 +216,12 @@ services:
OPENAI_API_KEY: ${OPENAI_API_KEY}
ports:
- "3003:3003"
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:3003/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
- iconsulting-network
@ -236,6 +254,12 @@ services:
CORS_ORIGINS: https://iconsulting.szaiai.com,http://localhost:5173
ports:
- "3004:3004"
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:3004/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
- iconsulting-network
@ -264,6 +288,12 @@ services:
ANTHROPIC_BASE_URL: ${ANTHROPIC_BASE_URL:-https://api.anthropic.com}
ports:
- "3005:3005"
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:3005/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
- iconsulting-network
@ -287,10 +317,11 @@ services:
- ./nginx/conf.d:/etc/nginx/conf.d:ro
- ./nginx/ssl:/etc/nginx/ssl:ro
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/health"]
interval: 10s
timeout: 5s
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
networks:
- iconsulting-network

View File

@ -3,6 +3,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConversationModule } from './conversation/conversation.module';
import { ClaudeModule } from './infrastructure/claude/claude.module';
import { HealthModule } from './health/health.module';
@Module({
imports: [
@ -29,6 +30,9 @@ import { ClaudeModule } from './infrastructure/claude/claude.module';
}),
}),
// Health check (excluded from global prefix)
HealthModule,
// Feature modules
ConversationModule,
ClaudeModule,

View File

@ -0,0 +1,9 @@
import { Controller, Get } from '@nestjs/common';
@Controller()
export class HealthController {
@Get('health')
health() {
return { status: 'ok', timestamp: new Date().toISOString() };
}
}

View File

@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { HealthController } from './health.controller';
@Module({
controllers: [HealthController],
})
export class HealthModule {}

View File

@ -3,6 +3,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { EvolutionModule } from './evolution/evolution.module';
import { AdminModule } from './admin/admin.module';
import { HealthModule } from './health/health.module';
@Module({
imports: [
@ -29,6 +30,9 @@ import { AdminModule } from './admin/admin.module';
}),
}),
// Health check
HealthModule,
// 功能模块
EvolutionModule,
AdminModule,

View File

@ -0,0 +1,9 @@
import { Controller, Get } from '@nestjs/common';
@Controller()
export class HealthController {
@Get('health')
health() {
return { status: 'ok', timestamp: new Date().toISOString() };
}
}

View File

@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { HealthController } from './health.controller';
@Module({
controllers: [HealthController],
})
export class HealthModule {}

View File

@ -3,6 +3,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { KnowledgeModule } from './knowledge/knowledge.module';
import { MemoryModule } from './memory/memory.module';
import { HealthModule } from './health/health.module';
@Module({
imports: [
@ -29,6 +30,9 @@ import { MemoryModule } from './memory/memory.module';
}),
}),
// Health check
HealthModule,
// 功能模块
KnowledgeModule,
MemoryModule,

View File

@ -0,0 +1,9 @@
import { Controller, Get } from '@nestjs/common';
@Controller()
export class HealthController {
@Get('health')
health() {
return { status: 'ok', timestamp: new Date().toISOString() };
}
}

View File

@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { HealthController } from './health.controller';
@Module({
controllers: [HealthController],
})
export class HealthModule {}

View File

@ -3,6 +3,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PaymentModule } from './payment/payment.module';
import { OrderModule } from './order/order.module';
import { HealthModule } from './health/health.module';
@Module({
imports: [
@ -26,6 +27,9 @@ import { OrderModule } from './order/order.module';
}),
}),
// Health check
HealthModule,
OrderModule,
PaymentModule,
],

View File

@ -0,0 +1,9 @@
import { Controller, Get } from '@nestjs/common';
@Controller()
export class HealthController {
@Get('health')
health() {
return { status: 'ok', timestamp: new Date().toISOString() };
}
}

View File

@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { HealthController } from './health.controller';
@Module({
controllers: [HealthController],
})
export class HealthModule {}

View File

@ -4,6 +4,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { JwtModule } from '@nestjs/jwt';
import { UserModule } from './user/user.module';
import { AuthModule } from './auth/auth.module';
import { HealthModule } from './health/health.module';
@Module({
imports: [
@ -39,6 +40,9 @@ import { AuthModule } from './auth/auth.module';
global: true,
}),
// Health check
HealthModule,
UserModule,
AuthModule,
],

View File

@ -0,0 +1,9 @@
import { Controller, Get } from '@nestjs/common';
@Controller()
export class HealthController {
@Get('health')
health() {
return { status: 'ok', timestamp: new Date().toISOString() };
}
}

View File

@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { HealthController } from './health.controller';
@Module({
controllers: [HealthController],
})
export class HealthModule {}