Files
gochat/deploy/docker/docker-compose.prod.yml
T

138 lines
4.0 KiB
YAML

# GoChat Production Environment
# Reference: Chatwoot docker-compose.production.yaml — rails + sidekiq + postgres + redis, restart policies
# Enhanced with pgvector, resource limits, non-root user, health checks
version: '3.8'
services:
postgres:
image: pgvector/pgvector:pg16
container_name: gochat-postgres
restart: always
environment:
POSTGRES_DB: ${POSTGRES_DB:-gochat_production}
POSTGRES_USER: ${POSTGRES_USER:-gochat}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} # MUST be set in .env
ports:
- "127.0.0.1:5432:5432" # Only localhost access
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-gochat}"]
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
limits:
memory: 1G
redis:
image: redis:7-alpine
container_name: gochat-redis
restart: always
command: redis-server --requirepass "${REDIS_PASSWORD}" --appendonly yes --maxmemory 512mb --maxmemory-policy allkeys-lru
ports:
- "127.0.0.1:6379:6379" # Only localhost access
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
limits:
memory: 512M
gochat:
image: gochat/gochat:${GOCHAT_VERSION:-latest}
container_name: gochat-app
restart: always
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
ports:
- "127.0.0.1:3000:3000" # Reverse proxy should handle external access
env_file: ../../.env
environment:
- GOCHAT_ENV=production
- GOCHAT_DATABASE_DSN=postgres://${POSTGRES_USER:-gochat}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-gochat_production}?sslmode=disable
- GOCHAT_REDIS_DSN=redis://:${REDIS_PASSWORD}@redis:6379
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 30s
timeout: 5s
start_period: 15s
retries: 3
deploy:
resources:
limits:
memory: 512M
cpus: '1.0'
reservations:
memory: 256M
cpus: '0.5'
worker:
image: gochat/gochat:${GOCHAT_VERSION:-latest}
container_name: gochat-worker
restart: always
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
command: ["serve", "--worker-only"]
env_file: ../../.env
environment:
- GOCHAT_ENV=production
- GOCHAT_DATABASE_DSN=postgres://${POSTGRES_USER:-gochat}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-gochat_production}?sslmode=disable
- GOCHAT_REDIS_DSN=redis://:${REDIS_PASSWORD}@redis:6379
deploy:
resources:
limits:
memory: 512M
cpus: '1.0'
shangwutong:
image: gochat/shangwutong:${SHANGWUTONG_VERSION:-latest}
container_name: gochat-shangwutong
restart: always
stop_grace_period: ${SWT_SHUTDOWN_TIMEOUT:-30s}
environment:
SWT_CONNECTOR_LISTEN: :9100
SWT_CONNECTOR_DB_PATH: /data/connector.db
GOCHAT_BASE_URL: http://gochat:3000
GOCHAT_CONNECTOR_SERVICE_TOKEN: ${GOCHAT_CONNECTOR_SERVICE_TOKEN:-}
SWT_MAX_INFLIGHT_HEARTBEATS: ${SWT_MAX_INFLIGHT_HEARTBEATS:-64}
SWT_INBOUND_WORKERS: ${SWT_INBOUND_WORKERS:-8}
SWT_OUTBOUND_WORKERS: ${SWT_OUTBOUND_WORKERS:-8}
SWT_SHUTDOWN_TIMEOUT: ${SWT_SHUTDOWN_TIMEOUT:-30s}
volumes:
- shangwutong_data:/data
- shangwutong_backups:/backup
healthcheck:
test: ["CMD", "wget", "-q", "-T", "3", "-O", "/dev/null", "http://127.0.0.1:9100/readyz"]
interval: 30s
timeout: 5s
start_period: 15s
retries: 3
deploy:
resources:
limits:
memory: 512M
cpus: '1.0'
reservations:
memory: 128M
cpus: '0.25'
volumes:
postgres_data:
redis_data:
shangwutong_data:
shangwutong_backups: