@parcha/agentrun-computer 0.1.0-beta.34 → 0.1.0-beta.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +251 -46
- package/box/Dockerfile +3 -1
- package/box/agentrun-archil +59 -7
- package/box/build-daytona.py +20 -4
- package/dist/browser.d.ts +73 -23
- package/dist/browser.js +141 -17
- package/dist/browserbase.d.ts +48 -25
- package/dist/browserbase.js +176 -29
- package/dist/chrome.d.ts +3 -4
- package/dist/chrome.js +6 -11
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/conformance/browserbase.js +1 -1
- package/dist/conformance/cases/provider.js +78 -3
- package/dist/conformance/daytona.d.ts +4 -0
- package/dist/conformance/daytona.js +7 -1
- package/dist/conformance/e2b.js +2 -1
- package/dist/conformance/fixture.js +24 -2
- package/dist/conformance/kernel.js +1 -1
- package/dist/conformance/kind.js +2 -1
- package/dist/conformance/{local.d.ts → local-chrome.d.ts} +7 -7
- package/dist/conformance/{local.js → local-chrome.js} +11 -11
- package/dist/conformance/orgo.d.ts +11 -5
- package/dist/conformance/orgo.js +37 -8
- package/dist/conformance/phone-harness.js +2 -1
- package/dist/conformance/report.js +3 -2
- package/dist/conformance/runner.js +25 -7
- package/dist/conformance/types.d.ts +21 -8
- package/dist/conformance/types.js +10 -0
- package/dist/conformance/windows-fixture.d.ts +1 -0
- package/dist/conformance/windows-fixture.js +37 -0
- package/dist/daytona.d.ts +16 -35
- package/dist/daytona.js +87 -95
- package/dist/descriptor.d.ts +116 -0
- package/dist/descriptor.js +92 -0
- package/dist/descriptors/browserbase.d.ts +25 -0
- package/dist/descriptors/browserbase.js +20 -0
- package/dist/descriptors/daytona.d.ts +83 -0
- package/dist/descriptors/daytona.js +81 -0
- package/dist/descriptors/docker.d.ts +12 -0
- package/dist/descriptors/docker.js +17 -0
- package/dist/descriptors/e2b.d.ts +22 -0
- package/dist/descriptors/e2b.js +19 -0
- package/dist/descriptors/index.d.ts +256 -0
- package/dist/descriptors/index.js +19 -0
- package/dist/descriptors/kernel.d.ts +21 -0
- package/dist/descriptors/kernel.js +17 -0
- package/dist/descriptors/local-chrome.d.ts +17 -0
- package/dist/descriptors/local-chrome.js +21 -0
- package/dist/descriptors/modal.d.ts +54 -0
- package/dist/descriptors/modal.js +48 -0
- package/dist/descriptors/orgo.d.ts +99 -0
- package/dist/descriptors/orgo.js +49 -0
- package/dist/descriptors/phone-harness.d.ts +33 -0
- package/dist/descriptors/phone-harness.js +23 -0
- package/dist/descriptors/shared.d.ts +7 -0
- package/dist/descriptors/shared.js +6 -0
- package/dist/desktop.d.ts +4 -4
- package/dist/desktop.js +4 -4
- package/dist/docker/egress.d.ts +5 -4
- package/dist/docker/egress.js +7 -6
- package/dist/docker/image.js +17 -15
- package/dist/docker/inspect.d.ts +147 -0
- package/dist/docker/inspect.js +335 -0
- package/dist/docker.d.ts +6 -6
- package/dist/docker.js +53 -47
- package/dist/drift.d.ts +3 -145
- package/dist/drift.js +5 -334
- package/dist/e2b.d.ts +2 -8
- package/dist/e2b.js +17 -23
- package/dist/index.d.ts +9 -12
- package/dist/index.js +14 -12
- package/dist/isolation.js +2 -2
- package/dist/janitor.d.ts +20 -2
- package/dist/janitor.js +67 -19
- package/dist/kernel.d.ts +19 -29
- package/dist/kernel.js +110 -32
- package/dist/kinds.d.ts +59 -34
- package/dist/kinds.js +19 -117
- package/dist/labels.d.ts +20 -0
- package/dist/labels.js +62 -1
- package/dist/{local.d.ts → local-chrome.d.ts} +8 -9
- package/dist/{local.js → local-chrome.js} +26 -19
- package/dist/local-supervisor.d.ts +3 -3
- package/dist/local-supervisor.js +3 -3
- package/dist/modal.d.ts +6 -25
- package/dist/modal.js +86 -88
- package/dist/mount-archil.d.ts +25 -3
- package/dist/mount-archil.js +43 -12
- package/dist/orgo-channel.js +16 -13
- package/dist/orgo-desktop.d.ts +162 -0
- package/dist/orgo-desktop.js +1856 -0
- package/dist/orgo-names.d.ts +178 -0
- package/dist/orgo-names.js +287 -0
- package/dist/orgo.d.ts +34 -20
- package/dist/orgo.js +424 -173
- package/dist/phone-harness.d.ts +7 -12
- package/dist/phone-harness.js +70 -54
- package/dist/protocol.d.ts +5 -0
- package/dist/provider.d.ts +153 -10
- package/dist/provider.js +48 -1
- package/dist/providers.d.ts +23 -24
- package/dist/providers.js +14 -17
- package/dist/result.d.ts +11 -1
- package/dist/result.js +11 -0
- package/dist/test-connection.js +2 -2
- package/package.json +42 -2
package/dist/docker.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// The Docker provisioner: every call through the docker CLI with execFile or spawn, never a shell.
|
|
2
|
-
// and the inspect reading follow pi-transport's Docker box.
|
|
1
|
+
// The Docker provisioner: every call through the docker CLI with execFile or spawn, never a shell.
|
|
3
2
|
import { execFile, spawn } from "node:child_process";
|
|
4
3
|
import { randomBytes } from "node:crypto";
|
|
5
4
|
import { readFileSync, statSync } from "node:fs";
|
|
@@ -8,8 +7,10 @@ import { setTimeout as sleep } from "node:timers/promises";
|
|
|
8
7
|
import { fileURLToPath } from "node:url";
|
|
9
8
|
import { DaemonClient } from "./client.js";
|
|
10
9
|
import { daemonCopy, defaultDaemonCache } from "./daemon-copy.js";
|
|
10
|
+
import { DOCKER } from "./descriptors/docker.js";
|
|
11
11
|
import { DESKTOP_GROUPS, desktopOf, startDisplay } from "./desktop.js";
|
|
12
|
-
import { COMPUTER_LABEL,
|
|
12
|
+
import { COMPUTER_LABEL, DAEMON_IN_COMPUTER, DEADLINE_LABEL, DEFAULT_CPUS, DEFAULT_MEMORY_MB, DEFAULT_PIDS, helloDrift, WORK, } from "./drift.js";
|
|
13
|
+
import { CPU_PERIOD_US, DAEMON_DIR_IN_COMPUTER, drift, egressShaped, hostOf, inspectDrift, mountOf, networkOf, samePolicy, tmpfsOf, } from "./docker/inspect.js";
|
|
13
14
|
import { DOCKER_RECIPE, ensureImage, imageSourceProblem } from "./docker/image.js";
|
|
14
15
|
import { ALLOW_PORTS, allowOf, containerSigns, EGRESS_IMAGE, EGRESS_LABEL, EGRESS_MOUNT, EGRESS_READY_MS, EGRESS_SOCKET, egressCode, egressCodeProblem, egressNameOf, egressRunArgs, egressVolumeArgs, hostAddresses, MAX_ALLOW, policyWords, RELAY_FLAG, } from "./docker/egress.js";
|
|
15
16
|
import { daemonStage, daemonVerified, egressStage, egressStaged } from "./docker/stage.js";
|
|
@@ -17,19 +18,16 @@ import { EGRESS_READY } from "./docker/egress-proxy.js";
|
|
|
17
18
|
import { OLD_ENGINE, outsideWords, subpathOf, VOLUME_SUBPATH_ENGINE, volumeMount, volumeOf } from "./docker/volume.js";
|
|
18
19
|
import { addressBytes } from "./docker/egress-table.js";
|
|
19
20
|
import { checkMount, WORKSPACE } from "./mount.js";
|
|
20
|
-
import { checkGpu,
|
|
21
|
-
import {
|
|
21
|
+
import { checkGpu, checkTenure, runLifetimeMs, } from "./provider.js";
|
|
22
|
+
import { failFor, ok, vendorFail } from "./result.js";
|
|
22
23
|
import { daemonWatch } from "./screen-watch.js";
|
|
23
24
|
import { countTested } from "./test-connection.js";
|
|
25
|
+
/** This module's failures: one with code vendor names Docker. */
|
|
26
|
+
const fail = failFor("docker");
|
|
24
27
|
/** The mount kinds a Docker computer takes, as capabilities().mount declares them: a bind of a folder on this host. */
|
|
25
|
-
export const MOUNT =
|
|
26
|
-
/** The
|
|
27
|
-
export const
|
|
28
|
-
/** The machine kind and groups of each configuration: a linux computer, and one made with the desktop option. */
|
|
29
|
-
export const CAPABILITIES = [
|
|
30
|
-
{ kind: "linux", groups: ["exec", "files", "processes"] },
|
|
31
|
-
{ kind: "desktop", groups: ["exec", "files", "processes", ...DESKTOP_GROUPS] },
|
|
32
|
-
];
|
|
28
|
+
export const MOUNT = DOCKER.mounts;
|
|
29
|
+
/** The machine kind and groups of each configuration (its descriptor's): a linux computer, and a desktop. */
|
|
30
|
+
export const CAPABILITIES = DOCKER.capabilities;
|
|
33
31
|
/**
|
|
34
32
|
* Docker's architecture as `docker version` reports it (amd64, arm64), within timeoutMs, or an error in words. The docker
|
|
35
33
|
* CLI runs with this process's environment, as every call of the provider does, so it asks the Docker the provider uses.
|
|
@@ -81,10 +79,13 @@ const HELLO_TIMEOUT_MS = 30_000;
|
|
|
81
79
|
/** Ids a list() inspect takes at once, so its argv and output stay bounded however many computers match. */
|
|
82
80
|
const INSPECT_BATCH = 50;
|
|
83
81
|
/** Only the fields list() reads, in inspect's own shape: a whole inspect is kilobytes a container, and execFile's
|
|
84
|
-
* output is capped. The user and init's command are an allowlist's read-back: its relay, and its proxy's user.
|
|
82
|
+
* output is capped. The user and init's command are an allowlist's read-back: its relay, and its proxy's user.
|
|
83
|
+
* Docker runs the template on the inspect's JSON as a map and a missing key fails the whole inspect, so a field Docker
|
|
84
|
+
* leaves out when empty is read with index, which reads null: HostConfig.Mounts is absent from a container made with no
|
|
85
|
+
* --mount (one the label filter matches yet this provider never made), and one such container would fail the list. */
|
|
85
86
|
const LIST_FORMAT = '{"Id":{{json .Id}},"Name":{{json .Name}},"State":{"Running":{{json .State.Running}}},' +
|
|
86
87
|
'"Config":{"Labels":{{json .Config.Labels}},"User":{{json .Config.User}},"Cmd":{{json .Config.Cmd}}},' +
|
|
87
|
-
'"HostConfig":{"NetworkMode":{{json .HostConfig.NetworkMode}},"Mounts":{{json .HostConfig
|
|
88
|
+
'"HostConfig":{"NetworkMode":{{json .HostConfig.NetworkMode}},"Mounts":{{json (index .HostConfig "Mounts")}}},"NetworkSettings":{"Networks":{{json .NetworkSettings.Networks}}},"Mounts":{{json .Mounts}}}';
|
|
88
89
|
/** The longest lifetime: 30 days. A computer meant to live longer is asked for again. No extend(): the deadline is a
|
|
89
90
|
* container label, and a label cannot change after create. */
|
|
90
91
|
const MAX_LIFETIME_MS = 30 * 24 * 60 * 60 * 1000;
|
|
@@ -193,7 +194,7 @@ export class DockerProvider {
|
|
|
193
194
|
return {
|
|
194
195
|
kind: this.#desktop ? "desktop" : "linux",
|
|
195
196
|
lifetime: "janitor",
|
|
196
|
-
network: [...
|
|
197
|
+
network: [...DOCKER.network],
|
|
197
198
|
allow: { domains: { max: MAX_ALLOW, ports: [...ALLOW_PORTS] }, cidrs: { max: MAX_ALLOW, ports: [...ALLOW_PORTS] }, mixed: true },
|
|
198
199
|
networkReadBack: true,
|
|
199
200
|
isolation: "container",
|
|
@@ -214,6 +215,10 @@ export class DockerProvider {
|
|
|
214
215
|
image(options = {}) {
|
|
215
216
|
return ensureImage(this.#image, { ...options, docker: this.#docker });
|
|
216
217
|
}
|
|
218
|
+
/** The provider contract's prepareImage (its descriptor declares it): image(), its recipe built or its image pulled. */
|
|
219
|
+
prepareImage(context = {}) {
|
|
220
|
+
return this.image(context);
|
|
221
|
+
}
|
|
217
222
|
/** The spec's refusals, and the host's once create, attach or host() has read it: its problems, a bind or an
|
|
218
223
|
* allowlist on a host that remaps user ids, and an allowlist on a Docker host this provider does not run on. */
|
|
219
224
|
check(spec) {
|
|
@@ -247,13 +252,13 @@ export class DockerProvider {
|
|
|
247
252
|
const refusals = [];
|
|
248
253
|
const refuse = (field, message) => refusals.push({ field, message });
|
|
249
254
|
const given = spec;
|
|
250
|
-
const { image,
|
|
255
|
+
const { image, network, cpus, memoryMb, pids, labels, workdir, user, mount } = given;
|
|
251
256
|
if (typeof image !== "string" || image.trim() === "" || image.startsWith("-")) {
|
|
252
257
|
refuse("image", "an image is required, such as debian:bookworm-slim");
|
|
253
258
|
}
|
|
254
259
|
else if (image.includes("\0"))
|
|
255
260
|
refuse("image", NUL);
|
|
256
|
-
refusals.push(...
|
|
261
|
+
refusals.push(...checkTenure(given, this.capabilities(), "Docker"));
|
|
257
262
|
if (typeof network === "object" && network !== null && "allow" in network) {
|
|
258
263
|
const allow = allowOf(network.allow);
|
|
259
264
|
if ("problem" in allow)
|
|
@@ -377,7 +382,7 @@ export class DockerProvider {
|
|
|
377
382
|
const name = `computer-${randomBytes(6).toString("hex")}`;
|
|
378
383
|
// The lifetime counts from here: what the proxy and docker run take comes out of it.
|
|
379
384
|
const lifetimeFrom = Date.now();
|
|
380
|
-
const deadline = new Date(lifetimeFrom + spec
|
|
385
|
+
const deadline = new Date(lifetimeFrom + runLifetimeMs(spec)).toISOString();
|
|
381
386
|
if (allow !== undefined) {
|
|
382
387
|
// The proxy first, ready before the computer exists: a computer never runs with an allowlist it cannot reach.
|
|
383
388
|
const started = await this.#startEgress(name, user, deadline, allow, spec.labels ?? {}, signal);
|
|
@@ -424,7 +429,7 @@ export class DockerProvider {
|
|
|
424
429
|
// A run that failed or was aborted may still have made the container; an allowlist's proxy and volume go with it.
|
|
425
430
|
const released = await this.release({ id: name, name }, "delete");
|
|
426
431
|
if (started.ok)
|
|
427
|
-
return
|
|
432
|
+
return vendorFail("docker", `docker run failed: ${started.value.stderr.trim()}`);
|
|
428
433
|
// Cut off before its own exit: the daemon may still make the computer after release looked, and then its egress
|
|
429
434
|
// volume with it (#settle).
|
|
430
435
|
const left = await this.#settle([name], allow === undefined ? [] : [egressNameOf(name)]);
|
|
@@ -443,11 +448,11 @@ export class DockerProvider {
|
|
|
443
448
|
if (state?.Running !== true) {
|
|
444
449
|
await this.release(ref, "delete");
|
|
445
450
|
// Init exits 0 at its deadline: one that passed before docker run finished is a lifetime the host's start ate.
|
|
446
|
-
if (state?.ExitCode === 0 && Date.now() >= lifetimeFrom + spec
|
|
447
|
-
return fail("timeout", `the computer ${name}'s lifetime of ${spec
|
|
451
|
+
if (state?.ExitCode === 0 && Date.now() >= lifetimeFrom + runLifetimeMs(spec)) {
|
|
452
|
+
return fail("timeout", `the computer ${name}'s lifetime of ${runLifetimeMs(spec) / 1000} s ended before docker run finished (it took ${Math.round(ranMs / 100) / 10} s), so init ended it and it was removed`);
|
|
448
453
|
}
|
|
449
454
|
const why = state ? `status ${state.Status}, exit code ${state.ExitCode}${state.Error ? `: ${state.Error}` : ""}` : "it could not be inspected";
|
|
450
|
-
return
|
|
455
|
+
return vendorFail("docker", `the computer ${name} was not running after its start (${why}), so it was removed`);
|
|
451
456
|
}
|
|
452
457
|
if (this.#desktop) {
|
|
453
458
|
const shown = await this.#startDisplay(ref, this.#desktop, signal);
|
|
@@ -482,7 +487,7 @@ export class DockerProvider {
|
|
|
482
487
|
if (!pulled.ok)
|
|
483
488
|
return signal?.aborted ? aborted() : pulled;
|
|
484
489
|
if (pulled.value.exitCode !== 0)
|
|
485
|
-
return
|
|
490
|
+
return vendorFail("docker", `docker pull ${image} failed, so nothing was made: ${pulled.value.stderr.trim()}`);
|
|
486
491
|
return ok(undefined);
|
|
487
492
|
}
|
|
488
493
|
/**
|
|
@@ -551,7 +556,7 @@ export class DockerProvider {
|
|
|
551
556
|
if (!volume.ok)
|
|
552
557
|
return volume;
|
|
553
558
|
if (volume.value.exitCode !== 0)
|
|
554
|
-
return
|
|
559
|
+
return vendorFail("docker", `docker volume create ${proxy} failed: ${volume.value.stderr.trim()}`);
|
|
555
560
|
const { image, hint, readyMs } = this.#egress;
|
|
556
561
|
const args = egressRunArgs({ name, user, image, allow, local: this.#hostLocal(), deadline, code: this.#code, labels, ...(hint === undefined ? {} : { hint }) });
|
|
557
562
|
const ran = await this.#run(args, signal);
|
|
@@ -562,7 +567,7 @@ export class DockerProvider {
|
|
|
562
567
|
return fail(ran.error.code, `${ran.error.message === "docker run was aborted" ? "create was aborted during docker run of the egress proxy" : ran.error.message}; ${words}`);
|
|
563
568
|
}
|
|
564
569
|
if (ran.value.exitCode !== 0)
|
|
565
|
-
return
|
|
570
|
+
return vendorFail("docker", `docker run of the egress proxy ${proxy} failed: ${ran.value.stderr.trim()}`);
|
|
566
571
|
// Every call of the poll ends at the readiness bound, so a docker that stops answering cannot hold create past it: a
|
|
567
572
|
// call the bound cut off is the timeout, and the caller's own abort stays aborted.
|
|
568
573
|
const bound = AbortSignal.timeout(readyMs);
|
|
@@ -588,7 +593,7 @@ export class DockerProvider {
|
|
|
588
593
|
const state = found.value[0]?.State;
|
|
589
594
|
if (state?.Running !== true) {
|
|
590
595
|
const words = said.trim().split("\n").filter(Boolean).slice(-3).join("; ");
|
|
591
|
-
return
|
|
596
|
+
return vendorFail("docker", `the egress proxy ${proxy} ended (exit code ${state?.ExitCode ?? "unknown"}) before it was ready${words ? `: ${words}` : ""}`);
|
|
592
597
|
}
|
|
593
598
|
await sleep(EGRESS_POLL_MS, undefined, { signal: either }).catch(() => undefined);
|
|
594
599
|
if (signal?.aborted)
|
|
@@ -730,13 +735,13 @@ export class DockerProvider {
|
|
|
730
735
|
if (!ran.ok)
|
|
731
736
|
return ran;
|
|
732
737
|
if (ran.value.exitCode !== 0)
|
|
733
|
-
return
|
|
738
|
+
return vendorFail("docker", `docker info failed: ${ran.value.stderr.trim()}`);
|
|
734
739
|
let info;
|
|
735
740
|
try {
|
|
736
741
|
info = JSON.parse(ran.value.stdout);
|
|
737
742
|
}
|
|
738
743
|
catch {
|
|
739
|
-
return
|
|
744
|
+
return vendorFail("docker", `docker info wrote what is not JSON: ${ran.value.stdout.slice(0, 200)}`);
|
|
740
745
|
}
|
|
741
746
|
this.#host = hostOf(info);
|
|
742
747
|
return ok(this.#host);
|
|
@@ -858,7 +863,8 @@ export class DockerProvider {
|
|
|
858
863
|
if (hello.error.code !== "gone")
|
|
859
864
|
return hello;
|
|
860
865
|
const words = stderr.trim() || hello.error.message;
|
|
861
|
-
|
|
866
|
+
const why = `cannot reach the daemon in ${ref.name}: ${words}`;
|
|
867
|
+
return noSuchContainer(words) ? fail("not_found", why) : vendorFail("docker", why);
|
|
862
868
|
}
|
|
863
869
|
return ok({ client, hello: hello.value, close });
|
|
864
870
|
}
|
|
@@ -914,7 +920,7 @@ export class DockerProvider {
|
|
|
914
920
|
if (!ran.ok)
|
|
915
921
|
return countTested("Docker", ran);
|
|
916
922
|
if (ran.value.exitCode !== 0)
|
|
917
|
-
return countTested("Docker",
|
|
923
|
+
return countTested("Docker", vendorFail("docker", `docker ps failed: ${ran.value.stderr.trim()}`));
|
|
918
924
|
const names = ran.value.stdout.split("\n").map((line) => line.trim());
|
|
919
925
|
return countTested("Docker", ok({ count: names.filter((name) => NAME.test(name)).length }));
|
|
920
926
|
}
|
|
@@ -929,7 +935,7 @@ export class DockerProvider {
|
|
|
929
935
|
if (!ran.ok)
|
|
930
936
|
return ran;
|
|
931
937
|
if (ran.value.exitCode !== 0)
|
|
932
|
-
return
|
|
938
|
+
return vendorFail("docker", `docker ps failed: ${ran.value.stderr.trim()}`);
|
|
933
939
|
const ids = ran.value.stdout.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
934
940
|
const infos = [];
|
|
935
941
|
const local = this.#hostLocal();
|
|
@@ -971,7 +977,7 @@ export class DockerProvider {
|
|
|
971
977
|
if (!alive.ok)
|
|
972
978
|
return alive;
|
|
973
979
|
if (alive.value.exitCode !== 0)
|
|
974
|
-
return
|
|
980
|
+
return vendorFail("docker", `docker ps failed: ${alive.value.stderr.trim()}`);
|
|
975
981
|
const computers = new Set(lines(alive.value.stdout).filter((name) => NAME.test(name)));
|
|
976
982
|
const at = now.getTime();
|
|
977
983
|
const grace = this.#leftoverGraceMs();
|
|
@@ -992,7 +998,7 @@ export class DockerProvider {
|
|
|
992
998
|
if (!ps.ok)
|
|
993
999
|
return ps;
|
|
994
1000
|
if (ps.value.exitCode !== 0)
|
|
995
|
-
return
|
|
1001
|
+
return vendorFail("docker", `docker ps for egress proxies failed: ${ps.value.stderr.trim()}`);
|
|
996
1002
|
const ids = lines(ps.value.stdout);
|
|
997
1003
|
for (let from = 0; from < ids.length; from += INSPECT_BATCH) {
|
|
998
1004
|
const found = await this.#inspect(ids.slice(from, from + INSPECT_BATCH), signal);
|
|
@@ -1005,7 +1011,7 @@ export class DockerProvider {
|
|
|
1005
1011
|
if (!ran.ok)
|
|
1006
1012
|
return ran;
|
|
1007
1013
|
if (ran.value.exitCode !== 0 && !noSuchContainer(ran.value.stderr))
|
|
1008
|
-
return
|
|
1014
|
+
return vendorFail("docker", `docker rm of the egress proxy ${nameOf(proxy)} failed: ${ran.value.stderr.trim()}`);
|
|
1009
1015
|
removed.push(nameOf(proxy));
|
|
1010
1016
|
}
|
|
1011
1017
|
}
|
|
@@ -1013,7 +1019,7 @@ export class DockerProvider {
|
|
|
1013
1019
|
if (!ls.ok)
|
|
1014
1020
|
return ls;
|
|
1015
1021
|
if (ls.value.exitCode !== 0)
|
|
1016
|
-
return
|
|
1022
|
+
return vendorFail("docker", `docker volume ls for egress volumes failed: ${ls.value.stderr.trim()}`);
|
|
1017
1023
|
const names = lines(ls.value.stdout);
|
|
1018
1024
|
for (let from = 0; from < names.length; from += INSPECT_BATCH) {
|
|
1019
1025
|
const read = await this.#run(["volume", "inspect", "--format", "{{json .}}", ...names.slice(from, from + INSPECT_BATCH)], signal);
|
|
@@ -1025,7 +1031,7 @@ export class DockerProvider {
|
|
|
1025
1031
|
volume = JSON.parse(line);
|
|
1026
1032
|
}
|
|
1027
1033
|
catch {
|
|
1028
|
-
return
|
|
1034
|
+
return vendorFail("docker", `docker volume inspect wrote a line that is not JSON: ${line.slice(0, 200)}`);
|
|
1029
1035
|
}
|
|
1030
1036
|
if (typeof volume.Name !== "string" || !leftover(volume.Labels, volume.CreatedAt))
|
|
1031
1037
|
continue;
|
|
@@ -1033,7 +1039,7 @@ export class DockerProvider {
|
|
|
1033
1039
|
if (!ran.ok)
|
|
1034
1040
|
return ran;
|
|
1035
1041
|
if (ran.value.exitCode !== 0)
|
|
1036
|
-
return
|
|
1042
|
+
return vendorFail("docker", `docker volume rm ${volume.Name} failed: ${ran.value.stderr.trim()}`);
|
|
1037
1043
|
removed.push(`${volume.Name} (volume)`);
|
|
1038
1044
|
}
|
|
1039
1045
|
}
|
|
@@ -1088,19 +1094,19 @@ export class DockerProvider {
|
|
|
1088
1094
|
if (!ran.ok)
|
|
1089
1095
|
return ran;
|
|
1090
1096
|
if (ran.value.exitCode !== 0 && !noSuchContainer(ran.value.stderr))
|
|
1091
|
-
return
|
|
1097
|
+
return vendorFail("docker", `docker ${args[0]} ${ref.name} failed: ${ran.value.stderr.trim()}`);
|
|
1092
1098
|
const label = `label=${EGRESS_LABEL}=${ref.name}`;
|
|
1093
1099
|
const proxies = await this.#run(["ps", "-a", "--no-trunc", "--filter", label, "--format", "{{.ID}}"]);
|
|
1094
1100
|
if (!proxies.ok)
|
|
1095
1101
|
return proxies;
|
|
1096
1102
|
if (proxies.value.exitCode !== 0)
|
|
1097
|
-
return
|
|
1103
|
+
return vendorFail("docker", `docker ps for ${ref.name}'s egress proxy failed: ${proxies.value.stderr.trim()}`);
|
|
1098
1104
|
for (const id of proxies.value.stdout.split("\n").map((line) => line.trim()).filter(Boolean)) {
|
|
1099
1105
|
const ended = await this.#run(how === "stop" ? ["stop", id] : ["rm", "--force", id]);
|
|
1100
1106
|
if (!ended.ok)
|
|
1101
1107
|
return ended;
|
|
1102
1108
|
if (ended.value.exitCode !== 0 && !noSuchContainer(ended.value.stderr))
|
|
1103
|
-
return
|
|
1109
|
+
return vendorFail("docker", `docker ${how === "stop" ? "stop" : "rm"} of ${ref.name}'s egress proxy failed: ${ended.value.stderr.trim()}`);
|
|
1104
1110
|
}
|
|
1105
1111
|
if (how === "stop")
|
|
1106
1112
|
return ok(undefined);
|
|
@@ -1108,13 +1114,13 @@ export class DockerProvider {
|
|
|
1108
1114
|
if (!volumes.ok)
|
|
1109
1115
|
return volumes;
|
|
1110
1116
|
if (volumes.value.exitCode !== 0)
|
|
1111
|
-
return
|
|
1117
|
+
return vendorFail("docker", `docker volume ls for ${ref.name}'s egress volume failed: ${volumes.value.stderr.trim()}`);
|
|
1112
1118
|
for (const volume of volumes.value.stdout.split("\n").map((line) => line.trim()).filter(Boolean)) {
|
|
1113
1119
|
const removed = await this.#run(["volume", "rm", "--force", volume]);
|
|
1114
1120
|
if (!removed.ok)
|
|
1115
1121
|
return removed;
|
|
1116
1122
|
if (removed.value.exitCode !== 0)
|
|
1117
|
-
return
|
|
1123
|
+
return vendorFail("docker", `docker volume rm ${volume} failed: ${removed.value.stderr.trim()}`);
|
|
1118
1124
|
}
|
|
1119
1125
|
return ok(undefined);
|
|
1120
1126
|
}
|
|
@@ -1126,14 +1132,14 @@ export class DockerProvider {
|
|
|
1126
1132
|
const { exitCode, stdout, stderr } = ran.value;
|
|
1127
1133
|
const errors = stderr.split("\n").filter((line) => line.trim() !== "" && !noSuchContainer(line));
|
|
1128
1134
|
if (exitCode !== 0 && errors.length > 0)
|
|
1129
|
-
return
|
|
1135
|
+
return vendorFail("docker", `docker inspect failed: ${errors.join("; ")}`);
|
|
1130
1136
|
const found = [];
|
|
1131
1137
|
for (const line of stdout.split("\n").filter((line) => line.trim() !== "")) {
|
|
1132
1138
|
try {
|
|
1133
1139
|
found.push(JSON.parse(line));
|
|
1134
1140
|
}
|
|
1135
1141
|
catch {
|
|
1136
|
-
return
|
|
1142
|
+
return vendorFail("docker", `docker inspect wrote a line that is not JSON: ${line.slice(0, 200)}`);
|
|
1137
1143
|
}
|
|
1138
1144
|
}
|
|
1139
1145
|
return ok(found);
|
|
@@ -1148,8 +1154,8 @@ export class DockerProvider {
|
|
|
1148
1154
|
if (typeof error.code === "number")
|
|
1149
1155
|
return done(ok({ exitCode: error.code, stdout, stderr }));
|
|
1150
1156
|
if (error.code === "ENOENT")
|
|
1151
|
-
return done(
|
|
1152
|
-
done(
|
|
1157
|
+
return done(vendorFail("docker", `the docker CLI (${this.#docker}) was not found`));
|
|
1158
|
+
done(vendorFail("docker", `docker ${args[0]} failed: ${error.message}`));
|
|
1153
1159
|
});
|
|
1154
1160
|
});
|
|
1155
1161
|
}
|
package/dist/drift.d.ts
CHANGED
|
@@ -1,115 +1,19 @@
|
|
|
1
|
-
import { type EgressCode } from "./docker/egress.js";
|
|
2
|
-
import { type DockerVolume } from "./docker/volume.js";
|
|
3
|
-
import { type MountReadBack } from "./mount.js";
|
|
4
1
|
import { type ComputerKind, type Group, type HelloResult } from "./protocol.js";
|
|
5
|
-
import type {
|
|
2
|
+
import type { NetworkPolicy, NetworkSpec } from "./provider.js";
|
|
6
3
|
/** Where the daemon is mounted in each computer, read-only. */
|
|
7
4
|
export declare const DAEMON_IN_COMPUTER = "/opt/agentrun/computerd";
|
|
8
|
-
/** With the Docker provider's volume option, where the daemon's staged directory is mounted read-only: its computerd is
|
|
9
|
-
* DAEMON_IN_COMPUTER (src/docker/stage.ts). */
|
|
10
|
-
export declare const DAEMON_DIR_IN_COMPUTER = "/opt/agentrun";
|
|
11
5
|
export declare const COMPUTER_LABEL = "agentrun.computer";
|
|
12
6
|
export declare const DEADLINE_LABEL = "agentrun.computer.deadline";
|
|
13
7
|
/** Serve's box sizes, when the spec names none. */
|
|
14
8
|
export declare const DEFAULT_CPUS = 2;
|
|
15
9
|
export declare const DEFAULT_MEMORY_MB = 4096;
|
|
16
10
|
export declare const DEFAULT_PIDS = 1024;
|
|
17
|
-
/** CPUs are a CFS quota of each 100 ms, as serve gives them: Docker refuses a --cpus above its own CPU count. */
|
|
18
|
-
export declare const CPU_PERIOD_US = 100000;
|
|
19
11
|
/** The computer's home and default workdir: a tmpfs its user owns. The run's folder, when bound, is at WORKSPACE. */
|
|
20
12
|
export declare const WORK = "/work";
|
|
21
13
|
/** Where init's socket lives (the daemon's DefaultSocket's directory): a tmpfs the computer's user owns, mode 0700. */
|
|
22
14
|
export declare const SOCKET_DIR = "/run/agentrun";
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
* computer's memory, so /work holds half of it: a full /work is ENOSPC before the memory limit could OOM-kill a
|
|
26
|
-
* process. /run/agentrun holds only init's socket.
|
|
27
|
-
*/
|
|
28
|
-
export declare function tmpfsOf(user: string, memoryMb: number): Record<string, string>;
|
|
29
|
-
/** The parts of `docker inspect` a computer is checked by; HostConfig and Config are checked whole. */
|
|
30
|
-
export interface DockerInspect {
|
|
31
|
-
Id?: string;
|
|
32
|
-
Name?: string;
|
|
33
|
-
State?: {
|
|
34
|
-
Running?: boolean;
|
|
35
|
-
Status?: string;
|
|
36
|
-
ExitCode?: number;
|
|
37
|
-
Error?: string;
|
|
38
|
-
};
|
|
39
|
-
AppArmorProfile?: string;
|
|
40
|
-
ProcessLabel?: string;
|
|
41
|
-
Config?: {
|
|
42
|
-
User?: string;
|
|
43
|
-
Image?: string;
|
|
44
|
-
WorkingDir?: string;
|
|
45
|
-
Env?: string[] | null;
|
|
46
|
-
Entrypoint?: string[] | null;
|
|
47
|
-
Cmd?: string[] | null;
|
|
48
|
-
Labels?: Record<string, string> | null;
|
|
49
|
-
[field: string]: unknown;
|
|
50
|
-
};
|
|
51
|
-
HostConfig?: {
|
|
52
|
-
NetworkMode?: string;
|
|
53
|
-
CapDrop?: string[] | null;
|
|
54
|
-
CapAdd?: string[] | null;
|
|
55
|
-
Privileged?: boolean;
|
|
56
|
-
SecurityOpt?: string[] | null;
|
|
57
|
-
PidsLimit?: number | null;
|
|
58
|
-
Memory?: number;
|
|
59
|
-
MemorySwap?: number;
|
|
60
|
-
CpuPeriod?: number;
|
|
61
|
-
CpuQuota?: number;
|
|
62
|
-
Tmpfs?: Record<string, string> | null;
|
|
63
|
-
Mounts?: Array<Record<string, unknown>> | null;
|
|
64
|
-
MaskedPaths?: string[] | null;
|
|
65
|
-
ReadonlyPaths?: string[] | null;
|
|
66
|
-
[field: string]: unknown;
|
|
67
|
-
};
|
|
68
|
-
Mounts?: Array<{
|
|
69
|
-
Type?: string;
|
|
70
|
-
Name?: string;
|
|
71
|
-
Source?: string;
|
|
72
|
-
Destination?: string;
|
|
73
|
-
RW?: boolean;
|
|
74
|
-
Propagation?: string;
|
|
75
|
-
}> | null;
|
|
76
|
-
NetworkSettings?: {
|
|
77
|
-
Networks?: Record<string, unknown> | null;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
/** What `docker info` reports of the host's enforcement, as the provider reads it. */
|
|
81
|
-
export interface DockerInfo {
|
|
82
|
-
Architecture?: string;
|
|
83
|
-
SecurityOptions?: string[] | null;
|
|
84
|
-
MemoryLimit?: boolean;
|
|
85
|
-
SwapLimit?: boolean;
|
|
86
|
-
PidsLimit?: boolean;
|
|
87
|
-
CPUCfsQuota?: boolean;
|
|
88
|
-
CPUCfsPeriod?: boolean;
|
|
89
|
-
ServerVersion?: string;
|
|
90
|
-
}
|
|
91
|
-
/** A Docker host as the provider reads it: its architecture in Go's names, its security modules, and what it lacks. */
|
|
92
|
-
export interface DockerHost {
|
|
93
|
-
arch: string;
|
|
94
|
-
/** The Docker Engine's major version (docker info's ServerVersion), when it reads as one. */
|
|
95
|
-
engine?: number;
|
|
96
|
-
apparmor: boolean;
|
|
97
|
-
selinux: boolean;
|
|
98
|
-
/** Each enforcement the host lacks, in words; a computer is refused on a host with any. */
|
|
99
|
-
problems: string[];
|
|
100
|
-
/**
|
|
101
|
-
* Present when the host remaps user ids (docker info's name=userns: userns-remap; name=rootless: rootless Docker): a
|
|
102
|
-
* computer's uid is then another uid on the host. No problem for a computer, but a bind of the run folder is refused.
|
|
103
|
-
*/
|
|
104
|
-
remap?: "userns" | "rootless";
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* The host's enforcement, from docker info. A computer's sizes are cgroup limits, so a host that does not enforce one
|
|
108
|
-
* makes it configuration only; seccomp is required, since a computer's only syscall filter is Docker's default
|
|
109
|
-
* profile. AppArmor and SELinux are read, not required: a host has the one its distribution ships or neither, and a
|
|
110
|
-
* computer must then carry the profile or label Docker gives every container (the drift check).
|
|
111
|
-
*/
|
|
112
|
-
export declare function hostOf(info: DockerInfo | null | undefined): DockerHost;
|
|
15
|
+
/** A value as a drift sentence shows it: JSON, or "nothing". */
|
|
16
|
+
export declare const show: (value: unknown) => string;
|
|
113
17
|
/** What the daemon must report: the provider's version, kind and groups, and the host's architecture. */
|
|
114
18
|
export interface HelloExpected {
|
|
115
19
|
version: string;
|
|
@@ -120,43 +24,6 @@ export interface HelloExpected {
|
|
|
120
24
|
/** The daemon was started with --own-network: hello must say which fence holds its programs (NETWORK_FENCES). */
|
|
121
25
|
fence?: true;
|
|
122
26
|
}
|
|
123
|
-
export interface DriftExpected extends HelloExpected {
|
|
124
|
-
/** The daemon file on the host the computer binds, as it was mounted: for DockerProvider, its copy of the daemon. */
|
|
125
|
-
daemonPath: string;
|
|
126
|
-
/** The deadline label's value, as it was set. */
|
|
127
|
-
deadline: string;
|
|
128
|
-
/** The uid:gid the computer was asked to run as. */
|
|
129
|
-
user: string;
|
|
130
|
-
/** Whether the host's Docker gives every container an AppArmor profile, or an SELinux label (hostOf). */
|
|
131
|
-
apparmor: boolean;
|
|
132
|
-
selinux: boolean;
|
|
133
|
-
/** For a computer with an allowlist: its proxy container's inspect (none when it is gone), and where the proxy's code
|
|
134
|
-
* is on the host, as it was bound. */
|
|
135
|
-
proxy?: DockerInspect | null;
|
|
136
|
-
egressCode?: EgressCode;
|
|
137
|
-
/** For a computer with an allowlist: the Docker host's own addresses its proxy must refuse (its --local holds each). */
|
|
138
|
-
hostAddresses?: readonly string[];
|
|
139
|
-
/** The provider's volume option: the daemon and the run's folder are then that volume's subpaths, not binds. */
|
|
140
|
-
volume?: DockerVolume;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* How create mounts a path of this host at `target`: a bind of it, or, with the provider's volume option, the volume's
|
|
144
|
-
* subpath, as HostConfig.Mounts records it (Docker keeps `volume-nocopy` and the subpath under VolumeOptions). Undefined
|
|
145
|
-
* for a path outside the volume, which create never mounts.
|
|
146
|
-
*/
|
|
147
|
-
export declare function mountAsked(path: string, target: string, readonly: boolean, volume: DockerVolume | undefined): Record<string, unknown> | undefined;
|
|
148
|
-
/** Whether a computer's inspect shows any part of an allowlist: the egress volume at its path, or init's relay. */
|
|
149
|
-
export declare function egressShaped(inspected: DockerInspect | null | undefined): boolean;
|
|
150
|
-
/**
|
|
151
|
-
* The network a computer is on, read back from inspect: `none` is network mode none on no network but Docker's own
|
|
152
|
-
* `none`, `open` is the default bridge alone. An allowlist is network mode none with the computer's egress volume
|
|
153
|
-
* mounted read-only at EGRESS_MOUNT and init relaying to its socket, and the list read back from `proxy`, the
|
|
154
|
-
* computer's proxy container's inspect (egressOf: none when it is gone), which must refuse each of `local`, the Docker
|
|
155
|
-
* host's own addresses. Anything else is reported in words, never as a policy it might widen to.
|
|
156
|
-
*/
|
|
157
|
-
export declare function networkOf(inspected: DockerInspect | null | undefined, proxy?: DockerInspect | null, code?: EgressCode, local?: readonly string[]): NetworkPolicy;
|
|
158
|
-
/** Whether a policy read back is the one declared: the same string, or an allowlist with the same entries, normalized. */
|
|
159
|
-
export declare function samePolicy(declared: NetworkSpec, read: NetworkPolicy): boolean;
|
|
160
27
|
/**
|
|
161
28
|
* What `computerd probe` reports from inside a computer: the uid:gid its programs run as, the kernel, reached (the
|
|
162
29
|
* targets that answered: bytes came back) and accepted (those that accepted a connection and sent nothing back). One
|
|
@@ -189,14 +56,5 @@ export declare function probeNetworkDrift(probe: ProbeReport): string[];
|
|
|
189
56
|
* and sent nothing back. A firewall that accepts first and decides after looks so from inside; only an answer is drift.
|
|
190
57
|
*/
|
|
191
58
|
export declare function probeNotes(probe: ProbeReport, network: NetworkSpec | NetworkPolicy): string[];
|
|
192
|
-
/**
|
|
193
|
-
* What is mounted at /workspace, read back from inspect: a read-write bind is the run's folder; nothing is undefined;
|
|
194
|
-
* anything else (read-only, a volume, two mounts) is reported in words, never as a bind it might be.
|
|
195
|
-
*/
|
|
196
|
-
export declare function mountOf(inspected: DockerInspect | null | undefined, volume?: DockerVolume): MountReadBack | undefined;
|
|
197
59
|
/** Every way hello differs from what the provider expects. */
|
|
198
60
|
export declare function helloDrift(hello: HelloResult | null | undefined, expected: HelloExpected): string[];
|
|
199
|
-
/** Every way a created computer differs from its spec, from inspect and hello. */
|
|
200
|
-
export declare function drift(spec: ComputerSpec, inspected: DockerInspect | null | undefined, hello: HelloResult | null | undefined, expected: DriftExpected): string[];
|
|
201
|
-
/** Every way a computer's docker inspect differs from its spec: the fields create asks for, and the closed check. */
|
|
202
|
-
export declare function inspectDrift(spec: ComputerSpec, inspected: DockerInspect | null | undefined, expected: DriftExpected): string[];
|