File size: 4,991 Bytes
89b26ae
 
 
 
 
 
 
 
 
 
 
 
 
001f209
 
 
 
ae9f511
 
c86cb95
 
 
001f209
 
 
 
89b26ae
ff063df
 
 
89b26ae
 
 
 
 
 
 
ae9f511
89b26ae
ae9f511
 
89b26ae
ff063df
 
 
89b26ae
f99e8df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae9f511
 
 
 
89b26ae
 
 
d09789a
 
 
 
 
89b26ae
 
 
 
d09789a
 
 
 
 
 
 
 
473f6fd
 
ae9f511
 
89b26ae
 
 
 
ae9f511
89b26ae
 
 
473f6fd
 
 
 
 
 
 
89b26ae
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# Base Python image with correct version
FROM python:3.12-slim-bookworm AS base

# Set shared environment variables
ENV NODE_VERSION=20.11.0 \
    NODE_OPTIONS="--max_old_space_size=2048" \
    NEXT_TELEMETRY_DISABLED=1 \
    NODE_ENV=production \
    PYTHONDONTWRITEBYTECODE=1 \
    POETRY_NO_INTERACTION=1 \
    POETRY_VIRTUALENVS_CREATE=false \
    POETRY_CACHE_DIR=/cache/poetry

# Install system dependencies
RUN apt-get update && apt-get install -y \
    curl \
    git \
    gcc \
    python3-dev \
    libgmp-dev \
    libmpfr-dev \
    libmpc-dev \
    && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && npm install -g npm@latest \
    && rm -rf /var/lib/apt/lists/*

# Pull official images
FROM langgenius/dify-web:latest AS web
FROM langgenius/dify-api:latest AS api

# Final stage
FROM base

# Create non-root user (required by Hugging Face)
RUN useradd -m -u 1000 user

# Set up directory structure and persistent storage
WORKDIR /app
RUN mkdir -p api web /data/storage && \
    chown -R user:user /app /data

# Copy from official images instead of building
COPY --from=web --chown=user /app/web /app/web/
COPY --from=api --chown=user /app/api /app/api/


RUN pip install --no-cache-dir \
    gunicorn \
    gevent \
    grpcio \
    grpcio-tools \
    pydantic-settings \
    pydantic \
    flask \
    flask-cors \
    flask-sqlalchemy \
    flask-migrate \
    flask-login \
    flask-limiter \
    flask-restful \
    fastapi \
    uvicorn \
    python-multipart \
    python-jose[cryptography] \
    passlib[bcrypt] \
    sqlalchemy \
    psycopg2-binary \
    alembic \
    redis \
    celery \
    flower \
    pytest \
    pytest-cov \
    pytest-asyncio \
    httpx \
    PyYAML \
    python-dotenv \
    requests \
    aiohttp \
    boto3 \
    minio \
    tiktoken \
    openai \
    tenacity \
    cryptography \
    gmpy2==2.2.1 \
    transformers \
    torch \
    sentencepiece \
    protobuf \
    anthropic==0.23.1 \
    authlib==1.3.1 \
    azure-ai-inference==1.0.0b3 \
    azure-ai-ml==1.20.0 \
    azure-identity==1.16.1 \
    beautifulsoup4==4.12.2 \
    bs4==0.0.1 \
    cachetools==5.3.0 \
    chardet==5.1.0 \
    cohere==5.2.4 \
    dashscope[tokenizer]==1.17.0 \
    fal-client==0.5.6 \
    flask-compress==1.14 \
    google-ai-generativelanguage==0.6.9 \
    google-api-core==2.18.0 \
    google-api-python-client==2.90.0 \
    google-auth==2.29.0 \
    google-auth-httplib2==0.2.0 \
    google-cloud-aiplatform==1.49.0 \
    google-generativeai==0.8.1 \
    googleapis-common-protos==1.63.0 \
    huggingface-hub==0.16.4 \
    jieba==0.42.1 \
    langfuse==2.51.3 \
    langsmith==0.1.77 \
    mailchimp-transactional==1.0.50 \
    markdown==3.5.1 \
    nomic==3.1.2 \
    novita-client==0.5.7 \
    numpy==1.26.4 \
    oci==2.135.1 \
    openpyxl==3.1.5 \
    pandas[performance,excel]==2.2.2 \
    pycryptodome==3.19.1 \
    pydantic-extra-types==2.9.0 \
    pyjwt==2.8.0 \
    pypdfium2==4.17.0 \
    python-docx==1.1.0 \
    readabilipy==0.2.0 \
    redis[hiredis]==5.0.3 \
    replicate==0.22.0 \
    resend==0.7.0 \
    sagemaker==2.231.0 \
    scikit-learn==1.5.1 \
    sentry-sdk[flask]==1.44.1 \
    starlette==0.41.0 \
    tencentcloud-sdk-python-hunyuan==3.0.1158 \
    tokenizers==0.15.0 \
    unstructured[docx,epub,md,msg,ppt,pptx]==0.16.1 \
    validators==0.21.0 \
    volcengine-python-sdk[ark]==1.0.98 \
    websocket-client==1.7.0 \
    werkzeug==3.0.1 \
    xinference-client==0.15.2 \
    yarl==1.9.4 \
    youtube-transcript-api==0.6.2 \
    zhipuai==2.1.5

# Create symlink for persistent storage
RUN ln -s /data/storage /app/api/storage

# Set environment variables
ENV FLASK_APP=app.py \
    EDITION=SELF_HOSTED \
    DEPLOY_ENV=PRODUCTION \
    MODE=api \
    LOG_LEVEL=INFO \
    DEBUG=false \
    FLASK_DEBUG=false \
    SECRET_KEY=sk-9f73s3ljTXVcMT3Blb3ljTqtsKiGHXVcMT3BlbkFJLK7U \
    CONSOLE_API_URL=http://127.0.0.1:7860 \
    CONSOLE_WEB_URL=http://127.0.0.1:3000 \
    SERVICE_API_URL=http://127.0.0.1:7860 \
    APP_WEB_URL=http://127.0.0.1:3000 \
    DB_USERNAME=postgres \
    DB_PASSWORD=difyai123456 \
    DB_HOST=db \
    DB_PORT=5432 \
    DB_DATABASE=dify \
    REDIS_HOST=redis \
    REDIS_PORT=6379 \
    REDIS_PASSWORD=difyai123456 \
    HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PYTHONPATH=/app/api \
    STORAGE_PATH=/data/storage

USER user
EXPOSE 7860 3000

# Create startup script
RUN echo '#!/bin/bash\n\
echo "===== Application Startup at $(date "+%Y-%m-%d %H:%M:%S") ====="\n\
echo "Starting Dify services..."\n\
cd /app/api && \
PYTHONPATH=/app/api python -m gunicorn app:app \
    --bind 0.0.0.0:7860 \
    --worker-class gevent \
    --workers 1 \
    --timeout 300 \
    --preload &\n\
echo "Starting API server on port 7860..."\n\
cd /app/web && node server.js &\n\
echo "Starting Next.js server on port 3000..."\n\
wait' > /app/entrypoint.sh && \
    chmod +x /app/entrypoint.sh

WORKDIR /app

CMD ["./entrypoint.sh"]