Severian commited on
Commit
54e6e52
·
verified ·
1 Parent(s): 6fb5312

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +26 -110
Dockerfile CHANGED
@@ -9,94 +9,55 @@ ENV POETRY_VERSION=1.8.4 \
9
  POETRY_CACHE_DIR=/tmp/poetry_cache \
10
  PYTHONDONTWRITEBYTECODE=1
11
 
12
- # Create users first
13
- RUN useradd -m -u 1000 user
14
-
15
- # Install system dependencies and set up directories
16
- RUN apt-get update && apt-get install -y \
17
- postgresql \
18
- && rm -rf /var/lib/apt/lists/* \
19
- && mkdir -p /var/run/postgresql /var/lib/postgresql/data \
20
- && chown postgres:postgres /var/run/postgresql /var/lib/postgresql/data \
21
- && chmod 2777 /var/run/postgresql \
22
- && chmod 700 /var/lib/postgresql/data
23
 
24
- # Create application directories
25
- RUN mkdir -p /app/api /app/web /data/storage && \
26
- chown -R user:user /app /data && \
27
- chmod 777 /data /app && \
28
- chown -R postgres:postgres /var/lib/postgresql/data && \
29
- chmod 700 /var/lib/postgresql/data
30
 
31
- # Install remaining system dependencies
32
- RUN apt-get update && apt-get install -y \
33
- curl \
34
- git \
35
- gcc \
36
- python3-dev \
37
- libgmp-dev \
38
- libmpfr-dev \
39
- libmpc-dev \
40
- nodejs \
41
- npm \
42
- postgresql \
43
- postgresql-contrib \
44
- && rm -rf /var/lib/apt/lists/* \
45
- && pip install --no-cache-dir "poetry==${POETRY_VERSION}"
46
 
47
- # Initialize PostgreSQL database as postgres user
48
  USER postgres
49
  RUN /usr/lib/postgresql/15/bin/initdb -D /var/lib/postgresql/data && \
50
  echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf && \
51
- echo "listen_addresses='*'" >> /var/lib/postgresql/data/postgresql.conf && \
52
- echo "unix_socket_directories = '/var/run/postgresql'" >> /var/lib/postgresql/data/postgresql.conf
53
 
54
- # Switch to user for remaining operations
55
  USER user
56
-
57
- # Set environment for user
58
  ENV HOME=/home/user \
59
  PATH=/home/user/.local/bin:$PATH
60
 
61
- # Pull official images
62
- FROM langgenius/dify-web:latest AS web
63
- FROM langgenius/dify-api:latest AS api
64
-
65
- # Final stage (continuing from line 32)
66
- FROM base
67
-
68
- # Set up directory structure
69
  WORKDIR /app
70
- RUN mkdir -p api web /data/storage && \
71
- chown -R user:user /app /data
72
-
73
- # Copy from official images with correct ownership
74
  COPY --from=web --chown=user:user /app/web /app/web/
75
  COPY --from=api --chown=user:user /app/api /app/api/
76
 
77
- # Install API dependencies using Poetry
78
  WORKDIR /app/api
79
  COPY --from=api --chown=user /app/api/pyproject.toml /app/api/poetry.lock /app/api/poetry.toml ./
80
- RUN poetry install --no-root --no-dev
 
81
 
82
- # Create symlink for persistent storage
83
  RUN ln -s /data/storage /app/api/storage
84
 
85
- # Set environment variables
86
  ENV FLASK_APP=app.py \
87
  EDITION=SELF_HOSTED \
88
  DEPLOY_ENV=PRODUCTION \
89
  MODE=api \
90
- LOG_LEVEL=INFO \
91
- DEBUG=false \
92
- FLASK_DEBUG=false \
93
- SECRET_KEY=sk-9f73s3ljTXVcMT3Blb3ljTqtsKiGHXVcMT3BlbkFJLK7U \
94
- CONSOLE_API_URL=http://127.0.0.1:7860 \
95
- CONSOLE_WEB_URL=http://127.0.0.1:3000 \
96
- SERVICE_API_URL=http://127.0.0.1:7860 \
97
- APP_WEB_URL=http://127.0.0.1:3000 \
98
- DIFY_PORT=7860 \
99
- DIFY_BIND_ADDRESS=0.0.0.0 \
100
  DB_USERNAME=postgres \
101
  DB_PASSWORD=difyai123456 \
102
  DB_HOST=localhost \
@@ -105,55 +66,10 @@ ENV FLASK_APP=app.py \
105
  REDIS_HOST=localhost \
106
  REDIS_PORT=6379 \
107
  REDIS_PASSWORD=difyai123456 \
108
- CELERY_BROKER_URL=amqp://guest:guest@localhost:5672// \
109
- CELERY_RESULT_BACKEND=redis://localhost:6379/0 \
110
- PYTHONPATH=/app/api \
111
- STORAGE_PATH=/data/storage
112
 
113
  EXPOSE 7860 3000
114
 
115
- # Create startup script with connection retries
116
- RUN echo '#!/bin/bash\n\
117
- echo "===== Application Startup at $(date "+%Y-%m-%d %H:%M:%S") ====="\n\
118
- \n\
119
- # Start PostgreSQL directly as postgres user\n\
120
- su postgres -c "/usr/lib/postgresql/15/bin/pg_ctl -D /var/lib/postgresql/data -l /var/log/postgresql/postgresql.log start"\n\
121
- \n\
122
- max_tries=30\n\
123
- count=0\n\
124
- echo "Checking database connection..."\n\
125
- until PGPASSWORD=$DB_PASSWORD psql -h localhost -p 5432 -U postgres -c "SELECT 1" > /dev/null 2>&1; do\n\
126
- echo "Waiting for database connection..."\n\
127
- sleep 2\n\
128
- count=$((count+1))\n\
129
- if [ $count -gt $max_tries ]; then\n\
130
- echo "Failed to connect to database after $max_tries attempts"\n\
131
- exit 1\n\
132
- fi\n\
133
- done\n\
134
- \n\
135
- # Create database and user if they dont exist\n\
136
- PGPASSWORD=$DB_PASSWORD psql -h localhost -U postgres -c "CREATE DATABASE $DB_DATABASE;" || true\n\
137
- PGPASSWORD=$DB_PASSWORD psql -h localhost -U postgres -c "CREATE USER $DB_USERNAME WITH PASSWORD '\''$DB_PASSWORD'\'';" || true\n\
138
- PGPASSWORD=$DB_PASSWORD psql -h localhost -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE $DB_DATABASE TO $DB_USERNAME;" || true\n\
139
- \n\
140
- echo "Database connection successful"\n\
141
- \n\
142
- # Start application services\n\
143
- cd /app/api && poetry run python -m flask db upgrade\n\
144
- \n\
145
- cd /app/api && poetry run python -m gunicorn app:app \
146
- --bind ${DIFY_BIND_ADDRESS:-0.0.0.0}:${DIFY_PORT:-7860} \
147
- --worker-class gevent \
148
- --workers 1 \
149
- --timeout 300 \
150
- --preload &\n\
151
- \n\
152
- cd /app/web && node server.js &\n\
153
- \n\
154
- wait' > /app/entrypoint.sh && \
155
- chmod +x /app/entrypoint.sh
156
-
157
  WORKDIR /app
158
 
159
  CMD ["./entrypoint.sh"]
 
9
  POETRY_CACHE_DIR=/tmp/poetry_cache \
10
  PYTHONDONTWRITEBYTECODE=1
11
 
12
+ # Pull official images first
13
+ FROM langgenius/dify-web:latest AS web
14
+ FROM langgenius/dify-api:latest AS api
 
 
 
 
 
 
 
 
15
 
16
+ # Final stage
17
+ FROM base
 
 
 
 
18
 
19
+ # Create users and set up directories
20
+ RUN useradd -m -u 1000 user && \
21
+ apt-get update && \
22
+ apt-get install -y postgresql postgresql-contrib curl git gcc python3-dev \
23
+ libgmp-dev libmpfr-dev libmpc-dev nodejs npm && \
24
+ rm -rf /var/lib/apt/lists/* && \
25
+ mkdir -p /var/run/postgresql /var/lib/postgresql/data /app/api /app/web /data/storage && \
26
+ chown -R postgres:postgres /var/run/postgresql /var/lib/postgresql/data && \
27
+ chmod 2777 /var/run/postgresql && \
28
+ chmod 700 /var/lib/postgresql/data && \
29
+ chown -R user:user /app /data
 
 
 
 
30
 
31
+ # Initialize PostgreSQL
32
  USER postgres
33
  RUN /usr/lib/postgresql/15/bin/initdb -D /var/lib/postgresql/data && \
34
  echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf && \
35
+ echo "listen_addresses='*'" >> /var/lib/postgresql/data/postgresql.conf
 
36
 
37
+ # Switch back to user
38
  USER user
 
 
39
  ENV HOME=/home/user \
40
  PATH=/home/user/.local/bin:$PATH
41
 
42
+ # Copy application files
 
 
 
 
 
 
 
43
  WORKDIR /app
 
 
 
 
44
  COPY --from=web --chown=user:user /app/web /app/web/
45
  COPY --from=api --chown=user:user /app/api /app/api/
46
 
47
+ # Set up API dependencies
48
  WORKDIR /app/api
49
  COPY --from=api --chown=user /app/api/pyproject.toml /app/api/poetry.lock /app/api/poetry.toml ./
50
+ RUN pip install --no-cache-dir "poetry==${POETRY_VERSION}" && \
51
+ poetry install --no-root --no-dev
52
 
53
+ # Create storage symlink
54
  RUN ln -s /data/storage /app/api/storage
55
 
56
+ # Add all environment variables from the compose file
57
  ENV FLASK_APP=app.py \
58
  EDITION=SELF_HOSTED \
59
  DEPLOY_ENV=PRODUCTION \
60
  MODE=api \
 
 
 
 
 
 
 
 
 
 
61
  DB_USERNAME=postgres \
62
  DB_PASSWORD=difyai123456 \
63
  DB_HOST=localhost \
 
66
  REDIS_HOST=localhost \
67
  REDIS_PORT=6379 \
68
  REDIS_PASSWORD=difyai123456 \
69
+ VECTOR_STORE=weaviate
 
 
 
70
 
71
  EXPOSE 7860 3000
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  WORKDIR /app
74
 
75
  CMD ["./entrypoint.sh"]