@parcha/agentrun-computer 0.1.0-beta.34 → 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 +144 -26
- package/dist/browser.d.ts +12 -13
- package/dist/browser.js +16 -14
- package/dist/browserbase.d.ts +3 -5
- package/dist/browserbase.js +16 -13
- package/dist/chrome.js +1 -1
- 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.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.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 +3 -34
- package/dist/daytona.js +34 -61
- 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 -6
- package/dist/docker.js +46 -42
- package/dist/drift.d.ts +3 -145
- package/dist/drift.js +5 -334
- package/dist/e2b.d.ts +2 -8
- package/dist/e2b.js +16 -22
- package/dist/index.d.ts +8 -11
- package/dist/index.js +13 -11
- package/dist/isolation.js +2 -2
- package/dist/janitor.d.ts +18 -1
- package/dist/janitor.js +67 -19
- package/dist/kernel.d.ts +3 -5
- package/dist/kernel.js +19 -16
- package/dist/kinds.d.ts +54 -34
- package/dist/kinds.js +19 -117
- package/dist/labels.d.ts +12 -0
- package/dist/labels.js +39 -1
- package/dist/{local.d.ts → local-chrome.d.ts} +5 -8
- package/dist/{local.js → local-chrome.js} +19 -16
- package/dist/local-supervisor.d.ts +3 -3
- package/dist/local-supervisor.js +3 -3
- package/dist/modal.d.ts +3 -22
- package/dist/modal.js +15 -31
- 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 -15
- package/dist/orgo.js +46 -107
- package/dist/phone-harness.d.ts +4 -10
- package/dist/phone-harness.js +45 -46
- package/dist/provider.d.ts +91 -10
- package/dist/provider.js +42 -0
- 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
|
@@ -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,19 +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 { checkGpu,
|
|
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
|
|
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
|
-
];
|
|
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;
|
|
33
32
|
/**
|
|
34
33
|
* Docker's architecture as `docker version` reports it (amd64, arm64), within timeoutMs, or an error in words. The docker
|
|
35
34
|
* CLI runs with this process's environment, as every call of the provider does, so it asks the Docker the provider uses.
|
|
@@ -193,7 +192,7 @@ export class DockerProvider {
|
|
|
193
192
|
return {
|
|
194
193
|
kind: this.#desktop ? "desktop" : "linux",
|
|
195
194
|
lifetime: "janitor",
|
|
196
|
-
network: [...
|
|
195
|
+
network: [...DOCKER.network],
|
|
197
196
|
allow: { domains: { max: MAX_ALLOW, ports: [...ALLOW_PORTS] }, cidrs: { max: MAX_ALLOW, ports: [...ALLOW_PORTS] }, mixed: true },
|
|
198
197
|
networkReadBack: true,
|
|
199
198
|
isolation: "container",
|
|
@@ -214,6 +213,10 @@ export class DockerProvider {
|
|
|
214
213
|
image(options = {}) {
|
|
215
214
|
return ensureImage(this.#image, { ...options, docker: this.#docker });
|
|
216
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
|
+
}
|
|
217
220
|
/** The spec's refusals, and the host's once create, attach or host() has read it: its problems, a bind or an
|
|
218
221
|
* allowlist on a host that remaps user ids, and an allowlist on a Docker host this provider does not run on. */
|
|
219
222
|
check(spec) {
|
|
@@ -253,7 +256,7 @@ export class DockerProvider {
|
|
|
253
256
|
}
|
|
254
257
|
else if (image.includes("\0"))
|
|
255
258
|
refuse("image", NUL);
|
|
256
|
-
refusals.push(...
|
|
259
|
+
refusals.push(...checkTenure(given, this.capabilities(), "Docker"));
|
|
257
260
|
if (typeof network === "object" && network !== null && "allow" in network) {
|
|
258
261
|
const allow = allowOf(network.allow);
|
|
259
262
|
if ("problem" in allow)
|
|
@@ -377,7 +380,7 @@ export class DockerProvider {
|
|
|
377
380
|
const name = `computer-${randomBytes(6).toString("hex")}`;
|
|
378
381
|
// The lifetime counts from here: what the proxy and docker run take comes out of it.
|
|
379
382
|
const lifetimeFrom = Date.now();
|
|
380
|
-
const deadline = new Date(lifetimeFrom + spec
|
|
383
|
+
const deadline = new Date(lifetimeFrom + runLifetimeMs(spec)).toISOString();
|
|
381
384
|
if (allow !== undefined) {
|
|
382
385
|
// The proxy first, ready before the computer exists: a computer never runs with an allowlist it cannot reach.
|
|
383
386
|
const started = await this.#startEgress(name, user, deadline, allow, spec.labels ?? {}, signal);
|
|
@@ -424,7 +427,7 @@ export class DockerProvider {
|
|
|
424
427
|
// A run that failed or was aborted may still have made the container; an allowlist's proxy and volume go with it.
|
|
425
428
|
const released = await this.release({ id: name, name }, "delete");
|
|
426
429
|
if (started.ok)
|
|
427
|
-
return
|
|
430
|
+
return vendorFail("docker", `docker run failed: ${started.value.stderr.trim()}`);
|
|
428
431
|
// Cut off before its own exit: the daemon may still make the computer after release looked, and then its egress
|
|
429
432
|
// volume with it (#settle).
|
|
430
433
|
const left = await this.#settle([name], allow === undefined ? [] : [egressNameOf(name)]);
|
|
@@ -443,11 +446,11 @@ export class DockerProvider {
|
|
|
443
446
|
if (state?.Running !== true) {
|
|
444
447
|
await this.release(ref, "delete");
|
|
445
448
|
// 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
|
|
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`);
|
|
448
451
|
}
|
|
449
452
|
const why = state ? `status ${state.Status}, exit code ${state.ExitCode}${state.Error ? `: ${state.Error}` : ""}` : "it could not be inspected";
|
|
450
|
-
return
|
|
453
|
+
return vendorFail("docker", `the computer ${name} was not running after its start (${why}), so it was removed`);
|
|
451
454
|
}
|
|
452
455
|
if (this.#desktop) {
|
|
453
456
|
const shown = await this.#startDisplay(ref, this.#desktop, signal);
|
|
@@ -482,7 +485,7 @@ export class DockerProvider {
|
|
|
482
485
|
if (!pulled.ok)
|
|
483
486
|
return signal?.aborted ? aborted() : pulled;
|
|
484
487
|
if (pulled.value.exitCode !== 0)
|
|
485
|
-
return
|
|
488
|
+
return vendorFail("docker", `docker pull ${image} failed, so nothing was made: ${pulled.value.stderr.trim()}`);
|
|
486
489
|
return ok(undefined);
|
|
487
490
|
}
|
|
488
491
|
/**
|
|
@@ -551,7 +554,7 @@ export class DockerProvider {
|
|
|
551
554
|
if (!volume.ok)
|
|
552
555
|
return volume;
|
|
553
556
|
if (volume.value.exitCode !== 0)
|
|
554
|
-
return
|
|
557
|
+
return vendorFail("docker", `docker volume create ${proxy} failed: ${volume.value.stderr.trim()}`);
|
|
555
558
|
const { image, hint, readyMs } = this.#egress;
|
|
556
559
|
const args = egressRunArgs({ name, user, image, allow, local: this.#hostLocal(), deadline, code: this.#code, labels, ...(hint === undefined ? {} : { hint }) });
|
|
557
560
|
const ran = await this.#run(args, signal);
|
|
@@ -562,7 +565,7 @@ export class DockerProvider {
|
|
|
562
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}`);
|
|
563
566
|
}
|
|
564
567
|
if (ran.value.exitCode !== 0)
|
|
565
|
-
return
|
|
568
|
+
return vendorFail("docker", `docker run of the egress proxy ${proxy} failed: ${ran.value.stderr.trim()}`);
|
|
566
569
|
// Every call of the poll ends at the readiness bound, so a docker that stops answering cannot hold create past it: a
|
|
567
570
|
// call the bound cut off is the timeout, and the caller's own abort stays aborted.
|
|
568
571
|
const bound = AbortSignal.timeout(readyMs);
|
|
@@ -588,7 +591,7 @@ export class DockerProvider {
|
|
|
588
591
|
const state = found.value[0]?.State;
|
|
589
592
|
if (state?.Running !== true) {
|
|
590
593
|
const words = said.trim().split("\n").filter(Boolean).slice(-3).join("; ");
|
|
591
|
-
return
|
|
594
|
+
return vendorFail("docker", `the egress proxy ${proxy} ended (exit code ${state?.ExitCode ?? "unknown"}) before it was ready${words ? `: ${words}` : ""}`);
|
|
592
595
|
}
|
|
593
596
|
await sleep(EGRESS_POLL_MS, undefined, { signal: either }).catch(() => undefined);
|
|
594
597
|
if (signal?.aborted)
|
|
@@ -730,13 +733,13 @@ export class DockerProvider {
|
|
|
730
733
|
if (!ran.ok)
|
|
731
734
|
return ran;
|
|
732
735
|
if (ran.value.exitCode !== 0)
|
|
733
|
-
return
|
|
736
|
+
return vendorFail("docker", `docker info failed: ${ran.value.stderr.trim()}`);
|
|
734
737
|
let info;
|
|
735
738
|
try {
|
|
736
739
|
info = JSON.parse(ran.value.stdout);
|
|
737
740
|
}
|
|
738
741
|
catch {
|
|
739
|
-
return
|
|
742
|
+
return vendorFail("docker", `docker info wrote what is not JSON: ${ran.value.stdout.slice(0, 200)}`);
|
|
740
743
|
}
|
|
741
744
|
this.#host = hostOf(info);
|
|
742
745
|
return ok(this.#host);
|
|
@@ -858,7 +861,8 @@ export class DockerProvider {
|
|
|
858
861
|
if (hello.error.code !== "gone")
|
|
859
862
|
return hello;
|
|
860
863
|
const words = stderr.trim() || hello.error.message;
|
|
861
|
-
|
|
864
|
+
const why = `cannot reach the daemon in ${ref.name}: ${words}`;
|
|
865
|
+
return noSuchContainer(words) ? fail("not_found", why) : vendorFail("docker", why);
|
|
862
866
|
}
|
|
863
867
|
return ok({ client, hello: hello.value, close });
|
|
864
868
|
}
|
|
@@ -914,7 +918,7 @@ export class DockerProvider {
|
|
|
914
918
|
if (!ran.ok)
|
|
915
919
|
return countTested("Docker", ran);
|
|
916
920
|
if (ran.value.exitCode !== 0)
|
|
917
|
-
return countTested("Docker",
|
|
921
|
+
return countTested("Docker", vendorFail("docker", `docker ps failed: ${ran.value.stderr.trim()}`));
|
|
918
922
|
const names = ran.value.stdout.split("\n").map((line) => line.trim());
|
|
919
923
|
return countTested("Docker", ok({ count: names.filter((name) => NAME.test(name)).length }));
|
|
920
924
|
}
|
|
@@ -929,7 +933,7 @@ export class DockerProvider {
|
|
|
929
933
|
if (!ran.ok)
|
|
930
934
|
return ran;
|
|
931
935
|
if (ran.value.exitCode !== 0)
|
|
932
|
-
return
|
|
936
|
+
return vendorFail("docker", `docker ps failed: ${ran.value.stderr.trim()}`);
|
|
933
937
|
const ids = ran.value.stdout.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
934
938
|
const infos = [];
|
|
935
939
|
const local = this.#hostLocal();
|
|
@@ -971,7 +975,7 @@ export class DockerProvider {
|
|
|
971
975
|
if (!alive.ok)
|
|
972
976
|
return alive;
|
|
973
977
|
if (alive.value.exitCode !== 0)
|
|
974
|
-
return
|
|
978
|
+
return vendorFail("docker", `docker ps failed: ${alive.value.stderr.trim()}`);
|
|
975
979
|
const computers = new Set(lines(alive.value.stdout).filter((name) => NAME.test(name)));
|
|
976
980
|
const at = now.getTime();
|
|
977
981
|
const grace = this.#leftoverGraceMs();
|
|
@@ -992,7 +996,7 @@ export class DockerProvider {
|
|
|
992
996
|
if (!ps.ok)
|
|
993
997
|
return ps;
|
|
994
998
|
if (ps.value.exitCode !== 0)
|
|
995
|
-
return
|
|
999
|
+
return vendorFail("docker", `docker ps for egress proxies failed: ${ps.value.stderr.trim()}`);
|
|
996
1000
|
const ids = lines(ps.value.stdout);
|
|
997
1001
|
for (let from = 0; from < ids.length; from += INSPECT_BATCH) {
|
|
998
1002
|
const found = await this.#inspect(ids.slice(from, from + INSPECT_BATCH), signal);
|
|
@@ -1005,7 +1009,7 @@ export class DockerProvider {
|
|
|
1005
1009
|
if (!ran.ok)
|
|
1006
1010
|
return ran;
|
|
1007
1011
|
if (ran.value.exitCode !== 0 && !noSuchContainer(ran.value.stderr))
|
|
1008
|
-
return
|
|
1012
|
+
return vendorFail("docker", `docker rm of the egress proxy ${nameOf(proxy)} failed: ${ran.value.stderr.trim()}`);
|
|
1009
1013
|
removed.push(nameOf(proxy));
|
|
1010
1014
|
}
|
|
1011
1015
|
}
|
|
@@ -1013,7 +1017,7 @@ export class DockerProvider {
|
|
|
1013
1017
|
if (!ls.ok)
|
|
1014
1018
|
return ls;
|
|
1015
1019
|
if (ls.value.exitCode !== 0)
|
|
1016
|
-
return
|
|
1020
|
+
return vendorFail("docker", `docker volume ls for egress volumes failed: ${ls.value.stderr.trim()}`);
|
|
1017
1021
|
const names = lines(ls.value.stdout);
|
|
1018
1022
|
for (let from = 0; from < names.length; from += INSPECT_BATCH) {
|
|
1019
1023
|
const read = await this.#run(["volume", "inspect", "--format", "{{json .}}", ...names.slice(from, from + INSPECT_BATCH)], signal);
|
|
@@ -1025,7 +1029,7 @@ export class DockerProvider {
|
|
|
1025
1029
|
volume = JSON.parse(line);
|
|
1026
1030
|
}
|
|
1027
1031
|
catch {
|
|
1028
|
-
return
|
|
1032
|
+
return vendorFail("docker", `docker volume inspect wrote a line that is not JSON: ${line.slice(0, 200)}`);
|
|
1029
1033
|
}
|
|
1030
1034
|
if (typeof volume.Name !== "string" || !leftover(volume.Labels, volume.CreatedAt))
|
|
1031
1035
|
continue;
|
|
@@ -1033,7 +1037,7 @@ export class DockerProvider {
|
|
|
1033
1037
|
if (!ran.ok)
|
|
1034
1038
|
return ran;
|
|
1035
1039
|
if (ran.value.exitCode !== 0)
|
|
1036
|
-
return
|
|
1040
|
+
return vendorFail("docker", `docker volume rm ${volume.Name} failed: ${ran.value.stderr.trim()}`);
|
|
1037
1041
|
removed.push(`${volume.Name} (volume)`);
|
|
1038
1042
|
}
|
|
1039
1043
|
}
|
|
@@ -1088,19 +1092,19 @@ export class DockerProvider {
|
|
|
1088
1092
|
if (!ran.ok)
|
|
1089
1093
|
return ran;
|
|
1090
1094
|
if (ran.value.exitCode !== 0 && !noSuchContainer(ran.value.stderr))
|
|
1091
|
-
return
|
|
1095
|
+
return vendorFail("docker", `docker ${args[0]} ${ref.name} failed: ${ran.value.stderr.trim()}`);
|
|
1092
1096
|
const label = `label=${EGRESS_LABEL}=${ref.name}`;
|
|
1093
1097
|
const proxies = await this.#run(["ps", "-a", "--no-trunc", "--filter", label, "--format", "{{.ID}}"]);
|
|
1094
1098
|
if (!proxies.ok)
|
|
1095
1099
|
return proxies;
|
|
1096
1100
|
if (proxies.value.exitCode !== 0)
|
|
1097
|
-
return
|
|
1101
|
+
return vendorFail("docker", `docker ps for ${ref.name}'s egress proxy failed: ${proxies.value.stderr.trim()}`);
|
|
1098
1102
|
for (const id of proxies.value.stdout.split("\n").map((line) => line.trim()).filter(Boolean)) {
|
|
1099
1103
|
const ended = await this.#run(how === "stop" ? ["stop", id] : ["rm", "--force", id]);
|
|
1100
1104
|
if (!ended.ok)
|
|
1101
1105
|
return ended;
|
|
1102
1106
|
if (ended.value.exitCode !== 0 && !noSuchContainer(ended.value.stderr))
|
|
1103
|
-
return
|
|
1107
|
+
return vendorFail("docker", `docker ${how === "stop" ? "stop" : "rm"} of ${ref.name}'s egress proxy failed: ${ended.value.stderr.trim()}`);
|
|
1104
1108
|
}
|
|
1105
1109
|
if (how === "stop")
|
|
1106
1110
|
return ok(undefined);
|
|
@@ -1108,13 +1112,13 @@ export class DockerProvider {
|
|
|
1108
1112
|
if (!volumes.ok)
|
|
1109
1113
|
return volumes;
|
|
1110
1114
|
if (volumes.value.exitCode !== 0)
|
|
1111
|
-
return
|
|
1115
|
+
return vendorFail("docker", `docker volume ls for ${ref.name}'s egress volume failed: ${volumes.value.stderr.trim()}`);
|
|
1112
1116
|
for (const volume of volumes.value.stdout.split("\n").map((line) => line.trim()).filter(Boolean)) {
|
|
1113
1117
|
const removed = await this.#run(["volume", "rm", "--force", volume]);
|
|
1114
1118
|
if (!removed.ok)
|
|
1115
1119
|
return removed;
|
|
1116
1120
|
if (removed.value.exitCode !== 0)
|
|
1117
|
-
return
|
|
1121
|
+
return vendorFail("docker", `docker volume rm ${volume} failed: ${removed.value.stderr.trim()}`);
|
|
1118
1122
|
}
|
|
1119
1123
|
return ok(undefined);
|
|
1120
1124
|
}
|
|
@@ -1126,14 +1130,14 @@ export class DockerProvider {
|
|
|
1126
1130
|
const { exitCode, stdout, stderr } = ran.value;
|
|
1127
1131
|
const errors = stderr.split("\n").filter((line) => line.trim() !== "" && !noSuchContainer(line));
|
|
1128
1132
|
if (exitCode !== 0 && errors.length > 0)
|
|
1129
|
-
return
|
|
1133
|
+
return vendorFail("docker", `docker inspect failed: ${errors.join("; ")}`);
|
|
1130
1134
|
const found = [];
|
|
1131
1135
|
for (const line of stdout.split("\n").filter((line) => line.trim() !== "")) {
|
|
1132
1136
|
try {
|
|
1133
1137
|
found.push(JSON.parse(line));
|
|
1134
1138
|
}
|
|
1135
1139
|
catch {
|
|
1136
|
-
return
|
|
1140
|
+
return vendorFail("docker", `docker inspect wrote a line that is not JSON: ${line.slice(0, 200)}`);
|
|
1137
1141
|
}
|
|
1138
1142
|
}
|
|
1139
1143
|
return ok(found);
|
|
@@ -1148,8 +1152,8 @@ export class DockerProvider {
|
|
|
1148
1152
|
if (typeof error.code === "number")
|
|
1149
1153
|
return done(ok({ exitCode: error.code, stdout, stderr }));
|
|
1150
1154
|
if (error.code === "ENOENT")
|
|
1151
|
-
return done(
|
|
1152
|
-
done(
|
|
1155
|
+
return done(vendorFail("docker", `the docker CLI (${this.#docker}) was not found`));
|
|
1156
|
+
done(vendorFail("docker", `docker ${args[0]} failed: ${error.message}`));
|
|
1153
1157
|
});
|
|
1154
1158
|
});
|
|
1155
1159
|
}
|
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[];
|