Spaces:
Sleeping
Sleeping
Download Dockerfile from leonsimon23/difybackend: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/spaces/leonsimon23/difybackend/resolve/main/Dockerfile
- Command line
-
hf download hf://spaces/leonsimon23/difybackend/Dockerfile
-
curl -L -o Dockerfile https://huggingface.co/spaces/leonsimon23/difybackend/resolve/main/Dockerfile
1.35 kB
| # 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"] |