Spaces:
Build error
Build error
# Base stage for git operations | |
FROM alpine/git AS repo | |
WORKDIR /app | |
RUN git clone https://github.com/langgenius/dify.git . | |
# Web builder stage | |
FROM node:20.11-alpine3.19 AS web-builder | |
WORKDIR /app | |
# Copy repository web files | |
COPY --from=repo /app/web ./web/ | |
WORKDIR /app/web | |
# Configure build environment | |
ENV NODE_OPTIONS="--max_old_space_size=2048" \ | |
NEXT_TELEMETRY_DISABLED=1 \ | |
NODE_ENV=production | |
# Install dependencies and build | |
RUN yarn install --frozen-lockfile --network-timeout 300000 && \ | |
yarn add --dev @types/node @types/react && \ | |
yarn build | |
# Python builder stage | |
FROM python:3.10-slim-bookworm AS python-builder | |
# Install build dependencies | |
RUN apt-get update && \ | |
apt-get install -y --no-install-recommends \ | |
build-essential \ | |
git \ | |
&& rm -rf /var/lib/apt/lists/* | |
WORKDIR /app | |
# Copy repository API files | |
COPY --from=repo /app/api ./api/ | |
WORKDIR /app/api | |
# Install poetry and dependencies | |
RUN pip install --no-cache-dir poetry && \ | |
poetry config virtualenvs.create false && \ | |
poetry install --no-dev --no-interaction --no-ansi | |
# Final stage | |
FROM python:3.10-slim-bookworm | |
# Set up user (required by Hugging Face) | |
RUN useradd -m -u 1000 user | |
# Install runtime dependencies | |
RUN apt-get update && \ | |
apt-get install -y --no-install-recommends \ | |
nodejs \ | |
npm \ | |
postgresql-client \ | |
redis-tools \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Create app directory structure | |
WORKDIR /app | |
RUN mkdir -p api web storage/files && chown -R user:user /app | |
# Copy built artifacts | |
COPY --from=python-builder --chown=user /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages | |
COPY --from=python-builder --chown=user /app/api /app/api/ | |
COPY --from=web-builder --chown=user /app/web/.next /app/web/.next | |
COPY --from=web-builder --chown=user /app/web/public /app/web/public | |
COPY --from=web-builder --chown=user /app/web/package.json /app/web/package.json | |
# Copy entrypoint script from repo | |
COPY --from=repo --chown=user /app/docker/api/entrypoint.sh /app/entrypoint.sh | |
RUN chmod +x /app/entrypoint.sh | |
# Install additional Python packages | |
RUN pip install --no-cache-dir gunicorn gevent psycopg2-binary redis | |
# Set environment variables | |
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 \ | |
NODE_ENV=production \ | |
HOME=/app | |
# Switch to non-root user | |
USER user | |
# Expose Hugging Face required port | |
EXPOSE 7860 | |
WORKDIR /app | |
CMD ["./entrypoint.sh"] |