From 85130db6ea3dc7c87819cdddd311c95479078545 Mon Sep 17 00:00:00 2001 From: yueli Date: Wed, 2 Sep 2026 18:39:09 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20Docker=20=E6=9E=84=E5=BB=BA=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=B8=85=E5=8D=8E=E9=95=9C=E5=83=8F=E6=BA=90=E5=B9=B6?= =?UTF-8?q?=E5=90=AF=E7=94=A8=20BuildKit=20pip=20=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=8C=82=E8=BD=BD=EF=BC=8C=E5=A4=A7=E5=B9=85=E5=8A=A0=E9=80=9F?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inventory-backend/.dockerignore | 20 ++++++++++++++++++++ inventory-backend/Dockerfile | 9 ++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/inventory-backend/.dockerignore b/inventory-backend/.dockerignore index 4f7f6f2..c038fa9 100644 --- a/inventory-backend/.dockerignore +++ b/inventory-backend/.dockerignore @@ -10,3 +10,23 @@ uploads pgdata .env 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 diff --git a/inventory-backend/Dockerfile b/inventory-backend/Dockerfile index 5b9ec6a..0d1bdc3 100644 --- a/inventory-backend/Dockerfile +++ b/inventory-backend/Dockerfile @@ -5,9 +5,12 @@ WORKDIR /app # 1. 复制依赖并安装 COPY requirements.txt . -# 安装依赖 + gunicorn -RUN pip install --no-cache-dir -r requirements.txt && \ - pip install --no-cache-dir gunicorn +# 安装依赖 + gunicorn(清华镜像源 + BuildKit 缓存挂载) +# ★ 关键优化:pip 下载的 wheel 会缓存在宿主 /root/.cache/pip, +# 只要 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. 复制后端代码 COPY . .