version: '3.8'

services:
  redis:
    image: redis:7-alpine
    container_name: coc_redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    command: redis-server --appendonly yes
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 3

  api:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: coc_api
    ports:
      - "5000:5000"
    volumes:
      - .:/app
    env_file:
      - .env
    environment:
      - FLASK_ENV=development
      - REDIS_URL=redis://redis:6379/0
    depends_on:
      redis:
        condition: service_healthy
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5000/api/v1/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

  rq-worker:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: coc_rq_worker
    command: rq worker ai_tasks combat_tasks marketplace_tasks --url redis://redis:6379/0 --with-scheduler
    volumes:
      - .:/app
    depends_on:
      redis:
        condition: service_healthy
    env_file:
      - .env
    environment:
      - REDIS_URL=redis://redis:6379/0
    restart: unless-stopped

volumes:
  redis_data:
    driver: local
