@parcha/agentrun-computer 0.1.0-beta.33 → 0.1.0-beta.35
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 +308 -36
- package/dist/browser.d.ts +13 -14
- package/dist/browser.js +22 -17
- package/dist/browserbase.d.ts +3 -3
- package/dist/browserbase.js +16 -11
- package/dist/child.d.ts +2 -0
- package/dist/child.js +13 -2
- package/dist/chrome.d.ts +73 -0
- package/dist/chrome.js +224 -0
- 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/gpu.d.ts +2 -0
- package/dist/conformance/cases/gpu.js +108 -0
- package/dist/conformance/cases/health.js +83 -3
- package/dist/conformance/cases/index.js +2 -0
- package/dist/conformance/cases/mount.d.ts +8 -1
- package/dist/conformance/cases/mount.js +4 -3
- package/dist/conformance/cases/provider.js +92 -3
- package/dist/conformance/cli.js +46 -7
- package/dist/conformance/daytona.js +2 -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-chrome.d.ts +30 -0
- package/dist/conformance/local-chrome.js +36 -0
- 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 +13 -7
- package/dist/conformance/runner.js +68 -18
- package/dist/conformance/types.d.ts +78 -18
- 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 +4 -6
- package/dist/daytona.js +97 -52
- package/dist/descriptor.d.ts +94 -0
- package/dist/descriptor.js +81 -0
- package/dist/descriptors/browserbase.d.ts +24 -0
- package/dist/descriptors/browserbase.js +18 -0
- package/dist/descriptors/daytona.d.ts +62 -0
- package/dist/descriptors/daytona.js +49 -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 +229 -0
- package/dist/descriptors/index.js +19 -0
- package/dist/descriptors/kernel.d.ts +20 -0
- package/dist/descriptors/kernel.js +15 -0
- package/dist/descriptors/local-chrome.d.ts +17 -0
- package/dist/descriptors/local-chrome.js +21 -0
- package/dist/descriptors/modal.d.ts +50 -0
- package/dist/descriptors/modal.js +38 -0
- package/dist/descriptors/orgo.d.ts +88 -0
- package/dist/descriptors/orgo.js +44 -0
- package/dist/descriptors/phone-harness.d.ts +28 -0
- package/dist/descriptors/phone-harness.js +20 -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 +1 -1
- 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 -4
- package/dist/docker.js +53 -41
- package/dist/drift.d.ts +6 -146
- package/dist/drift.js +14 -334
- package/dist/e2b.d.ts +2 -6
- package/dist/e2b.js +19 -22
- package/dist/index.d.ts +9 -10
- package/dist/index.js +14 -10
- package/dist/isolation.d.ts +0 -2
- package/dist/isolation.js +2 -18
- package/dist/janitor.d.ts +18 -1
- package/dist/janitor.js +67 -19
- package/dist/kernel.d.ts +3 -3
- package/dist/kernel.js +19 -14
- package/dist/kinds.d.ts +56 -30
- package/dist/kinds.js +19 -97
- package/dist/labels.d.ts +18 -0
- package/dist/labels.js +65 -2
- package/dist/local-chrome.d.ts +86 -0
- package/dist/local-chrome.js +475 -0
- package/dist/local-supervisor.d.ts +51 -0
- package/dist/local-supervisor.js +221 -0
- package/dist/modal.d.ts +15 -7
- package/dist/modal.js +83 -39
- package/dist/mount-archil.js +4 -4
- package/dist/orgo-channel.js +16 -13
- package/dist/orgo-desktop.d.ts +153 -0
- package/dist/orgo-desktop.js +1614 -0
- package/dist/orgo-names.d.ts +52 -0
- package/dist/orgo-names.js +84 -0
- package/dist/orgo.d.ts +18 -13
- package/dist/orgo.js +54 -128
- package/dist/phone-harness.d.ts +4 -8
- package/dist/phone-harness.js +48 -46
- package/dist/protocol.d.ts +20 -0
- package/dist/protocol.js +9 -0
- package/dist/provider.d.ts +151 -10
- package/dist/provider.js +70 -0
- package/dist/providers.d.ts +22 -17
- package/dist/providers.js +14 -16
- 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
|
@@ -8,8 +8,10 @@ import { setTimeout as sleep } from "node:timers/promises";
|
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { DaemonClient } from "./client.js";
|
|
10
10
|
import { daemonCopy, defaultDaemonCache } from "./daemon-copy.js";
|
|
11
|
+
import { DOCKER } from "./descriptors/docker.js";
|
|
11
12
|
import { DESKTOP_GROUPS, desktopOf, startDisplay } from "./desktop.js";
|
|
12
|
-
import { COMPUTER_LABEL,
|
|
13
|
+
import { COMPUTER_LABEL, DAEMON_IN_COMPUTER, DEADLINE_LABEL, DEFAULT_CPUS, DEFAULT_MEMORY_MB, DEFAULT_PIDS, helloDrift, WORK, } from "./drift.js";
|
|
14
|
+
import { CPU_PERIOD_US, DAEMON_DIR_IN_COMPUTER, drift, egressShaped, hostOf, inspectDrift, mountOf, networkOf, samePolicy, tmpfsOf, } from "./docker/inspect.js";
|
|
13
15
|
import { DOCKER_RECIPE, ensureImage, imageSourceProblem } from "./docker/image.js";
|
|
14
16
|
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
17
|
import { daemonStage, daemonVerified, egressStage, egressStaged } from "./docker/stage.js";
|
|
@@ -17,17 +19,16 @@ import { EGRESS_READY } from "./docker/egress-proxy.js";
|
|
|
17
19
|
import { OLD_ENGINE, outsideWords, subpathOf, VOLUME_SUBPATH_ENGINE, volumeMount, volumeOf } from "./docker/volume.js";
|
|
18
20
|
import { addressBytes } from "./docker/egress-table.js";
|
|
19
21
|
import { checkMount, WORKSPACE } from "./mount.js";
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
+
import { checkGpu, checkTenure, runLifetimeMs, } from "./provider.js";
|
|
23
|
+
import { failFor, ok, vendorFail } from "./result.js";
|
|
22
24
|
import { daemonWatch } from "./screen-watch.js";
|
|
23
25
|
import { countTested } from "./test-connection.js";
|
|
26
|
+
/** This module's failures: one with code vendor names Docker. */
|
|
27
|
+
const fail = failFor("docker");
|
|
24
28
|
/** 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 machine kind and groups of each configuration: a linux computer, and
|
|
27
|
-
export const CAPABILITIES =
|
|
28
|
-
{ kind: "linux", groups: ["exec", "files", "processes"] },
|
|
29
|
-
{ kind: "desktop", groups: ["exec", "files", "processes", ...DESKTOP_GROUPS] },
|
|
30
|
-
];
|
|
29
|
+
export const MOUNT = DOCKER.mounts;
|
|
30
|
+
/** The machine kind and groups of each configuration (its descriptor's): a linux computer, and a desktop. */
|
|
31
|
+
export const CAPABILITIES = DOCKER.capabilities;
|
|
31
32
|
/**
|
|
32
33
|
* Docker's architecture as `docker version` reports it (amd64, arm64), within timeoutMs, or an error in words. The docker
|
|
33
34
|
* CLI runs with this process's environment, as every call of the provider does, so it asks the Docker the provider uses.
|
|
@@ -73,6 +74,8 @@ const USER_FORM = "a uid or uid:gid in numbers, such as 1000:1000; a name is ref
|
|
|
73
74
|
const MAX_PIDS = 4_194_304;
|
|
74
75
|
/** Docker's least --memory. */
|
|
75
76
|
const MIN_MEMORY_MB = 6;
|
|
77
|
+
/** The most CPUs whose quota (CPU_PERIOD_US each) is still a whole number Docker takes. */
|
|
78
|
+
const MAX_CPUS = Math.floor(Number.MAX_SAFE_INTEGER / CPU_PERIOD_US);
|
|
76
79
|
const HELLO_TIMEOUT_MS = 30_000;
|
|
77
80
|
/** Ids a list() inspect takes at once, so its argv and output stay bounded however many computers match. */
|
|
78
81
|
const INSPECT_BATCH = 50;
|
|
@@ -84,7 +87,7 @@ const LIST_FORMAT = '{"Id":{{json .Id}},"Name":{{json .Name}},"State":{"Running"
|
|
|
84
87
|
/** The longest lifetime: 30 days. A computer meant to live longer is asked for again. No extend(): the deadline is a
|
|
85
88
|
* container label, and a label cannot change after create. */
|
|
86
89
|
const MAX_LIFETIME_MS = 30 * 24 * 60 * 60 * 1000;
|
|
87
|
-
const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "cpus", "memoryMb", "pids", "labels", "workdir", "user", "mount"]);
|
|
90
|
+
const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "cpus", "memoryMb", "pids", "labels", "workdir", "user", "mount", "gpu"]);
|
|
88
91
|
const NUL = "a NUL byte cannot be passed to docker run";
|
|
89
92
|
/** What --mount's comma-separated fields cannot hold in a source path. */
|
|
90
93
|
const MOUNT_UNSAFE = /[,"\r\n]/;
|
|
@@ -189,7 +192,7 @@ export class DockerProvider {
|
|
|
189
192
|
return {
|
|
190
193
|
kind: this.#desktop ? "desktop" : "linux",
|
|
191
194
|
lifetime: "janitor",
|
|
192
|
-
network: [
|
|
195
|
+
network: [...DOCKER.network],
|
|
193
196
|
allow: { domains: { max: MAX_ALLOW, ports: [...ALLOW_PORTS] }, cidrs: { max: MAX_ALLOW, ports: [...ALLOW_PORTS] }, mixed: true },
|
|
194
197
|
networkReadBack: true,
|
|
195
198
|
isolation: "container",
|
|
@@ -210,6 +213,10 @@ export class DockerProvider {
|
|
|
210
213
|
image(options = {}) {
|
|
211
214
|
return ensureImage(this.#image, { ...options, docker: this.#docker });
|
|
212
215
|
}
|
|
216
|
+
/** The provider contract's prepareImage (its descriptor declares it): image(), its recipe built or its image pulled. */
|
|
217
|
+
prepareImage(context = {}) {
|
|
218
|
+
return this.image(context);
|
|
219
|
+
}
|
|
213
220
|
/** The spec's refusals, and the host's once create, attach or host() has read it: its problems, a bind or an
|
|
214
221
|
* allowlist on a host that remaps user ids, and an allowlist on a Docker host this provider does not run on. */
|
|
215
222
|
check(spec) {
|
|
@@ -249,7 +256,7 @@ export class DockerProvider {
|
|
|
249
256
|
}
|
|
250
257
|
else if (image.includes("\0"))
|
|
251
258
|
refuse("image", NUL);
|
|
252
|
-
refusals.push(...
|
|
259
|
+
refusals.push(...checkTenure(given, this.capabilities(), "Docker"));
|
|
253
260
|
if (typeof network === "object" && network !== null && "allow" in network) {
|
|
254
261
|
const allow = allowOf(network.allow);
|
|
255
262
|
if ("problem" in allow)
|
|
@@ -259,6 +266,9 @@ export class DockerProvider {
|
|
|
259
266
|
refuse("network", NETWORKS);
|
|
260
267
|
if (cpus !== undefined && !(isNumber(cpus) && cpus >= 0.01))
|
|
261
268
|
refuse("cpus", "cpus must be a number of CPUs of at least 0.01");
|
|
269
|
+
// Its CFS quota is a whole number of microseconds per period: a count too large for one is no quota Docker takes.
|
|
270
|
+
else if (cpus !== undefined && !Number.isSafeInteger(Math.round(cpus * CPU_PERIOD_US)))
|
|
271
|
+
refuse("cpus", `cpus must be at most ${MAX_CPUS}`);
|
|
262
272
|
if (memoryMb !== undefined && !(isWhole(memoryMb) && memoryMb >= MIN_MEMORY_MB)) {
|
|
263
273
|
refuse("memoryMb", `memoryMb must be a whole number of MiB, at least ${MIN_MEMORY_MB}`);
|
|
264
274
|
}
|
|
@@ -284,6 +294,7 @@ export class DockerProvider {
|
|
|
284
294
|
if (mounts.length === 0 && typeof path === "string" && MOUNT_UNSAFE.test(path)) {
|
|
285
295
|
refuse("mount", `mount.path ${JSON.stringify(path)}: a Docker mount cannot hold a comma, a double quote or a line break in its path`);
|
|
286
296
|
}
|
|
297
|
+
refusals.push(...checkGpu(given.gpu, this.capabilities()));
|
|
287
298
|
for (const [field, value] of Object.entries(given)) {
|
|
288
299
|
if (!SPEC_FIELDS.has(field) && value !== undefined)
|
|
289
300
|
refuse(field, `a Docker computer does not support ${field}`);
|
|
@@ -369,7 +380,7 @@ export class DockerProvider {
|
|
|
369
380
|
const name = `computer-${randomBytes(6).toString("hex")}`;
|
|
370
381
|
// The lifetime counts from here: what the proxy and docker run take comes out of it.
|
|
371
382
|
const lifetimeFrom = Date.now();
|
|
372
|
-
const deadline = new Date(lifetimeFrom + spec
|
|
383
|
+
const deadline = new Date(lifetimeFrom + runLifetimeMs(spec)).toISOString();
|
|
373
384
|
if (allow !== undefined) {
|
|
374
385
|
// The proxy first, ready before the computer exists: a computer never runs with an allowlist it cannot reach.
|
|
375
386
|
const started = await this.#startEgress(name, user, deadline, allow, spec.labels ?? {}, signal);
|
|
@@ -416,7 +427,7 @@ export class DockerProvider {
|
|
|
416
427
|
// A run that failed or was aborted may still have made the container; an allowlist's proxy and volume go with it.
|
|
417
428
|
const released = await this.release({ id: name, name }, "delete");
|
|
418
429
|
if (started.ok)
|
|
419
|
-
return
|
|
430
|
+
return vendorFail("docker", `docker run failed: ${started.value.stderr.trim()}`);
|
|
420
431
|
// Cut off before its own exit: the daemon may still make the computer after release looked, and then its egress
|
|
421
432
|
// volume with it (#settle).
|
|
422
433
|
const left = await this.#settle([name], allow === undefined ? [] : [egressNameOf(name)]);
|
|
@@ -435,11 +446,11 @@ export class DockerProvider {
|
|
|
435
446
|
if (state?.Running !== true) {
|
|
436
447
|
await this.release(ref, "delete");
|
|
437
448
|
// Init exits 0 at its deadline: one that passed before docker run finished is a lifetime the host's start ate.
|
|
438
|
-
if (state?.ExitCode === 0 && Date.now() >= lifetimeFrom + spec
|
|
439
|
-
return fail("timeout", `the computer ${name}'s lifetime of ${spec
|
|
449
|
+
if (state?.ExitCode === 0 && Date.now() >= lifetimeFrom + runLifetimeMs(spec)) {
|
|
450
|
+
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`);
|
|
440
451
|
}
|
|
441
452
|
const why = state ? `status ${state.Status}, exit code ${state.ExitCode}${state.Error ? `: ${state.Error}` : ""}` : "it could not be inspected";
|
|
442
|
-
return
|
|
453
|
+
return vendorFail("docker", `the computer ${name} was not running after its start (${why}), so it was removed`);
|
|
443
454
|
}
|
|
444
455
|
if (this.#desktop) {
|
|
445
456
|
const shown = await this.#startDisplay(ref, this.#desktop, signal);
|
|
@@ -474,7 +485,7 @@ export class DockerProvider {
|
|
|
474
485
|
if (!pulled.ok)
|
|
475
486
|
return signal?.aborted ? aborted() : pulled;
|
|
476
487
|
if (pulled.value.exitCode !== 0)
|
|
477
|
-
return
|
|
488
|
+
return vendorFail("docker", `docker pull ${image} failed, so nothing was made: ${pulled.value.stderr.trim()}`);
|
|
478
489
|
return ok(undefined);
|
|
479
490
|
}
|
|
480
491
|
/**
|
|
@@ -543,7 +554,7 @@ export class DockerProvider {
|
|
|
543
554
|
if (!volume.ok)
|
|
544
555
|
return volume;
|
|
545
556
|
if (volume.value.exitCode !== 0)
|
|
546
|
-
return
|
|
557
|
+
return vendorFail("docker", `docker volume create ${proxy} failed: ${volume.value.stderr.trim()}`);
|
|
547
558
|
const { image, hint, readyMs } = this.#egress;
|
|
548
559
|
const args = egressRunArgs({ name, user, image, allow, local: this.#hostLocal(), deadline, code: this.#code, labels, ...(hint === undefined ? {} : { hint }) });
|
|
549
560
|
const ran = await this.#run(args, signal);
|
|
@@ -554,7 +565,7 @@ export class DockerProvider {
|
|
|
554
565
|
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}`);
|
|
555
566
|
}
|
|
556
567
|
if (ran.value.exitCode !== 0)
|
|
557
|
-
return
|
|
568
|
+
return vendorFail("docker", `docker run of the egress proxy ${proxy} failed: ${ran.value.stderr.trim()}`);
|
|
558
569
|
// Every call of the poll ends at the readiness bound, so a docker that stops answering cannot hold create past it: a
|
|
559
570
|
// call the bound cut off is the timeout, and the caller's own abort stays aborted.
|
|
560
571
|
const bound = AbortSignal.timeout(readyMs);
|
|
@@ -580,7 +591,7 @@ export class DockerProvider {
|
|
|
580
591
|
const state = found.value[0]?.State;
|
|
581
592
|
if (state?.Running !== true) {
|
|
582
593
|
const words = said.trim().split("\n").filter(Boolean).slice(-3).join("; ");
|
|
583
|
-
return
|
|
594
|
+
return vendorFail("docker", `the egress proxy ${proxy} ended (exit code ${state?.ExitCode ?? "unknown"}) before it was ready${words ? `: ${words}` : ""}`);
|
|
584
595
|
}
|
|
585
596
|
await sleep(EGRESS_POLL_MS, undefined, { signal: either }).catch(() => undefined);
|
|
586
597
|
if (signal?.aborted)
|
|
@@ -722,13 +733,13 @@ export class DockerProvider {
|
|
|
722
733
|
if (!ran.ok)
|
|
723
734
|
return ran;
|
|
724
735
|
if (ran.value.exitCode !== 0)
|
|
725
|
-
return
|
|
736
|
+
return vendorFail("docker", `docker info failed: ${ran.value.stderr.trim()}`);
|
|
726
737
|
let info;
|
|
727
738
|
try {
|
|
728
739
|
info = JSON.parse(ran.value.stdout);
|
|
729
740
|
}
|
|
730
741
|
catch {
|
|
731
|
-
return
|
|
742
|
+
return vendorFail("docker", `docker info wrote what is not JSON: ${ran.value.stdout.slice(0, 200)}`);
|
|
732
743
|
}
|
|
733
744
|
this.#host = hostOf(info);
|
|
734
745
|
return ok(this.#host);
|
|
@@ -850,7 +861,8 @@ export class DockerProvider {
|
|
|
850
861
|
if (hello.error.code !== "gone")
|
|
851
862
|
return hello;
|
|
852
863
|
const words = stderr.trim() || hello.error.message;
|
|
853
|
-
|
|
864
|
+
const why = `cannot reach the daemon in ${ref.name}: ${words}`;
|
|
865
|
+
return noSuchContainer(words) ? fail("not_found", why) : vendorFail("docker", why);
|
|
854
866
|
}
|
|
855
867
|
return ok({ client, hello: hello.value, close });
|
|
856
868
|
}
|
|
@@ -906,7 +918,7 @@ export class DockerProvider {
|
|
|
906
918
|
if (!ran.ok)
|
|
907
919
|
return countTested("Docker", ran);
|
|
908
920
|
if (ran.value.exitCode !== 0)
|
|
909
|
-
return countTested("Docker",
|
|
921
|
+
return countTested("Docker", vendorFail("docker", `docker ps failed: ${ran.value.stderr.trim()}`));
|
|
910
922
|
const names = ran.value.stdout.split("\n").map((line) => line.trim());
|
|
911
923
|
return countTested("Docker", ok({ count: names.filter((name) => NAME.test(name)).length }));
|
|
912
924
|
}
|
|
@@ -921,7 +933,7 @@ export class DockerProvider {
|
|
|
921
933
|
if (!ran.ok)
|
|
922
934
|
return ran;
|
|
923
935
|
if (ran.value.exitCode !== 0)
|
|
924
|
-
return
|
|
936
|
+
return vendorFail("docker", `docker ps failed: ${ran.value.stderr.trim()}`);
|
|
925
937
|
const ids = ran.value.stdout.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
926
938
|
const infos = [];
|
|
927
939
|
const local = this.#hostLocal();
|
|
@@ -963,7 +975,7 @@ export class DockerProvider {
|
|
|
963
975
|
if (!alive.ok)
|
|
964
976
|
return alive;
|
|
965
977
|
if (alive.value.exitCode !== 0)
|
|
966
|
-
return
|
|
978
|
+
return vendorFail("docker", `docker ps failed: ${alive.value.stderr.trim()}`);
|
|
967
979
|
const computers = new Set(lines(alive.value.stdout).filter((name) => NAME.test(name)));
|
|
968
980
|
const at = now.getTime();
|
|
969
981
|
const grace = this.#leftoverGraceMs();
|
|
@@ -984,7 +996,7 @@ export class DockerProvider {
|
|
|
984
996
|
if (!ps.ok)
|
|
985
997
|
return ps;
|
|
986
998
|
if (ps.value.exitCode !== 0)
|
|
987
|
-
return
|
|
999
|
+
return vendorFail("docker", `docker ps for egress proxies failed: ${ps.value.stderr.trim()}`);
|
|
988
1000
|
const ids = lines(ps.value.stdout);
|
|
989
1001
|
for (let from = 0; from < ids.length; from += INSPECT_BATCH) {
|
|
990
1002
|
const found = await this.#inspect(ids.slice(from, from + INSPECT_BATCH), signal);
|
|
@@ -997,7 +1009,7 @@ export class DockerProvider {
|
|
|
997
1009
|
if (!ran.ok)
|
|
998
1010
|
return ran;
|
|
999
1011
|
if (ran.value.exitCode !== 0 && !noSuchContainer(ran.value.stderr))
|
|
1000
|
-
return
|
|
1012
|
+
return vendorFail("docker", `docker rm of the egress proxy ${nameOf(proxy)} failed: ${ran.value.stderr.trim()}`);
|
|
1001
1013
|
removed.push(nameOf(proxy));
|
|
1002
1014
|
}
|
|
1003
1015
|
}
|
|
@@ -1005,7 +1017,7 @@ export class DockerProvider {
|
|
|
1005
1017
|
if (!ls.ok)
|
|
1006
1018
|
return ls;
|
|
1007
1019
|
if (ls.value.exitCode !== 0)
|
|
1008
|
-
return
|
|
1020
|
+
return vendorFail("docker", `docker volume ls for egress volumes failed: ${ls.value.stderr.trim()}`);
|
|
1009
1021
|
const names = lines(ls.value.stdout);
|
|
1010
1022
|
for (let from = 0; from < names.length; from += INSPECT_BATCH) {
|
|
1011
1023
|
const read = await this.#run(["volume", "inspect", "--format", "{{json .}}", ...names.slice(from, from + INSPECT_BATCH)], signal);
|
|
@@ -1017,7 +1029,7 @@ export class DockerProvider {
|
|
|
1017
1029
|
volume = JSON.parse(line);
|
|
1018
1030
|
}
|
|
1019
1031
|
catch {
|
|
1020
|
-
return
|
|
1032
|
+
return vendorFail("docker", `docker volume inspect wrote a line that is not JSON: ${line.slice(0, 200)}`);
|
|
1021
1033
|
}
|
|
1022
1034
|
if (typeof volume.Name !== "string" || !leftover(volume.Labels, volume.CreatedAt))
|
|
1023
1035
|
continue;
|
|
@@ -1025,7 +1037,7 @@ export class DockerProvider {
|
|
|
1025
1037
|
if (!ran.ok)
|
|
1026
1038
|
return ran;
|
|
1027
1039
|
if (ran.value.exitCode !== 0)
|
|
1028
|
-
return
|
|
1040
|
+
return vendorFail("docker", `docker volume rm ${volume.Name} failed: ${ran.value.stderr.trim()}`);
|
|
1029
1041
|
removed.push(`${volume.Name} (volume)`);
|
|
1030
1042
|
}
|
|
1031
1043
|
}
|
|
@@ -1080,19 +1092,19 @@ export class DockerProvider {
|
|
|
1080
1092
|
if (!ran.ok)
|
|
1081
1093
|
return ran;
|
|
1082
1094
|
if (ran.value.exitCode !== 0 && !noSuchContainer(ran.value.stderr))
|
|
1083
|
-
return
|
|
1095
|
+
return vendorFail("docker", `docker ${args[0]} ${ref.name} failed: ${ran.value.stderr.trim()}`);
|
|
1084
1096
|
const label = `label=${EGRESS_LABEL}=${ref.name}`;
|
|
1085
1097
|
const proxies = await this.#run(["ps", "-a", "--no-trunc", "--filter", label, "--format", "{{.ID}}"]);
|
|
1086
1098
|
if (!proxies.ok)
|
|
1087
1099
|
return proxies;
|
|
1088
1100
|
if (proxies.value.exitCode !== 0)
|
|
1089
|
-
return
|
|
1101
|
+
return vendorFail("docker", `docker ps for ${ref.name}'s egress proxy failed: ${proxies.value.stderr.trim()}`);
|
|
1090
1102
|
for (const id of proxies.value.stdout.split("\n").map((line) => line.trim()).filter(Boolean)) {
|
|
1091
1103
|
const ended = await this.#run(how === "stop" ? ["stop", id] : ["rm", "--force", id]);
|
|
1092
1104
|
if (!ended.ok)
|
|
1093
1105
|
return ended;
|
|
1094
1106
|
if (ended.value.exitCode !== 0 && !noSuchContainer(ended.value.stderr))
|
|
1095
|
-
return
|
|
1107
|
+
return vendorFail("docker", `docker ${how === "stop" ? "stop" : "rm"} of ${ref.name}'s egress proxy failed: ${ended.value.stderr.trim()}`);
|
|
1096
1108
|
}
|
|
1097
1109
|
if (how === "stop")
|
|
1098
1110
|
return ok(undefined);
|
|
@@ -1100,13 +1112,13 @@ export class DockerProvider {
|
|
|
1100
1112
|
if (!volumes.ok)
|
|
1101
1113
|
return volumes;
|
|
1102
1114
|
if (volumes.value.exitCode !== 0)
|
|
1103
|
-
return
|
|
1115
|
+
return vendorFail("docker", `docker volume ls for ${ref.name}'s egress volume failed: ${volumes.value.stderr.trim()}`);
|
|
1104
1116
|
for (const volume of volumes.value.stdout.split("\n").map((line) => line.trim()).filter(Boolean)) {
|
|
1105
1117
|
const removed = await this.#run(["volume", "rm", "--force", volume]);
|
|
1106
1118
|
if (!removed.ok)
|
|
1107
1119
|
return removed;
|
|
1108
1120
|
if (removed.value.exitCode !== 0)
|
|
1109
|
-
return
|
|
1121
|
+
return vendorFail("docker", `docker volume rm ${volume} failed: ${removed.value.stderr.trim()}`);
|
|
1110
1122
|
}
|
|
1111
1123
|
return ok(undefined);
|
|
1112
1124
|
}
|
|
@@ -1118,14 +1130,14 @@ export class DockerProvider {
|
|
|
1118
1130
|
const { exitCode, stdout, stderr } = ran.value;
|
|
1119
1131
|
const errors = stderr.split("\n").filter((line) => line.trim() !== "" && !noSuchContainer(line));
|
|
1120
1132
|
if (exitCode !== 0 && errors.length > 0)
|
|
1121
|
-
return
|
|
1133
|
+
return vendorFail("docker", `docker inspect failed: ${errors.join("; ")}`);
|
|
1122
1134
|
const found = [];
|
|
1123
1135
|
for (const line of stdout.split("\n").filter((line) => line.trim() !== "")) {
|
|
1124
1136
|
try {
|
|
1125
1137
|
found.push(JSON.parse(line));
|
|
1126
1138
|
}
|
|
1127
1139
|
catch {
|
|
1128
|
-
return
|
|
1140
|
+
return vendorFail("docker", `docker inspect wrote a line that is not JSON: ${line.slice(0, 200)}`);
|
|
1129
1141
|
}
|
|
1130
1142
|
}
|
|
1131
1143
|
return ok(found);
|
|
@@ -1140,8 +1152,8 @@ export class DockerProvider {
|
|
|
1140
1152
|
if (typeof error.code === "number")
|
|
1141
1153
|
return done(ok({ exitCode: error.code, stdout, stderr }));
|
|
1142
1154
|
if (error.code === "ENOENT")
|
|
1143
|
-
return done(
|
|
1144
|
-
done(
|
|
1155
|
+
return done(vendorFail("docker", `the docker CLI (${this.#docker}) was not found`));
|
|
1156
|
+
done(vendorFail("docker", `docker ${args[0]} failed: ${error.message}`));
|
|
1145
1157
|
});
|
|
1146
1158
|
});
|
|
1147
1159
|
}
|
package/dist/drift.d.ts
CHANGED
|
@@ -1,115 +1,19 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
3
|
-
import { type MountReadBack } from "./mount.js";
|
|
4
|
-
import type { ComputerKind, Group, HelloResult } from "./protocol.js";
|
|
5
|
-
import type { ComputerSpec, NetworkPolicy, NetworkSpec } from "./provider.js";
|
|
1
|
+
import { type ComputerKind, type Group, type HelloResult } from "./protocol.js";
|
|
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;
|
|
@@ -117,44 +21,9 @@ export interface HelloExpected {
|
|
|
117
21
|
groups: Group[];
|
|
118
22
|
/** Go's name (amd64, arm64); not checked when absent. */
|
|
119
23
|
arch?: string;
|
|
24
|
+
/** The daemon was started with --own-network: hello must say which fence holds its programs (NETWORK_FENCES). */
|
|
25
|
+
fence?: true;
|
|
120
26
|
}
|
|
121
|
-
export interface DriftExpected extends HelloExpected {
|
|
122
|
-
/** The daemon file on the host the computer binds, as it was mounted: for DockerProvider, its copy of the daemon. */
|
|
123
|
-
daemonPath: string;
|
|
124
|
-
/** The deadline label's value, as it was set. */
|
|
125
|
-
deadline: string;
|
|
126
|
-
/** The uid:gid the computer was asked to run as. */
|
|
127
|
-
user: string;
|
|
128
|
-
/** Whether the host's Docker gives every container an AppArmor profile, or an SELinux label (hostOf). */
|
|
129
|
-
apparmor: boolean;
|
|
130
|
-
selinux: boolean;
|
|
131
|
-
/** For a computer with an allowlist: its proxy container's inspect (none when it is gone), and where the proxy's code
|
|
132
|
-
* is on the host, as it was bound. */
|
|
133
|
-
proxy?: DockerInspect | null;
|
|
134
|
-
egressCode?: EgressCode;
|
|
135
|
-
/** For a computer with an allowlist: the Docker host's own addresses its proxy must refuse (its --local holds each). */
|
|
136
|
-
hostAddresses?: readonly string[];
|
|
137
|
-
/** The provider's volume option: the daemon and the run's folder are then that volume's subpaths, not binds. */
|
|
138
|
-
volume?: DockerVolume;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* How create mounts a path of this host at `target`: a bind of it, or, with the provider's volume option, the volume's
|
|
142
|
-
* subpath, as HostConfig.Mounts records it (Docker keeps `volume-nocopy` and the subpath under VolumeOptions). Undefined
|
|
143
|
-
* for a path outside the volume, which create never mounts.
|
|
144
|
-
*/
|
|
145
|
-
export declare function mountAsked(path: string, target: string, readonly: boolean, volume: DockerVolume | undefined): Record<string, unknown> | undefined;
|
|
146
|
-
/** Whether a computer's inspect shows any part of an allowlist: the egress volume at its path, or init's relay. */
|
|
147
|
-
export declare function egressShaped(inspected: DockerInspect | null | undefined): boolean;
|
|
148
|
-
/**
|
|
149
|
-
* The network a computer is on, read back from inspect: `none` is network mode none on no network but Docker's own
|
|
150
|
-
* `none`, `open` is the default bridge alone. An allowlist is network mode none with the computer's egress volume
|
|
151
|
-
* mounted read-only at EGRESS_MOUNT and init relaying to its socket, and the list read back from `proxy`, the
|
|
152
|
-
* computer's proxy container's inspect (egressOf: none when it is gone), which must refuse each of `local`, the Docker
|
|
153
|
-
* host's own addresses. Anything else is reported in words, never as a policy it might widen to.
|
|
154
|
-
*/
|
|
155
|
-
export declare function networkOf(inspected: DockerInspect | null | undefined, proxy?: DockerInspect | null, code?: EgressCode, local?: readonly string[]): NetworkPolicy;
|
|
156
|
-
/** Whether a policy read back is the one declared: the same string, or an allowlist with the same entries, normalized. */
|
|
157
|
-
export declare function samePolicy(declared: NetworkSpec, read: NetworkPolicy): boolean;
|
|
158
27
|
/**
|
|
159
28
|
* What `computerd probe` reports from inside a computer: the uid:gid its programs run as, the kernel, reached (the
|
|
160
29
|
* targets that answered: bytes came back) and accepted (those that accepted a connection and sent nothing back). One
|
|
@@ -187,14 +56,5 @@ export declare function probeNetworkDrift(probe: ProbeReport): string[];
|
|
|
187
56
|
* and sent nothing back. A firewall that accepts first and decides after looks so from inside; only an answer is drift.
|
|
188
57
|
*/
|
|
189
58
|
export declare function probeNotes(probe: ProbeReport, network: NetworkSpec | NetworkPolicy): string[];
|
|
190
|
-
/**
|
|
191
|
-
* What is mounted at /workspace, read back from inspect: a read-write bind is the run's folder; nothing is undefined;
|
|
192
|
-
* anything else (read-only, a volume, two mounts) is reported in words, never as a bind it might be.
|
|
193
|
-
*/
|
|
194
|
-
export declare function mountOf(inspected: DockerInspect | null | undefined, volume?: DockerVolume): MountReadBack | undefined;
|
|
195
59
|
/** Every way hello differs from what the provider expects. */
|
|
196
60
|
export declare function helloDrift(hello: HelloResult | null | undefined, expected: HelloExpected): string[];
|
|
197
|
-
/** Every way a created computer differs from its spec, from inspect and hello. */
|
|
198
|
-
export declare function drift(spec: ComputerSpec, inspected: DockerInspect | null | undefined, hello: HelloResult | null | undefined, expected: DriftExpected): string[];
|
|
199
|
-
/** Every way a computer's docker inspect differs from its spec: the fields create asks for, and the closed check. */
|
|
200
|
-
export declare function inspectDrift(spec: ComputerSpec, inspected: DockerInspect | null | undefined, expected: DriftExpected): string[];
|