leonsimon23 commited on
Commit
9c468e2
·
verified ·
1 Parent(s): 468ae61

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +14 -4
Dockerfile CHANGED
@@ -3,6 +3,7 @@ FROM python:3.11-slim
3
 
4
  WORKDIR /app
5
 
 
6
  RUN apt-get update && apt-get install -y --no-install-recommends \
7
  git \
8
  build-essential \
@@ -10,22 +11,31 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
10
  curl \
11
  && rm -rf /var/lib/apt/lists/*
12
 
 
13
  RUN pip install --upgrade pip
14
 
 
15
  RUN mkdir -p /app && chmod -R 777 /app
16
 
17
- # 使用HF_TOKEN环境变量
18
- ENV HF_TOKEN=${HF_TOKEN}
19
- RUN git clone https://oauth2:${HF_TOKEN}@github.com/leoncool23/magicdoctor_backend.git . || (echo "GIT CLONE FAILED!" && exit 1)
 
 
 
20
 
 
21
  RUN pip install --no-cache-dir -r requirements.txt \
22
- || (echo "PIP INSTALL FAILED!" && exit 1)
23
 
 
24
  ENV FLASK_APP=app/main.py
25
  ENV FLASK_ENV=production
26
  ENV PYTHONPATH=/app
27
  ENV PORT=7860
28
 
 
29
  EXPOSE 7860
30
 
 
31
  CMD ["sh", "-c", "python app/init_db.py && gunicorn --workers 4 --worker-class gevent --timeout 300 --bind 0.0.0.0:7860 'app.main:app'"]
 
3
 
4
  WORKDIR /app
5
 
6
+ # 1. 安装必要的系统工具 (git, curl 等)
7
  RUN apt-get update && apt-get install -y --no-install-recommends \
8
  git \
9
  build-essential \
 
11
  curl \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # 2. 升级 pip
15
  RUN pip install --upgrade pip
16
 
17
+ # 3. 创建并授权工作目录
18
  RUN mkdir -p /app && chmod -R 777 /app
19
 
20
+ # 4. 使用 secret 挂载方式安全地克隆私有仓库
21
+ # - 这是最关键的一步。它会从 /run/secrets/ 中读取 GITHUB_TOKEN
22
+ # - 这种方式非常安全,token 不会出现在任何日志或中间镜像层中
23
+ RUN --mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
24
+ git clone https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@github.com/leoncool23/magicdoctor_backend.git . \
25
+ || (echo "GIT CLONE FAILED! - 请检查 GITHUB_TOKEN 是否正确并有 repo 权限。" && exit 1)
26
 
27
+ # 5. 安装 Python 依赖
28
  RUN pip install --no-cache-dir -r requirements.txt \
29
+ || (echo "PIP INSTALL FAILED! - 请检查 requirements.txt 文件是否正确。" && exit 1)
30
 
31
+ # 6. 设置运行时环境变量
32
  ENV FLASK_APP=app/main.py
33
  ENV FLASK_ENV=production
34
  ENV PYTHONPATH=/app
35
  ENV PORT=7860
36
 
37
+ # 7. 暴露端口
38
  EXPOSE 7860
39
 
40
+ # 8. 启动命令
41
  CMD ["sh", "-c", "python app/init_db.py && gunicorn --workers 4 --worker-class gevent --timeout 300 --bind 0.0.0.0:7860 'app.main:app'"]