leonsimon23 commited on
Commit
b7e4633
·
verified ·
1 Parent(s): 946dea3

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +32 -0
Dockerfile ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用官方Python 3.9 slim镜像
2
+ FROM python:3.9-slim
3
+
4
+ # 设置工作目录
5
+ WORKDIR /app
6
+
7
+ # --- 准备工作:安装git ---
8
+ RUN apt-get update && apt-get install -y --no-install-recommends git
9
+
10
+ # --- 关键步骤:使用PAT克隆私有仓库 ---
11
+ # 1. 从Hugging Face Secrets中获取GitHub用户名和PAT
12
+ # 这两个Secrets将在Hugging Face界面上设置
13
+ # --mount=type=secret... 允许我们在构建时安全地访问这些Secrets
14
+ # 我们将用户名和PAT写入临时文件
15
+ RUN --mount=type=secret,id=GH_USERNAME \
16
+ --mount=type=secret,id=GH_TOKEN \
17
+ git clone https://$(cat /run/secrets/GH_USERNAME):$(cat /run/secrets/GH_TOKEN)@github.com/YOUR_USERNAME/YOUR_REPO_NAME.git .
18
+
19
+ # --- 设置Python环境 ---
20
+ # 1. 安装Python依赖
21
+ # 这里的 requirements.txt 已经在git clone后存在于工作目录中
22
+ RUN pip install --no-cache-dir -r requirements.txt
23
+
24
+ # 2. 安装Gunicorn用于生产环境
25
+ RUN pip install gunicorn
26
+
27
+ # --- 运行应用 ---
28
+ # 暴露端口 (Hugging Face Spaces通常使用7860)
29
+ EXPOSE 7860
30
+
31
+ # 启动应用的命令
32
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]