Spaces:
Runtime error
Runtime error
Update hf-entrypoint.sh
Browse files11 unmodified lines12131415161718192021222311 unmodified lines353637383940414243444546474849505 unmodified lines5657585960616263646566676869707172737475767778798081828384858687888990919293949596978 unmodified lines1061071081091101111124 unmodified lines11711811912011 unmodified lines# Clean up useless macOS metadata files that cause permission errorsfind /home/frappe/frappe-bench/apps -name ".DS_Store" -type f -delete# Copy core directories to the persistent bucketcp -r /home/frappe/frappe-bench/apps /data/cp -r /home/frappe/frappe-bench/sites /data/fi# Ensure the logs directory exists in the persistent bucketmkdir -p /data/logs# Replace the container's ephemeral directories with symlinks to your bucket11 unmodified linesSITE_NAME=${SITE_NAME:-"huggingface.local"}mkdir -p sites/$SITE_NAME/logs# Force psycopg2 to use SSL (Required by Aiven)export PGSSLMODE=requirecat <<EOF > sites/$SITE_NAME/site_config.json{"db_name": "$DB_NAME","db_password": "$DB_PASSWORD","db_type": "postgres","db_host": "$DB_HOST","db_port": ${DB_PORT:-13280},"aws_access_key_id": "$S3_ACCESS_KEY","aws_secret_access_key": "$S3_SECRET_KEY","endpoint_url": "$S3_ENDPOINT_URL",5 unmodified linesbench use $SITE_NAME# ==========================================# 2.a. DATABASE INITIALIZATION# ==========================================# Check if the database has tables. If it fails to query tabDefaultValue,# it assumes the database is empty and runs the installer.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..."# We use --force to overwrite any partial artifacts and --admin-password to set the Administrator loginbench new-site $SITE_NAME \--db-name $DB_NAME \--db-password $DB_PASSWORD \--db-host $DB_HOST \--db-port ${DB_PORT:-13280} \--db-type postgres \--admin-password "admin" \--force \--no-mariadb-socketecho "Schema built successfully! Your Administrator password is: admin"fi# ==========================================# 3. DYNAMIC CUSTOM APP INSTALLER# ==========================================if [ ! -z "$CUSTOM_APPS" ]; thenecho "Detected CUSTOM_APPS variable. Checking persistent storage..."# Handle both comma and space-separated listsFORMATTED_APPS=$(echo "$CUSTOM_APPS" | tr ',' ' ')for REPO_URL in $FORMATTED_APPS; doif [ -n "$REPO_URL" ]; thenAPP_NAME=$(basename -s .git "$REPO_URL")# Check if the app is already cached in your /data bucketif [ ! -d "apps/$APP_NAME" ]; thenecho "App not found in cache. Fetching and compiling $APP_NAME..."bench get-app --resolve-deps "$REPO_URL"8 unmodified linesfi# ==========================================# 4. START GUNICORN# ==========================================echo "Starting Gunicorn on port 7860..."exec /home/frappe/frappe-bench/env/bin/gunicorn \4 unmodified lines--worker-class=gthread \--timeout=120 \--preload \frappe.app:application11 unmodified lines1213141516171819202111 unmodified lines33343536373839404142434445464748495 unmodified lines5556575859606162636465666768697071727374757677787980818283848586878889909192938 unmodified lines1021031041051061071084 unmodified lines11311411511611 unmodified lines# Clean up useless macOS metadata files that cause permission errorsfind /home/frappe/frappe-bench/apps -name ".DS_Store" -type f -deletecp -r /home/frappe/frappe-bench/apps /data/cp -r /home/frappe/frappe-bench/sites /data/fimkdir -p /data/logs# Replace the container's ephemeral directories with symlinks to your bucket11 unmodified linesSITE_NAME=${SITE_NAME:-"huggingface.local"}mkdir -p sites/$SITE_NAME/logs# Make SSL requirement configurable, but default to required for managed databasesexport PGSSLMODE=${PGSSLMODE:-require}# Notice the standard Postgres port 5432 is now the default fallbackcat <<EOF > sites/$SITE_NAME/site_config.json{"db_name": "$DB_NAME","db_password": "$DB_PASSWORD","db_type": "postgres","db_host": "$DB_HOST","db_port": ${DB_PORT:-5432},"aws_access_key_id": "$S3_ACCESS_KEY","aws_secret_access_key": "$S3_SECRET_KEY","endpoint_url": "$S3_ENDPOINT_URL",5 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..."# Generic root user targeting, defaulting to standard "postgres" if not providedbench new-site $SITE_NAME \--db-name "$DB_NAME" \--db-password "$DB_PASSWORD" \--db-host "$DB_HOST" \--db-port "${DB_PORT:-5432}" \--db-type postgres \--db-root-username "${DB_ROOT_USER:-postgres}" \--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"8 unmodified linesfi# ==========================================# 5. START GUNICORN# ==========================================echo "Starting Gunicorn on port 7860..."exec /home/frappe/frappe-bench/env/bin/gunicorn \4 unmodified lines--worker-class=gthread \--timeout=120 \--preload \frappe.app:application
hf-entrypoint.sh+16-20