Underground-Digital/Workflow-Engine
0
1# Base Python image with correct version2FROM python:3.12-slim-bookworm AS base3 4# Set shared environment variables5ENV NODE_VERSION=20.11.0 \6 NODE_OPTIONS="--max_old_space_size=2048" \7 NEXT_TELEMETRY_DISABLED=1 \8 NODE_ENV=production \9 PYTHONDONTWRITEBYTECODE=1 \10 POETRY_NO_INTERACTION=1 \11 POETRY_VIRTUALENVS_CREATE=false \12 POETRY_CACHE_DIR=/cache/poetry13 14# Install Node.js15RUN apt-get update && apt-get install -y curl && \16 curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \17 apt-get install -y nodejs && \18 npm install -g npm@latest19 20# Web builder stage21FROM base AS web-builder22 23WORKDIR /app/web24 25# Pull and build web components26RUN git clone --depth 1 https://github.com/langgenius/dify.git . && \27 cd web && \28 npm ci && \29 npm run build && \30 npm run standalone31 32# API builder stage33FROM base AS api-builder34 35WORKDIR /app/api36 37# Pull and build API components38RUN git clone --depth 1 https://github.com/langgenius/dify.git . && \39 cd api && \40 pip install --no-cache-dir poetry && \41 poetry install --no-dev && \42 poetry build43 44# Final stage45FROM base46 47# Create non-root user (required by Hugging Face)48RUN useradd -m -u 1000 user49 50# Install runtime dependencies51RUN apt-get update && \52 apt-get install -y --no-install-recommends \53 git \54 && rm -rf /var/lib/apt/lists/*55 56# Set up directory structure57WORKDIR /app58RUN mkdir -p api web && chown -R user:user /app59 60# Copy artifacts from builders61COPY --from=api-builder --chown=user /app/api /app/api/62COPY --from=web-builder --chown=user /app/web/.next /app/web/.next/63COPY --from=web-builder --chown=user /app/web/public /app/web/public/64COPY --from=web-builder --chown=user /app/web/.next/standalone /app/web/65COPY --from=web-builder --chown=user /app/web/.next/static /app/web/.next/static/66 67# Install Python requirements68RUN pip install --no-cache-dir gunicorn gevent69 70# Set environment variables for Hugging Face Spaces71ENV FLASK_APP=app.py \72 EDITION=SELF_HOSTED \73 DEPLOY_ENV=PRODUCTION \74 CONSOLE_API_URL=http://127.0.0.1:7860 \75 CONSOLE_WEB_URL=http://127.0.0.1:3000 \76 SERVICE_API_URL=http://127.0.0.1:7860 \77 APP_WEB_URL=http://127.0.0.1:3000 \78 HOME=/app79 80# Switch to non-root user81USER user82 83# Expose Hugging Face Spaces required ports84EXPOSE 7860 300085 86# Create startup script87RUN echo '#!/bin/bash\n\88echo "===== Application Startup at $(date "+%Y-%m-%d %H:%M:%S") ====="\n\89echo "Starting Dify services..."\n\90cd /app/api && python -m gunicorn app:app --bind 0.0.0.0:7860 --worker-class gevent --workers 1 &\n\91echo "Starting API server on port 7860..."\n\92cd /app/web && node server.js &\n\93echo "Starting Next.js server on port 3000..."\n\94wait' > /app/entrypoint.sh && \95 chmod +x /app/entrypoint.sh96 97WORKDIR /app98 99CMD ["./entrypoint.sh"]