services:
  ray_head:
    build:
      context: .
      dockerfile: images/argus-ray-node/Dockerfile
      args:
        BASE_IMAGE: verlai/verl:sgl055.latest
    image: argus/argus-ray-node:v2.5
    container_name: argus-ray-head
    ports:
      - "8265:8265"
      - "8080:8080"
    volumes:
      # NOTE: this compose file is intended for the dev env layout like:
      #   /home2/argus/infra/mvp/{shared,verl,src/mvp}
      # so from `src/mvp/` the shared/verl dirs are `../../shared` and `../../verl`.
      - ../../verl:/workspace/verl
      - ../../shared:/private
      - .:/workspace/mvp
    shm_size: "10g"
    ulimits:
      nofile:
        soft: 65536
        hard: 65536
    cap_add:
      - SYS_ADMIN
      - SYS_PTRACE
    networks:
      - argus-ray-net
    environment:
      ARGUS_ROLE: "head"
      ARGUS_SHARED_ROOT: "/private"
      ARGUS_CLUSTER_NAME: "argus-ray"
      ARGUS_LOG_DIR: "/private/common/logs"
      HF_HOME: "/private/hf"
      HUGGINGFACE_HUB_CACHE: "/private/hf/hub"
      TRANSFORMERS_CACHE: "/private/hf/transformers"
      HF_ENDPOINT: "https://hf-mirror.com"
      PYTHONUNBUFFERED: "1"

  # v3.0: Data management service (SFTPGo).
  # - SFTP: 2022
  # - Admin API/UI: 8080 (mapped to host 8081 to avoid collision with MVP API server on 8080)
  #
  # NOTE: This is for dev / h1 E2E. In prod you may use an internal mirror image/tag and different ports.
  sftpgo:
    image: drakkan/sftpgo:latest
    container_name: argus-sftpgo
    user: "0:0"
    ports:
      - "2022:2022"
      - "8081:8080"
    volumes:
      - ../../shared:/private
      - ../../shared/common/sftpgo:/var/lib/sftpgo
    networks:
      - argus-ray-net
    environment:
      # Create a default admin on first start (used by API server to manage users).
      # Override on host as needed:
      #   export SFTPGO_ADMIN_PASSWORD=...
      SFTPGO_DATA_PROVIDER__CREATE_DEFAULT_ADMIN: "true"
      # Persist the sqlite DB under the mounted metadata dir; otherwise it defaults to a relative path.
      SFTPGO_DATA_PROVIDER__NAME: "/var/lib/sftpgo/sftpgo.db"
      SFTPGO_DEFAULT_ADMIN_USERNAME: "admin"
      SFTPGO_DEFAULT_ADMIN_PASSWORD: "${SFTPGO_ADMIN_PASSWORD:-my-dev-sftpgo-admin}"
      # Explicitly pin default ports via env-var schema (double-underscore for nesting).
      SFTPGO_HTTPD__BINDINGS__0__PORT: "8080"
      SFTPGO_SFTPD__BINDINGS__0__PORT: "2022"

  ray_worker_0:
    image: argus/argus-ray-node:v2.5
    container_name: argus-ray-worker-0
    volumes:
      - ../../verl:/workspace/verl
      - ../../shared:/private
      - .:/workspace/mvp
    shm_size: "10g"
    ulimits:
      nofile:
        soft: 65536
        hard: 65536
    cap_add:
      - SYS_ADMIN
      - SYS_PTRACE
    networks:
      - argus-ray-net
    runtime: nvidia
    environment:
      ARGUS_ROLE: "worker"
      ARGUS_SHARED_ROOT: "/private"
      ARGUS_CLUSTER_NAME: "argus-ray"
      ARGUS_LOG_DIR: "/private/common/logs"
      ARGUS_WORKER_RESOURCES_KV: "worker_node=100"
      NVIDIA_VISIBLE_DEVICES: "0,1,2,3"
      NVIDIA_DRIVER_CAPABILITIES: "all"
      HF_HOME: "/private/hf"
      HUGGINGFACE_HUB_CACHE: "/private/hf/hub"
      TRANSFORMERS_CACHE: "/private/hf/transformers"
      HF_ENDPOINT: "https://hf-mirror.com"
      PYTHONUNBUFFERED: "1"

  ray_worker_1:
    image: argus/argus-ray-node:v2.5
    container_name: argus-ray-worker-1
    volumes:
      - ../../verl:/workspace/verl
      - ../../shared:/private
      - .:/workspace/mvp
    shm_size: "10g"
    ulimits:
      nofile:
        soft: 65536
        hard: 65536
    cap_add:
      - SYS_ADMIN
      - SYS_PTRACE
    networks:
      - argus-ray-net
    runtime: nvidia
    environment:
      ARGUS_ROLE: "worker"
      ARGUS_SHARED_ROOT: "/private"
      ARGUS_CLUSTER_NAME: "argus-ray"
      ARGUS_LOG_DIR: "/private/common/logs"
      ARGUS_WORKER_RESOURCES_KV: "worker_node=100"
      NVIDIA_VISIBLE_DEVICES: "4,5,6,7"
      NVIDIA_DRIVER_CAPABILITIES: "all"
      HF_HOME: "/private/hf"
      HUGGINGFACE_HUB_CACHE: "/private/hf/hub"
      TRANSFORMERS_CACHE: "/private/hf/transformers"
      HF_ENDPOINT: "https://hf-mirror.com"
      PYTHONUNBUFFERED: "1"

networks:
  argus-ray-net:
    driver: bridge
