leonsimon23 commited on
Commit
e0e7e31
·
verified ·
1 Parent(s): af8fdad

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +25 -10
Dockerfile CHANGED
@@ -3,29 +3,44 @@ FROM python:3.11-slim
3
 
4
  WORKDIR /app
5
 
6
- # 1. 安装git
7
- RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
8
-
9
- # 2. 升级pip
 
 
 
 
 
 
 
 
10
  RUN pip install --upgrade pip
11
 
12
- # 3. 使用secret挂载方式安全地克隆私有仓库
13
  RUN --mount=type=secret,id=GITHUB_TOKEN,required=true \
14
  git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/leoncool23/difybackend.git . \
15
  && chmod -R 777 /app
16
 
17
- # 4. 安装Python依赖
18
  RUN pip install --no-cache-dir -r requirements.txt
19
 
20
- # 5. 设置环境变量
21
  ENV FLASK_APP=app.py
22
  ENV FLASK_ENV=production
23
  ENV PORT=7860
 
24
  # Dify API endpoint 默认值(可以在 Hugging Face Space 设置中覆盖)
25
  ENV DIFY_API_ENDPOINT=https://api.dify.ai/v1
 
 
 
 
 
 
26
 
27
- # 6. 暴露端口
28
  EXPOSE 7860
29
 
30
- # 7. 启动命令
31
- CMD ["gunicorn", "--workers", "4", "--bind", "0.0.0.0:7860", "app:app"]
 
3
 
4
  WORKDIR /app
5
 
6
+ # 1. 安装git和其他必要工具
7
+ RUN apt-get update && \
8
+ apt-get install -y --no-install-recommends \
9
+ git \
10
+ curl \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
+ # 2. 创建持久的会话目录并设置权限
14
+ RUN mkdir -p /data/flask_session && \
15
+ chmod 777 /data/flask_session
16
+
17
+ # 3. 升级pip
18
  RUN pip install --upgrade pip
19
 
20
+ # 4. 使用secret挂载方式安全地克隆私有仓库
21
  RUN --mount=type=secret,id=GITHUB_TOKEN,required=true \
22
  git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/leoncool23/difybackend.git . \
23
  && chmod -R 777 /app
24
 
25
+ # 5. 安装Python依赖
26
  RUN pip install --no-cache-dir -r requirements.txt
27
 
28
+ # 6. 设置环境变量
29
  ENV FLASK_APP=app.py
30
  ENV FLASK_ENV=production
31
  ENV PORT=7860
32
+ ENV SESSION_DIR=/data/flask_session
33
  # Dify API endpoint 默认值(可以在 Hugging Face Space 设置中覆盖)
34
  ENV DIFY_API_ENDPOINT=https://api.dify.ai/v1
35
+ # Gunicorn 配置
36
+ ENV GUNICORN_CMD_ARGS="--workers=4 --timeout=120 --keep-alive=120 --log-level=info --access-logfile=- --error-logfile=- --capture-output"
37
+
38
+ # 7. 健康检查
39
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
40
+ CMD curl -f http://localhost:7860/ || exit 1
41
 
42
+ # 8. 暴露端口
43
  EXPOSE 7860
44
 
45
+ # 9. 启动命令
46
+ CMD ["gunicorn", "app:app"]