services:
  langfuse-worker:
    image: docker.io/langfuse/langfuse-worker:3
    restart: always
    depends_on:
      langfuse-postgres:
        condition: service_healthy
      langfuse-minio:
        condition: service_healthy
      langfuse-redis:
        condition: service_healthy
      langfuse-clickhouse:
        condition: service_healthy
    environment: &langfuse_env
      NEXTAUTH_URL: "http://localhost:3001"
      DATABASE_URL: "postgresql://langfuse:langfuse@langfuse-postgres:5432/langfuse"
      SALT: "clientsflow-local-salt"
      ENCRYPTION_KEY: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
      TELEMETRY_ENABLED: "false"
      CLICKHOUSE_MIGRATION_URL: "clickhouse://langfuse-clickhouse:9000"
      CLICKHOUSE_URL: "http://langfuse-clickhouse:8123"
      CLICKHOUSE_USER: "clickhouse"
      CLICKHOUSE_PASSWORD: "clickhouse"
      CLICKHOUSE_CLUSTER_ENABLED: "false"
      LANGFUSE_S3_EVENT_UPLOAD_BUCKET: "langfuse"
      LANGFUSE_S3_EVENT_UPLOAD_REGION: "auto"
      LANGFUSE_S3_EVENT_UPLOAD_ACCESS_KEY_ID: "minio"
      LANGFUSE_S3_EVENT_UPLOAD_SECRET_ACCESS_KEY: "miniosecret"
      LANGFUSE_S3_EVENT_UPLOAD_ENDPOINT: "http://langfuse-minio:9000"
      LANGFUSE_S3_EVENT_UPLOAD_FORCE_PATH_STYLE: "true"
      LANGFUSE_S3_EVENT_UPLOAD_PREFIX: "events/"
      LANGFUSE_S3_MEDIA_UPLOAD_BUCKET: "langfuse"
      LANGFUSE_S3_MEDIA_UPLOAD_REGION: "auto"
      LANGFUSE_S3_MEDIA_UPLOAD_ACCESS_KEY_ID: "minio"
      LANGFUSE_S3_MEDIA_UPLOAD_SECRET_ACCESS_KEY: "miniosecret"
      LANGFUSE_S3_MEDIA_UPLOAD_ENDPOINT: "http://langfuse-minio:9000"
      LANGFUSE_S3_MEDIA_UPLOAD_FORCE_PATH_STYLE: "true"
      LANGFUSE_S3_MEDIA_UPLOAD_PREFIX: "media/"
      REDIS_HOST: "langfuse-redis"
      REDIS_PORT: "6379"
      REDIS_AUTH: "langfuse-redis"
      REDIS_TLS_ENABLED: "false"

  langfuse-web:
    image: docker.io/langfuse/langfuse:3
    restart: always
    depends_on:
      langfuse-postgres:
        condition: service_healthy
      langfuse-minio:
        condition: service_healthy
      langfuse-redis:
        condition: service_healthy
      langfuse-clickhouse:
        condition: service_healthy
    expose:
      - "3000"
    environment:
      <<: *langfuse_env
      NEXTAUTH_SECRET: "clientsflow-local-nextauth-secret"
      LANGFUSE_INIT_ORG_ID: "org-clientsflow"
      LANGFUSE_INIT_ORG_NAME: "Clientsflow Local"
      LANGFUSE_INIT_PROJECT_ID: "proj-clientsflow"
      LANGFUSE_INIT_PROJECT_NAME: "clientsflow"
      LANGFUSE_INIT_PROJECT_PUBLIC_KEY: "pk-lf-local"
      LANGFUSE_INIT_PROJECT_SECRET_KEY: "sk-lf-local"
      LANGFUSE_INIT_USER_EMAIL: "admin@clientsflow.local"
      LANGFUSE_INIT_USER_NAME: "Local Admin"
      LANGFUSE_INIT_USER_PASSWORD: "clientsflow-local-admin"
    networks:
      default: {}
      dokploy-network:
        aliases:
          - langfuse-web

  langfuse-clickhouse:
    image: docker.io/clickhouse/clickhouse-server:latest
    restart: always
    user: "101:101"
    environment:
      CLICKHOUSE_DB: "default"
      CLICKHOUSE_USER: "clickhouse"
      CLICKHOUSE_PASSWORD: "clickhouse"
    volumes:
      - langfuse_clickhouse_data:/var/lib/clickhouse
      - langfuse_clickhouse_logs:/var/log/clickhouse-server
    healthcheck:
      test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:8123/ping || exit 1"]
      interval: 5s
      timeout: 5s
      retries: 20
      start_period: 5s

  langfuse-minio:
    image: cgr.dev/chainguard/minio:latest
    restart: always
    entrypoint: sh
    command: -c 'mkdir -p /data/langfuse && minio server --address ":9000" --console-address ":9001" /data'
    environment:
      MINIO_ROOT_USER: "minio"
      MINIO_ROOT_PASSWORD: "miniosecret"
    volumes:
      - langfuse_minio_data:/data
    healthcheck:
      test: ["CMD", "mc", "ready", "local"]
      interval: 2s
      timeout: 5s
      retries: 15
      start_period: 5s

  langfuse-redis:
    image: docker.io/redis:7-alpine
    restart: always
    command: ["redis-server", "--requirepass", "langfuse-redis", "--maxmemory-policy", "noeviction"]
    healthcheck:
      test: ["CMD-SHELL", "redis-cli -a langfuse-redis ping | grep PONG"]
      interval: 3s
      timeout: 5s
      retries: 20
      start_period: 5s

  langfuse-postgres:
    image: postgres:16-alpine
    restart: always
    environment:
      POSTGRES_DB: "langfuse"
      POSTGRES_USER: "langfuse"
      POSTGRES_PASSWORD: "langfuse"
    volumes:
      - langfuse_postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U langfuse -d langfuse"]
      interval: 3s
      timeout: 3s
      retries: 20
      start_period: 5s

volumes:
  langfuse_postgres_data:
  langfuse_clickhouse_data:
  langfuse_clickhouse_logs:
  langfuse_minio_data:

networks:
  dokploy-network:
    name: dokploy-network
    external: true
