version: '3.8'

services:
  # Redis 服務 (Celery 後端和緩存)
  redis:
    image: redis:7-alpine
    container_name: panjit-translator-redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    restart: unless-stopped
    command: redis-server --appendonly yes

  # 主應用服務
  app:
    build: 
      context: .
      dockerfile: Dockerfile
    container_name: panjit-translator-app
    ports:
      - "12010:12010"
    volumes:
      - ./uploads:/app/uploads
      - ./cache:/app/cache
      - ./logs:/app/logs
    depends_on:
      - redis
    environment:
      - REDIS_URL=redis://redis:6379/0
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:12010/api/v1/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  # Celery Worker 服務
  celery-worker:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: panjit-translator-worker
    volumes:
      - ./uploads:/app/uploads
      - ./cache:/app/cache
      - ./logs:/app/logs
    depends_on:
      - redis
      - app
    environment:
      - REDIS_URL=redis://redis:6379/0
    restart: unless-stopped
    command: celery -A app.celery worker --loglevel=info --concurrency=4
    healthcheck:
      test: ["CMD", "celery", "-A", "app.celery", "inspect", "ping"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  # Celery Beat 調度服務 (可選，如果需要定期任務)
  celery-beat:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: panjit-translator-beat
    volumes:
      - ./uploads:/app/uploads
      - ./cache:/app/cache
      - ./logs:/app/logs
    depends_on:
      - redis
      - app
    environment:
      - REDIS_URL=redis://redis:6379/0
    restart: unless-stopped
    command: celery -A app.celery beat --loglevel=info

volumes:
  redis_data:
    driver: local

networks:
  default:
    name: panjit-translator-network