Severian commited on
Commit
073e2d1
·
verified ·
1 Parent(s): d2e32da

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +71 -76
Dockerfile CHANGED
@@ -14,9 +14,6 @@ ENV POETRY_VERSION=1.8.4 \
14
  PORT=7860 \
15
  NODE_ENV=production
16
 
17
- # Create user first (HF Spaces requirement)
18
- RUN useradd -m -u 1000 user
19
-
20
  # Install system dependencies and set up locales
21
  RUN apt-get update && apt-get install -y \
22
  curl \
@@ -114,82 +111,18 @@ http {
114
  }
115
  EOF
116
 
117
- RUN mkdir -p /var/log/nginx && \
118
- chown -R user:user /var/log/nginx && \
 
 
119
  touch /run/nginx.pid && \
120
- chown -R user:user /run/nginx.pid && \
121
- chown -R user:user /var/lib/nginx && \
122
  chmod -R 755 /var/lib/nginx && \
123
- chmod -R 755 /etc/nginx && \
124
- chmod -R 777 /run
125
-
126
- # Set up PostgreSQL directories with standard locations
127
- RUN mkdir -p /var/run/postgresql /var/lib/postgresql/data /var/log/postgresql && \
128
- chown -R user:user /var/run/postgresql /var/lib/postgresql/data /var/log/postgresql && \
129
- chmod 700 /var/lib/postgresql/data
130
-
131
- # Create application directories
132
- RUN mkdir -p /app/api /app/web /data/storage && \
133
- chown -R user:user /app /data && \
134
  chmod 777 /data /app
135
 
136
- # Switch to user for remaining operations
137
- USER user
138
-
139
- # Set environment for user
140
- ENV HOME=/home/user \
141
- PATH=/usr/lib/postgresql/15/bin:/home/user/.local/bin:$PATH \
142
- PGDATA=/var/lib/postgresql/data
143
-
144
- # Pull official images
145
- FROM langgenius/dify-web:latest AS web
146
- FROM langgenius/dify-api:latest AS api
147
-
148
- # Final stage
149
- FROM base
150
-
151
- # Set up directory structure
152
- WORKDIR /app
153
- RUN mkdir -p api web /data/storage
154
-
155
- # Copy from official images
156
- COPY --from=web --chown=user:user /app/web /app/web/
157
- COPY --from=api --chown=user:user /app/api /app/api/
158
-
159
- # Install API dependencies using Poetry
160
- WORKDIR /app/api
161
- COPY --from=api --chown=user /app/api/pyproject.toml /app/api/poetry.lock /app/api/poetry.toml ./
162
- RUN poetry install --no-root --no-dev
163
-
164
- # Create symlink for persistent storage
165
- RUN ln -s /data/storage /app/api/storage
166
-
167
- # Set environment variables
168
- ENV FLASK_APP=app.py \
169
- EDITION=SELF_HOSTED \
170
- DEPLOY_ENV=PRODUCTION \
171
- MODE=api \
172
- LOG_LEVEL=INFO \
173
- DEBUG=false \
174
- FLASK_DEBUG=false \
175
- SECRET_KEY=sk-9f73s3ljTXVcMT3Blb3ljTqtsKiGHXVcMT3BlbkFJLK7U \
176
- CONSOLE_API_URL=https://${SPACE_ID}.hf.space \
177
- CONSOLE_WEB_URL=https://${SPACE_ID}.hf.space \
178
- SERVICE_API_URL=https://${SPACE_ID}.hf.space \
179
- APP_WEB_URL=https://${SPACE_ID}.hf.space \
180
- DIFY_PORT=5001 \
181
- DIFY_BIND_ADDRESS=127.0.0.1 \
182
- DB_USERNAME=user \
183
- DB_PASSWORD=difyai123456 \
184
- DB_HOST=localhost \
185
- DB_PORT=5432 \
186
- DB_DATABASE=dify \
187
- PYTHONPATH=/app/api \
188
- STORAGE_PATH=/data/storage
189
-
190
- EXPOSE 7860
191
-
192
- # Create startup script
193
  COPY <<-'EOT' /app/entrypoint.sh
194
  #!/bin/bash
195
  set -e
@@ -312,7 +245,69 @@ while true; do
312
  done
313
  EOT
314
 
