From 1a2df120af95dd519e73eb09a019798baa119c1b Mon Sep 17 00:00:00 2001 From: zetaloop Date: Fri, 24 Apr 2026 08:16:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20bake=20=E6=96=87=E4=BB=B6=E5=86=99?= =?UTF-8?q?=E5=85=A5=E9=A1=B9=E7=9B=AE=E6=A0=B9=E7=9B=AE=E5=BD=95=E4=BB=A5?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20buildx=20context=20=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bake JSON 原先写入系统临时目录,buildx 默认以 bake 文件所在目录作为 构建 context,导致 COPY . . 复制空目录,go build 命中旧的 mount cache 产出旧二进制,源码变更后镜像内容不变。改为写入项目根目录的 .bake.json。 --- .gitignore | 5 ++++- deploy/dev/build.py | 10 ++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index a42f474..e93c2f3 100644 --- a/.gitignore +++ b/.gitignore @@ -125,4 +125,7 @@ DockerFile # Go compiled binaries app/*/api/api app/*/rpc/rpc -app/*/mq/mq \ No newline at end of file +app/*/mq/mq + +# Build artifacts +.bake.json \ No newline at end of file diff --git a/deploy/dev/build.py b/deploy/dev/build.py index 441b80c..b6361cf 100644 --- a/deploy/dev/build.py +++ b/deploy/dev/build.py @@ -5,7 +5,6 @@ import json import os import subprocess import sys -import tempfile from glob import glob from pathlib import Path @@ -100,21 +99,20 @@ def main(): "target": targets, } - fd, bakefile = tempfile.mkstemp(prefix="juwan-bake-", suffix=".json") + bakefile = ROOT_DIR / ".bake.json" try: - with os.fdopen(fd, "w") as f: - json.dump(bake, f, indent=2) + bakefile.write_text(json.dumps(bake, indent=2)) print(f"Generated {len(targets)} targets -> {bakefile}") names = list(targets.keys()) for i in range(0, len(names), BAKE_BATCH_SIZE): batch = names[i : i + BAKE_BATCH_SIZE] subprocess.run( - ["docker", "buildx", "bake", "--load", "-f", bakefile, *batch], + ["docker", "buildx", "bake", "--load", "-f", str(bakefile), *batch], check=True, ) finally: - os.unlink(bakefile) + bakefile.unlink(missing_ok=True) main()