Spaces:
Runtime error
Runtime error
Update hf-entrypoint.sh
Browse files123456789101112131415161718192021222324252614 unmodified lines414243444546474849505152535455564 unmodified lines6162636465666768697071727374757677787980818283848586878889909192938 unmodified lines102103104105#!/bin/bashset -e# Start Redis in the background so Frappe has a cache to connect toecho "Starting local Redis server..."redis-server --daemonize yescd /home/frappe/frappe-bench# ==========================================# 1. PERSISTENT STORAGE INITIALIZATION# ==========================================# ... [Keep your existing persistent storage section exactly the same] ...# ==========================================# 2. SITE CONFIGURATION# ==========================================SITE_NAME=${SITE_NAME:-"huggingface.local"}mkdir -p sites/$SITE_NAME/logsexport PGSSLMODE=${PGSSLMODE:-require}# We add the three mandatory Redis queues pointing to our new local servercat <<EOF > sites/$SITE_NAME/site_config.json{"db_name": "$DB_NAME",14 unmodified linesbench use $SITE_NAME# ... [Keep the rest of your script exactly the same] ...# ==========================================# 3. DATABASE INITIALIZATION# ==========================================echo "Checking database status..."if ! bench --site $SITE_NAME execute frappe.db.get_global --args "['installed_apps']" > /dev/null 2>&1; thenecho "Database appears empty. Running bench new-site to build schema..."# Generic root user targeting, defaulting to standard "postgres" if not providedbench new-site $SITE_NAME \--db-name "$DB_NAME" \--db-password "$DB_PASSWORD" \4 unmodified lines--db-root-password "$DB_ROOT_PASSWORD" \--admin-password "admin" \--forceecho "Schema built successfully! Your Administrator password is: admin"fi# ==========================================# 4. DYNAMIC CUSTOM APP INSTALLER# ==========================================if [ ! -z "$CUSTOM_APPS" ]; thenecho "Detected CUSTOM_APPS variable. Checking persistent storage..."FORMATTED_APPS=$(echo "$CUSTOM_APPS" | tr ',' ' ')for REPO_URL in $FORMATTED_APPS; doif [ -n "$REPO_URL" ]; thenAPP_NAME=$(basename -s .git "$REPO_URL")if [ ! -d "apps/$APP_NAME" ]; thenecho "App not found in cache. Fetching and compiling $APP_NAME..."bench get-app --resolve-deps "$REPO_URL"echo "Installing $APP_NAME to site $SITE_NAME..."bench --site "$SITE_NAME" install-app "$APP_NAME" || trueelseecho "SUCCESS: $APP_NAME is already compiled and loaded from /data cache."fifidonefi# ==========================================8 unmodified lines--worker-class=gthread \--timeout=120 \--preload \frappe.app:application12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535414 unmodified lines6970717273747576777879804 unmodified lines8586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241258 unmodified lines134135136137#!/bin/bashset -eecho "Starting local Redis server..."redis-server --daemonize yescd /home/frappe/frappe-benchSITE_NAME=${SITE_NAME:-"huggingface.local"}# ==========================================# 1. PERFORMANCE CACHE ROUTING (Speed Fix)# ==========================================# We use a new cache folder (/data/hf_cache) to ignore any old broken symlinksif [ ! -d "/data/hf_cache/apps" ]; thenecho "First boot: Building cache in persistent storage..."mkdir -p /data/hf_cachefind /home/frappe/frappe-bench/apps -name ".DS_Store" -type f -delete# Store compiled code in the bucketcp -r /home/frappe/frappe-bench/apps /data/hf_cache/cp -r /home/frappe/frappe-bench/sites /data/hf_cache/elseecho "Restoring apps from persistent cache to fast local disk..."# Execute code from fast local container disk, not the slow network bucket!rm -rf /home/frappe/frappe-bench/appscp -r /data/hf_cache/apps /home/frappe/frappe-bench/appsrm -rf /home/frappe/frappe-bench/sites/assetscp -r /data/hf_cache/sites/assets /home/frappe/frappe-bench/sites/assetsfi# Ensure global logs route properlymkdir -p /data/hf_cache/logsrm -rf /home/frappe/frappe-bench/logsln -s /data/hf_cache/logs /home/frappe/frappe-bench/logs# ==========================================# 2. SITE CONFIGURATION (UI Fix)# ==========================================# Only symlink the specific site data folder to preserve user uploadsmkdir -p /data/hf_cache/sites/$SITE_NAMErm -rf /home/frappe/frappe-bench/sites/$SITE_NAMEln -s /data/hf_cache/sites/$SITE_NAME /home/frappe/frappe-bench/sites/$SITE_NAMEmkdir -p sites/$SITE_NAME/logs# CRITICAL UI FIX: Tell Gunicorn to serve static CSS/JS filesecho '{"serve_default_site": true}' > sites/common_site_config.jsonexport PGSSLMODE=${PGSSLMODE:-require}cat <<EOF > sites/$SITE_NAME/site_config.json{"db_name": "$DB_NAME",14 unmodified linesbench use $SITE_NAME# ==========================================# 3. DATABASE INITIALIZATION# ==========================================echo "Checking database status..."if ! bench --site $SITE_NAME execute frappe.db.get_global --args "['installed_apps']" > /dev/null 2>&1; thenecho "Database appears empty. Running bench new-site to build schema..."bench new-site $SITE_NAME \--db-name "$DB_NAME" \--db-password "$DB_PASSWORD" \4 unmodified lines--db-root-password "$DB_ROOT_PASSWORD" \--admin-password "admin" \--forceecho "Schema built successfully! Administrator password is: admin"fi# ==========================================# 4. DYNAMIC CUSTOM APP INSTALLER# ==========================================if [ ! -z "$CUSTOM_APPS" ]; thenecho "Detected CUSTOM_APPS variable. Checking..."FORMATTED_APPS=$(echo "$CUSTOM_APPS" | tr ',' ' ')APPS_UPDATED=falsefor REPO_URL in $FORMATTED_APPS; doif [ -n "$REPO_URL" ]; thenAPP_NAME=$(basename -s .git "$REPO_URL")if [ ! -d "apps/$APP_NAME" ]; thenecho "Fetching and compiling $APP_NAME..."bench get-app --resolve-deps "$REPO_URL"echo "Installing $APP_NAME to site $SITE_NAME..."bench --site "$SITE_NAME" install-app "$APP_NAME" || trueAPPS_UPDATED=trueelseecho "SUCCESS: $APP_NAME is already compiled."fifidone# If we compiled new apps, sync the updated code and CSS assets back to the permanent cacheif [ "$APPS_UPDATED" = true ]; thenecho "Syncing newly compiled apps to persistent storage..."rm -rf /data/hf_cache/appsrm -rf /data/hf_cache/sites/assetscp -r /home/frappe/frappe-bench/apps /data/hf_cache/cp -r /home/frappe/frappe-bench/sites/assets /data/hf_cache/sites/fifi# ==========================================8 unmodified lines--worker-class=gthread \--timeout=120 \--preload \frappe.app:application
hf-entrypoint.sh+50-18