mirror of
https://github.com/andrewyng/openworker.git
synced 2026-11-20 20:37:44 +00:00
Allow developers to easily build AI apps without worrying about the harness part. Bundles the Rust agent runtime as a SDK (Rust and TypeScript) for building desktop and web applications. Applications can manage a local harness or connect to an authenticated harness service on k8s with separately scaled workers and sandbox execution. The implementation is primarily contained in harness/, with deployment tooling in deploy/, Markdown guides in docs/harness/guides/, and the static documentation site in docs-site/. It does not replace the existing Python harness or migrate OpenWorker Desktop. Co-authored-by: Devika Verma <devikaverma11@gmail.com>
93 lines
3.0 KiB
JavaScript
93 lines
3.0 KiB
JavaScript
// Explicit local kind image import. No registry push, default context or image pruning.
|
|
import { spawn } from "node:child_process";
|
|
import { once } from "node:events";
|
|
import { run } from "./local.mjs";
|
|
const [kind, cluster, app, runner] = process.argv.slice(2);
|
|
if (
|
|
!kind ||
|
|
!/^[-a-z0-9]+$/.test(cluster) ||
|
|
![app, runner].every((s) => s && /^[a-zA-Z0-9./_-]+:[a-zA-Z0-9._-]+$/.test(s))
|
|
)
|
|
throw Error(
|
|
"Usage: node load-images.mjs /path/to/kind CLUSTER APP:TAG RUNNER:TAG",
|
|
);
|
|
const nodes = (await run(kind, ["get", "nodes", "--name", cluster]))
|
|
.trim()
|
|
.split("\n");
|
|
if (!nodes.length || nodes.some((n) => !n.startsWith(cluster + "-")))
|
|
throw Error("Unexpected kind node inventory");
|
|
const refs = [];
|
|
let platform;
|
|
const canonical = (tag) =>
|
|
!tag.includes("/")
|
|
? "docker.io/library/" + tag
|
|
: /[.:]/.test(tag.split("/")[0]) || tag.startsWith("localhost/")
|
|
? tag
|
|
: "docker.io/" + tag;
|
|
for (const tag of [app, runner]) {
|
|
const [meta] = JSON.parse(await run("docker", ["image", "inspect", tag]));
|
|
if (!/^sha256:[a-f0-9]{64}$/.test(meta.Id) || meta.Os !== "linux")
|
|
throw Error("Expected Linux content-addressed image");
|
|
const p = "linux/" + meta.Architecture;
|
|
if (platform && platform !== p)
|
|
throw Error("App and runner CPU architecture differ");
|
|
platform = p;
|
|
}
|
|
for (const node of nodes) {
|
|
const save = spawn("docker", ["image", "save", app, runner], {
|
|
stdio: ["ignore", "pipe", "inherit"],
|
|
});
|
|
const load = spawn(
|
|
"docker",
|
|
[
|
|
"exec",
|
|
"-i",
|
|
node,
|
|
"ctr",
|
|
"-n",
|
|
"k8s.io",
|
|
"images",
|
|
"import",
|
|
"--platform",
|
|
platform,
|
|
"--digests",
|
|
"-",
|
|
],
|
|
{ stdio: ["pipe", "ignore", "inherit"] },
|
|
);
|
|
save.stdout.pipe(load.stdin);
|
|
load.stdin.on("error", () => {});
|
|
const codes = await Promise.all([once(save, "exit"), once(load, "exit")]);
|
|
if (codes.some(([c]) => c !== 0)) throw Error("Image import failed");
|
|
const inventory = (
|
|
await run("docker", ["exec", node, "ctr", "-n", "k8s.io", "images", "list"])
|
|
)
|
|
.split("\n")
|
|
.map((line) => line.trim().split(/\s+/));
|
|
for (const [i, tag] of [app, runner].entries()) {
|
|
const source = canonical(tag),
|
|
digest = inventory.find((fields) => fields[0] === source)?.[2];
|
|
if (!/^sha256:[a-f0-9]{64}$/.test(digest || ""))
|
|
throw Error("Imported manifest digest unavailable");
|
|
const target = source.slice(0, source.lastIndexOf(":")) + "@" + digest;
|
|
if (refs[i] && refs[i] !== target)
|
|
throw Error("Node image manifests differ");
|
|
refs[i] = target;
|
|
if (!inventory.some((fields) => fields[0] === target))
|
|
await run("docker", [
|
|
"exec",
|
|
node,
|
|
"ctr",
|
|
"-n",
|
|
"k8s.io",
|
|
"images",
|
|
"tag",
|
|
source,
|
|
target,
|
|
]);
|
|
else if (inventory.find((fields) => fields[0] === target)[2] !== digest)
|
|
throw Error("Existing digest reference conflicts");
|
|
}
|
|
}
|
|
console.log(JSON.stringify({ image: refs[0], runnerImage: refs[1] }, null, 2));
|