services:
  drone:
    build: .
    # Scale the swarm: docker compose up --build --scale drone=${DRONE_COUNT:-5}
    deploy:
      replicas: ${DRONE_COUNT:-5}
    environment:
      FLIGHT_ID: ${FLIGHT_ID:-}
      SEED: ${SEED:-42}
      DURATION_S: ${DURATION_S:-120}
      SPEEDUP: ${SPEEDUP:-1.0}
      IMU_HZ: ${IMU_HZ:-50}
      STATE_HZ: ${STATE_HZ:-5}
      # Compose default bridge network: subnet-directed broadcast works
      BROADCAST_ADDR: ${BROADCAST_ADDR:-255.255.255.255}
    volumes:
      - ${SWARM_T1_DIR:-../var/t1}:/data

  # --- Monitoring profile: docker compose --profile monitoring up ---

  exporter:
    build: .
    profiles: [monitoring]
    command: ["python", "monitoring/exporter.py"]
    environment:
      DATA_DIR: /data
      SCAN_INTERVAL_S: "5"
    volumes:
      - ${SWARM_T1_DIR:-../var/t1}:/data:ro
      - ./monitoring:/app/monitoring:ro
    ports:
      - "${EXPORTER_PORT:-9105}:9105"

  explorer:
    build: .
    profiles: [monitoring]
    command: ["python", "explorer/server.py"]
    environment:
      DATA_DIR: /data
    volumes:
      - ${SWARM_T1_DIR:-../var/t1}:/data:ro
      - ./explorer:/app/explorer:ro
    ports:
      - "${EXPLORER_UI_PORT:-8088}:8088"

  prometheus:
    image: prom/prometheus:v2.53.0
    profiles: [monitoring]
    volumes:
      - ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro
    ports:
      - "${PROMETHEUS_PORT:-9090}:9090"

  grafana:
    image: grafana/grafana:11.1.0
    profiles: [monitoring]
    environment:
      GF_AUTH_ANONYMOUS_ENABLED: "true"
      GF_AUTH_ANONYMOUS_ORG_ROLE: Admin
      GF_AUTH_DISABLE_LOGIN_FORM: "true"
      # Air-gap hygiene: no phone-home, no update checks, no plugin fetches
      GF_ANALYTICS_REPORTING_ENABLED: "false"
      GF_ANALYTICS_CHECK_FOR_UPDATES: "false"
      GF_ANALYTICS_CHECK_FOR_PLUGIN_UPDATES: "false"
    volumes:
      - ./monitoring/grafana/provisioning:/etc/grafana/provisioning:ro
      - ./monitoring/grafana/dashboards:/var/lib/grafana/dashboards:ro
    ports:
      - "${GRAFANA_PORT:-3000}:3000"
    depends_on:
      - prometheus
