File size: 1,709 Bytes
a4bef0b
 
 
12e3afc
 
53d8b27
 
 
 
 
 
 
 
 
a300380
53d8b27
a300380
 
53d8b27
 
 
a300380
53d8b27
a300380
 
53d8b27
a4bef0b
53d8b27
 
 
 
 
 
 
e3a6f0b
 
a4bef0b
 
 
 
 
 
12e3afc
a4bef0b
12e3afc
070b654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12e3afc
070b654
 
 
 
a4bef0b
12e3afc
e3a6f0b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
set -e

echo "Starting Dify services..."

# Set database connection variables from environment
export PGHOST="${DB_HOST:-db}"
export PGPORT="${DB_PORT:-5432}"
export PGUSER="${DB_USERNAME:-postgres}"
export PGPASSWORD="${DB_PASSWORD:-difyai123456}"
export PGDATABASE="${DB_DATABASE:-dify}"

# Wait for PostgreSQL with proper credentials
until pg_isready -h "$PGHOST" -p "$PGPORT" -U "$PGUSER"; do
    echo "PostgreSQL is unavailable - sleeping"
    sleep 2
done

# Wait for Redis with proper credentials
until redis-cli -h "${REDIS_HOST:-redis}" -p "${REDIS_PORT:-6379}" \
    -a "${REDIS_PASSWORD:-difyai123456}" ping; do
    echo "Redis is unavailable - sleeping"
    sleep 2
done

# Initialize database if needed
cd /app/api
if [ ! -f ".db_initialized" ]; then
    echo "Initializing database..."
    flask db upgrade
    touch .db_initialized
fi

# Start API server in background
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