From 9e972f2b61aa838a08fb97b96b3bfb45fd218594 Mon Sep 17 00:00:00 2001 From: zqlit Date: Sun, 4 Oct 2026 13:07:31 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E4=BF=AE=20CNB=20docker=20build=20?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=EF=BC=88by=20=E5=BF=85=E9=A1=BB?= =?UTF-8?q?=E5=88=97=E5=87=BA=20bin/linux/hugo=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 首跑失败在镜像构建: COPY bin/linux/hugo /usr/local/bin/hugo ERROR: failed to compute cache key ... "bin/linux/hugo": not found 根因(CNB 官方文档原文):docker build 的构建上下文里「只包含 Dockerfile 和 by 声明的文件」,未出现在 by 列表中的文件在构建时一律视为不存在。 原配置 by:[package.json] 既漏了 hugo 二进制,又列了个 Dockerfile 根本 没 COPY 的 package.json。 改为 by: [bin/linux/hugo] / versionBy: [bin/linux/hugo]。 --- .cnb.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.cnb.yml b/.cnb.yml index 72f7ebdb..3fae26e0 100644 --- a/.cnb.yml +++ b/.cnb.yml @@ -240,11 +240,15 @@ main: - name: 构建并发布(境内外双线路) runner: cpus: 4 # 4 核 8G;160 核时/月 → 约 240 次 + # ★ CNB 的 docker build 上下文「只含 Dockerfile + by 列出的文件」, + # 未列入的一律视为不存在(官方原文)。Dockerfile 要 COPY bin/linux/hugo, + # 故必须写进 by。漏掉会报: + # failed to compute cache key ... "bin/linux/hugo": not found docker: build: dockerfile: deploy/Dockerfile - by: [package.json] - versionBy: [package-lock.json] + by: [bin/linux/hugo] + versionBy: [bin/linux/hugo] imports: - https://cnb.cool/zqlit/blog-secrets/-/blob/main/secrets.yml lock: # 对应原 concurrency.cancel-in-progress @@ -261,11 +265,15 @@ main: - name: 定时构建(每天 09:00) runner: cpus: 4 + # ★ CNB 的 docker build 上下文「只含 Dockerfile + by 列出的文件」, + # 未列入的一律视为不存在(官方原文)。Dockerfile 要 COPY bin/linux/hugo, + # 故必须写进 by。漏掉会报: + # failed to compute cache key ... "bin/linux/hugo": not found docker: build: dockerfile: deploy/Dockerfile - by: [package.json] - versionBy: [package-lock.json] + by: [bin/linux/hugo] + versionBy: [bin/linux/hugo] imports: - https://cnb.cool/zqlit/blog-secrets/-/blob/main/secrets.yml lock: