
services:
  db:
    image:  docker.iranserver.com/mysql:8
    container_name: ai-mysql
    environment:
      MYSQL_DATABASE: ${DB_NAME:-ai}
      MYSQL_USER: ${DB_USER:-ai}
      MYSQL_PASSWORD: ${DB_PASSWORD:-changeme}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-changeme}
    volumes:
      - ai_mysql_data:/var/lib/mysql
    ports:
      - "3307:3306"
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${DB_PASSWORD:-changeme}"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - crop_network

  phpmyadmin:
    image: docker-mirror.liara.ir/phpmyadmin:latest
    container_name: ai-phpmyadmin
    environment:
      PMA_HOST: ai-mysql
      PMA_PORT: 3306
      UPLOAD_LIMIT: 64M
    ports:
      - "8083:80"
    depends_on:
      db:
        condition: service_healthy
    networks:
      - crop_network

  redis:
    image: redis:7-alpine
    container_name: ai-redis
    networks:
      - crop_network

  qdrant:
    image: qdrant/qdrant:latest
    container_name: ai-qdrant
    ports:
      - "6333:6333"  # REST API
      - "6334:6334"  # gRPC
    volumes:
      - qdrant_data:/qdrant/storage
    restart: unless-stopped
    networks:
      - crop_network

  web:
    build:
      context: .
      args:
        APT_MIRROR: mirror2.chabokan.net
        PIP_INDEX_URL: https://package-mirror.liara.ir/repository/pypi/simple
        PIP_EXTRA_INDEX_URL: https://mirror.cdn.ir/repository/pypi/simple
        PYTHON_MIRROR: mirror2.chabokan.net
    container_name: ai-web
    command: ["python", "manage.py", "runserver", "0.0.0.0:8000"]
    volumes:
      - .:/app
      - ./logs:/app/logs
    ports:
      - "8020:8000"
    env_file:
      - .env
    environment:
      DB_HOST: ai-mysql
      CELERY_BROKER_URL: redis://ai-redis:6379/0
      CELERY_RESULT_BACKEND: redis://ai-redis:6379/0
      QDRANT_HOST: ai-qdrant
      QDRANT_PORT: 6333
      ENABLE_PROXYCHAINS: ${ENABLE_PROXYCHAINS:-0}
      PROXYCHAINS_PROXY_TYPE: ${PROXYCHAINS_PROXY_TYPE:-socks4}
      PROXYCHAINS_PROXY_HOST: ${PROXYCHAINS_PROXY_HOST:-host.docker.internal}
      PROXYCHAINS_PROXY_PORT: ${PROXYCHAINS_PROXY_PORT:-10808}
      PROXYCHAINS_CHAIN_MODE: ${PROXYCHAINS_CHAIN_MODE:-strict_chain}
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started
      qdrant:
        condition: service_started
    networks:
      - crop_network
    extra_hosts:
      - "host.docker.internal:host-gateway"

  celery:
    build:
      context: .
      args:
        APT_MIRROR: mirror2.chabokan.net
        PIP_INDEX_URL: https://package-mirror.liara.ir/repository/pypi/simple
        PIP_EXTRA_INDEX_URL: https://mirror.cdn.ir/repository/pypi/simple
        PYTHON_MIRROR: mirror2.chabokan.net
    container_name: ai-celery
    command: celery -A config worker -l info
    volumes:
      - .:/app
      - ./logs:/app/logs
    env_file:
      - .env
    environment:
      DB_HOST: ai-mysql
      CELERY_BROKER_URL: redis://ai-redis:6379/0
      CELERY_RESULT_BACKEND: redis://ai-redis:6379/0
      SKIP_MIGRATE: "1"
      ENABLE_PROXYCHAINS: ${ENABLE_PROXYCHAINS:-0}
      PROXYCHAINS_PROXY_TYPE: ${PROXYCHAINS_PROXY_TYPE:-socks4}
      PROXYCHAINS_PROXY_HOST: ${PROXYCHAINS_PROXY_HOST:-host.docker.internal}
      PROXYCHAINS_PROXY_PORT: ${PROXYCHAINS_PROXY_PORT:-10808}
      PROXYCHAINS_CHAIN_MODE: ${PROXYCHAINS_CHAIN_MODE:-strict_chain}
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started
    networks:
      - crop_network
    extra_hosts:
      - "host.docker.internal:host-gateway"

volumes:
  ai_mysql_data:
  qdrant_data:

networks:
  crop_network:
    external: true
