Files
goose/scripts/setup_langfuse.sh
Bradley Axen 1c9a7c0b05 feat: V1.0 (#734)
Co-authored-by: Michael Neale <michael.neale@gmail.com>
Co-authored-by: Wendy Tang <wendytang@squareup.com>
Co-authored-by: Jarrod Sibbison <72240382+jsibbison-square@users.noreply.github.com>
Co-authored-by: Alex Hancock <alex.hancock@example.com>
Co-authored-by: Alex Hancock <alexhancock@block.xyz>
Co-authored-by: Lifei Zhou <lifei@squareup.com>
Co-authored-by: Wes <141185334+wesrblock@users.noreply.github.com>
Co-authored-by: Max Novich <maksymstepanenko1990@gmail.com>
Co-authored-by: Zaki Ali <zaki@squareup.com>
Co-authored-by: Salman Mohammed <smohammed@squareup.com>
Co-authored-by: Kalvin C <kalvinnchau@users.noreply.github.com>
Co-authored-by: Alec Thomas <alec@swapoff.org>
Co-authored-by: lily-de <119957291+lily-de@users.noreply.github.com>
Co-authored-by: kalvinnchau <kalvin@block.xyz>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Rizel Scarlett <rizel@squareup.com>
Co-authored-by: bwrage <bwrage@squareup.com>
Co-authored-by: Kalvin Chau <kalvin@squareup.com>
Co-authored-by: Alice Hau <110418948+ahau-square@users.noreply.github.com>
Co-authored-by: Alistair Gray <ajgray@stripe.com>
Co-authored-by: Nahiyan Khan <nahiyan.khan@gmail.com>
Co-authored-by: Alex Hancock <alexhancock@squareup.com>
Co-authored-by: Nahiyan Khan <nahiyan@squareup.com>
Co-authored-by: marcelle <1852848+laanak08@users.noreply.github.com>
Co-authored-by: Yingjie He <yingjiehe@block.xyz>
Co-authored-by: Yingjie He <yingjiehe@squareup.com>
Co-authored-by: Lily Delalande <ldelalande@block.xyz>
Co-authored-by: Adewale Abati <acekyd01@gmail.com>
Co-authored-by: Ebony Louis <ebony774@gmail.com>
Co-authored-by: Angie Jones <jones.angie@gmail.com>
Co-authored-by: Ebony Louis <55366651+EbonyLouis@users.noreply.github.com>
2025-01-24 13:04:43 -08:00

118 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
# setup_langfuse.sh
#
# This script sets up and runs Langfuse locally for development and testing purposes.
#
# Key functionalities:
# 1. Downloads the latest docker-compose.yaml from the Langfuse repository
# 2. Starts Langfuse using Docker Compose with default initialization variables
# 3. Waits for the service to be available
# 4. Launches a browser to open the local Langfuse UI
# 5. Prints login credentials from the environment file
#
# Usage:
# ./setup_langfuse.sh
#
# Requirements:
# - Docker
# - curl
# - A .env.langfuse.local file in the env directory
#
# Note: This script is intended for local development use only.
set -e
SCRIPT_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
LANGFUSE_DOCKER_COMPOSE_URL="https://raw.githubusercontent.com/langfuse/langfuse/main/docker-compose.yml"
LANGFUSE_DOCKER_COMPOSE_FILE="langfuse-docker-compose.yaml"
LANGFUSE_ENV_FILE="$SCRIPT_DIR/.env.langfuse.local"
check_dependencies() {
local dependencies=("curl" "docker")
local missing_dependencies=()
for cmd in "${dependencies[@]}"; do
if ! command -v "$cmd" &> /dev/null; then
missing_dependencies+=("$cmd")
fi
done
if [ ${#missing_dependencies[@]} -ne 0 ]; then
echo "Missing dependencies: ${missing_dependencies[*]}"
exit 1
fi
}
download_docker_compose() {
if ! curl --fail --location --output "$SCRIPT_DIR/langfuse-docker-compose.yaml" "$LANGFUSE_DOCKER_COMPOSE_URL"; then
echo "Failed to download docker-compose file from $LANGFUSE_DOCKER_COMPOSE_URL"
exit 1
fi
}
start_docker_compose() {
docker compose --env-file "$LANGFUSE_ENV_FILE" -f "$LANGFUSE_DOCKER_COMPOSE_FILE" up --detach
}
wait_for_service() {
echo "Waiting for Langfuse to start..."
local retries=10
local count=0
until curl --silent http://localhost:3000 > /dev/null; do
((count++))
if [ "$count" -ge "$retries" ]; then
echo "Max retries reached. Langfuse did not start in time."
exit 1
fi
sleep 1
done
echo "Langfuse is now available!"
}
launch_browser() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
xdg-open "http://localhost:3000"
elif [[ "$OSTYPE" == "darwin"* ]]; then
open "http://localhost:3000"
else
echo "Please open http://localhost:3000 to view Langfuse traces."
fi
}
get_project_keys() {
local public_key
local secret_key
if [ -f "$LANGFUSE_ENV_FILE" ]; then
# Try to get keys from env file
public_key=$(grep -E "^LANGFUSE_INIT_PROJECT_PUBLIC_KEY=" "$LANGFUSE_ENV_FILE" | cut -d'=' -f2)
secret_key=$(grep -E "^LANGFUSE_INIT_PROJECT_SECRET_KEY=" "$LANGFUSE_ENV_FILE" | cut -d'=' -f2)
fi
# Use environment variables if set, otherwise use defaults
echo "export LANGFUSE_INIT_PROJECT_PUBLIC_KEY=${public_key:-$DEFAULT_PUBLIC_KEY}"
echo "export LANGFUSE_INIT_PROJECT_SECRET_KEY=${secret_key:-$DEFAULT_SECRET_KEY}"
}
print_login_variables() {
if [ -f "$LANGFUSE_ENV_FILE" ]; then
echo "If not already logged in use the following credentials to log in:"
grep -E "LANGFUSE_INIT_USER_EMAIL|LANGFUSE_INIT_USER_PASSWORD" "$LANGFUSE_ENV_FILE"
else
echo "Langfuse environment file with local credentials not found."
fi
echo
echo "Project keys (add these to your environment):"
get_project_keys
echo
}
check_dependencies
pushd "$SCRIPT_DIR" > /dev/null
download_docker_compose
start_docker_compose
wait_for_service
print_login_variables
launch_browser
popd > /dev/null