dify / Dockerfile
Severian's picture
Update Dockerfile for correct directory structure
b2b04b8
raw
history blame
3.2 kB
# ============================================
# Base stage for shared configuration
# ============================================
FROM node:20.11-alpine3.19 AS base
# Configure build environment with optimized settings
ENV NODE_OPTIONS="--max_old_space_size=2048" \
NEXT_TELEMETRY_DISABLED=1 \
NODE_ENV=production \
PYTHONDONTWRITEBYTECODE=1 \
TZ=UTC
# ============================================
# Web builder stage - optimized
# ============================================
FROM base AS web-builder
WORKDIR /app/web
# Copy only necessary files for build
COPY web/package.json web/yarn.lock ./
COPY web/next.config.js ./
COPY web/postcss.config.js ./
COPY web/tailwind.config.js ./
COPY web/tsconfig.json ./
COPY web/app ./app
COPY web/public ./public
# Install only production dependencies
RUN yarn config set network-timeout 300000 && \
yarn install --frozen-lockfile --production=true && \
yarn add --dev autoprefixer postcss tailwindcss code-inspector-plugin && \
yarn cache clean
# Build with reduced memory usage
ENV NODE_ENV=production
RUN yarn build
# ============================================
# Python builder stage - optimized
# ============================================
FROM python:3.10-slim-bookworm AS python-builder
# Install minimal build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc libffi-dev && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app/api
# Install poetry
RUN pip install --no-cache-dir poetry==1.8.3
# Install only production dependencies
COPY api/pyproject.toml api/poetry.lock ./
RUN poetry config virtualenvs.create false && \
poetry install --no-dev --no-interaction --no-ansi
# ============================================
# Final stage - minimal
# ============================================
FROM python:3.10-slim-bookworm
# Create non-root user
RUN useradd -m -u 1000 user
# Install only essential runtime packages
RUN apt-get update && \
apt-get install -y --no-install-recommends \
nodejs npm curl && \
rm -rf /var/lib/apt/lists/*
# Set up directory structure
WORKDIR /app
RUN mkdir -p api web && chown -R user:user /app
# Copy only necessary files
COPY --from=python-builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --chown=user api/ /app/api/
COPY --from=web-builder --chown=user /app/web/.next/standalone /app/web
COPY --from=web-builder --chown=user /app/web/.next/static /app/web/.next/static
COPY --from=web-builder --chown=user /app/web/public /app/web/public
# 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 \
PATH="/usr/local/bin:${PATH}" \
PYTHONPATH=/app/api \
MAIL_TYPE=resend \
MAIL_RESEND_API_KEY=null \
TZ=UTC
USER user
EXPOSE 7860 3000
# Copy and setup entrypoint
COPY --chown=user docker/entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh
WORKDIR /app
CMD ["./entrypoint.sh"]