services:

  # ============================================================
  # HADOOP DATANODE 2
  # ============================================================
  datanode2:
    image: apache/hadoop:3.3.6
    container_name: datanode2
    hostname: datanode2
    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
      - datanode2-data:/hadoop/dfs/data
    extra_hosts:
      - "namenode:10.0.0.15"
    networks: [ids-net]
    mem_limit: 2g
    restart: unless-stopped

  # ============================================================
  # SPARK WORKER 2
  # ============================================================
  spark-worker2:
    image: spark-with-numpy:3.5.0
    container_name: spark-worker2
    network_mode: host
    command: >
      /opt/spark/bin/spark-class org.apache.spark.deploy.worker.Worker
      --host 10.0.0.18
      --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.18
      - SPARK_LOCAL_IP=10.0.0.18
    volumes:
      - ./models:/models
      - ./spark:/opt/spark-apps
    restart: unless-stopped
  # ============================================================
  # POSTGRESQL
  # ============================================================
  postgres:
    image: postgres:15
    container_name: postgres
    hostname: postgres
    environment:
      POSTGRES_DB: ids_db
      POSTGRES_USER: ids_user
      POSTGRES_PASSWORD: ids_pass123
    ports:
      - "5432:5432"
    volumes:
      - postgres-data:/var/lib/postgresql/data
    networks: [ids-net]
    mem_limit: 1g
    restart: unless-stopped

  # ============================================================

  pcap-watcher:
    build: ./pcap-watcher
    container_name: pcap-watcher
    volumes:
      - ./pcaps_input:/input
      - ./source_attacks:/source_attacks
    networks: [ids-net]
    mem_limit: 512m
    restart: unless-stopped
  # ===================================================

  dripper:
    build: ./dripper
    container_name: dripper
    volumes:
      - ./source_attacks:/source_attacks
      - ./output:/output
    extra_hosts:
      - "namenode:10.0.0.15"
    depends_on:
      - pcap-watcher
    networks: [ids-net]
    mem_limit: 512m
    restart: unless-stopped

  # FILEBEAT
  # ============================================================
  filebeat:
    build: ./vm-server
    container_name: filebeat-vm3
    hostname: vm-server-3
    volumes:
      - /home/ubuntu/ids-project/output:/output:ro
    extra_hosts:
      - "kafka:10.0.0.15"
    networks: [ids-net]
    mem_limit: 512m
    restart: unless-stopped

networks:
  ids-net:
    driver: bridge

volumes:
  datanode2-data:
  postgres-data:
  vm3-logs:
