Pommsn commited on
Commit
007df08
·
verified ·
1 Parent(s): 5b80172

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +61 -16
Dockerfile CHANGED
@@ -1,28 +1,73 @@
1
- # 1. ดึงไฟล์หน้าเว็บ
2
- FROM langgenius/dify-web:latest AS web-assets
3
 
4
- # 2. ใช้ฐานเป็น API
5
- FROM langgenius/dify-api:latest
 
 
6
 
7
- # ⚠️ จุดแก้สำคัญ: เพิ่ม 'redis-server' ลงไปใน apt-get install
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  USER root
9
  RUN apt-get update && apt-get install -y \
10
- nginx \
11
  redis-server \
12
- nodejs \
13
- npm \
 
 
 
14
  && rm -rf /var/lib/apt/lists/*
15
 
16
- # ตั้งค่าภาษา
17
- ENV LANG C.UTF-8
18
- ENV LC_ALL C.UTF-8
19
 
20
- # ก๊อปปี้ไฟล์ต่างๆ
21
- COPY --from=web-assets /app/web /app/web
22
  COPY nginx.conf /etc/nginx/nginx.conf
23
  COPY start.sh /app/start.sh
 
 
24
  RUN chmod +x /app/start.sh
25
 
26
- # เข้าทำงานที่โฟลเดอร์ API
27
- WORKDIR /app/api
28
- ENTRYPOINT ["/bin/bash", "/app/start.sh"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
  COPY start.sh /app/start.sh
43
+
44
+ # Make start script executable
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
53
+ ENV MODE=api
54
+ ENV LOG_LEVEL=INFO
55
+ ENV FLASK_DEBUG=false
56
+ ENV DEBUG=false
57
+ 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"]