refactor(deploy): make device manager releases declarative

This commit is contained in:
Codex
2026-08-11 10:37:13 +03:00
parent 1adbabefcf
commit 72b4846b32
4 changed files with 546 additions and 110 deletions
@@ -12,7 +12,7 @@ const devicePlaneRoot = resolve(platformRoot, "device-plane");
const designRoot = resolve(process.env.NODEDC_DEVICE_MANAGER_SOURCE_ROOT || resolve(platformRoot, "../NODEDC_DESIGN_GUIDELINE"));
const managerRoot = resolve(designRoot, "apps/device-manager");
const artifactDir = resolve(process.env.NODEDC_DEPLOY_ARTIFACT_DIR || resolve(scriptDir, "../deploy-artifacts"));
const [patchId = "device-manager-control-plane-v3-20260811-005", ...extra] = process.argv.slice(2);
const [patchId = "device-manager-release-20260811-006", ...extra] = process.argv.slice(2);
if (extra.length || !/^[A-Za-z0-9._-]{1,96}$/.test(patchId)) throw new Error("usage: build-device-manager-control-plane-artifact.mjs [patch-id]");
const entries = [
@@ -26,7 +26,7 @@ const entries = [
"services/device-gateway/package.json",
"services/device-edge-relay/package.json",
"services/device-manager",
"deployment/device-manager-control-plane-v3.json",
"deployment/device-manager-release-v1.json",
];
const stage = await mkdtemp(join(tmpdir(), "nodedc-device-manager-control-plane-"));
const payload = join(stage, "payload");
@@ -40,6 +40,17 @@ try {
if (build.status !== 0) throw new Error(`device_manager_build_failed:${build.stderr || build.stdout}`);
await mkdir(payload, { recursive: true });
for (const entry of entries) {
if (entry === "deployment/device-manager-release-v1.json") {
const descriptor = JSON.parse(await readFile(resolve(devicePlaneRoot, entry), "utf8"));
if (descriptor.releaseId !== "__PATCH_ID__") {
throw new Error("device_manager_release_template_id_mismatch");
}
descriptor.releaseId = patchId;
const destination = join(payload, entry);
await mkdir(dirname(destination), { recursive: true });
await writeFile(destination, `${JSON.stringify(descriptor, null, 2)}\n`, "utf8");
continue;
}
if (entry === "services/device-manager") {
const destination = join(payload, entry);
await mkdir(destination, { recursive: true });
@@ -89,16 +100,21 @@ try {
if (compose.includes(forbidden)) throw new Error(`device_manager_compose_boundary_violation:${forbidden}`);
}
const descriptor = JSON.parse(await readFile(
join(payload, "deployment/device-manager-control-plane-v3.json"),
join(payload, "deployment/device-manager-release-v1.json"),
"utf8",
));
const predecessor = descriptor.predecessor;
if (
descriptor.schemaVersion !== "nodedc.device-plane.device-manager-control-plane.v3"
|| descriptor.predecessor?.patchId !== "device-manager-control-plane-v2-reconciliation-20260811-004"
|| descriptor.predecessor?.artifactSha256 !== "09600bfd99717314b43936e17ffaaf6b6fca1f2fd008beddddc68480cdf3d284"
|| descriptor.predecessor?.mode !== "failed-v2-control-plane-baseline-adoption"
descriptor.schemaVersion !== "nodedc.device-plane.device-manager-release.v1"
|| descriptor.releaseId !== patchId
|| !["activate", "upgrade"].includes(descriptor.action)
|| !predecessor
|| !["reconciliation", "release"].includes(predecessor.kind)
|| !/^[A-Za-z0-9._-]{1,96}$/.test(predecessor.patchId || "")
|| !/^[a-f0-9]{64}$/.test(predecessor.artifactSha256 || "")
|| (descriptor.action === "activate") !== (predecessor.kind === "reconciliation")
|| descriptor.healthGate !== "bounded-container-grace+core-contract"
|| descriptor.rollback !== "restore-v2-reconciled-baseline"
|| descriptor.rollback !== "restore-preapply-snapshot"
) throw new Error("device_manager_activation_successor_contract_mismatch");
await writeFile(join(stage, "manifest.env"), `id=${patchId}\ncomponent=device-plane\ntype=app-overlay\n`, "utf8");
await writeFile(join(stage, "files.txt"), `${entries.join("\n")}\n`, "utf8");