ai-engine / Dockerfile
Severian's picture
Update Dockerfile
ff063df verified
raw
history blame
2.08 kB
# 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 \
&& 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
WORKDIR /app
RUN mkdir -p api web && chown -R user:user /app
# 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/
# Install Python requirements
RUN pip install --no-cache-dir gunicorn gevent
# Set environment variables for Hugging Face Spaces
ENV FLASK_APP=app.py \
EDITION=SELF_HOSTED \
DEPLOY_ENV=PRODUCTION \
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 \
HOME=/app
# Switch to non-root user
USER user
# Expose Hugging Face Spaces required ports
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 && python -m gunicorn app:app --bind 0.0.0.0:7860 --worker-class gevent --workers 1 &\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"]