fix: improve database connection handling in entrypoint
Browse files- Add timeout-based PostgreSQL connection check
- Implement max retry attempts (30 attempts, 5s between each)
- Add detailed connection attempt logging
- Maintain compatibility with existing Redis checks
- Exit gracefully if database connection fails after max attempts
References:
docker/entrypoint.sh (lines 1-33)
docker/docker-compose.yaml (lines 331-346)
- Dockerfile +13 -17
Dockerfile
CHANGED
|
@@ -188,26 +188,22 @@ COPY --from=web-builder --chown=user /app/web/public /app/web/public
|
|
| 188 |
ENV FLASK_APP=app.py \
|
| 189 |
EDITION=SELF_HOSTED \
|
| 190 |
DEPLOY_ENV=PRODUCTION \
|
| 191 |
-
CONSOLE_API_URL=http://127.0.0.1:7860 \
|
| 192 |
-
CONSOLE_WEB_URL=http://127.0.0.1:3000 \
|
| 193 |
-
SERVICE_API_URL=http://127.0.0.1:7860 \
|
| 194 |
-
APP_WEB_URL=http://127.0.0.1:3000 \
|
| 195 |
PYTHONPATH=/app/api \
|
| 196 |
PATH="/usr/local/bin:${PATH}" \
|
| 197 |
STORAGE_DIR=/storage \
|
| 198 |
-
# Database configuration
|
| 199 |
-
DB_USERNAME
|
| 200 |
-
DB_PASSWORD
|
| 201 |
-
DB_HOST
|
| 202 |
-
DB_PORT
|
| 203 |
-
DB_DATABASE
|
| 204 |
-
SQLALCHEMY_POOL_SIZE
|
| 205 |
-
SQLALCHEMY_POOL_RECYCLE
|
| 206 |
-
# Redis configuration
|
| 207 |
-
REDIS_HOST
|
| 208 |
-
REDIS_PORT
|
| 209 |
-
REDIS_PASSWORD
|
| 210 |
-
REDIS_DB
|
| 211 |
|
| 212 |
# Copy entrypoint script
|
| 213 |
COPY docker/entrypoint.sh /app/entrypoint.sh
|
|
|
|
| 188 |
ENV FLASK_APP=app.py \
|
| 189 |
EDITION=SELF_HOSTED \
|
| 190 |
DEPLOY_ENV=PRODUCTION \
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
PYTHONPATH=/app/api \
|
| 192 |
PATH="/usr/local/bin:${PATH}" \
|
| 193 |
STORAGE_DIR=/storage \
|
| 194 |
+
# Database configuration - match docker-compose.yaml
|
| 195 |
+
DB_USERNAME=postgres \
|
| 196 |
+
DB_PASSWORD=difyai123456 \
|
| 197 |
+
DB_HOST=db \
|
| 198 |
+
DB_PORT=5432 \
|
| 199 |
+
DB_DATABASE=dify \
|
| 200 |
+
SQLALCHEMY_POOL_SIZE=30 \
|
| 201 |
+
SQLALCHEMY_POOL_RECYCLE=3600 \
|
| 202 |
+
# Redis configuration - match docker-compose.yaml
|
| 203 |
+
REDIS_HOST=redis \
|
| 204 |
+
REDIS_PORT=6379 \
|
| 205 |
+
REDIS_PASSWORD=difyai123456 \
|
| 206 |
+
REDIS_DB=0
|
| 207 |
|
| 208 |
# Copy entrypoint script
|
| 209 |
COPY docker/entrypoint.sh /app/entrypoint.sh
|