# =============================================================================
# Stack nginx + varnish — tests d'intégration ja4ebpf
#
# Architecture :
#   traffic-gen ─HTTPS→ nginx (TLS, port 443) ─HTTP→ varnish (port 6081)
#                                                         ↓
#                                               backend HTTP simple (port 8080)
#                          ↑
#                       ja4ebpf (uprobe nginx/libssl + hook TC)
#
# nginx termine le TLS et proxyfie vers Varnish en HTTP/1.1 (cleartext).
# Varnish ajoute un en-tête Via et le header X-Varnish pour les tests.
# ja4ebpf capture côté nginx : JA4 depuis le ClientHello, L7 depuis SSL_read.
# =============================================================================

services:

  clickhouse:
    image: clickhouse/clickhouse-server:24.8
    hostname: clickhouse
    environment:
      CLICKHOUSE_DB: ja4_processing
      CLICKHOUSE_USER: default
      CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
    volumes:
      - ../platform/clickhouse-init.sh:/docker-entrypoint-initdb.d/00_init.sh
      - ../../../shared/clickhouse/00_database.sql:/initdb-src/00_database.sql:ro
      - ../../../shared/clickhouse/01_raw_tables.sql:/initdb-src/01_raw_tables.sql:ro
      - ../../../shared/clickhouse/02_dictionaries.sql:/initdb-src/02_dictionaries.sql:ro
      - ../../../shared/clickhouse/03_anubis_tables.sql:/initdb-src/03_anubis_tables.sql:ro
      - ../../../shared/clickhouse/04_mv_http_logs.sql:/initdb-src/04_mv_http_logs.sql:ro
      - ../../../shared/clickhouse/05_aggregation_tables.sql:/initdb-src/05_aggregation_tables.sql:ro
      - ../../../shared/clickhouse/06_ml_tables.sql:/initdb-src/06_ml_tables.sql:ro
      - ../../../shared/clickhouse/07_ai_features_view.sql:/initdb-src/07_ai_features_view.sql:ro
      - ../../../shared/clickhouse/08_users.sql:/initdb-src/08_users.sql:ro
      - ../../../shared/clickhouse/09_audit_table.sql:/initdb-src/09_audit_table.sql:ro
      - ../../../shared/clickhouse/10_perf_indexes.sql:/initdb-src/10_perf_indexes.sql:ro
      - ../../../shared/clickhouse/11_views.sql:/initdb-src/11_views.sql:ro
      - ../../../shared/clickhouse/12_thesis_features.sql:/initdb-src/12_thesis_features.sql:ro
      - ../../../shared/data/browser_h2.csv:/initdb-src/browser_h2.csv:ro
      - ../platform/csv-stubs:/var/lib/clickhouse/user_files
    ports: ["9000:9000","8123:8123"]
    healthcheck:
      test: ["CMD","clickhouse-client","--query","SELECT 1"]
      interval: 5s
      timeout: 3s
      retries: 30
    networks: [ja4net]

  platform:
    build:
      context: ../../..
      dockerfile: tests/integration/nginx-varnish/platform/Dockerfile
      args:
        BASE_IMAGE: ${PLATFORM_BASE_IMAGE:-rockylinux:9}
    hostname: platform
    cap_add: [NET_ADMIN, BPF, SYS_PTRACE]
    privileged: true
    environment:
      JA4EBPF_CH_ADDR: "clickhouse:9000"
    depends_on:
      clickhouse:
        condition: service_healthy
    ports: ["443:443","80:80"]
    healthcheck:
      test: ["CMD","curl","-sfk","https://localhost/health"]
      interval: 5s
      timeout: 3s
      retries: 30
    networks: [ja4net]

  traffic-gen:
    build:
      context: ../traffic-gen
    hostname: traffic-gen
    depends_on:
      platform:
        condition: service_healthy
    networks: [ja4net]

networks:
  ja4net:
    driver: bridge
