Pikilap commited on
Commit
e85e91a
·
verified ·
1 Parent(s): d0246ac

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +13 -11
Dockerfile CHANGED
@@ -1,30 +1,32 @@
1
  # 使用官方Python镜像
2
  FROM python:3.9-slim
3
 
4
- # 安装系统依赖(必须放在用户创建前)
5
  RUN apt-get update && \
6
  apt-get install -y --no-install-recommends git && \
7
  rm -rf /var/lib/apt/lists/*
8
 
9
- # 创建应用目录(保持默认用户以正确执行Git操作)
10
  WORKDIR /app
11
-
12
- # 克隆私有仓库(使用Space的secret注入)
13
  ARG GITHUB_TOKEN
14
- RUN git clone https://${GITHUB_TOKEN}@github.com/luoh-an/luoh-api.git && \
 
 
 
15
  cd luoh-api && \
16
  rm -rf .git && \
17
  find . -type d -name "__pycache__" -exec rm -rf {} + && \
18
- find . -type f -name "*.pyc" -delete
 
 
 
 
19
 
20
- # 设置非root用户(必须在复制文件前执行)
21
  RUN useradd -m appuser && chown -R appuser:appuser /app
22
  USER appuser
23
 
24
- # 设置工作目录
25
- WORKDIR /app/luoh-api
26
-
27
- # 安装Python依赖(使用仓库内的requirements.txt)
28
  RUN pip install --user --no-cache-dir -r requirements.txt
29
 
30
  EXPOSE 7860
 
1
  # 使用官方Python镜像
2
  FROM python:3.9-slim
3
 
4
+ # 第一阶段:系统准备
5
  RUN apt-get update && \
6
  apt-get install -y --no-install-recommends git && \
7
  rm -rf /var/lib/apt/lists/*
8
 
9
+ # 第二阶段:安全克隆
10
  WORKDIR /app
 
 
11
  ARG GITHUB_TOKEN
12
+
13
+ # 使用GitHub App Token认证(推荐)
14
+ RUN git config --global url."https://api:${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/" && \
15
+ git clone https://github.com/luoh-an/luoh-api.git && \
16
  cd luoh-api && \
17
  rm -rf .git && \
18
  find . -type d -name "__pycache__" -exec rm -rf {} + && \
19
+ find . -type f -name "*.pyc" -delete && \
20
+ git config --global --unset url."https://github.com/".insteadOf
21
+
22
+ # 第三阶段:应用设置
23
+ WORKDIR /app/luoh-api
24
 
25
+ # 使用非root用户
26
  RUN useradd -m appuser && chown -R appuser:appuser /app
27
  USER appuser
28
 
29
+ # 安装依赖
 
 
 
30
  RUN pip install --user --no-cache-dir -r requirements.txt
31
 
32
  EXPOSE 7860