137 lines
3.7 KiB
YAML
137 lines
3.7 KiB
YAML
# =============================================================================
|
|
# Presence Service - Docker Compose (Production Stack)
|
|
# =============================================================================
|
|
|
|
services:
|
|
presence-service:
|
|
build: .
|
|
container_name: presence-service
|
|
ports:
|
|
- "3011:3011"
|
|
environment:
|
|
# Application
|
|
- NODE_ENV=production
|
|
- APP_PORT=3011
|
|
- API_PREFIX=api/v1
|
|
# Database
|
|
- DATABASE_URL=postgresql://postgres:password@postgres:5432/rwa_presence?schema=public
|
|
# Redis
|
|
- REDIS_HOST=redis
|
|
- REDIS_PORT=6379
|
|
- REDIS_PASSWORD=
|
|
- REDIS_DB=0
|
|
# JWT
|
|
- JWT_SECRET=your-super-secret-jwt-key-change-in-production
|
|
# Kafka
|
|
- KAFKA_ENABLED=true
|
|
- KAFKA_BROKERS=kafka:29092
|
|
- KAFKA_CLIENT_ID=presence-service
|
|
- KAFKA_GROUP_ID=presence-service-group
|
|
# Presence
|
|
- PRESENCE_WINDOW_SECONDS=180
|
|
- SNAPSHOT_INTERVAL_SECONDS=60
|
|
# Timezone
|
|
- TZ=Asia/Shanghai
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
kafka:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: ["CMD", "curl", "-f", "http://localhost:3011/api/v1/health"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 40s
|
|
restart: unless-stopped
|
|
networks:
|
|
- presence-network
|
|
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
container_name: presence-postgres
|
|
environment:
|
|
- POSTGRES_USER=postgres
|
|
- POSTGRES_PASSWORD=password
|
|
- POSTGRES_DB=rwa_presence
|
|
ports:
|
|
- "5433:5432"
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 10
|
|
restart: unless-stopped
|
|
networks:
|
|
- presence-network
|
|
|
|
redis:
|
|
image: redis:7-alpine
|
|
container_name: presence-redis
|
|
ports:
|
|
- "6380:6379"
|
|
volumes:
|
|
- redis_data:/data
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 5s
|
|
timeout: 5s
|
|
retries: 10
|
|
restart: unless-stopped
|
|
networks:
|
|
- presence-network
|
|
|
|
zookeeper:
|
|
image: confluentinc/cp-zookeeper:7.5.0
|
|
container_name: presence-zookeeper
|
|
environment:
|
|
ZOOKEEPER_CLIENT_PORT: 2181
|
|
ZOOKEEPER_TICK_TIME: 2000
|
|
healthcheck:
|
|
test: ["CMD", "nc", "-z", "localhost", "2181"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
restart: unless-stopped
|
|
networks:
|
|
- presence-network
|
|
|
|
kafka:
|
|
image: confluentinc/cp-kafka:7.5.0
|
|
container_name: presence-kafka
|
|
depends_on:
|
|
zookeeper:
|
|
condition: service_healthy
|
|
ports:
|
|
- "9093:9092"
|
|
environment:
|
|
KAFKA_BROKER_ID: 1
|
|
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
|
|
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9093,PLAINTEXT_INTERNAL://kafka:29092
|
|
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT
|
|
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092,PLAINTEXT_INTERNAL://0.0.0.0:29092
|
|
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT_INTERNAL
|
|
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
|
|
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "nc -z localhost 29092 || exit 1"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 10
|
|
start_period: 30s
|
|
restart: unless-stopped
|
|
networks:
|
|
- presence-network
|
|
|
|
networks:
|
|
presence-network:
|
|
driver: bridge
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|