Update Dockerfile
Browse files- Dockerfile +31 -3
Dockerfile
CHANGED
|
@@ -32,6 +32,7 @@ RUN apt-get update && apt-get install -y \
|
|
| 32 |
postgresql-contrib \
|
| 33 |
locales \
|
| 34 |
nginx \
|
|
|
|
| 35 |
&& rm -rf /var/lib/apt/lists/* \
|
| 36 |
&& pip install --no-cache-dir "poetry==${POETRY_VERSION}" \
|
| 37 |
&& sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \
|
|
@@ -141,7 +142,7 @@ check_service() {
|
|
| 141 |
|
| 142 |
echo "Checking $service..."
|
| 143 |
for i in $(seq 1 $max_attempts); do
|
| 144 |
-
if curl -s "$url" >/dev/null; then
|
| 145 |
echo "$service is ready"
|
| 146 |
return 0
|
| 147 |
fi
|
|
@@ -152,6 +153,26 @@ check_service() {
|
|
| 152 |
return 1
|
| 153 |
}
|
| 154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
# Initialize PostgreSQL database if not already initialized
|
| 156 |
if [ ! -f "$PGDATA/PG_VERSION" ]; then
|
| 157 |
echo "Initializing PostgreSQL database..."
|
|
@@ -207,6 +228,7 @@ echo "Database connection successful"
|
|
| 207 |
cd /app/api && poetry run python -m flask db upgrade
|
| 208 |
|
| 209 |
# Start API server
|
|
|
|
| 210 |
cd /app/api && poetry run python -m gunicorn app:app \
|
| 211 |
--bind ${DIFY_BIND_ADDRESS:-127.0.0.1}:${DIFY_PORT:-5001} \
|
| 212 |
--worker-class gevent \
|
|
@@ -218,19 +240,25 @@ cd /app/api && poetry run python -m gunicorn app:app \
|
|
| 218 |
|
| 219 |
# Wait for API to be ready
|
| 220 |
echo "Waiting for API server to be ready..."
|
| 221 |
-
|
| 222 |
|
| 223 |
# Start frontend server
|
|
|
|
| 224 |
cd /app/web && PORT=3000 node server.js &
|
| 225 |
|
| 226 |
# Wait for frontend to be ready
|
| 227 |
echo "Waiting for frontend server to be ready..."
|
| 228 |
-
|
| 229 |
|
| 230 |
# Start nginx with debug logging
|
| 231 |
echo "Starting nginx..."
|
| 232 |
nginx -g "daemon off; error_log /var/log/nginx/error.log debug;" &
|
| 233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
# Monitor all processes
|
| 235 |
while true; do
|
| 236 |
if ! pgrep -f "gunicorn" > /dev/null; then
|
|
|
|
| 32 |
postgresql-contrib \
|
| 33 |
locales \
|
| 34 |
nginx \
|
| 35 |
+
netcat-openbsd \
|
| 36 |
&& rm -rf /var/lib/apt/lists/* \
|
| 37 |
&& pip install --no-cache-dir "poetry==${POETRY_VERSION}" \
|
| 38 |
&& sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \
|
|
|
|
| 142 |
|
| 143 |
echo "Checking $service..."
|
| 144 |
for i in $(seq 1 $max_attempts); do
|
| 145 |
+
if curl -s "$url" >/dev/null 2>&1; then
|
| 146 |
echo "$service is ready"
|
| 147 |
return 0
|
| 148 |
fi
|
|
|
|
| 153 |
return 1
|
| 154 |
}
|
| 155 |
|
| 156 |
+
# Function to check if a port is in use
|
| 157 |
+
wait_for_port() {
|
| 158 |
+
local port=$1
|
| 159 |
+
local service=$2
|
| 160 |
+
local max_attempts=$3
|
| 161 |
+
local wait_time=$4
|
| 162 |
+
|
| 163 |
+
echo "Waiting for $service on port $port..."
|
| 164 |
+
for i in $(seq 1 $max_attempts); do
|
| 165 |
+
if nc -z localhost $port; then
|
| 166 |
+
echo "$service is listening on port $port"
|
| 167 |
+
return 0
|
| 168 |
+
fi
|
| 169 |
+
echo "Waiting for $service (attempt $i/$max_attempts)..."
|
| 170 |
+
sleep $wait_time
|
| 171 |
+
done
|
| 172 |
+
echo "$service failed to bind to port $port"
|
| 173 |
+
return 1
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
# Initialize PostgreSQL database if not already initialized
|
| 177 |
if [ ! -f "$PGDATA/PG_VERSION" ]; then
|
| 178 |
echo "Initializing PostgreSQL database..."
|
|
|
|
| 228 |
cd /app/api && poetry run python -m flask db upgrade
|
| 229 |
|
| 230 |
# Start API server
|
| 231 |
+
echo "Starting API server..."
|
| 232 |
cd /app/api && poetry run python -m gunicorn app:app \
|
| 233 |
--bind ${DIFY_BIND_ADDRESS:-127.0.0.1}:${DIFY_PORT:-5001} \
|
| 234 |
--worker-class gevent \
|
|
|
|
| 240 |
|
| 241 |
# Wait for API to be ready
|
| 242 |
echo "Waiting for API server to be ready..."
|
| 243 |
+
wait_for_port 5001 "API" 30 2
|
| 244 |
|
| 245 |
# Start frontend server
|
| 246 |
+
echo "Starting frontend server..."
|
| 247 |
cd /app/web && PORT=3000 node server.js &
|
| 248 |
|
| 249 |
# Wait for frontend to be ready
|
| 250 |
echo "Waiting for frontend server to be ready..."
|
| 251 |
+
wait_for_port 3000 "Frontend" 30 2
|
| 252 |
|
| 253 |
# Start nginx with debug logging
|
| 254 |
echo "Starting nginx..."
|
| 255 |
nginx -g "daemon off; error_log /var/log/nginx/error.log debug;" &
|
| 256 |
|
| 257 |
+
# Wait for nginx to be ready
|
| 258 |
+
wait_for_port 7860 "Nginx" 30 2
|
| 259 |
+
|
| 260 |
+
echo "All services are running. Starting monitoring..."
|
| 261 |
+
|
| 262 |
# Monitor all processes
|
| 263 |
while true; do
|
| 264 |
if ! pgrep -f "gunicorn" > /dev/null; then
|