315
- RUN chmod +x /app/entrypoint.sh
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
 
317
  WORKDIR /app
318
 
 
14
  PORT=7860 \
15
  NODE_ENV=production
16
 
 
 
 
17
  # Install system dependencies and set up locales
18
  RUN apt-get update && apt-get install -y \
19
  curl \
 
111
  }
112
  EOF
113
 
114
+ # Set up directories and permissions
115
+ RUN mkdir -p /var/log/nginx /var/run/postgresql /var/lib/postgresql/data /var/log/postgresql /app/api /app/web /data/storage && \
116
+ chown -R root:root /etc/nginx && \
117
+ chmod -R 755 /etc/nginx && \
118
  touch /run/nginx.pid && \
119
+ chown -R root:root /run/nginx.pid && \
 
120
  chmod -R 755 /var/lib/nginx && \
121
+ chmod -R 777 /run && \
122
+ chmod 700 /var/lib/postgresql/data && \
 
 
 
 
 
 
 
 
 
123
  chmod 777 /data /app
124
 
125
+ # Create and configure entrypoint script
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  COPY <<-'EOT' /app/entrypoint.sh
127
  #!/bin/bash
128
  set -e
 
245
  done
246
  EOT
247
 
248
+ # Set permissions for entrypoint script
249
+ RUN chmod +x /app/entrypoint.sh && \
250
+ chown user:user /app/entrypoint.sh
251
+
252
+ # Create user after setting up all files and permissions
253
+ RUN useradd -m -u 1000 user && \
254
+ chown -R user:user /var/run/postgresql /var/lib/postgresql/data /var/log/postgresql /app /data /var/log/nginx
255
+
256
+ # Switch to user for remaining operations
257
+ USER user
258
+
259
+ # Set environment for user
260
+ ENV HOME=/home/user \
261
+ PATH=/usr/lib/postgresql/15/bin:/home/user/.local/bin:$PATH \
262
+ PGDATA=/var/lib/postgresql/data
263
+
264
+ # Pull official images
265
+ FROM langgenius/dify-web:latest AS web
266
+ FROM langgenius/dify-api:latest AS api
267
+
268
+ # Final stage
269
+ FROM base
270
+
271
+ # Set up directory structure
272
+ WORKDIR /app
273
+ RUN mkdir -p api web /data/storage
274
+
275
+ # Copy from official images
276
+ COPY --from=web --chown=user:user /app/web /app/web/
277
+ COPY --from=api --chown=user:user /app/api /app/api/
278
+
279
+ # Install API dependencies using Poetry
280
+ WORKDIR /app/api
281
+ COPY --from=api --chown=user /app/api/pyproject.toml /app/api/poetry.lock /app/api/poetry.toml ./
282
+ RUN poetry install --no-root --no-dev
283
+
284
+ # Create symlink for persistent storage
285
+ RUN ln -s /data/storage /app/api/storage
286
+
287
+ # Set environment variables
288
+ ENV FLASK_APP=app.py \
289
+ EDITION=SELF_HOSTED \
290
+ DEPLOY_ENV=PRODUCTION \
291
+ MODE=api \
292
+ LOG_LEVEL=INFO \
293
+ DEBUG=false \
294
+ FLASK_DEBUG=false \
295
+ SECRET_KEY=sk-9f73s3ljTXVcMT3Blb3ljTqtsKiGHXVcMT3BlbkFJLK7U \
296
+ CONSOLE_API_URL=https://${SPACE_ID}.hf.space \
297
+ CONSOLE_WEB_URL=https://${SPACE_ID}.hf.space \
298
+ SERVICE_API_URL=https://${SPACE_ID}.hf.space \
299
+ APP_WEB_URL=https://${SPACE_ID}.hf.space \
300
+ DIFY_PORT=5001 \
301
+ DIFY_BIND_ADDRESS=127.0.0.1 \
302
+ DB_USERNAME=user \
303
+ DB_PASSWORD=difyai123456 \
304
+ DB_HOST=localhost \
305
+ DB_PORT=5432 \
306
+ DB_DATABASE=dify \
307
+ PYTHONPATH=/app/api \
308
+ STORAGE_PATH=/data/storage
309
+
310
+ EXPOSE 7860
311
 
312
  WORKDIR /app
313