dify / docker /entrypoint.sh
Severian's picture
feat: optimize Dockerfile for HuggingFace Spaces deployment
a300380
raw
history blame
1.25 kB
#!/bin/bash
set -e
echo "Starting Dify services..."
# Wait for PostgreSQL
until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c '\q'; do
echo "PostgreSQL is unavailable - sleeping"
sleep 1
done
# Wait for Redis
until redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" ping; do
echo "Redis is unavailable - sleeping"
sleep 1
done
# Start API server in background
cd /app/api
echo "Starting API server on port 7860..."
gunicorn --bind 0.0.0.0:7860 \
--workers 1 \
--worker-class gevent \
--timeout 200 \
--preload \
app:app &
# Start Next.js web server
cd /app/web
echo "Starting Next.js server on port 3000..."
# Ensure standalone directory exists
if [ ! -d ".next/standalone" ]; then
echo "Error: Next.js standalone build not found"
exit 1
fi
# Copy static files if they exist
if [ -d ".next/static" ]; then
mkdir -p .next/standalone/.next
cp -r .next/static .next/standalone/.next/
fi
# Copy public files if they exist
if [ -d "public" ]; then
cp -r public .next/standalone/
fi
cd .next/standalone
echo "Starting Next.js standalone server..."
NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1 \
node server.js &
# Wait for both processes
wait