File size: 1,353 Bytes
d57b5f1
 
 
 
 
e0e7e31
 
 
 
 
 
 
fb4526d
d57b5f1
 
fb4526d
d57b5f1
bdfd3b6
 
d57b5f1
fb4526d
 
 
 
e0e7e31
d57b5f1
 
e0e7e31
bdfd3b6
 
 
8b51ca2
ef7d63e
 
e0e7e31
 
 
 
 
 
bdfd3b6
e0e7e31
d57b5f1
 
e0e7e31
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# syntax=docker/dockerfile:1.4
FROM python:3.11-slim

WORKDIR /app

# 1. 安装git和其他必要工具
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    git \
    curl \
    && rm -rf /var/lib/apt/lists/*

# 2. 升级pip
RUN pip install --upgrade pip

# 3. 使用secret挂载方式安全地克隆私有仓库
RUN --mount=type=secret,id=GITHUB_TOKEN,required=true \
    git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/leoncool23/difybackend.git . \
    && chmod -R 777 /app

# 4. 创建应用目录下的会话目录并设置权限
RUN mkdir -p /app/flask_session && \
    chmod 777 /app/flask_session

# 5. 安装Python依赖
RUN pip install --no-cache-dir -r requirements.txt

# 6. 设置环境变量
ENV FLASK_APP=app.py
ENV FLASK_ENV=production
ENV PORT=7860
ENV SESSION_DIR=/app/flask_session
# Dify API endpoint 默认值(可以在 Hugging Face Space 设置中覆盖)
ENV DIFY_API_ENDPOINT=https://api.dify.ai/v1
# Gunicorn 配置
ENV GUNICORN_CMD_ARGS="--workers=4 --timeout=120 --keep-alive=120 --log-level=info --access-logfile=- --error-logfile=- --capture-output"

# 7. 健康检查
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:7860/ || exit 1

# 8. 暴露端口
EXPOSE 7860

# 9. 启动命令
CMD ["gunicorn", "app:app"]