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

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +11 -15
Dockerfile CHANGED
@@ -1,35 +1,31 @@
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
- # 设置非root用户
10
- RUN useradd -m appuser
11
- USER appuser
12
  WORKDIR /app
13
 
14
- # 通过环境变量注入GitHub Token(自动由Space secrets提供)
15
- ENV GITHUB_TOKEN=""
16
-
17
- # 克隆私有仓库并立即清理
18
  RUN git clone https://${GITHUB_TOKEN}@github.com/luoh-an/luoh-api.git && \
19
  cd luoh-api && \
20
  rm -rf .git && \
21
  find . -type d -name "__pycache__" -exec rm -rf {} + && \
22
  find . -type f -name "*.pyc" -delete
23
 
24
- # 设置项目目录
 
 
 
 
25
  WORKDIR /app/luoh-api
26
 
27
- # 安装Python依赖(优化缓存机制)
28
- COPY --chown=appuser requirements.txt .
29
  RUN pip install --user --no-cache-dir -r requirements.txt
30
 
31
- # 暴露Space默认端口
32
  EXPOSE 7860
33
-
34
- # 启动命令
35
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "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
+ # 创建应用目录(保持默认用户以正确执行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
 
 
31
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]