perf: Docker 构建使用清华镜像源并启用 BuildKit pip 缓存挂载,大幅加速重复构建
This commit is contained in:
@ -10,3 +10,23 @@ uploads
|
|||||||
pgdata
|
pgdata
|
||||||
.env
|
.env
|
||||||
simhei.ttf
|
simhei.ttf
|
||||||
|
|
||||||
|
# ---- 补充排除项 ----
|
||||||
|
# Windows 残留空文件
|
||||||
|
nul
|
||||||
|
# 数据库备份文件(避免打进镜像/context)
|
||||||
|
*.dump
|
||||||
|
*.sql.gz
|
||||||
|
*.tar.gz
|
||||||
|
*.gz
|
||||||
|
*.log
|
||||||
|
# 数据库迁移脚本(运行时用 volume 挂载宿主机,镜像内不需要)
|
||||||
|
db_migrations
|
||||||
|
# 测试脚本与缓存
|
||||||
|
test_*.py
|
||||||
|
tests
|
||||||
|
.pytest_cache
|
||||||
|
.coverage
|
||||||
|
# 运维修复脚本(宿主机保留,无需进镜像)
|
||||||
|
fix_*.py
|
||||||
|
fix_*.sql
|
||||||
|
|||||||
@ -5,9 +5,12 @@ WORKDIR /app
|
|||||||
|
|
||||||
# 1. 复制依赖并安装
|
# 1. 复制依赖并安装
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
# 安装依赖 + gunicorn
|
# 安装依赖 + gunicorn(清华镜像源 + BuildKit 缓存挂载)
|
||||||
RUN pip install --no-cache-dir -r requirements.txt && \
|
# ★ 关键优化:pip 下载的 wheel 会缓存在宿主 /root/.cache/pip,
|
||||||
pip install --no-cache-dir gunicorn
|
# 只要 requirements.txt 不变,重复构建不再重新下载(首次约100s,之后秒级)
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
|
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt && \
|
||||||
|
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple gunicorn
|
||||||
|
|
||||||
# 2. 复制后端代码
|
# 2. 复制后端代码
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|||||||
Reference in New Issue
Block a user