# ClickHouse — Columnar OLAP Database for Smart City Analytics
# Usage: docker compose -p smart-city -f clickhouse/docker-compose.yml up -d
# Ports: 8123=HTTP Interface, 9000=Native TCP
services:
  clickhouse:
    image: clickhouse/clickhouse-server:latest
    container_name: smart-city-clickhouse
    networks:
      - traefik-public
      - smartcity-shared
    ports:
      - "8123:8123"   # HTTP interface (for queries, Grafana)
      - "9000:9000"   # Native TCP (for clickhouse-client)
    volumes:
      - clickhouse-data:/var/lib/clickhouse
      - ./config.xml:/etc/clickhouse-server/config.d/config.xml:ro
    environment:
      - CLICKHOUSE_USER=default
      - CLICKHOUSE_PASSWORD=Digitribe972
    deploy:
      resources:
        limits:
          memory: 2G
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost:8123/ping"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 30s
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.clickhouse.rule=Host(`clickhouse.digitribe.fr')"
      - "traefik.http.routers.clickhouse.entrypoints=websecure"
      - "traefik.http.routers.clickhouse.tls=true"
      - "traefik.http.services.clickhouse.loadbalancer.server.port=8123"

networks:
  traefik-public:
    external: true
  smartcity-shared:
    external: true

volumes:
  clickhouse-data:
