Spaces:
Sleeping
Sleeping
Dafa commited on
Upload entrypoint-hf.sh
Browse files- entrypoint-hf.sh +114 -0
entrypoint-hf.sh
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
# Function to create Jekyll site via API
|
| 5 |
+
create_jekyll_site() {
|
| 6 |
+
local site_name="$1"
|
| 7 |
+
local site_dir="/app/projects/$site_name"
|
| 8 |
+
|
| 9 |
+
echo "Creating Jekyll site: $site_name"
|
| 10 |
+
|
| 11 |
+
# Create directory
|
| 12 |
+
mkdir -p "$site_dir"
|
| 13 |
+
cd "$site_dir"
|
| 14 |
+
|
| 15 |
+
# Initialize Jekyll site
|
| 16 |
+
if [ ! -f "_config.yml" ]; then
|
| 17 |
+
jekyll new . --force --blank
|
| 18 |
+
|
| 19 |
+
# Create basic Gemfile for HF compatibility
|
| 20 |
+
cat > Gemfile << 'EOF'
|
| 21 |
+
source "https://rubygems.org"
|
| 22 |
+
gem "jekyll", "~> 4.3"
|
| 23 |
+
gem "webrick", "~> 1.7"
|
| 24 |
+
group :jekyll_plugins do
|
| 25 |
+
gem "jekyll-feed", "~> 0.12"
|
| 26 |
+
end
|
| 27 |
+
EOF
|
| 28 |
+
|
| 29 |
+
bundle install --path .bundle
|
| 30 |
+
echo "Jekyll site created successfully"
|
| 31 |
+
else
|
| 32 |
+
echo "Jekyll site already exists"
|
| 33 |
+
fi
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
# Function to build Jekyll site
|
| 37 |
+
build_jekyll_site() {
|
| 38 |
+
local site_dir="$1"
|
| 39 |
+
|
| 40 |
+
echo "Building Jekyll site in: $site_dir"
|
| 41 |
+
cd "$site_dir"
|
| 42 |
+
|
| 43 |
+
if [ -f "Gemfile" ]; then
|
| 44 |
+
bundle install --path .bundle
|
| 45 |
+
JEKYLL_ENV=production bundle exec jekyll build
|
| 46 |
+
else
|
| 47 |
+
jekyll build
|
| 48 |
+
fi
|
| 49 |
+
|
| 50 |
+
echo "Jekyll site built successfully"
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
# Function to serve Jekyll site (untuk development)
|
| 54 |
+
serve_jekyll_site() {
|
| 55 |
+
local site_dir="$1"
|
| 56 |
+
local port="${2:-4000}"
|
| 57 |
+
|
| 58 |
+
echo "Serving Jekyll site from: $site_dir on port: $port"
|
| 59 |
+
cd "$site_dir"
|
| 60 |
+
|
| 61 |
+
if [ -f "Gemfile" ]; then
|
| 62 |
+
bundle install --path .bundle
|
| 63 |
+
bundle exec jekyll serve --host 0.0.0.0 --port "$port"
|
| 64 |
+
else
|
| 65 |
+
jekyll serve --host 0.0.0.0 --port "$port"
|
| 66 |
+
fi
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
# Initialize environment
|
| 70 |
+
init_environment() {
|
| 71 |
+
echo "Initializing Jekyll Studio environment for Hugging Face Spaces..."
|
| 72 |
+
|
| 73 |
+
# Create necessary directories
|
| 74 |
+
mkdir -p /app/projects /app/templates
|
| 75 |
+
|
| 76 |
+
# Set proper permissions
|
| 77 |
+
chmod -R 755 /app/projects /app/templates 2>/dev/null || true
|
| 78 |
+
|
| 79 |
+
# Set default environment variables
|
| 80 |
+
export NEXTAUTH_SECRET=${NEXTAUTH_SECRET:-"hf-spaces-jekyll-studio-secret"}
|
| 81 |
+
export NEXTAUTH_URL=${NEXTAUTH_URL:-"https://$SPACE_ID-$SPACE_AUTHOR_NAME.hf.space"}
|
| 82 |
+
export NEXT_TELEMETRY_DISABLED=1
|
| 83 |
+
|
| 84 |
+
echo "Environment initialized successfully"
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
# Main command handling
|
| 88 |
+
case "$1" in
|
| 89 |
+
"create-site")
|
| 90 |
+
create_jekyll_site "$2"
|
| 91 |
+
;;
|
| 92 |
+
"build-site")
|
| 93 |
+
build_jekyll_site "$2"
|
| 94 |
+
;;
|
| 95 |
+
"serve-site")
|
| 96 |
+
serve_jekyll_site "$2" "$3"
|
| 97 |
+
;;
|
| 98 |
+
"start")
|
| 99 |
+
init_environment
|
| 100 |
+
echo "Starting Jekyll Studio on Hugging Face Spaces..."
|
| 101 |
+
echo "Next.js server starting on port $PORT"
|
| 102 |
+
exec npm start -- -p "$PORT"
|
| 103 |
+
;;
|
| 104 |
+
*)
|
| 105 |
+
echo "Jekyll Studio HF Entrypoint"
|
| 106 |
+
echo "Available commands:"
|
| 107 |
+
echo " create-site <name> - Create new Jekyll site"
|
| 108 |
+
echo " build-site <dir> - Build Jekyll site"
|
| 109 |
+
echo " serve-site <dir> - Serve Jekyll site"
|
| 110 |
+
echo " start - Start Next.js server (default)"
|
| 111 |
+
init_environment
|
| 112 |
+
exec npm start -- -p "${PORT:-7860}"
|
| 113 |
+
;;
|
| 114 |
+
esac
|