Update Dockerfile for correct directory structure
Browse files- Dockerfile +22 -113
Dockerfile
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
# Base stage with shared configuration
|
| 2 |
FROM node:20.11-alpine3.19 AS base
|
| 3 |
|
| 4 |
-
# Configure build environment
|
| 5 |
-
ENV NODE_OPTIONS="--max_old_space_size=
|
| 6 |
NEXT_TELEMETRY_DISABLED=1 \
|
| 7 |
NODE_ENV=production \
|
| 8 |
PYTHONDONTWRITEBYTECODE=1 \
|
|
@@ -18,24 +18,20 @@ WORKDIR /app/web
|
|
| 18 |
# Copy package files first
|
| 19 |
COPY web/package.json web/yarn.lock ./
|
| 20 |
|
| 21 |
-
# Install
|
| 22 |
-
RUN
|
|
|
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
RUN yarn install --frozen-lockfile --network-timeout 600000 && \
|
| 26 |
-
yarn add --dev @types/node @types/react code-inspector-plugin autoprefixer postcss tailwindcss
|
| 27 |
-
|
| 28 |
-
# Copy source files
|
| 29 |
COPY web/ .
|
| 30 |
|
| 31 |
-
# Build
|
| 32 |
-
|
| 33 |
-
RUN yarn build || (echo "Build failed with exit code $?" && exit 1)
|
| 34 |
|
| 35 |
# Python builder stage
|
| 36 |
FROM python:3.10-slim-bookworm AS python-builder
|
| 37 |
|
| 38 |
-
# Install build dependencies
|
| 39 |
RUN apt-get update && \
|
| 40 |
apt-get install -y --no-install-recommends \
|
| 41 |
build-essential \
|
|
@@ -43,10 +39,8 @@ RUN apt-get update && \
|
|
| 43 |
|
| 44 |
WORKDIR /app/api
|
| 45 |
|
| 46 |
-
# Install and
|
| 47 |
RUN pip install --no-cache-dir poetry
|
| 48 |
-
|
| 49 |
-
# Copy Python files and install dependencies
|
| 50 |
COPY api/pyproject.toml api/poetry.lock ./
|
| 51 |
RUN poetry config virtualenvs.create false && \
|
| 52 |
poetry install --no-dev --no-interaction --no-ansi
|
|
@@ -54,68 +48,37 @@ RUN poetry config virtualenvs.create false && \
|
|
| 54 |
# Final stage
|
| 55 |
FROM python:3.10-slim-bookworm
|
| 56 |
|
| 57 |
-
# Set up
|
| 58 |
RUN useradd -m -u 1000 user
|
| 59 |
|
| 60 |
-
# Install runtime dependencies
|
| 61 |
RUN apt-get update && \
|
| 62 |
apt-get install -y --no-install-recommends \
|
| 63 |
nodejs \
|
| 64 |
npm \
|
| 65 |
-
curl \
|
| 66 |
-
libgmp-dev \
|
| 67 |
-
libmpfr-dev \
|
| 68 |
-
libmpc-dev \
|
| 69 |
-
fonts-noto-cjk \
|
| 70 |
-
ffmpeg \
|
| 71 |
&& rm -rf /var/lib/apt/lists/*
|
| 72 |
|
| 73 |
-
# Create app
|
| 74 |
WORKDIR /app
|
| 75 |
-
RUN mkdir -p api web
|
| 76 |
|
| 77 |
-
# Install Python packages
|
| 78 |
RUN pip install --no-cache-dir \
|
| 79 |
gunicorn \
|
| 80 |
gevent \
|
| 81 |
flask \
|
| 82 |
cloudscraper \
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
transformers \
|
| 87 |
-
celery \
|
| 88 |
-
arxiv \
|
| 89 |
-
matplotlib \
|
| 90 |
-
duckduckgo_search \
|
| 91 |
-
jsonpath_ng \
|
| 92 |
-
pydub \
|
| 93 |
-
qrcode \
|
| 94 |
-
twilio \
|
| 95 |
-
vanna \
|
| 96 |
-
wikipedia \
|
| 97 |
-
yfinance \
|
| 98 |
-
scipy \
|
| 99 |
-
nltk \
|
| 100 |
-
unstructured
|
| 101 |
-
|
| 102 |
-
# Download NLTK data
|
| 103 |
-
RUN python -m nltk.downloader punkt averaged_perceptron_tagger
|
| 104 |
-
|
| 105 |
-
# Copy Python environment and set permissions
|
| 106 |
COPY --from=python-builder --chown=user /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
|
| 107 |
COPY --chown=user api/ /app/api/
|
| 108 |
-
|
| 109 |
-
# Copy web build artifacts with correct permissions
|
| 110 |
COPY --from=web-builder --chown=user /app/web/.next /app/web/.next
|
| 111 |
COPY --from=web-builder --chown=user /app/web/public /app/web/public
|
| 112 |
COPY --from=web-builder --chown=user /app/web/node_modules /app/web/node_modules
|
| 113 |
COPY --from=web-builder --chown=user /app/web/package.json /app/web/package.json
|
| 114 |
|
| 115 |
-
#
|
| 116 |
-
VOLUME ["/app/api/storage"]
|
| 117 |
-
|
| 118 |
-
# Set environment variables
|
| 119 |
ENV FLASK_APP=app.py \
|
| 120 |
EDITION=SELF_HOSTED \
|
| 121 |
DEPLOY_ENV=PRODUCTION \
|
|
@@ -127,68 +90,14 @@ ENV FLASK_APP=app.py \
|
|
| 127 |
HOME=/app \
|
| 128 |
PATH="/usr/local/bin:${PATH}" \
|
| 129 |
PYTHONPATH=/app/api \
|
| 130 |
-
TZ=UTC \
|
| 131 |
-
NLTK_DATA=/usr/local/share/nltk_data \
|
| 132 |
-
# Database configuration
|
| 133 |
-
DB_USERNAME=postgres \
|
| 134 |
-
DB_PASSWORD=difyai123456 \
|
| 135 |
-
DB_HOST=localhost \
|
| 136 |
-
DB_PORT=5432 \
|
| 137 |
-
DB_DATABASE=dify \
|
| 138 |
-
# Redis configuration
|
| 139 |
-
REDIS_HOST=localhost \
|
| 140 |
-
REDIS_PORT=6379 \
|
| 141 |
-
REDIS_DB=0 \
|
| 142 |
-
# Mail configuration - Using resend as default
|
| 143 |
MAIL_TYPE=resend \
|
| 144 |
-
|
| 145 |
-
MAIL_DEFAULT_SENDER_NAME=Dify \
|
| 146 |
-
MAIL_RESEND_API_KEY=null \
|
| 147 |
-
# Storage configuration
|
| 148 |
-
STORAGE_TYPE=local \
|
| 149 |
-
STORAGE_LOCAL_PATH=/app/api/storage \
|
| 150 |
-
# Vector store configuration
|
| 151 |
-
VECTOR_STORE=qdrant \
|
| 152 |
-
QDRANT_URL=http://localhost:6333 \
|
| 153 |
-
# Security configuration
|
| 154 |
-
SECRET_KEY=your-secret-key \
|
| 155 |
-
SECURITY_PASSWORD_SALT=your-password-salt \
|
| 156 |
-
# Core configuration
|
| 157 |
-
EDITION=SELF_HOSTED \
|
| 158 |
-
DEPLOY_ENV=PRODUCTION \
|
| 159 |
-
# Disable telemetry
|
| 160 |
-
DISABLE_TELEMETRY=true \
|
| 161 |
-
# Debug mode
|
| 162 |
-
DEBUG=false \
|
| 163 |
-
# Log level
|
| 164 |
-
LOG_LEVEL=INFO \
|
| 165 |
-
# Allow demo mode
|
| 166 |
-
DEMO_MODE=false \
|
| 167 |
-
# Disable registration
|
| 168 |
-
DISABLE_REGISTRATION=false \
|
| 169 |
-
# Additional required configurations
|
| 170 |
-
CELERY_BROKER_URL=redis://localhost:6379/1 \
|
| 171 |
-
CELERY_RESULT_BACKEND=redis://localhost:6379/2 \
|
| 172 |
-
SENTRY_DSN="" \
|
| 173 |
-
SENTRY_TRACES_SAMPLE_RATE=1.0 \
|
| 174 |
-
SENTRY_PROFILES_SAMPLE_RATE=1.0 \
|
| 175 |
-
OAUTH_REDIRECT_PATH=/console/api/oauth/authorize \
|
| 176 |
-
OAUTH_REDIRECT_INDEX_PATH=/console/api/oauth/callback \
|
| 177 |
-
CONSOLE_URL=http://localhost:3000 \
|
| 178 |
-
SERVICE_API_URL=http://localhost:7860 \
|
| 179 |
-
APP_API_URL=http://localhost:7860 \
|
| 180 |
-
APP_WEB_URL=http://localhost:3000
|
| 181 |
-
|
| 182 |
-
# Switch to the non-root user
|
| 183 |
-
USER user
|
| 184 |
|
| 185 |
-
|
| 186 |
-
EXPOSE 7860 3000
|
| 187 |
|
| 188 |
-
# Setup entrypoint
|
| 189 |
COPY --chown=user docker/entrypoint.sh /app/entrypoint.sh
|
| 190 |
RUN chmod +x /app/entrypoint.sh
|
| 191 |
|
| 192 |
WORKDIR /app
|
| 193 |
-
|
| 194 |
CMD ["./entrypoint.sh"]
|
|
|
|
| 1 |
# Base stage with shared configuration
|
| 2 |
FROM node:20.11-alpine3.19 AS base
|
| 3 |
|
| 4 |
+
# Configure build environment with optimized settings
|
| 5 |
+
ENV NODE_OPTIONS="--max_old_space_size=3072" \
|
| 6 |
NEXT_TELEMETRY_DISABLED=1 \
|
| 7 |
NODE_ENV=production \
|
| 8 |
PYTHONDONTWRITEBYTECODE=1 \
|
|
|
|
| 18 |
# Copy package files first
|
| 19 |
COPY web/package.json web/yarn.lock ./
|
| 20 |
|
| 21 |
+
# Install only necessary dependencies
|
| 22 |
+
RUN yarn install --frozen-lockfile --production=false --network-timeout 300000 && \
|
| 23 |
+
yarn add code-inspector-plugin autoprefixer postcss tailwindcss
|
| 24 |
|
| 25 |
+
# Copy web source files
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
COPY web/ .
|
| 27 |
|
| 28 |
+
# Build with optimized settings
|
| 29 |
+
RUN yarn build
|
|
|
|
| 30 |
|
| 31 |
# Python builder stage
|
| 32 |
FROM python:3.10-slim-bookworm AS python-builder
|
| 33 |
|
| 34 |
+
# Install build dependencies
|
| 35 |
RUN apt-get update && \
|
| 36 |
apt-get install -y --no-install-recommends \
|
| 37 |
build-essential \
|
|
|
|
| 39 |
|
| 40 |
WORKDIR /app/api
|
| 41 |
|
| 42 |
+
# Install poetry and dependencies
|
| 43 |
RUN pip install --no-cache-dir poetry
|
|
|
|
|
|
|
| 44 |
COPY api/pyproject.toml api/poetry.lock ./
|
| 45 |
RUN poetry config virtualenvs.create false && \
|
| 46 |
poetry install --no-dev --no-interaction --no-ansi
|
|
|
|
| 48 |
# Final stage
|
| 49 |
FROM python:3.10-slim-bookworm
|
| 50 |
|
| 51 |
+
# Set up user for Hugging Face
|
| 52 |
RUN useradd -m -u 1000 user
|
| 53 |
|
| 54 |
+
# Install runtime dependencies
|
| 55 |
RUN apt-get update && \
|
| 56 |
apt-get install -y --no-install-recommends \
|
| 57 |
nodejs \
|
| 58 |
npm \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
&& rm -rf /var/lib/apt/lists/*
|
| 60 |
|
| 61 |
+
# Create app structure
|
| 62 |
WORKDIR /app
|
| 63 |
+
RUN mkdir -p api web && chown -R user:user /app
|
| 64 |
|
| 65 |
+
# Install core Python packages
|
| 66 |
RUN pip install --no-cache-dir \
|
| 67 |
gunicorn \
|
| 68 |
gevent \
|
| 69 |
flask \
|
| 70 |
cloudscraper \
|
| 71 |
+
transformers
|
| 72 |
+
|
| 73 |
+
# Copy environments and files
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
COPY --from=python-builder --chown=user /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
|
| 75 |
COPY --chown=user api/ /app/api/
|
|
|
|
|
|
|
| 76 |
COPY --from=web-builder --chown=user /app/web/.next /app/web/.next
|
| 77 |
COPY --from=web-builder --chown=user /app/web/public /app/web/public
|
| 78 |
COPY --from=web-builder --chown=user /app/web/node_modules /app/web/node_modules
|
| 79 |
COPY --from=web-builder --chown=user /app/web/package.json /app/web/package.json
|
| 80 |
|
| 81 |
+
# Set core environment variables
|
|
|
|
|
|
|
|
|
|
| 82 |
ENV FLASK_APP=app.py \
|
| 83 |
EDITION=SELF_HOSTED \
|
| 84 |
DEPLOY_ENV=PRODUCTION \
|
|
|
|
| 90 |
HOME=/app \
|
| 91 |
PATH="/usr/local/bin:${PATH}" \
|
| 92 |
PYTHONPATH=/app/api \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
MAIL_TYPE=resend \
|
| 94 |
+
MAIL_RESEND_API_KEY=null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
+
USER user
|
| 97 |
+
EXPOSE 7860 3000
|
| 98 |
|
|
|
|
| 99 |
COPY --chown=user docker/entrypoint.sh /app/entrypoint.sh
|
| 100 |
RUN chmod +x /app/entrypoint.sh
|
| 101 |
|
| 102 |
WORKDIR /app
|
|
|
|
| 103 |
CMD ["./entrypoint.sh"]
|