From 924f5452d2570ccf8e7cf9dc5c269c4c969a7ecd Mon Sep 17 00:00:00 2001 From: "mula.liu" Date: Sun, 26 Apr 2026 15:27:02 +0800 Subject: [PATCH] v0.1.5 --- bot-images/Dashboard.Dockerfile | 16 ++++++++++++---- bot-images/build.sh | 4 +--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/bot-images/Dashboard.Dockerfile b/bot-images/Dashboard.Dockerfile index 41871ad..b55428e 100644 --- a/bot-images/Dashboard.Dockerfile +++ b/bot-images/Dashboard.Dockerfile @@ -18,13 +18,21 @@ RUN python -m venv /opt/venv WORKDIR /app COPY pyproject.toml README.md LICENSE THIRD_PARTY_NOTICES.md ./ + +# 3. 先安装第三方依赖。该层只依赖 pyproject.toml,源码改动不会触发整套依赖重装。 +RUN --mount=type=cache,target=/root/.cache/pip \ + python -m pip install -i https://mirrors.aliyun.com/pypi/simple/ --upgrade \ + --no-compile pip setuptools wheel aiohttp hatchling && \ + python -c 'import tomllib; data=tomllib.load(open("pyproject.toml","rb")); deps=list(data["project"].get("dependencies", [])); deps.extend(data["project"].get("optional-dependencies", {}).get("wecom", [])); print("\n".join(deps))' > /tmp/requirements.txt && \ + pip install --no-compile -i https://mirrors.aliyun.com/pypi/simple/ -r /tmp/requirements.txt && \ + rm -f /tmp/requirements.txt + COPY nanobot/ nanobot/ COPY bridge/ bridge/ -# 3. 在 builder 中完成 Python 依赖安装,避免源码和编译工具进入最终镜像 -RUN python -m pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --upgrade \ - --no-compile pip setuptools wheel aiohttp && \ - pip install --no-cache-dir --no-compile -i https://mirrors.aliyun.com/pypi/simple/ ".[wecom]" && \ +# 4. 源码层只安装 nanobot 本体,不重复解析/下载第三方依赖。 +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install --no-compile --no-deps --no-build-isolation . && \ find /opt/venv -type d -name __pycache__ -prune -exec rm -rf {} + && \ find /opt/venv -name '*.pyc' -delete diff --git a/bot-images/build.sh b/bot-images/build.sh index dfd5578..0b64f2d 100755 --- a/bot-images/build.sh +++ b/bot-images/build.sh @@ -21,8 +21,6 @@ build_image() { echo ">> [2/3] 拷贝 dashboard.py 到 channels 目录 ..." if [ -d "${BASE_DIR}/${dir_name}/nanobot/channels" ]; then cp "${BASE_DIR}/dashboard.py" "${BASE_DIR}/${dir_name}/nanobot/channels/" - elif [ -d "${BASE_DIR}/${dir_name}/channels" ]; then - cp "${BASE_DIR}/dashboard.py" "${BASE_DIR}/${dir_name}/channels/" else # 兜底创建 nanobot/channels/ mkdir -p "${BASE_DIR}/${dir_name}/nanobot/channels/" @@ -32,7 +30,7 @@ build_image() { # 3. 执行 Docker build echo ">> [3/3] 开始打包 Docker 镜像: ${image_name} ..." cd "${BASE_DIR}/${dir_name}" - docker build -f Dashboard.Dockerfile -t "${image_name}" . + DOCKER_BUILDKIT=1 docker build -f Dashboard.Dockerfile -t "${image_name}" . echo "==================================================" echo "✅ 构建完成: ${image_name}"