# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# 🚀 BUILT & MAINTAINED BY THE ALTSTACK
# 🌍 https://thealtstack.com
# 💡 Open-source deployment templates for modern self-hosting.
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━


services:
  db:
    image: postgres:14-alpine
    container_name: posthog-db
    restart: unless-stopped
    environment:
      - POSTGRES_PASSWORD=posthog
      - POSTGRES_DB=posthog
      - POSTGRES_USER=posthog
    volumes:
      - posthog_postgres_data:/var/lib/postgresql/data

  redis:
    image: redis:6-alpine
    container_name: posthog-redis
    restart: unless-stopped
    volumes:
      - posthog_redis_data:/data

  clickhouse:
    image: clickhouse/clickhouse-server:22.3-alpine
    container_name: posthog-clickhouse
    restart: unless-stopped
    environment:
      - CLICKHOUSE_DB=posthog
      - CLICKHOUSE_USER=default
      - CLICKHOUSE_PASSWORD=
    volumes:
      - posthog_clickhouse_data:/var/lib/clickhouse

  kafka:
    image: confluentinc/cp-kafka:7.5.3
    container_name: posthog-kafka
    restart: unless-stopped
    depends_on:
      - zookeeper
    environment:
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
      - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092
      - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1

  zookeeper:
    image: confluentinc/cp-zookeeper:7.5.3
    container_name: posthog-zookeeper
    restart: unless-stopped
    environment:
      - ZOOKEEPER_CLIENT_PORT=2181
      - ZOOKEEPER_TICK_TIME=2000

  posthog:
    image: posthog/posthog:release-1.40.0
    container_name: posthog
    restart: unless-stopped
    depends_on:
      - db
      - redis
      - clickhouse
      - kafka
    ports:
      - "8002:8000"
    environment:
      - DATABASE_URL=postgres://posthog:posthog@db:5432/posthog
      - REDIS_URL=redis://redis:6379/
      - CLICKHOUSE_HOST=clickhouse
      - KAFKA_HOSTS=kafka:9092
      - SECRET_KEY=please-change-this-secret-key-in-production-12345
      - SKIP_SERVICE_VERSION_REQUIREMENTS=1
    volumes:
      - ./uploads:/app/static/uploads

volumes:
  posthog_postgres_data:
  posthog_redis_data:
  posthog_clickhouse_data:
