feat: optimize Dockerfile for HuggingFace Spaces deployment
Browse files- Dockerfile +9 -2
- api/app_factory.py +2 -1
- docker/entrypoint.sh +12 -0
Dockerfile
CHANGED
@@ -105,7 +105,8 @@ RUN pip install --no-cache-dir \
|
|
105 |
torch \
|
106 |
tensorflow \
|
107 |
sentencepiece \
|
108 |
-
tokenizers
|
|
|
109 |
poetry config virtualenvs.create false && \
|
110 |
poetry install --no-dev --no-interaction --no-ansi
|
111 |
|
@@ -189,7 +190,13 @@ ENV FLASK_APP=app.py \
|
|
189 |
APP_WEB_URL=http://127.0.0.1:3000 \
|
190 |
PYTHONPATH=/app/api \
|
191 |
PATH="/usr/local/bin:${PATH}" \
|
192 |
-
STORAGE_DIR=/storage
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
|
194 |
# Copy entrypoint script
|
195 |
COPY docker/entrypoint.sh /app/entrypoint.sh
|
|
|
105 |
torch \
|
106 |
tensorflow \
|
107 |
sentencepiece \
|
108 |
+
tokenizers \
|
109 |
+
tiktoken && \
|
110 |
poetry config virtualenvs.create false && \
|
111 |
poetry install --no-dev --no-interaction --no-ansi
|
112 |
|
|
|
190 |
APP_WEB_URL=http://127.0.0.1:3000 \
|
191 |
PYTHONPATH=/app/api \
|
192 |
PATH="/usr/local/bin:${PATH}" \
|
193 |
+
STORAGE_DIR=/storage \
|
194 |
+
POSTGRES_HOST=db \
|
195 |
+
POSTGRES_PORT=5432 \
|
196 |
+
POSTGRES_DB=dify \
|
197 |
+
REDIS_HOST=redis \
|
198 |
+
REDIS_PORT=6379 \
|
199 |
+
REDIS_DB=0
|
200 |
|
201 |
# Copy entrypoint script
|
202 |
COPY docker/entrypoint.sh /app/entrypoint.sh
|
api/app_factory.py
CHANGED
@@ -37,6 +37,7 @@ from extensions.ext_database import db
|
|
37 |
from extensions.ext_login import login_manager
|
38 |
from libs.passport import PassportService
|
39 |
from services.account_service import AccountService
|
|
|
40 |
|
41 |
|
42 |
class DifyApp(Flask):
|
@@ -83,7 +84,7 @@ def initialize_extensions(app):
|
|
83 |
ext_compress.init_app(app)
|
84 |
ext_code_based_extension.init()
|
85 |
ext_database.init_app(app)
|
86 |
-
ext_migrate.init(app, db)
|
87 |
ext_redis.init_app(app)
|
88 |
ext_storage.init_app(app)
|
89 |
ext_celery.init_app(app)
|
|
|
37 |
from extensions.ext_login import login_manager
|
38 |
from libs.passport import PassportService
|
39 |
from services.account_service import AccountService
|
40 |
+
from flask_migrate import Migrate
|
41 |
|
42 |
|
43 |
class DifyApp(Flask):
|
|
|
84 |
ext_compress.init_app(app)
|
85 |
ext_code_based_extension.init()
|
86 |
ext_database.init_app(app)
|
87 |
+
ext_migrate.init(app, ext_database.db)
|
88 |
ext_redis.init_app(app)
|
89 |
ext_storage.init_app(app)
|
90 |
ext_celery.init_app(app)
|
docker/entrypoint.sh
CHANGED
@@ -3,6 +3,18 @@ set -e
|
|
3 |
|
4 |
echo "Starting Dify services..."
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# Start API server in background
|
7 |
cd /app/api
|
8 |
echo "Starting API server on port 7860..."
|
|
|
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..."
|