fix: bake 文件写入项目根目录以修复 buildx context 缓存问题
bake JSON 原先写入系统临时目录,buildx 默认以 bake 文件所在目录作为 构建 context,导致 COPY . . 复制空目录,go build 命中旧的 mount cache 产出旧二进制,源码变更后镜像内容不变。改为写入项目根目录的 .bake.json。
This commit is contained in:
@@ -126,3 +126,6 @@ DockerFile
|
||||
app/*/api/api
|
||||
app/*/rpc/rpc
|
||||
app/*/mq/mq
|
||||
|
||||
# Build artifacts
|
||||
.bake.json
|
||||
+4
-6
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user