ai-engine / Dockerfile
Severian's picture
Update Dockerfile
645f280 verified
raw
history blame
3.72 kB
# Base Python image with correct version
FROM python:3.11-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~=22.0.0 \
gevent~=24.11.1 \
flask~=3.0.1 \
flask-cors~=4.0.0 \
flask-sqlalchemy~=3.1.1 \
grpcio~=1.59.0 \
grpcio-tools~=1.59.0 \
pydantic-settings~=2.6.0 \
pydantic~=2.9.2 \
flask-migrate~=4.0.0 \
flask-login~=0.6.3 \
flask-limiter~=3.8.0 \
flask-restful~=0.3.10 \
fastapi~=0.109.0 \
uvicorn~=0.23.0 \
python-multipart~=0.0.17 \
python-jose[cryptography]~=3.3.0 \
passlib[bcrypt]~=1.7.4 \
sqlalchemy~=2.0.24 \
psycopg2-binary~=2.9.9 \
alembic~=1.14.0 \
"redis[hiredis]~=5.0.3" \
celery~=5.3.1 \
flower~=1.3.1 \
pytest~=7.4.3 \
pytest-cov~=4.1.0 \
pytest-asyncio~=0.21.1 \
httpx~=0.24.1 \
PyYAML~=6.0.1 \
python-dotenv~=1.11.4 \
requests~=2.31.0 \
aiohttp~=4.0.3 \
boto3~=2.0.2 \
minio~=7.1.1 \
tiktoken~=0.4.0 \
openai~=4.1.0 \
tenacity~=2.2.1 \
cryptography~=41.0.1 \
gmpy2==2.2.1 \
transformers~=4.33.2 \
torch~=2.1.0 \
sentencepiece~=0.1.99 \
protobuf~=5.1.1
# 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"]