build(deploy): package Hub service trust UI

This commit is contained in:
Codex
2026-08-10 23:31:02 +03:00
parent 0679142561
commit 4374a9b4e7
2 changed files with 96 additions and 0 deletions
@@ -0,0 +1,80 @@
#!/usr/bin/env node
import { createHash } from "node:crypto";
import { spawnSync } from "node:child_process";
import { cp, lstat, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const scriptDir = dirname(fileURLToPath(import.meta.url));
const launcherRoot = resolve(process.env.NODEDC_LAUNCHER_REPO || resolve(scriptDir, "../../../../data/nodedc_launcher"));
const artifactDir = resolve(process.env.NODEDC_DEPLOY_ARTIFACT_DIR || resolve(scriptDir, "../deploy-artifacts"));
const [patchId = "launcher-hub-service-trust-ui-20260810-001", ...extra] = process.argv.slice(2);
if (extra.length || !/^[A-Za-z0-9._-]{1,96}$/.test(patchId)) {
throw new Error("usage: build-launcher-hub-service-trust-ui-artifact.mjs [patch-id]");
}
const entries = [
"src/app/LauncherApp.tsx",
"src/styles/globals.css",
"src/widgets/admin-overlay/AdminOverlay.tsx",
];
const stage = await mkdtemp(join(tmpdir(), "nodedc-launcher-hub-service-trust-ui-"));
const payload = join(stage, "payload");
const target = join(artifactDir, `nodedc-launcher-${patchId}.tgz`);
try {
await mkdir(payload, { recursive: true });
for (const entry of entries) {
const source = resolve(launcherRoot, entry);
const sourceStat = await lstat(source);
if (!sourceStat.isFile() || sourceStat.isSymbolicLink()) throw new Error(`launcher_source_rejected:${entry}`);
const destination = join(payload, entry);
await mkdir(dirname(destination), { recursive: true });
await cp(source, destination, { force: true });
}
const app = await readFile(join(payload, "src/app/LauncherApp.tsx"), "utf8");
const overlay = await readFile(join(payload, "src/widgets/admin-overlay/AdminOverlay.tsx"), "utf8");
const styles = await readFile(join(payload, "src/styles/globals.css"), "utf8");
for (const required of ["upsertAdminGrant", 'targetType: "client"', "pendingClientGrantAssignments"]) {
if (!app.includes(required)) throw new Error(`launcher_hub_grant_contract_missing:${required}`);
}
for (const required of ["authentikGroupName", "authHandoffPath", "onSetClientServiceGrant"]) {
if (!overlay.includes(required)) throw new Error(`launcher_hub_service_trust_contract_missing:${required}`);
}
if (!styles.includes(".client-service-grants")) throw new Error("launcher_hub_service_trust_style_missing");
await writeFile(join(stage, "manifest.env"), `id=${patchId}\ncomponent=launcher\ntype=app-overlay\n`, "utf8");
await writeFile(join(stage, "files.txt"), `${entries.join("\n")}\n`, "utf8");
await mkdir(artifactDir, { recursive: true });
const tar = spawnSync("python3", ["-c", canonicalTarScript(), target, stage], { encoding: "utf8" });
if (tar.status !== 0) throw new Error(`tar_failed:${tar.stderr || tar.stdout}`);
const sha256 = createHash("sha256").update(await readFile(target)).digest("hex");
console.log(JSON.stringify({
ok: true,
patchId,
component: "launcher",
artifact: target,
sha256,
entries,
services: ["launcher"],
}, null, 2));
} finally {
await rm(stage, { recursive: true, force: true });
}
function canonicalTarScript() {
return [
"import gzip,io,pathlib,sys,tarfile",
"root=pathlib.Path(sys.argv[2])",
"with open(sys.argv[1],'wb') as out:",
" with gzip.GzipFile(filename='',mode='wb',fileobj=out,compresslevel=9,mtime=0) as gz:",
" with tarfile.open(fileobj=gz,mode='w',format=tarfile.PAX_FORMAT) as tar:",
" for top in ('manifest.env','files.txt','payload'):",
" p=root/top; paths=[p]+(sorted(p.rglob('*')) if p.is_dir() else [])",
" for x in paths:",
" info=tar.gettarinfo(str(x),arcname=x.relative_to(root).as_posix()); info.uid=info.gid=0; info.uname=info.gname='root'; info.mtime=0; info.mode=0o755 if info.isdir() else 0o644",
" with (open(x,'rb') if info.isfile() else io.BytesIO()) as src: tar.addfile(info,src if info.isfile() else None)",
].join("\n");
}
@@ -29,6 +29,11 @@ def load_runner():
RUNNER = load_runner()
LAUNCHER_HUB_SERVICE_TRUST_UI_ENTRIES = (
"src/app/LauncherApp.tsx",
"src/styles/globals.css",
"src/widgets/admin-overlay/AdminOverlay.tsx",
)
def healthy_device_plane_inventory():
@@ -120,6 +125,17 @@ class DeviceManagerControlPlaneArtifactsTest(unittest.TestCase):
self.assertEqual(len(RUNNER.component_builds("launcher", entries)), 1)
self.assertEqual(result["services"], ["launcher"])
def test_launcher_hub_service_trust_ui_artifact_is_exact(self):
manifest, entries, _names, result = self.assert_deterministic_artifact(
"build-launcher-hub-service-trust-ui-artifact.mjs",
"launcher-hub-service-trust-ui-unit-001",
LAUNCHER_HUB_SERVICE_TRUST_UI_ENTRIES,
)
self.assertEqual(manifest["component"], "launcher")
self.assertEqual(RUNNER.component_services("launcher", entries), ("launcher",))
self.assertEqual(len(RUNNER.component_builds("launcher", entries)), 1)
self.assertEqual(result["services"], ["launcher"])
def test_device_manager_artifact_selects_only_core_and_manager(self):
manifest, entries, names, result = self.assert_deterministic_artifact(
"build-device-manager-control-plane-artifact.mjs",