leonsimon23 commited on
Commit
18428ee
·
verified ·
1 Parent(s): 393a9bf

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +24 -20
Dockerfile CHANGED
@@ -1,30 +1,34 @@
1
- # 使用一个轻量级的 Python 镜像作为基础
2
  FROM python:3.9-slim
3
 
4
- # 安装 git,以便克隆仓库
5
- RUN apt-get update && apt-get install -y git
6
-
7
  # 设置工作目录
8
  WORKDIR /app
9
 
10
- # 声明构建参数,Hugging Face 会自动将 secrets 注入进来
11
- ARG GH_USER
12
- ARG GH_TOKEN
13
-
14
- # 声明私有仓库的URL
15
- ARG REPO_URL="https://github.com/leoncool23/DUCG_Modeler.git"
16
-
17
- # 使用 secrets 克隆私有仓库
18
- # --depth 1 表示只克隆最新的 commit,加快构建速度
19
- RUN git clone https://${GH_USER}:${GH_TOKEN}@${REPO_URL#https://} . --depth 1
20
-
21
- # 安装 Python 依赖
 
 
 
 
 
22
  RUN pip install --no-cache-dir -r requirements.txt
23
 
24
- # 暴露 Hugging Face Space 期望的端口
 
25
  EXPOSE 7860
26
 
27
- # 运行 gunicorn 服务器,使其监听所有网络接口
28
- # --workers 1 适用于小型应用
29
- # --bind 0.0.0.0:7860 是Hugging Face的要求
 
30
  CMD ["gunicorn", "--workers", "1", "--bind", "0.0.0.0:7860", "app:app"]
 
1
+ # 使用官方Python 3.9 slim镜像
2
  FROM python:3.9-slim
3
 
 
 
 
4
  # 设置工作目录
5
  WORKDIR /app
6
 
7
+ # --- 1. 准备工作:安装git ---
8
+ # 更新包列表并安装git,--no-install-recommends 避免安装不必要的包
9
+ RUN apt-get update && apt-get install -y --no-install-recommends git
10
+
11
+ # --- 2. 关键步骤:使用现代的、安全的 secrets 挂载方式克隆私有仓库 ---
12
+ # 请确保您的 Hugging Face Space Secrets 的名字与这里的 id 完全匹配。
13
+ # id=GH_USER 对应名为 GH_USER 的 secret。
14
+ # id=GH_TOKEN 对应名为 GH_TOKEN 的 secret。
15
+ #
16
+ # !! 重要 !!
17
+ # 请将下面的 'leoncool23/ducg-modeler-app.git' 替换为您自己的 GitHub 用户名和仓库名。
18
+ RUN --mount=type=secret,id=GH_USER \
19
+ --mount=type=secret,id=GH_TOKEN \
20
+ git clone https://$(cat /run/secrets/GH_USER):$(cat /run/secrets/GH_TOKEN)@github.com/leoncool23/DUCG_Modeler.git .
21
+
22
+ # --- 3. 设置Python环境 ---
23
+ # 安装 requirements.txt 文件中定义的所有依赖
24
  RUN pip install --no-cache-dir -r requirements.txt
25
 
26
+ # --- 4. 运行应用 ---
27
+ # 暴露 Hugging Face Spaces 期望的标准端口 7860
28
  EXPOSE 7860
29
 
30
+ # 使用 gunicorn 启动 Flask 应用。
31
+ # gunicorn 是一个生产级的 WSGI 服务器,比 Flask 自带的开发服务器更稳定。
32
+ # "--bind", "0.0.0.0:7860" 使应用可以从外部访问。
33
+ # "app:app" 指的是运行 app.py 文件中的 app 实例。
34
  CMD ["gunicorn", "--workers", "1", "--bind", "0.0.0.0:7860", "app:app"]