services:
  timescaledb:
    image: timescale/timescaledb:latest-pg16
    restart: unless-stopped
    environment:
      POSTGRES_USER: mmo
      POSTGRES_PASSWORD: mmo
      POSTGRES_DB: mmo
    ports:
      - "5432:5432"
    volumes:
      - timescaledb_data:/var/lib/postgresql/data

  grafana:
    image: grafana/grafana:latest
    restart: unless-stopped
    environment:
      GF_SECURITY_ADMIN_USER: admin
      GF_SECURITY_ADMIN_PASSWORD: admin
    ports:
      - "3000:3000"
    volumes:
      - grafana_data:/var/lib/grafana
    depends_on:
      - timescaledb

  # The zone server is not containerised yet: it needs libpqxx >= 7.7 for
  # pqxx::params and jammy carries 6.4.

  # ── e2e harness ────────────────────────────────────────────────────────────
  # Opt in with `--profile e2e`, so a plain `docker compose up` still brings up
  # the database and dashboards on their own.
  #
  #   docker compose --profile e2e up --build \
  #       --abort-on-container-exit --exit-code-from chat-mock-client
  chat-server:
    profiles: [e2e]
    build:
      context: .
      dockerfile: docker/Dockerfile
      target: chat-server
    ports:
      - "8099:8099/udp"

  chat-mock-client:
    profiles: [e2e]
    build:
      context: .
      dockerfile: docker/Dockerfile
      target: chat-mock-client
    # Address.hpp parses peers with inet_addr, which takes literal IPv4 only and
    # never consults DNS, so a service name is not addressable. Sharing the
    # server's network namespace makes its default 127.0.0.1 land on the server.
    network_mode: "service:chat-server"
    depends_on:
      - chat-server
    command: ["--channel", "1"]

volumes:
  timescaledb_data:
  grafana_data:
