Pikilap commited on
Commit
3f6532a
·
verified ·
1 Parent(s): edde402

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +10 -10
Dockerfile CHANGED
@@ -1,29 +1,29 @@
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
- # 必须使用构建参数传递Token
10
- ARG GITHUB_TOKEN
11
 
12
- # 直接使用Token克隆(需处理特殊字符)
13
- RUN git clone "https://$(echo ${GITHUB_TOKEN} | sed 's/@/%40/g')@github.com/luoh-an/luoh-api.git" && \
 
14
  cd luoh-api && \
15
  rm -rf .git && \
16
  find . -type d -name "__pycache__" -exec rm -rf {} + && \
17
  find . -type f -name "*.pyc" -delete
18
 
19
- # 第二阶段:应用设置
20
- WORKDIR /app/luoh-api
21
-
22
- # 使用非root用户
23
  RUN useradd -m appuser && chown -R appuser:appuser /app
24
  USER appuser
25
 
26
  # 安装依赖
 
27
  RUN pip install --user --no-cache-dir -r requirements.txt
28
 
 
29
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # syntax=docker/dockerfile:1.4
2
  FROM python:3.9-slim
3
 
4
+ # 安装 Git
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
 
12
+ # 使用 BuildKit 的安全凭证传递(关键修复)
13
+ RUN --mount=type=secret,id=GITHUB_TOKEN \
14
+ git clone "https://x-access-token:$(cat /run/secrets/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
  RUN pip install --user --no-cache-dir -r requirements.txt
27
 
28
+ EXPOSE 7860
29
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]