# =============================================================================
# Langfuse Self-Hosted - LLMOps 觀測平台
# Phase 15.1 (2026-03-26)
# 部署位置: 192.168.0.110 (DevOps 金庫)
# =============================================================================
#
# 部署指令:
#   scp -r infra/langfuse/ wooo@192.168.0.110:/opt/langfuse/
#   ssh wooo@192.168.0.110 "cd /opt/langfuse && docker-compose up -d"
#
# 存取:
#   http://192.168.0.110:3100
#
# =============================================================================

services:
  langfuse:
    image: langfuse/langfuse:2
    container_name: langfuse
    restart: unless-stopped
    ports:
      - "3100:3000"
    environment:
      # === Database ===
      DATABASE_URL: postgresql://langfuse:langfuse_secret@langfuse-db:5432/langfuse

      # === Auth ===
      NEXTAUTH_SECRET: ${NEXTAUTH_SECRET:-langfuse-secret-change-me-in-production}
      NEXTAUTH_URL: http://192.168.0.110:3100

      # === Security (Langfuse v2 必需) ===
      SALT: ${SALT:-langfuse-salt-change-me-in-production}
      ENCRYPTION_KEY: ${ENCRYPTION_KEY:-0000000000000000000000000000000000000000000000000000000000000000}

      # === Telemetry (可選關閉) ===
      TELEMETRY_ENABLED: "false"

      # === Self-hosted 模式 ===
      LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES: "true"

    depends_on:
      langfuse-db:
        condition: service_healthy
    networks:
      - langfuse-net

  langfuse-db:
    image: postgres:15-alpine
    container_name: langfuse-db
    restart: unless-stopped
    environment:
      POSTGRES_USER: langfuse
      POSTGRES_PASSWORD: langfuse_secret
      POSTGRES_DB: langfuse
    volumes:
      - langfuse-db-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U langfuse"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - langfuse-net

volumes:
  langfuse-db-data:
    driver: local

networks:
  langfuse-net:
    driver: bridge
