Update Dockerfile
Browse files- 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 |
-
#
|
| 10 |
WORKDIR /app
|
| 11 |
-
|
| 12 |
-
# 克隆私有仓库(使用Space的secret注入)
|
| 13 |
ARG GITHUB_TOKEN
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
#
|
| 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
|