fix: harden CI cargo downloads
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
|
||||
function assertCondition(condition: unknown, message: string, detail: unknown = {}): void {
|
||||
if (!condition) throw new Error(`${message}: ${JSON.stringify(detail)}`);
|
||||
}
|
||||
|
||||
const dockerfile = readFileSync("src/components/backend-core/Dockerfile", "utf8");
|
||||
const d601Pipeline = readFileSync("src/components/microservices/k3sctl-adapter/k3s/ci/unidesk-ci.pipeline.yaml", "utf8");
|
||||
const g14Pipeline = readFileSync("src/components/microservices/k3sctl-adapter/k3s/ci/unidesk-ci.pipeline.g14.yaml", "utf8");
|
||||
|
||||
for (const name of [
|
||||
"CARGO_HTTP_TIMEOUT",
|
||||
"CARGO_HTTP_LOW_SPEED_LIMIT",
|
||||
"CARGO_NET_RETRY",
|
||||
"CARGO_HTTP_MULTIPLEXING",
|
||||
"CARGO_REGISTRIES_CRATES_IO_PROTOCOL",
|
||||
]) {
|
||||
assertCondition(dockerfile.includes(`ARG ${name}=`), `backend-core Dockerfile must accept ${name}`, { name });
|
||||
assertCondition(dockerfile.includes(`${name}=${`$\{${name}\}`}`), `backend-core Dockerfile must export ${name}`, { name });
|
||||
assertCondition(d601Pipeline.includes(`--build-arg ${name}=`), `D601 CI pipeline must pass ${name}`, { name });
|
||||
assertCondition(g14Pipeline.includes(`--build-arg ${name}=`), `G14 CI pipeline must pass ${name}`, { name });
|
||||
}
|
||||
|
||||
assertCondition(
|
||||
dockerfile.includes("CARGO_HTTP_LOW_SPEED_LIMIT=1") && dockerfile.includes("CARGO_HTTP_TIMEOUT=180"),
|
||||
"backend-core Dockerfile must raise Cargo low-speed tolerance for proxied CI builds",
|
||||
dockerfile,
|
||||
);
|
||||
|
||||
console.log(JSON.stringify({
|
||||
ok: true,
|
||||
checks: [
|
||||
"backend-core Dockerfile accepts Cargo HTTP/retry build args",
|
||||
"D601/G14 CI pipelines pass Cargo HTTP/retry build args",
|
||||
"backend-core CI build tolerates slow proxied crates.io downloads",
|
||||
],
|
||||
}));
|
||||
Reference in New Issue
Block a user