services:
  fyp-django-dev:
    container_name: fyp-django-dev
    build:
      context: ../../
      dockerfile: compose/dev/django/Dockerfile
    env_file: ../../.env
    volumes:
      - ../../:/app
    ports:
      - "8000:8000"
    depends_on:
      fyp-postgres-dev:
        condition: service_healthy
      fyp-node-dev:
        condition: service_started

  fyp-node-dev:
    container_name: fyp-node-dev
    build:
      context: ../../
      dockerfile: compose/dev/node/Dockerfile
    environment:
      NODE_ENV: development
      CHOKIDAR_USEPOLLING: "true"
    stdin_open: true
    volumes:
      - ../../site:/app:delegated
      - /app/node_modules
    ports:
      - "5173:5173"

  fyp-postgres-dev:
    container_name: fyp-postgres-dev
    image: pgvector/pgvector:pg15
    env_file: ../../.env
    environment:
      POSTGRES_HOST_AUTH_METHOD: trust
    volumes:
      - fyp_postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -p 5432 -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
      interval: 5s
      timeout: 3s
      retries: 5
  
  fyp-redis-dev:
    container_name: fyp-redis-dev
    image: redis:7-alpine
    ports:
      - "6379:6379"
    volumes:
      - fyp_redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 5
  
  fyp-celery-dev:
    container_name: fyp-celery-dev
    build:
      context: ../../
      dockerfile: compose/dev/celery/Dockerfile
    env_file: ../../.env
    volumes:
      - ../../:/app
    depends_on:
      fyp-redis-dev:
        condition: service_healthy
      fyp-postgres-dev:
        condition: service_healthy

  fyp-inference-dev:
    container_name: fyp-inference-dev
    build:
      context: ../../
      dockerfile: compose/dev/inference/Dockerfile
    env_file: ../../.env
    volumes:
      - ../../:/app
      - ../../models:/app/models
      - ../../hf_cache:/root/.cache/huggingface
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
      - WATCHFILES_FORCE_POLLING=true
      - PYTHONPATH=/app
      - HF_HOME=/root/.cache/huggingface
      - HF_HUB_OFFLINE=0
    ports:
      - "0.0.0.0:58001:8001"
    depends_on:
      fyp-redis-dev:
        condition: service_healthy
      fyp-postgres-dev:
        condition: service_healthy

volumes:
  fyp_postgres_data:
  fyp_redis_data:
