Severian commited on
Commit
53d8b27
·
1 Parent(s): a300380

feat: optimize Dockerfile for HuggingFace Spaces deployment

Browse files
Files changed (1) hide show
  1. docker/entrypoint.sh +25 -7
docker/entrypoint.sh CHANGED
@@ -3,20 +3,38 @@ set -e
3
 
4
  echo "Starting Dify services..."
5
 
6
- # Wait for PostgreSQL
7
- until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c '\q'; do
 
 
 
 
 
 
 
 
 
 
8
  echo "PostgreSQL is unavailable - sleeping"
9
- sleep 1
10
  done
11
 
12
- # Wait for Redis
13
- until redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" ping; do
 
14
  echo "Redis is unavailable - sleeping"
15
- sleep 1
16
  done
17
 
18
- # Start API server in background
19
  cd /app/api
 
 
 
 
 
 
 
20
  echo "Starting API server on port 7860..."
21
  gunicorn --bind 0.0.0.0:7860 \
22
  --workers 1 \
 
3
 
4
  echo "Starting Dify services..."
5
 
6
+ # Install required database clients
7
+ apt-get update && apt-get install -y postgresql-client redis-tools
8
+
9
+ # Set database connection variables from environment
10
+ export PGHOST="${DB_HOST:-db}"
11
+ export PGPORT="${DB_PORT:-5432}"
12
+ export PGUSER="${DB_USERNAME:-postgres}"
13
+ export PGPASSWORD="${DB_PASSWORD:-difyai123456}"
14
+ export PGDATABASE="${DB_DATABASE:-dify}"
15
+
16
+ # Wait for PostgreSQL with proper credentials
17
+ until pg_isready -h "$PGHOST" -p "$PGPORT" -U "$PGUSER"; do
18
  echo "PostgreSQL is unavailable - sleeping"
19
+ sleep 2
20
  done
21
 
22
+ # Wait for Redis with proper credentials
23
+ until redis-cli -h "${REDIS_HOST:-redis}" -p "${REDIS_PORT:-6379}" \
24
+ -a "${REDIS_PASSWORD:-difyai123456}" ping; do
25
  echo "Redis is unavailable - sleeping"
26
+ sleep 2
27
  done
28
 
29
+ # Initialize database if needed
30
  cd /app/api
31
+ if [ ! -f ".db_initialized" ]; then
32
+ echo "Initializing database..."
33
+ flask db upgrade
34
+ touch .db_initialized
35
+ fi
36
+
37
+ # Start API server in background
38
  echo "Starting API server on port 7860..."
39
  gunicorn --bind 0.0.0.0:7860 \
40
  --workers 1 \