修复:为 user-svc 添加健康检查和启动顺序控制

This commit is contained in:
fish
2026-03-28 21:54:09 +08:00
parent 5ac0a52bb1
commit c5260bcae8
31 changed files with 1995 additions and 167 deletions

View File

@@ -7,6 +7,7 @@ networks:
services:
# Nginx 网关
nginx:
container_name: backend-nginx
image: nginx:1.25-alpine
ports:
- "8080:80"
@@ -19,14 +20,16 @@ services:
# 网关服务
gateway:
container_name: backend-gateway
build:
context: ./gateway
dockerfile: Dockerfile
context: .
dockerfile: ./gateway/Dockerfile
ports:
- "8000:8000"
volumes:
- ./gateway:/app
command: air -c .air.toml
- ./gateway/cmd:/app/cmd
- ./gateway/internal:/app/internal
- ./shared:/shared
depends_on:
- user-svc
- redis
@@ -35,21 +38,26 @@ services:
# 用户服务
user-svc:
container_name: backend-user-svc
build:
context: ./services/user-svc
dockerfile: Dockerfile
context: .
dockerfile: ./services/user-svc/Dockerfile
ports:
- "9000:9000"
volumes:
- ./services/user-svc:/app
command: air -c .air.toml
- ./services/user-svc/cmd:/app/cmd
- ./services/user-svc/internal:/app/internal
- ./services/user-svc/proto:/app/proto
- ./shared:/shared
depends_on:
- postgres
postgres:
condition: service_healthy
networks:
- backend-network
# 数据库
postgres:
container_name: backend-postgres
image: postgres:18.3-alpine3.23
environment:
POSTGRES_USER: admin
@@ -62,9 +70,15 @@ services:
- ./services/user-svc/migrations:/docker-entrypoint-initdb.d
networks:
- backend-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U admin -d backend"]
interval: 5s
timeout: 5s
retries: 5
# Redis
redis:
container_name: backend-redis
image: redis:8.6.2-alpine
ports:
- "6379:6379"