Pommsn commited on
Commit
54d9852
·
verified ·
1 Parent(s): fe19868

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +16 -32
Dockerfile CHANGED
@@ -1,41 +1,26 @@
1
- # Dify All-in-One Dockerfile for Hugging Face Spaces
2
- # Combines API + Web + Redis + Nginx in a single container
3
 
4
- # ============================================
5
- # Stage 1: Build Web Frontend
6
- # ============================================
7
- FROM node:20-alpine AS web-builder
8
 
9
- WORKDIR /app/web
10
-
11
- # Clone Dify Web
12
- RUN apk add --no-cache git && \
13
- git clone --depth 1 --branch 0.15.3 https://github.com/langgenius/dify.git /tmp/dify && \
14
- cp -r /tmp/dify/web/* . && \
15
- rm -rf /tmp/dify
16
-
17
- # Install dependencies and build
18
- RUN npm install --legacy-peer-deps && \
19
- npm run build
20
-
21
- # ============================================
22
- # Stage 2: Final Image
23
- # ============================================
24
  FROM langgenius/dify-api:0.15.3
25
 
26
- # Install Redis, Nginx, Node.js, and other dependencies
27
  USER root
 
 
28
  RUN apt-get update && apt-get install -y \
29
  redis-server \
30
  nginx \
 
 
31
  curl \
32
- && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
33
- && apt-get install -y nodejs \
34
  && apt-get clean \
35
  && rm -rf /var/lib/apt/lists/*
36
 
37
- # Copy Web build from Stage 1
38
- COPY --from=web-builder /app/web /app/web
39
 
40
  # Copy configuration files
41
  COPY nginx.conf /etc/nginx/nginx.conf
@@ -45,8 +30,8 @@ COPY start.sh /app/start.sh
45
  RUN chmod +x /app/start.sh
46
 
47
  # Create directories and set permissions
48
- RUN mkdir -p /app/api/storage /var/log/nginx /var/lib/nginx /run && \
49
- chown -R 1000:1000 /app /var/log/nginx /var/lib/nginx /run /etc/nginx
50
 
51
  # Environment variables
52
  ENV PORT=7860
@@ -58,16 +43,15 @@ ENV STORAGE_TYPE=local
58
  ENV STORAGE_LOCAL_PATH=/app/api/storage
59
  ENV GUNICORN_TIMEOUT=360
60
 
61
- # Expose Hugging Face Spaces port
62
  EXPOSE 7860
63
 
64
  # Health check
65
  HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \
66
- CMD curl -f http://localhost:7860/health || curl -f http://localhost:7860/ || exit 1
67
 
68
- # Switch to non-root user (required by HF Spaces)
69
  USER 1000
70
 
71
- # Start all services
72
  WORKDIR /app
73
  CMD ["/bin/bash", "/app/start.sh"]
 
1
+ # Dify All-in-One for Hugging Face Spaces
2
+ # Uses pre-built images to avoid OOM during build
3
 
4
+ FROM langgenius/dify-api:0.15.3 AS api
5
+ FROM langgenius/dify-web:0.15.3 AS web
 
 
6
 
7
+ # Final image based on API
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  FROM langgenius/dify-api:0.15.3
9
 
 
10
  USER root
11
+
12
+ # Install Redis, Nginx only (Node.js comes with web files)
13
  RUN apt-get update && apt-get install -y \
14
  redis-server \
15
  nginx \
16
+ nodejs \
17
+ npm \
18
  curl \
 
 
19
  && apt-get clean \
20
  && rm -rf /var/lib/apt/lists/*
21
 
22
+ # Copy pre-built web from official image
23
+ COPY --from=web /app/web /app/web
24
 
25
  # Copy configuration files
26
  COPY nginx.conf /etc/nginx/nginx.conf
 
30
  RUN chmod +x /app/start.sh
31
 
32
  # Create directories and set permissions
33
+ RUN mkdir -p /app/api/storage /var/log/nginx /var/lib/nginx /run /var/cache/nginx && \
34
+ chown -R 1000:1000 /app /var/log/nginx /var/lib/nginx /run /var/cache/nginx /etc/nginx
35
 
36
  # Environment variables
37
  ENV PORT=7860
 
43
  ENV STORAGE_LOCAL_PATH=/app/api/storage
44
  ENV GUNICORN_TIMEOUT=360
45
 
46
+ # Expose HF Spaces port
47
  EXPOSE 7860
48
 
49
  # Health check
50
  HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \
51
+ CMD curl -f http://localhost:7860/ || exit 1
52
 
53
+ # Switch to non-root user
54
  USER 1000
55
 
 
56
  WORKDIR /app
57
  CMD ["/bin/bash", "/app/start.sh"]