HF-test-lab/langfuse-dashboard-shared
2
1#!/bin/sh2 3# Create necessary directories in the persistent /data volume4echo "Creating necessary directories in the persistent /data volume..."5mkdir -p /data/postgresql/data /data/postgresql/run6chmod 0700 /data/postgresql/data7chmod 0755 /data/postgresql/run8 9# Initialize PostgreSQL if not already initialized10echo "Initializing PostgreSQL if not already initialized..."11if [ ! -f "/data/postgresql/data/PG_VERSION" ]; then12 # Initialize database13 echo "Initializing database..."14 initdb -D /data/postgresql/data15 16 # Modify pg_hba.conf to allow local connections17 echo "local all all trust" > /data/postgresql/data/pg_hba.conf18 echo "host all all 127.0.0.1/32 trust" >> /data/postgresql/data/pg_hba.conf19 echo "host all all ::1/128 trust" >> /data/postgresql/data/pg_hba.conf20 echo "host all all 0.0.0.0/0 trust" >> /data/postgresql/data/pg_hba.conf21 echo "host all all ::/0 trust" >> /data/postgresql/data/pg_hba.conf22fi23 24# Start PostgreSQL with the persistent directories25echo "Starting PostgreSQL..."26pg_ctl -D /data/postgresql/data -o "-c listen_addresses='*' -c unix_socket_directories='/data/postgresql/run'" start27 28# Wait for PostgreSQL to be ready29echo "Waiting for PostgreSQL to be ready..."30until pg_isready -h localhost; do31 echo "Waiting for PostgreSQL to be ready..."32 sleep 133done34 35# Create database and roles36echo "Creating database and roles..."37createuser -h /data/postgresql/run -s postgres || true38createdb -h /data/postgresql/run node || true39 40# Set NEXTAUTH_URL based on SPACE_HOST if available41if [ -n "$SPACE_ID" ]; then42 echo "Setting NEXTAUTH_URL to https://huggingface.co/spaces/${SPACE_ID}"43 # export NEXTAUTH_URL="https://huggingface.co/spaces/${SPACE_ID}"44 export NEXTAUTH_URL="https://${SPACE_HOST}"45else46 echo "WARNING: SPACE_ID not found"47fi48 49# Update DATABASE_URL to use TCP connection50export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/node"51 52# Export these environment variables to influence Next.js binding53export HOSTNAME="0.0.0.0"54export HOST="0.0.0.0"55export PORT=300056 57# Disable CSP headers to allow for embedded use within HF58export LANGFUSE_CSP_DISABLE="true"59 60# Preset oauth env vars based on injected space variables61# See https://huggingface.co/docs/hub/en/spaces-oauth#create-an-oauth-app62export AUTH_CUSTOM_CLIENT_ID=$OAUTH_CLIENT_ID63export AUTH_CUSTOM_CLIENT_SECRET=$OAUTH_CLIENT_SECRET64export AUTH_CUSTOM_ISSUER=$OPENID_PROVIDER_URL65export AUTH_CUSTOM_SCOPE=$OAUTH_SCOPES66export AUTH_CUSTOM_NAME="Hugging Face"67 68# Disable authentication via username/password to enforce authentication via HF69export AUTH_DISABLE_USERNAME_PASSWORD="true"70 71# Pass through AUTH_DISABLE_SIGNUP value if set, default to false if not set72if [ -n "$AUTH_DISABLE_SIGNUP" ]; then73 export AUTH_DISABLE_SIGNUP="$AUTH_DISABLE_SIGNUP"74else75 export AUTH_DISABLE_SIGNUP="false"76fi77 78# Start Next.js in the background79echo "Starting Next.js..."80./web/entrypoint.sh node ./web/server.js \81 --keepAliveTimeout 110000