version: "3.9"

services:
  postgres:
    build:
      context: ../../
      dockerfile: Dockerfile.demo
    container_name: ducklake_funnel_postgres
    environment:
      POSTGRES_DB: lake_demo
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - "${POSTGRES_PORT:-5432}:5432"
    volumes:
      - postgres_data:/var/lib/postgresql
      - ./postgres/init.sql:/docker-entrypoint-initdb.d/01_init.sql:ro
    command: >
      postgres
        -c shared_preload_libraries=pg_trickle
        -c listen_addresses='*'
        -c pg_trickle.ducklake_sink_s3_endpoint=http://minio:9000
        -c pg_trickle.ducklake_sink_s3_region=us-east-1
        -c pg_trickle.ducklake_sink_s3_access_key=minioadmin
        -c pg_trickle.ducklake_sink_s3_secret_key=minioadmin
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d lake_demo"]
      interval: 5s
      timeout: 5s
      retries: 10

  minio:
    image: minio/minio:latest
    container_name: ducklake_funnel_minio
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadmin
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - minio_data:/data
    healthcheck:
      test: ["CMD", "mc", "ready", "local"]
      interval: 5s
      timeout: 5s
      retries: 10

  generator:
    build:
      context: ./generator
      dockerfile: Dockerfile
    container_name: ducklake_funnel_generator
    environment:
      DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/lake_demo"
      EVENTS_PER_SECOND: "${EVENTS_PER_SECOND:-50}"
      PRODUCT_COUNT: "${PRODUCT_COUNT:-20}"
      USER_COUNT: "${USER_COUNT:-500}"
    depends_on:
      postgres:
        condition: service_healthy

  grafana:
    image: grafana/grafana:latest
    container_name: ducklake_funnel_grafana
    environment:
      GF_SECURITY_ADMIN_PASSWORD: admin
      GF_SECURITY_ADMIN_USER: admin
      GF_AUTH_ANONYMOUS_ENABLED: "true"
      GF_AUTH_ANONYMOUS_ORG_ROLE: Viewer
    ports:
      - "${GRAFANA_PORT:-3000}:3000"
    volumes:
      - ./grafana/provisioning:/etc/grafana/provisioning:ro
      - ./grafana/dashboards:/var/lib/grafana/dashboards:ro
      - grafana_data:/var/lib/grafana
    depends_on:
      postgres:
        condition: service_healthy

volumes:
  postgres_data:
  minio_data:
  grafana_data:
