File size: 2,464 Bytes
89b26ae
f998768
89b26ae
27b5a39
6516462
89b26ae
f998768
 
6516462
27b5a39
89b26ae
54e6e52
 
 
1d0e45c
54e6e52
 
17df3ec
54e6e52
 
 
 
 
 
 
 
 
 
 
704d8a2
54e6e52
704d8a2
53b476f
704d8a2
54e6e52
27b5a39
54e6e52
d0ebb79
5ed2aea
 
 
54e6e52
89b26ae
dac5c20
 
f99e8df
54e6e52
f998768
27b5a39
54e6e52
 
f99e8df
54e6e52
ae9f511
 
0c01f90
 
 
 
54e6e52
89b26ae
 
 
d09789a
 
 
cd6550a
d09789a
 
cd6550a
d09789a
 
0c01f90
 
89b26ae
 
 
 
 
0c01f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Base Python image with correct version
FROM python:3.12-slim-bookworm AS base

# Set shared environment variables
ENV POETRY_VERSION=1.8.4 \
    POETRY_NO_INTERACTION=1 \
    POETRY_VIRTUALENVS_CREATE=true \
    POETRY_VIRTUALENVS_IN_PROJECT=true \
    POETRY_CACHE_DIR=/tmp/poetry_cache \
    PYTHONDONTWRITEBYTECODE=1

# Pull official images first
FROM langgenius/dify-web:latest AS web
FROM langgenius/dify-api:latest AS api

# Final stage
FROM base

# Create users and set up directories
RUN useradd -m -u 1000 user && \
    apt-get update && \
    apt-get install -y postgresql postgresql-contrib curl git gcc python3-dev \
    libgmp-dev libmpfr-dev libmpc-dev nodejs npm && \
    rm -rf /var/lib/apt/lists/* && \
    mkdir -p /var/run/postgresql /var/lib/postgresql/data /app/api /app/web /data/storage && \
    chown -R postgres:postgres /var/run/postgresql /var/lib/postgresql/data && \
    chmod 2777 /var/run/postgresql && \
    chmod 700 /var/lib/postgresql/data && \
    chown -R user:user /app /data

# Initialize PostgreSQL
USER postgres
RUN /usr/lib/postgresql/15/bin/initdb -D /var/lib/postgresql/data && \
    echo "host all  all    0.0.0.0/0  md5" >> /var/lib/postgresql/data/pg_hba.conf && \
    echo "listen_addresses='*'" >> /var/lib/postgresql/data/postgresql.conf

# Switch back to user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Copy application files
WORKDIR /app
COPY --from=web --chown=user:user /app/web /app/web/
COPY --from=api --chown=user:user /app/api /app/api/

# Set up API dependencies
WORKDIR /app/api
COPY --from=api --chown=user /app/api/pyproject.toml /app/api/poetry.lock /app/api/poetry.toml ./
RUN pip install --no-cache-dir "poetry==${POETRY_VERSION}" && \
    poetry install --no-root --no-dev

# Create storage symlink
RUN ln -s /data/storage /app/api/storage

# Copy and set up entrypoint script
COPY --from=api --chown=user:user /entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

# Add all environment variables from the compose file
ENV FLASK_APP=app.py \
    EDITION=SELF_HOSTED \
    DEPLOY_ENV=PRODUCTION \
    MODE=api \
    DB_USERNAME=postgres \
    DB_PASSWORD=difyai123456 \
    DB_HOST=localhost \
    DB_PORT=5432 \
    DB_DATABASE=dify \
    REDIS_HOST=localhost \
    REDIS_PORT=6379 \
    REDIS_PASSWORD=difyai123456 \
    VECTOR_STORE=weaviate \
    MIGRATION_ENABLED=true

EXPOSE 7860 3000

WORKDIR /app

ENTRYPOINT ["/bin/bash", "/app/entrypoint.sh"]