services:

  # ============================================================
  # HADOOP DATANODE
  # ============================================================
  datanode:
    image: apache/hadoop:3.3.6
    container_name: datanode
    hostname: datanode
    user: root
    environment:
      - HADOOP_HOME=/opt/hadoop
    command: hdfs datanode
    ports:
      - "9864:9864"
      - "9866:9866"
      - "9867:9867"
    volumes:
      - ./hadoop/config/core-site.xml:/opt/hadoop/etc/hadoop/core-site.xml
      - ./hadoop/config/hdfs-site.xml:/opt/hadoop/etc/hadoop/hdfs-site.xml
      - datanode-data:/hadoop/dfs/data
    extra_hosts:
      - "namenode:10.0.0.15"
    networks: [ids-net]
    mem_limit: 2g
    restart: unless-stopped

  # ============================================================
  # SPARK WORKER
  # ============================================================
  spark-worker1:
    image: spark-with-numpy:3.5.0
    container_name: spark-worker1
    network_mode: host
    command: >
      /opt/spark/bin/spark-class org.apache.spark.deploy.worker.Worker
      --host 10.0.0.124
      --port 39000
      --webui-port 8081
      spark://10.0.0.15:7077
    environment:
      - SPARK_WORKER_MEMORY=4G
      - SPARK_WORKER_CORES=2
      - SPARK_LOCAL_HOSTNAME=10.0.0.124
      - SPARK_LOCAL_IP=10.0.0.124
    volumes:
      - ./models:/models
      - ./spark:/opt/spark-apps
    restart: unless-stopped
  # ============================================================
  # ============================================================
  # FASTAPI BACKEND
  # ============================================================
  fastapi:
    image: python:3.11-slim
    container_name: fastapi
    hostname: fastapi
    working_dir: /app
    command: >
      bash -c "apt-get update && apt-get install -y openssh-client --quiet &&
               pip install fastapi uvicorn[standard] psycopg2-binary pydantic websockets httpx --quiet &&
               uvicorn main:app --host 0.0.0.0 --port 8000 --reload"
    ports:
      - "8000:8000"
    volumes:
      - ./backend:/app
      - ./backend/id_rsa:/root/.ssh/id_rsa:ro
    environment:
      - DB_HOST=10.0.0.18
      - ADMIN_USERNAME=admin
      - ADMIN_PASSWORD=IDPS@2026
      - ABUSEIPDB_API_KEY=db475c2395c81f6876338aeeee858d113834c80a902f5b867d2072cc1dad26c61cb3a4abbcd192a2
      - DB_PASSWORD=ids_pass123
      - SPARK_HOST=10.0.0.15
      - SPARK_SSH_USER=ubuntu
    networks: [ids-net]
    mem_limit: 1g
    restart: unless-stopped

  # ============================================================
  # ============================================================
  # REACT DASHBOARD
  # ============================================================
  frontend:
    image: node:20-slim
    container_name: frontend
    working_dir: /app
    command: bash -c "npm install && npm run dev -- --host 0.0.0.0 --port 5173"
    ports:
      - "5173:5173"
    volumes:
      - ./frontend:/app
    environment:
      - VITE_API_URL=http://172.29.5.166:8000
    networks: [ids-net]
    mem_limit: 1g
    restart: unless-stopped
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
  #----------------------------------------------------------------
  # FILEBEAT
  # ============================================================
  filebeat:
    image: docker.elastic.co/beats/filebeat:8.15.0
    container_name: filebeat-vm2
    hostname: vm-server-2
    user: root
    command: ["--strict.perms=false", "-e"]
    volumes:
      - ./vm-server/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro
      - /home/ubuntu/ids-project/output:/output:ro
      - filebeat-registry:/usr/share/filebeat/data
    extra_hosts:
      - "kafka:10.0.0.15"
    networks: [ids-net]
    mem_limit: 512m
    restart: unless-stopped
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

networks:
  ids-net:
    driver: bridge

volumes:
  datanode-data:
  minio-data:
  vm2-logs:
  filebeat-registry:
