Spaces:
Sleeping
Sleeping
Create Dockerfile
Browse files- Dockerfile +35 -0
Dockerfile
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# 从Hugging Face Secrets中获取GitHub用户名和PAT
|
12 |
+
# 注意:URL路径中的 'leoncool23/Ducg_ModelCreate' 是硬编码的,必须与您的仓库完全匹配
|
13 |
+
RUN --mount=type=secret,id=GH_USERNAME \
|
14 |
+
--mount=type=secret,id=GH_TOKEN \
|
15 |
+
git clone https://$(cat /run/secrets/GH_USERNAME):$(cat /run/secrets/GH_TOKEN)@github.com/leoncool23/ducg_form_editor.git .
|
16 |
+
|
17 |
+
# --- 新增步骤:创建并授权持久化存储目录 ---
|
18 |
+
# 这是为了让应用能够写入和修改模型文件
|
19 |
+
RUN mkdir -p /data && chown -R 1000:1000 /data
|
20 |
+
|
21 |
+
# --- 设置Python环境 ---
|
22 |
+
# 安装Python依赖
|
23 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
24 |
+
|
25 |
+
# 安装Gunicorn用于生产环境
|
26 |
+
RUN pip install gunicorn
|
27 |
+
|
28 |
+
# --- 运行应用 ---
|
29 |
+
# 暴露端口 (Hugging Face Spaces默认使用7860)
|
30 |
+
EXPOSE 7860
|
31 |
+
|
32 |
+
# 启动应用的命令
|
33 |
+
# app:app 指的是在 app.py 文件中名为 app 的Flask实例
|
34 |
+
# --timeout 120 增加超时时间,以防复杂操作中断
|
35 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "120", "app:app"]
|