version: '3.8'

networks:
  analytics-local:
    driver: bridge

volumes:
  clickhouse-data:
  timescaledb-data:
  redis-data:

services:
  # ClickHouse Database
  clickhouse:
    image: clickhouse/clickhouse-server:latest
    container_name: analytics-clickhouse-local
    ports:
      - "8123:8123"
      - "9000:9000"
    volumes:
      - clickhouse-data:/var/lib/clickhouse
    environment:
      CLICKHOUSE_DB: analytics_local
      CLICKHOUSE_USER: analytics_user
      CLICKHOUSE_PASSWORD: local_password
      CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
    networks:
      - analytics-local
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8123/ping"]
      interval: 30s
      timeout: 5s
      retries: 3

  # TimescaleDB
  timescaledb:
    image: timescale/timescaledb:latest-pg14
    container_name: analytics-timescaledb-local
    ports:
      - "5432:5432"
    volumes:
      - timescaledb-data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: analytics_timeseries
      POSTGRES_USER: analytics_user
      POSTGRES_PASSWORD: local_password
      TIMESCALEDB_TELEMETRY: off
    networks:
      - analytics-local
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U analytics_user -d analytics_timeseries"]
      interval: 30s
      timeout: 5s
      retries: 3

  # Redis
  redis:
    image: redis:7-alpine
    container_name: analytics-redis-local
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    command: redis-server --appendonly yes --requirepass local_password
    networks:
      - analytics-local
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
      interval: 30s
      timeout: 5s
      retries: 3
