version: "3.8"

services:
  api:
  # image: evoapicloud/evo-ai:latest Use this image to pull from the repo
    image: evoai-api:latest # Use this image for local builds
    depends_on:
      - postgres
      - redis
    ports:
      - "8000:8000"
    env_file:
      - .env
    environment:
      POSTGRES_CONNECTION_STRING: postgresql://postgres:${POSTGRES_PASSWORD:-postgres}@postgres:5432/evo_ai
      REDIS_HOST: redis
      REDIS_PORT: ${REDIS_PORT:-6379}
      REDIS_PASSWORD: ${REDIS_PASSWORD:-""}
      REDIS_SSL: "false"
      REDIS_KEY_PREFIX: "a2a:"
      REDIS_TTL: 3600
      JWT_SECRET_KEY: ${JWT_SECRET_KEY}
      SENDGRID_API_KEY: ${SENDGRID_API_KEY}
      EMAIL_FROM: ${EMAIL_FROM}
      APP_URL: ${APP_URL}
      LOG_LEVEL: ${LOG_LEVEL:-INFO}
      DEBUG: ${DEBUG:-false}
    volumes:
      - ./logs:/app/logs
      - ./static:/app/static
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 15s
    deploy:
      resources:
        limits:
          cpus: "1"
          memory: 1G

  postgres:
    image: postgres:14-alpine
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
      POSTGRES_DB: evo_ai
    ports:
      - "${POSTGRES_PORT:-5432}:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s
    deploy:
      resources:
        limits:
          cpus: "1"
          memory: 1G

  redis:
    image: redis:alpine
    command:
      - redis-server
      - --appendonly
      - "yes"
      - --requirepass
      - "${REDIS_PASSWORD}"
    ports:
      - "${REDIS_PORT:-6379}:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 30s
      retries: 50
    deploy:
      resources:
        limits:
          cpus: "0.5"
          memory: 500M

volumes:
  postgres_data:
    name: ${POSTGRES_VOLUME_NAME:-evo-ai-postgres-data}
  redis_data:
    name: ${REDIS_VOLUME_NAME:-evo-ai-redis-data}
