services:
  selenium:
    container_name: selenium-standalone-chromium
    image: selenium/standalone-chromium:129.0
    volumes:
      - build-extension:/tmp/webrtc-internals-exporter
    shm_size: "2g"
    attach: false
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:4444/wd/hub/status"]
      interval: 5s
      timeout: 10s
      retries: 5
    pull_policy: always
    ports:
      - "7900:7900"
    networks:
      - backend

  telegraf:
    container_name: telegraf
    image: telegraf:1.33.1
    volumes:
      - ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
    environment:
      - DATABASE=${TELEGRAF_MONGODB_DATABASE:?"Database name is required"}
      - DSN=${TELEGRAF_MONGODB_DSN:?"DSN is required"}
      - HOSTNAME=${TELEGRAF_HOSTNAME:?"Hostname is required"}
      - SOCKET_PORT=${SOCKET_PORT:?"Socket port is required"}
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080"]
      interval: 5s
      timeout: 10s
      retries: 5
    pull_policy: always
    networks:
      - backend
  build-extension:
    container_name: build-extension
    image: node:22.14.0-bookworm-slim
    volumes:
      - ./webrtc-internals-exporter:/tmp/webrtc-internals-exporter:ro
      - build-extension:/tmp/webrtc-internals-exporter-build
    working_dir: /tmp/webrtc-internals-exporter-build/webpack
    command:
      - /bin/bash
      - -c
      - |
        cp -r /tmp/webrtc-internals-exporter/* /tmp/webrtc-internals-exporter-build
        npm install
        npm run build
    environment:
      - WEBRTC_INTERNALS_EXPORTER_URL=http://collector
    pull_policy: always
    networks:
      - backend

  collector:
    container_name: collector
    image: gitea.kobim.cloud/kobim/peertube-collector
    #build:
      #context: .
      #dockerfile: Dockerfile
    depends_on:
      selenium:
        condition: service_healthy
      telegraf:
        condition: service_healthy
      build-extension:
        condition: service_completed_successfully
    environment:
      - VIDEO_URL=${VIDEO_URL:?"Video URL is required"}
      - SOCKET_URL=telegraf
      - HUB_URL=http://selenium:4444
      - WEBRTC_INTERNALS_PATH=/tmp/webrtc-internals-exporter
    pull_policy: always
    networks:
      - backend

networks:
  backend:
    ipam:
      config:
        - subnet: 172.100.0.0/16

volumes:
  build-extension:
