Update Dockerfile
Browse files- Dockerfile +43 -23
Dockerfile
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
-
#
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
# Configure shared environment variables
|
| 6 |
-
ENV NODE_OPTIONS="--max_old_space_size=2048" \
|
| 7 |
NEXT_TELEMETRY_DISABLED=1 \
|
| 8 |
NODE_ENV=production \
|
| 9 |
PYTHONDONTWRITEBYTECODE=1 \
|
|
@@ -11,26 +11,38 @@ ENV NODE_OPTIONS="--max_old_space_size=2048" \
|
|
| 11 |
POETRY_VIRTUALENVS_CREATE=false \
|
| 12 |
POETRY_CACHE_DIR=/cache/poetry
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Web builder stage
|
| 15 |
-
FROM
|
| 16 |
|
| 17 |
WORKDIR /app/web
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
# API builder stage
|
| 25 |
-
FROM
|
| 26 |
|
| 27 |
WORKDIR /app/api
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# Final stage
|
| 33 |
-
FROM
|
| 34 |
|
| 35 |
# Create non-root user (required by Hugging Face)
|
| 36 |
RUN useradd -m -u 1000 user
|
|
@@ -38,8 +50,7 @@ RUN useradd -m -u 1000 user
|
|
| 38 |
# Install runtime dependencies
|
| 39 |
RUN apt-get update && \
|
| 40 |
apt-get install -y --no-install-recommends \
|
| 41 |
-
|
| 42 |
-
npm \
|
| 43 |
&& rm -rf /var/lib/apt/lists/*
|
| 44 |
|
| 45 |
# Set up directory structure
|
|
@@ -48,7 +59,10 @@ RUN mkdir -p api web && chown -R user:user /app
|
|
| 48 |
|
| 49 |
# Copy artifacts from builders
|
| 50 |
COPY --from=api-builder --chown=user /app/api /app/api/
|
| 51 |
-
COPY --from=web-builder --chown=user /app/web /app/web
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# Install Python requirements
|
| 54 |
RUN pip install --no-cache-dir gunicorn gevent
|
|
@@ -61,18 +75,24 @@ ENV FLASK_APP=app.py \
|
|
| 61 |
CONSOLE_WEB_URL=http://127.0.0.1:3000 \
|
| 62 |
SERVICE_API_URL=http://127.0.0.1:7860 \
|
| 63 |
APP_WEB_URL=http://127.0.0.1:3000 \
|
| 64 |
-
NODE_ENV=production \
|
| 65 |
HOME=/app
|
| 66 |
|
| 67 |
# Switch to non-root user
|
| 68 |
USER user
|
| 69 |
|
| 70 |
-
# Expose Hugging Face Spaces required
|
| 71 |
EXPOSE 7860 3000
|
| 72 |
|
| 73 |
-
#
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
WORKDIR /app
|
| 78 |
|
|
|
|
| 1 |
+
# Base Python image with correct version
|
| 2 |
+
FROM python:3.12-slim-bookworm AS base
|
| 3 |
|
| 4 |
+
# Set shared environment variables
|
| 5 |
+
ENV 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 \
|
|
|
|
| 11 |
POETRY_VIRTUALENVS_CREATE=false \
|
| 12 |
POETRY_CACHE_DIR=/cache/poetry
|
| 13 |
|
| 14 |
+
# Install Node.js
|
| 15 |
+
RUN 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@latest
|
| 19 |
+
|
| 20 |
# Web builder stage
|
| 21 |
+
FROM base AS web-builder
|
| 22 |
|
| 23 |
WORKDIR /app/web
|
| 24 |
|
| 25 |
+
# Pull and build web components
|
| 26 |
+
RUN git clone --depth 1 https://github.com/langgenius/dify.git . && \
|
| 27 |
+
cd web && \
|
| 28 |
+
npm ci && \
|
| 29 |
+
npm run build && \
|
| 30 |
+
npm run standalone
|
| 31 |
|
| 32 |
+
# API builder stage
|
| 33 |
+
FROM base AS api-builder
|
| 34 |
|
| 35 |
WORKDIR /app/api
|
| 36 |
|
| 37 |
+
# Pull and build API components
|
| 38 |
+
RUN 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 build
|
| 43 |
|
| 44 |
# Final stage
|
| 45 |
+
FROM base
|
| 46 |
|
| 47 |
# Create non-root user (required by Hugging Face)
|
| 48 |
RUN useradd -m -u 1000 user
|
|
|
|
| 50 |
# Install runtime dependencies
|
| 51 |
RUN 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 structure
|
|
|
|
| 59 |
|
| 60 |
# Copy artifacts from builders
|
| 61 |
COPY --from=api-builder --chown=user /app/api /app/api/
|
| 62 |
+
COPY --from=web-builder --chown=user /app/web/.next /app/web/.next/
|
| 63 |
+
COPY --from=web-builder --chown=user /app/web/public /app/web/public/
|
| 64 |
+
COPY --from=web-builder --chown=user /app/web/.next/standalone /app/web/
|
| 65 |
+
COPY --from=web-builder --chown=user /app/web/.next/static /app/web/.next/static/
|
| 66 |
|
| 67 |
# Install Python requirements
|
| 68 |
RUN pip install --no-cache-dir gunicorn gevent
|
|
|
|
| 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=/app
|
| 79 |
|
| 80 |
# Switch to non-root user
|
| 81 |
USER user
|
| 82 |
|
| 83 |
+
# Expose Hugging Face Spaces required ports
|
| 84 |
EXPOSE 7860 3000
|
| 85 |
|
| 86 |
+
# Create startup script
|
| 87 |
+
RUN echo '#!/bin/bash\n\
|
| 88 |
+
echo "===== Application Startup at $(date "+%Y-%m-%d %H:%M:%S") ====="\n\
|
| 89 |
+
echo "Starting Dify services..."\n\
|
| 90 |
+
cd /app/api && python -m gunicorn app:app --bind 0.0.0.0:7860 --worker-class gevent --workers 1 &\n\
|
| 91 |
+
echo "Starting API server on port 7860..."\n\
|
| 92 |
+
cd /app/web && node server.js &\n\
|
| 93 |
+
echo "Starting Next.js server on port 3000..."\n\
|
| 94 |
+
wait' > /app/entrypoint.sh && \
|
| 95 |
+
chmod +x /app/entrypoint.sh
|
| 96 |
|
| 97 |
WORKDIR /app
|
| 98 |
|