|
# Base image |
|
FROM python:3.12-slim-bookworm AS base |
|
|
|
# Set shared |
|
ENV |
|
POETRY_NO_INTERACTION=1 \ |
|
POETRY_VIRTUALENVS_CREATE=true |
|
POETRY_VIRTUALENVS_IN_PROJECT=true |
|
POETRY_CACHE_DIR=/tmp/poetry_cache |
|
PYTHONDONTWRITEBYTECODE=1 \ |
|
LANG=en_US.UTF-8 \ |
|
LANGUAGE=en_US:en |
|
LC_ALL=en_US.UTF-8 \ |
|
PORT=7860 \ |
|
NODE_ENV=production |
|
|
|
# Create |
|
RUN |
|
|
|
# Install |
|
RUN |
|
curl |
|
git |
|
gcc |
|
python3-dev |
|
libgmp-dev |
|
libmpfr-dev |
|
libmpc-dev |
|
nodejs |
|
npm |
|
postgresql |
|
postgresql-contrib |
|
locales |
|
nginx |
|
&& rm /var//apt//* \ |
|
&& pip install --no-cache-dir \ |
|
&& sed -i //locale.gen \ |
|
&& locale-gen |
|
|
|
# Configure nginx |
|
RUN rm //nginx//default || true |
|
COPY <<EOF //nginx/ |
|
events |
|
worker_connections ; |
|
} |
|
|
|
http { |
|
include /etc/nginx/mime.types; |
|
default_type application/octet-stream; |
|
sendfile on; |
|
keepalive_timeout 65; |
|
|
|
upstream frontend { |
|
server 127.0.0.1:3000; |
|
} |
|
|
|
upstream backend { |
|
server 127.0.0.1:5001; |
|
} |
|
|
|
server { |
|
listen 7860; |
|
server_name _; |
|
client_max_body_size 100M; |
|
|
|
location / { |
|
proxy_pass http: |
|
proxy_http_version 1.1; |
|
proxy_set_header Upgrade $http_upgrade; |
|
proxy_set_header Connection 'upgrade'; |
|
proxy_set_header Host $host; |
|
proxy_cache_bypass $http_upgrade; |
|
proxy_set_header X-Real-IP $remote_addr; |
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|
proxy_set_header X-Forwarded-Proto $scheme; |
|
proxy_read_timeout 300s; |
|
proxy_connect_timeout 75s; |
|
} |
|
|
|
location /api { |
|
proxy_pass http: |
|
proxy_http_version 1.1; |
|
proxy_set_header Upgrade $http_upgrade; |
|
proxy_set_header Connection 'upgrade'; |
|
proxy_set_header Host $host; |
|
proxy_cache_bypass $http_upgrade; |
|
proxy_set_header X-Real-IP $remote_addr; |
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|
proxy_set_header X-Forwarded-Proto $scheme; |
|
proxy_read_timeout 300s; |
|
proxy_connect_timeout 75s; |
|
} |
|
|
|
access_log /var/log/nginx/access.log; |
|
error_log /var/log/nginx/error.log; |
|
} |
|
} |
|
EOF |
|
|
|
RUN mkdir -p /var/log/nginx && \ |
|
chown -R user:user /var/log/nginx && \ |
|
touch /run/nginx.pid && \ |
|
chown -R user:user /run/nginx.pid && \ |
|
chown -R user:user /var/lib/nginx && \ |
|
chmod -R 755 /var/lib/nginx && \ |
|
chmod -R 755 /etc/nginx && \ |
|
chmod -R 777 /run |
|
|
|
# Set up |
|
RUN /var//postgresql //lib//data //log/ |
|
chown /var//postgresql //lib//data //log/ |
|
chmod /var//postgresql/ |
|
|
|
# Create |
|
RUN /app/ /app/ /data/ |
|
chown /app / |
|
chmod /data / |
|
|
|
# Switch |
|
USER |
|
|
|
# Set |
|
ENV /home/ |
|
PATH=/usr/lib/postgresql/15/bin:/home/user/.local/bin:$PATH \ |
|
PGDATA=/var/lib/postgresql/data |
|
|
|
# Pull official images |
|
FROM langgenius/dify-web:latest |
|
FROM /dify-api:latest AS api |
|
|
|
# Final stage |
|
FROM base |
|
|
|
# Set up directory structure |
|
WORKDIR / |
|
RUN /data/ |
|
|
|
# Copy |
|
COPY /app/ /app// |
|
COPY --from=api --chown=user:user //api //api/ |
|
|
|
# Install |
|
WORKDIR /app/ |
|
COPY /app//pyproject.toml //api/ /app//poetry.toml ./ |
|
RUN |
|
|
|
# Create |
|
RUN /data/ /app//storage |
|
|
|
# Set environment variables |
|
ENV FLASK_APP=app.py \ |
|
EDITION=SELF_HOSTED \ |
|
DEPLOY_ENV=PRODUCTION \ |
|
MODE=api \ |
|
LOG_LEVEL=INFO \ |
|
DEBUG=false \ |
|
FLASK_DEBUG=false \ |
|
SECRET_KEY=sk-9f73s3ljTXVcMT3Blb3ljTqtsKiGHXVcMT3BlbkFJLK7U \ |
|
CONSOLE_API_URL=https: |
|
CONSOLE_WEB_URL=https: |
|
SERVICE_API_URL=https: |
|
APP_WEB_URL=https: |
|
DIFY_PORT=5001 \ |
|
DIFY_BIND_ADDRESS=127.0.0.1 \ |
|
DB_USERNAME=user \ |
|
DB_PASSWORD=difyai123456 \ |
|
DB_HOST=localhost \ |
|
DB_PORT=5432 \ |
|
DB_DATABASE=dify \ |
|
PYTHONPATH=//api \ |
|
STORAGE_PATH=//storage |
|
|
|
EXPOSE 7860 |
|
|
|
# Create startup script |
|
RUN echo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
\*$PGDATA/ |
|
/postgresql.conf |
|
shared_buffers = 128MB$PGDATA/ |
|
|
|
|
|
|
|
|
|
/var//postgresql -c log_filename=postgresql-%Y-%m-%d_%H%M%S.log -c log_statement=all |
|
|
|
|
|
|
|
|
|
Checking database connection... |
|
|
|
|
|
PostgreSQL logs: |
|
|
|
|
|
Waiting for database connection... (${count}/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;" &\n\ |
|
\n\ |
|
wait' > /app/entrypoint.sh && \ |
|
chmod +x /app/entrypoint.sh |
|
|
|
WORKDIR /app |
|
|
|
CMD ["./entrypoint.sh"] |