fix: allow ci benchmark to disable buildkit cache

This commit is contained in:
lyon
2026-06-26 19:39:09 +08:00
parent f94e2c13a2
commit 36e863bd1b
2 changed files with 39 additions and 15 deletions
+30 -10
View File
@@ -35,6 +35,7 @@ const buildBackend = "buildkit";
const v02EnvReuseRuntimeMode = "env-reuse-git-mirror-checkout";
const defaultBuildkitCommand = process.env.HWLAB_BUILDKIT_BUILDCTL || "buildctl-daemonless.sh";
const defaultBuildkitAddr = process.env.HWLAB_BUILDKIT_ADDR || null;
const defaultBuildCacheMode = process.env.HWLAB_BUILDKIT_CACHE_MODE || "registry";
const defaultCatalogPath = process.env.HWLAB_ARTIFACT_CATALOG_PATH || "deploy/artifact-catalog.dev.json";
const defaultDeployPath = process.env.HWLAB_DEPLOY_MANIFEST_PATH || "deploy/deploy.yaml";
@@ -86,6 +87,7 @@ function parseArgs(argv) {
buildBackend,
buildkitCommand: defaultBuildkitCommand,
buildkitAddr: defaultBuildkitAddr,
buildCacheMode: defaultBuildCacheMode,
externalServiceReportDir: null,
externalServiceResultsEnv: false,
ciPlanPath: null,
@@ -114,6 +116,7 @@ function parseArgs(argv) {
else if (arg === "--affected-only") args.affectedOnly = true;
else if (arg === "--buildkit-command") args.buildkitCommand = readOption(argv, ++index, arg);
else if (arg === "--buildkit-addr") args.buildkitAddr = readOption(argv, ++index, arg);
else if (arg === "--build-cache-mode") args.buildCacheMode = readOption(argv, ++index, arg);
else if (arg === "--external-service-report-dir") args.externalServiceReportDir = readOption(argv, ++index, arg);
else if (arg === "--external-service-results-env") args.externalServiceResultsEnv = true;
else if (arg === "--ci-plan-path") args.ciPlanPath = readOption(argv, ++index, arg);
@@ -127,6 +130,7 @@ function parseArgs(argv) {
assert.ok(args.lane === "node" || isRuntimeArtifactLane(args.lane), `unknown artifact lane ${args.lane}`);
assert.ok(["short", "full"].includes(args.imageTagMode), `unknown image tag mode ${args.imageTagMode}`);
assert.ok(["registry", "disabled"].includes(args.buildCacheMode), `unknown build cache mode ${args.buildCacheMode}`);
return args;
}
@@ -211,6 +215,7 @@ function printHelp() {
" --affected-only default and only supported scope: build/publish affected services and reuse unchanged catalog digests",
" --buildkit-command PATH buildctl-daemonless.sh/buildctl command for buildkit backend",
" --buildkit-addr ADDR optional buildctl --addr endpoint for a sidecar BuildKit daemon",
" --build-cache-mode MODE registry or disabled; default: registry",
" --external-service-report-dir DIR collect affected service artifacts from per-service publish reports",
" --external-service-results-env collect service artifacts from HWLAB_SERVICE_RESULT_* env vars",
" --ci-plan-path PATH reuse plan-artifacts JSON to scope external service reports",
@@ -476,6 +481,20 @@ function buildkitRegistryOption(registryPrefix) {
: "";
}
function buildkitCacheArgs(args, cacheRef, registryOption) {
if (args.buildCacheMode === "disabled") return [];
return [
"--import-cache", `type=registry,ref=${cacheRef}${registryOption}`,
"--export-cache", `type=registry,ref=${cacheRef},mode=max${registryOption}`
];
}
function buildkitCacheEvidence(args, cacheRef) {
return args.buildCacheMode === "disabled"
? { buildkitCacheMode: "disabled" }
: { buildkitCacheMode: "registry", buildkitCacheRef: cacheRef };
}
function buildkitDigestFromMetadata(value) {
const keys = [
"containerimage.digest",
@@ -1318,8 +1337,7 @@ async function buildEnvReuseServiceWithBuildkit({ args, service, ref, buildCreat
"--local", `dockerfile=${tmpDir}`,
"--opt", "filename=Dockerfile",
"--metadata-file", metadataPath,
"--import-cache", `type=registry,ref=${cacheRef}${registryOption}`,
"--export-cache", `type=registry,ref=${cacheRef},mode=max${registryOption}`,
...buildkitCacheArgs(args, cacheRef, registryOption),
"--output", `type=image,name=${ref},push=true${registryOption}`
];
if (!args.quietBuild || ciTimingEnabled()) argsList.push("--progress", "plain");
@@ -1348,7 +1366,7 @@ async function buildEnvReuseServiceWithBuildkit({ args, service, ref, buildCreat
}),
logTail: tailText(`${result.stdout}\n${result.stderr}`, 12000),
buildBackend: "buildkit-env-reuse",
buildkitCacheRef: cacheRef,
...buildkitCacheEvidence(args, cacheRef),
buildkitBuildDurationMs: result.durationMs
};
}
@@ -1374,7 +1392,7 @@ async function buildEnvReuseServiceWithBuildkit({ args, service, ref, buildCreat
}),
pushLogTail: tailText(`${result.stdout}\n${result.stderr}`, 1200),
buildBackend: "buildkit-env-reuse",
buildkitCacheRef: cacheRef,
...buildkitCacheEvidence(args, cacheRef),
buildkitBuildDurationMs: Date.now() - startedAt
};
}
@@ -1388,7 +1406,7 @@ async function buildEnvReuseServiceWithBuildkit({ args, service, ref, buildCreat
digest,
repositoryDigest: `${repositoryFromImageRef(ref)}@${digest}`,
buildBackend: "buildkit-env-reuse",
buildkitCacheRef: cacheRef,
...buildkitCacheEvidence(args, cacheRef),
buildkitBuildDurationMs: Date.now() - startedAt,
publishDurationMs: args.mode === "publish" ? Date.now() - startedAt : null,
pushLogTail: tailText(`${result.stdout}\n${result.stderr}`, 1200)
@@ -1462,8 +1480,7 @@ async function buildServiceWithBuildkit({ args, service, ref, tag, buildCreatedA
"--local", `dockerfile=${tmpDir}`,
"--opt", "filename=Dockerfile",
"--metadata-file", metadataPath,
"--import-cache", `type=registry,ref=${cacheRef}${registryOption}`,
"--export-cache", `type=registry,ref=${cacheRef},mode=max${registryOption}`,
...buildkitCacheArgs(args, cacheRef, registryOption),
"--output", `type=image,name=${ref},push=true${registryOption}`
];
if (!args.quietBuild || ciTimingEnabled()) argsList.push("--progress", "plain");
@@ -1494,7 +1511,7 @@ async function buildServiceWithBuildkit({ args, service, ref, tag, buildCreatedA
}),
logTail: tailText(`${result.stdout}\n${result.stderr}`, 12000),
buildBackend: "buildkit",
buildkitCacheRef: cacheRef,
...buildkitCacheEvidence(args, cacheRef),
buildkitBuildDurationMs: result.durationMs
};
}
@@ -1521,7 +1538,7 @@ async function buildServiceWithBuildkit({ args, service, ref, tag, buildCreatedA
}),
pushLogTail: tailText(`${result.stdout}\n${result.stderr}`, 1200),
buildBackend: "buildkit",
buildkitCacheRef: cacheRef,
...buildkitCacheEvidence(args, cacheRef),
buildkitBuildDurationMs: Date.now() - startedAt
};
}
@@ -1536,7 +1553,7 @@ async function buildServiceWithBuildkit({ args, service, ref, tag, buildCreatedA
digest,
repositoryDigest: `${repositoryFromImageRef(ref)}@${digest}`,
buildBackend: "buildkit",
buildkitCacheRef: cacheRef,
...buildkitCacheEvidence(args, cacheRef),
buildkitBuildDurationMs: Date.now() - startedAt,
publishDurationMs: args.mode === "publish" ? Date.now() - startedAt : null,
pushLogTail: tailText(`${result.stdout}\n${result.stderr}`, 1200)
@@ -2214,6 +2231,7 @@ function createReport({ args, repo, commitId, shortCommit, mode, services, artif
buildBackend: args.buildBackend,
buildkitCommand: args.buildkitCommand,
buildkitAddr: args.buildkitAddr ?? null,
buildCacheMode: args.buildCacheMode,
producer,
registryCapabilities: summarizeRegistryCapabilities(registryCapabilities),
baseImage: args.baseImage ?? null,
@@ -2264,6 +2282,7 @@ function createReport({ args, repo, commitId, shortCommit, mode, services, artif
localImageId: artifact.localImageId,
buildkitBuildDurationMs: artifact.buildkitBuildDurationMs ?? null,
buildBackend: artifact.buildBackend ?? args.buildBackend,
buildkitCacheMode: artifact.buildkitCacheMode ?? args.buildCacheMode,
buildkitCacheRef: artifact.buildkitCacheRef ?? null,
cloudWebBuildDurationMs: artifact.cloudWebBuildDurationMs ?? null,
publishDurationMs: artifact.publishDurationMs ?? null,
@@ -2499,6 +2518,7 @@ async function main() {
distFreshness: service.distFreshness,
buildkitBuildDurationMs: service.buildkitBuildDurationMs,
buildBackend: service.buildBackend,
buildkitCacheMode: service.buildkitCacheMode,
buildkitCacheRef: service.buildkitCacheRef,
cloudWebBuildDurationMs: service.cloudWebBuildDurationMs,
publishDurationMs: service.publishDurationMs,
+9 -5
View File
@@ -2206,7 +2206,7 @@ if [ "$buildkit_ready" != "1" ]; then
echo '{"event":"buildkit-sidecar-not-ready","serviceId":"'"$(params.service-id)"'","addr":"'"$HWLAB_BUILDKIT_ADDR"'"}' >&2
exit 1
fi
HWLAB_CI_PLAN_VERIFY_REUSE_REGISTRY=1 node scripts/artifact-publish.mjs --publish --lane "$(params.lane)" --catalog-path "$(params.catalog-path)" --deploy-config deploy/deploy.yaml --image-tag-mode "$(params.image-tag-mode)" --registry-prefix "$(params.registry-prefix)" --report "/workspace/source/service-results/$(params.service-id).json" --tekton-results-dir /tekton/results --quiet-build --concurrency 1 --services "$(params.service-id)" --buildkit-command /workspace/buildkit-bin/buildctl --buildkit-addr "$HWLAB_BUILDKIT_ADDR"
HWLAB_CI_PLAN_VERIFY_REUSE_REGISTRY=1 node scripts/artifact-publish.mjs --publish --lane "$(params.lane)" --catalog-path "$(params.catalog-path)" --deploy-config deploy/deploy.yaml --image-tag-mode "$(params.image-tag-mode)" --registry-prefix "$(params.registry-prefix)" --report "/workspace/source/service-results/$(params.service-id).json" --tekton-results-dir /tekton/results --quiet-build --concurrency 1 --services "$(params.service-id)" --buildkit-command /workspace/buildkit-bin/buildctl --buildkit-addr "$HWLAB_BUILDKIT_ADDR" --build-cache-mode "$(params.build-cache-mode)"
`;
}
@@ -3138,7 +3138,8 @@ function perServiceBuildTask(serviceId, { runAfter = ["plan-artifacts"] } = {})
{ name: "image-tag-mode" },
{ name: "registry-prefix" },
{ name: "service-id" },
{ name: "base-image" }
{ name: "base-image" },
{ name: "build-cache-mode" }
],
results: serviceResultFields.map((field) => ({ name: field, description: `${serviceId} ${field}` })),
workspaces: [{ name: "source" }],
@@ -3163,7 +3164,8 @@ function perServiceBuildTask(serviceId, { runAfter = ["plan-artifacts"] } = {})
{ name: "image-tag-mode", value: "$(params.image-tag-mode)" },
{ name: "registry-prefix", value: "$(params.registry-prefix)" },
{ name: "service-id", value: serviceId },
{ name: "base-image", value: "$(params.base-image)" }
{ name: "base-image", value: "$(params.base-image)" },
{ name: "build-cache-mode", value: "$(params.build-cache-mode)" }
]
};
}
@@ -3545,7 +3547,8 @@ function tektonPipeline(args = { lane: "node" }, deploy = null) {
{ name: "revision", type: "string", description: "Full git commit SHA; the only source truth for image tags." },
{ name: "registry-prefix", type: "string", default: defaultRegistryPrefix },
{ name: "services", type: "string", default: servicesParamForLane(args.lane, deploy) },
{ name: "base-image", type: "string", default: defaultDevBaseImage }
{ name: "base-image", type: "string", default: defaultDevBaseImage },
{ name: "build-cache-mode", type: "string", default: "registry" }
],
workspaces: [
{ name: "source" },
@@ -3674,7 +3677,8 @@ function tektonPipelineRunTemplate({ source, args }) {
{ name: "runtime-path", value: runtimePath },
{ name: "revision", value: source.full },
{ name: "registry-prefix", value: args.registryPrefix },
{ name: "base-image", value: defaultDevBaseImage }
{ name: "base-image", value: defaultDevBaseImage },
{ name: "build-cache-mode", value: "registry" }
],
workspaces: [
{ name: "source", volumeClaimTemplate: { spec: { accessModes: ["ReadWriteOnce"], resources: { requests: { storage: "8Gi" } } } } },