feat: add Sub2API image prepull command
Pipelines as Code CI / hwlab-web-probe-sentinel-nc01- Success
Pipelines as Code CI / hwlab-web-probe-sentinel-nc01- Success
This commit is contained in:
@@ -17,6 +17,7 @@ import { fingerprintSecretValues, parseEnvFile, readEnvSourceFile, readTextFile,
|
||||
import { apply, plan, status } from "./actions";
|
||||
import { defaultSub2ApiTargetId, readSub2ApiConfig, validateOptions } from "./config";
|
||||
import { configPath, platformInfraHelp, serviceName } from "./entry";
|
||||
import { imagePrepull } from "./image-prepull";
|
||||
import { isHostDockerTarget, resolveTarget } from "./manifest";
|
||||
import { validate } from "./policy";
|
||||
|
||||
@@ -88,6 +89,11 @@ export async function runPlatformInfraCommand(config: UniDeskConfig, args: strin
|
||||
const result = await apply(config, options);
|
||||
return options.full || options.raw ? result : renderSub2ApiApply(result);
|
||||
}
|
||||
if (action === "image-prepull") {
|
||||
const options = parseApplyOptions(args.slice(2));
|
||||
const result = await imagePrepull(config, options);
|
||||
return options.full || options.raw ? result : renderSub2ApiImagePrepull(result);
|
||||
}
|
||||
if (action === "status") {
|
||||
const options = parseDisclosureOptions(args.slice(2));
|
||||
const result = await status(config, options);
|
||||
@@ -307,6 +313,64 @@ function renderSub2ApiApply(result: Record<string, unknown>): RenderedCliResult
|
||||
return rendered(result, "platform-infra sub2api apply", lines);
|
||||
}
|
||||
|
||||
function renderSub2ApiImagePrepull(result: Record<string, unknown>): RenderedCliResult {
|
||||
const target = record(result.target);
|
||||
const mode = stringValue(result.mode);
|
||||
const targetId = stringValue(target.id, stringValue(result.target));
|
||||
const status = result.ok === false ? "failed" : "ok";
|
||||
const lines = [
|
||||
"PLATFORM-INFRA SUB2API IMAGE PREPULL",
|
||||
...table(["TARGET", "ROUTE", "NAMESPACE", "MODE", "STATUS"], [[targetId, stringValue(target.route), stringValue(target.namespace), mode, status]]),
|
||||
];
|
||||
if (mode === "async-job") {
|
||||
const job = record(result.job);
|
||||
const next = record(result.next);
|
||||
lines.push(
|
||||
"",
|
||||
"JOB",
|
||||
...table(["ID", "STATUS", "COMMAND"], [[stringValue(job.id), stringValue(job.status, "started"), stringValue(result.statusCommand)]]),
|
||||
"",
|
||||
"IMAGES",
|
||||
...table(["IMAGE"], arrayValues(result.images).map((image) => [stringValue(image)])),
|
||||
"",
|
||||
"NEXT",
|
||||
` status: ${stringValue(next.status, stringValue(result.statusCommand))}`,
|
||||
` verify: ${stringValue(next.verify, `bun scripts/cli.ts platform-infra sub2api image-prepull --target ${targetId}`)}`,
|
||||
` apply: ${stringValue(next.apply, `bun scripts/cli.ts platform-infra sub2api apply --target ${targetId} --confirm`)}`,
|
||||
);
|
||||
return rendered(result, "platform-infra sub2api image-prepull", lines);
|
||||
}
|
||||
const remote = record(result.remote);
|
||||
const imageRows = arrayRecords(remote.images).map((item) => [
|
||||
stringValue(item.image),
|
||||
stringValue(item.runtime),
|
||||
boolText(item.presentBefore),
|
||||
boolText(item.presentAfter),
|
||||
stringValue(record(item.pull).exitCode, "-"),
|
||||
stringValue(item.imageId, "-").slice(0, 24),
|
||||
]);
|
||||
const next = record(result.next);
|
||||
lines.push(
|
||||
"",
|
||||
"IMAGES",
|
||||
...(imageRows.length === 0 ? ["-"] : table(["IMAGE", "RUNTIME", "BEFORE", "AFTER", "PULL", "IMAGE_ID"], imageRows)),
|
||||
"",
|
||||
"CHECKS",
|
||||
...table(["CHECK", "VALUE"], [
|
||||
["ok", boolText(result.ok !== false)],
|
||||
["runtime", stringValue(remote.runtime)],
|
||||
["valuesPrinted", "false"],
|
||||
]),
|
||||
"",
|
||||
"NEXT",
|
||||
` apply: ${stringValue(next.apply, `bun scripts/cli.ts platform-infra sub2api apply --target ${targetId} --confirm`)}`,
|
||||
` status: ${stringValue(next.status, `bun scripts/cli.ts platform-infra sub2api status --target ${targetId}`)}`,
|
||||
` full: bun scripts/cli.ts platform-infra sub2api image-prepull --target ${targetId} ${mode === "confirmed" ? "--confirm --wait" : "--dry-run"} --full`,
|
||||
"Disclosure: default output is bounded; Secret values are not printed.",
|
||||
);
|
||||
return rendered(result, "platform-infra sub2api image-prepull", lines);
|
||||
}
|
||||
|
||||
function renderApplyRemoteSummary(remote: Record<string, unknown>): string[] {
|
||||
const steps = record(remote.steps);
|
||||
const stepRows = Object.entries(steps).map(([name, value]) => {
|
||||
|
||||
Reference in New Issue
Block a user