@parcha/agentrun-computer 0.1.0-beta.57 → 0.1.0-beta.59
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 +187 -62
- package/box/Dockerfile +4 -3
- package/box/install.sh +57 -11
- package/dist/agent37.js +6 -9
- package/dist/attach.d.ts +24 -4
- package/dist/attach.js +50 -19
- package/dist/boxd.js +22 -9
- package/dist/browserbase.d.ts +6 -2
- package/dist/browserbase.js +50 -7
- package/dist/child-env.d.ts +11 -0
- package/dist/child-env.js +22 -0
- package/dist/chrome.d.ts +5 -2
- package/dist/chrome.js +5 -2
- package/dist/cloudflare.d.ts +2 -0
- package/dist/cloudflare.js +5 -3
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +1 -1
- package/dist/conformance/agent37.d.ts +10 -38
- package/dist/conformance/agent37.js +25 -113
- package/dist/conformance/archil.d.ts +13 -3
- package/dist/conformance/archil.js +22 -17
- package/dist/conformance/boxd.d.ts +8 -31
- package/dist/conformance/boxd.js +19 -74
- package/dist/conformance/browserbase.d.ts +3 -6
- package/dist/conformance/browserbase.js +6 -17
- package/dist/conformance/cases/health.js +6 -3
- package/dist/conformance/cli.d.ts +3 -1
- package/dist/conformance/cli.js +69 -9
- package/dist/conformance/cloudflare.d.ts +3 -6
- package/dist/conformance/cloudflare.js +7 -15
- package/dist/conformance/daytona.d.ts +6 -20
- package/dist/conformance/daytona.js +22 -57
- package/dist/conformance/dial-only.d.ts +4 -3
- package/dist/conformance/dial-only.js +3 -3
- package/dist/conformance/docker.d.ts +4 -5
- package/dist/conformance/docker.js +8 -14
- package/dist/conformance/e2b.d.ts +10 -36
- package/dist/conformance/e2b.js +27 -84
- package/dist/conformance/fly.d.ts +3 -6
- package/dist/conformance/fly.js +2 -6
- package/dist/conformance/groundbox.d.ts +7 -23
- package/dist/conformance/groundbox.js +16 -56
- package/dist/conformance/index.d.ts +1 -0
- package/dist/conformance/index.js +1 -0
- package/dist/conformance/kernel.d.ts +3 -6
- package/dist/conformance/kernel.js +5 -15
- package/dist/conformance/kind.d.ts +0 -6
- package/dist/conformance/kind.js +0 -4
- package/dist/conformance/local-chrome.d.ts +5 -7
- package/dist/conformance/local-chrome.js +7 -11
- package/dist/conformance/modal.d.ts +10 -38
- package/dist/conformance/modal.js +27 -74
- package/dist/conformance/module-kit.d.ts +87 -0
- package/dist/conformance/module-kit.js +88 -0
- package/dist/conformance/morph.d.ts +7 -23
- package/dist/conformance/morph.js +20 -66
- package/dist/conformance/orgo.d.ts +5 -10
- package/dist/conformance/orgo.js +15 -27
- package/dist/conformance/phone-harness.d.ts +3 -5
- package/dist/conformance/phone-harness.js +3 -11
- package/dist/conformance/runner.d.ts +13 -3
- package/dist/conformance/runner.js +32 -11
- package/dist/conformance/smolcloud.d.ts +7 -23
- package/dist/conformance/smolcloud.js +16 -49
- package/dist/conformance/sweep.d.ts +10 -5
- package/dist/conformance/sweep.js +91 -38
- package/dist/conformance/tti.d.ts +69 -0
- package/dist/conformance/tti.js +205 -0
- package/dist/conformance/types.d.ts +9 -2
- package/dist/daytona.js +60 -20
- package/dist/descriptor.d.ts +10 -0
- package/dist/descriptor.js +7 -0
- package/dist/descriptors/browserbase.d.ts +3 -0
- package/dist/descriptors/browserbase.js +4 -0
- package/dist/descriptors/docker.d.ts +1 -0
- package/dist/descriptors/docker.js +3 -0
- package/dist/descriptors/env-names.d.ts +32 -0
- package/dist/descriptors/env-names.js +60 -0
- package/dist/descriptors/index.d.ts +9 -2
- package/dist/descriptors/kernel.d.ts +3 -0
- package/dist/descriptors/kernel.js +2 -0
- package/dist/descriptors/local-chrome.d.ts +1 -1
- package/dist/descriptors/local-chrome.js +5 -3
- package/dist/descriptors/phone-harness.d.ts +1 -1
- package/dist/descriptors/phone-harness.js +4 -2
- package/dist/docker/egress.d.ts +7 -0
- package/dist/docker/egress.js +8 -0
- package/dist/docker/image.d.ts +5 -1
- package/dist/docker/image.js +12 -8
- package/dist/docker.d.ts +63 -15
- package/dist/docker.js +181 -98
- package/dist/drift.js +6 -6
- package/dist/e2b.d.ts +2 -2
- package/dist/e2b.js +2 -3
- package/dist/groundbox.js +6 -6
- package/dist/host.d.ts +23 -0
- package/dist/hosted/download.d.ts +23 -0
- package/dist/hosted/download.js +144 -0
- package/dist/hosted/process.d.ts +5 -0
- package/dist/hosted/process.js +20 -0
- package/dist/hosted/provider.js +120 -48
- package/dist/hosted/rest.d.ts +19 -8
- package/dist/hosted/rest.js +47 -14
- package/dist/hosted/scripts.d.ts +10 -0
- package/dist/hosted/scripts.js +23 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/janitor.d.ts +7 -1
- package/dist/janitor.js +2 -2
- package/dist/kernel.js +1 -1
- package/dist/local-chrome.d.ts +5 -2
- package/dist/local-chrome.js +4 -2
- package/dist/local-supervisor.js +1 -0
- package/dist/modal.d.ts +6 -5
- package/dist/modal.js +7 -7
- package/dist/morph.js +5 -8
- package/dist/orgo-channel.d.ts +3 -2
- package/dist/orgo-channel.js +3 -3
- package/dist/orgo-desktop.js +2 -4
- package/dist/orgo.js +2 -4
- package/dist/phone-harness.d.ts +7 -5
- package/dist/phone-harness.js +60 -61
- package/dist/protocol.d.ts +10 -0
- package/dist/protocol.js +17 -0
- package/dist/provider.d.ts +6 -2
- package/dist/screen-watch.d.ts +6 -1
- package/dist/screen-watch.js +166 -12
- package/dist/vendor-sdk.d.ts +9 -0
- package/dist/vendor-sdk.js +26 -0
- package/package.json +8 -1
package/dist/docker.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { execFile, spawn } from "node:child_process";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { readFileSync, statSync } from "node:fs";
|
|
5
|
-
import { resolve } from "node:path";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
6
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { DaemonClient } from "./client.js";
|
|
@@ -11,8 +11,9 @@ import { DOCKER } from "./descriptors/docker.js";
|
|
|
11
11
|
import { DESKTOP_GROUPS, desktopOf, startDisplay } from "./desktop.js";
|
|
12
12
|
import { COMPUTER_LABEL, DAEMON_IN_COMPUTER, DEADLINE_LABEL, DEFAULT_CPUS, DEFAULT_MEMORY_MB, DEFAULT_PIDS, helloDrift, WORK, } from "./drift.js";
|
|
13
13
|
import { CPU_PERIOD_US, DAEMON_DIR_IN_COMPUTER, drift, egressShaped, hostOf, inspectDrift, mountOf, networkOf, samePolicy, tmpfsOf, } from "./docker/inspect.js";
|
|
14
|
+
import { dockerEnv } from "./child-env.js";
|
|
14
15
|
import { DOCKER_RECIPE, ensureImage, imageSourceProblem } from "./docker/image.js";
|
|
15
|
-
import { ALLOW_PORTS, allowOf, containerSigns, EGRESS_IMAGE, EGRESS_LABEL, EGRESS_MOUNT, EGRESS_NETWORK, EGRESS_READY_MS, EGRESS_SOCKET, egressCode, egressCodeProblem, egressNameOf, egressNetworkArgs, egressNetworkProblem, egressRunArgs, egressVolumeArgs, hostAddresses, MAX_ALLOW, policyWords, RELAY_FLAG, } from "./docker/egress.js";
|
|
16
|
+
import { ALLOW_PORTS, allowOf, containerSigns, EGRESS_IMAGE, EGRESS_LABEL, EGRESS_MOUNT, EGRESS_NETWORK, EGRESS_READY_MS, EGRESS_SOCKET, egressCode, egressCodeProblem, egressNameOf, egressNetworkArgs, egressNetworkProblem, egressRunArgs, egressVolumeArgs, hostAddresses, MAX_ALLOW, NO_CONFIG_PROXY, policyWords, RELAY_FLAG, } from "./docker/egress.js";
|
|
16
17
|
import { daemonStage, daemonVerified, egressStage, egressStaged } from "./docker/stage.js";
|
|
17
18
|
import { EGRESS_READY } from "./docker/egress-proxy.js";
|
|
18
19
|
import { OLD_ENGINE, outsideWords, subpathOf, VOLUME_SUBPATH_ENGINE, volumeMount, volumeOf } from "./docker/volume.js";
|
|
@@ -20,6 +21,7 @@ import { addressBytes } from "./docker/egress-table.js";
|
|
|
20
21
|
import { checkMount, WORKSPACE } from "./mount.js";
|
|
21
22
|
import { checkGpu, checkTenure, runLifetimeMs, } from "./provider.js";
|
|
22
23
|
import { failFor, ok, vendorFail } from "./result.js";
|
|
24
|
+
import { OWNER_LABEL, OWNER_SERVER_LABEL } from "./labels.js";
|
|
23
25
|
import { CreateRequests, endedWords, otherSpecWords } from "./create-requests.js";
|
|
24
26
|
import { daemonWatch } from "./screen-watch.js";
|
|
25
27
|
import { countTested } from "./test-connection.js";
|
|
@@ -27,11 +29,12 @@ import { countTested } from "./test-connection.js";
|
|
|
27
29
|
const fail = failFor("docker");
|
|
28
30
|
/**
|
|
29
31
|
* Docker's architecture as `docker version` reports it (amd64, arm64), within timeoutMs, or an error in words. The docker
|
|
30
|
-
* CLI runs with
|
|
32
|
+
* CLI runs with the names of `env` docker reads (dockerEnv), as every call of the provider does, so it asks the Docker the
|
|
33
|
+
* provider uses.
|
|
31
34
|
*/
|
|
32
|
-
export function dockerArch({ docker = "docker", timeoutMs = 30_000 } = {}) {
|
|
35
|
+
export function dockerArch({ docker = "docker", timeoutMs = 30_000, env } = {}) {
|
|
33
36
|
return new Promise((resolve, reject) => {
|
|
34
|
-
execFile(docker, ["version", "--format", "{{.Server.Arch}}"], { encoding: "utf8", timeout: timeoutMs, killSignal: "SIGKILL" }, (error, stdout, stderr) => {
|
|
37
|
+
execFile(docker, ["version", "--format", "{{.Server.Arch}}"], { env: dockerEnv(env), encoding: "utf8", timeout: timeoutMs, killSignal: "SIGKILL" }, (error, stdout, stderr) => {
|
|
35
38
|
if (!error)
|
|
36
39
|
return resolve(stdout.trim());
|
|
37
40
|
const killed = error.killed === true && error.signal === "SIGKILL";
|
|
@@ -40,19 +43,28 @@ export function dockerArch({ docker = "docker", timeoutMs = 30_000 } = {}) {
|
|
|
40
43
|
});
|
|
41
44
|
});
|
|
42
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* The daemon a Docker computer binds for Docker's architecture `arch` (dockerArch): computerd-linux-<arch> in `dir`,
|
|
48
|
+
* default this package's own build, and, when no such file is there, why, with the command that builds it. create()
|
|
49
|
+
* takes its daemon here, and so does a server's start check of Docker, so the two can't disagree.
|
|
50
|
+
*/
|
|
51
|
+
export function dockerDaemonOf(arch, dir = fileURLToPath(new URL(".", import.meta.url))) {
|
|
52
|
+
const path = join(dir, `computerd-linux-${arch}`);
|
|
53
|
+
return fileMode(path) === undefined ? { path, missing: `no daemon for Docker's ${arch} at ${path}: run npm run build:daemon -w @parcha/agentrun-computer` } : { path };
|
|
54
|
+
}
|
|
43
55
|
/**
|
|
44
56
|
* A DockerProvider from its options alone; it reads no environment. Without options.daemonPath it asks Docker its
|
|
45
|
-
* architecture and takes this package's daemon for it, and says when that daemon is not built. The image
|
|
46
|
-
* too (default the provider's own recipe): no image name is read from the environment.
|
|
57
|
+
* architecture and takes this package's daemon for it (dockerDaemonOf), and says when that daemon is not built. The image
|
|
58
|
+
* is an option too (default the provider's own recipe): no image name is read from the environment.
|
|
47
59
|
*/
|
|
48
60
|
export async function create(options = {}) {
|
|
49
61
|
const { timeoutMs, ...given } = options;
|
|
50
62
|
let daemonPath = given.daemonPath || undefined;
|
|
51
63
|
if (daemonPath === undefined) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
const daemon = dockerDaemonOf(await dockerArch({ ...(given.docker ? { docker: given.docker } : {}), ...(given.env ? { env: given.env } : {}), ...(timeoutMs === undefined ? {} : { timeoutMs }) }));
|
|
65
|
+
if (daemon.missing !== undefined)
|
|
66
|
+
throw new Error(daemon.missing);
|
|
67
|
+
daemonPath = daemon.path;
|
|
56
68
|
}
|
|
57
69
|
return new DockerProvider({ ...given, daemonPath });
|
|
58
70
|
}
|
|
@@ -102,9 +114,9 @@ const REQUEST_WAIT_MS = 120_000;
|
|
|
102
114
|
const REQUEST_POLL_MS = 500;
|
|
103
115
|
/** After a docker run cut off before its own exit: how long, at most, the leftovers are removed and looked for again,
|
|
104
116
|
* how often, and for how long in a row the looks must find none of them before they count as gone (#settle). */
|
|
105
|
-
const SETTLE_MS = 10_000;
|
|
117
|
+
export const SETTLE_MS = 10_000;
|
|
106
118
|
const SETTLE_EVERY_MS = 500;
|
|
107
|
-
const SETTLE_QUIET_MS = 3_000;
|
|
119
|
+
export const SETTLE_QUIET_MS = 3_000;
|
|
108
120
|
/** The label naming which create made a computer's container: after its own docker run failed or was cut off, a create
|
|
109
121
|
* removes the container it made, never one another create of the same request made under the name. */
|
|
110
122
|
const ATTEMPT_LABEL = "agentrun.computer.attempt";
|
|
@@ -114,15 +126,16 @@ const ASKED_LABEL = "agentrun.computer.labels";
|
|
|
114
126
|
/** What #settle reads of each container it looks for: its id, its name, and its labels (whose attempt it is). */
|
|
115
127
|
const SETTLE_FORMAT = '{"Id":{{json .Id}},"Name":{{json .Name}},"Config":{"Labels":{{json .Config.Labels}}}}';
|
|
116
128
|
/**
|
|
117
|
-
* Why #settle could not show its leftovers gone within
|
|
118
|
-
* last look still found; or, when the last look found none
|
|
119
|
-
* checked (`checked`), which could not be confirmed gone. Exported
|
|
129
|
+
* Why #settle could not show its leftovers gone within its bound (`bounds`, the defaults unless the provider was given
|
|
130
|
+
* its own), in words that always name them: `there`, what its last look still found; or, when the last look found none
|
|
131
|
+
* but the quiet window was not complete, every name it checked (`checked`), which could not be confirmed gone. Exported
|
|
132
|
+
* for its test.
|
|
120
133
|
*/
|
|
121
|
-
export function settleWords(checked, there) {
|
|
134
|
+
export function settleWords(checked, there, bounds = settleBoundsOf({})) {
|
|
122
135
|
if (there.length > 0)
|
|
123
|
-
return `${there.join(" and ")} ${there.length === 1 ? "was" : "were"} still there ${
|
|
136
|
+
return `${there.join(" and ")} ${there.length === 1 ? "was" : "were"} still there ${bounds.settleMs / 1000} s after docker run was cut off`;
|
|
124
137
|
const named = checked.length > 0 ? checked.join(" and ") : "what docker run may have made";
|
|
125
|
-
return `${named} could not be confirmed gone within ${
|
|
138
|
+
return `${named} could not be confirmed gone within ${bounds.settleMs / 1000} s after docker run was cut off: the last look found none, but not for ${bounds.quietMs / 1000} s in a row`;
|
|
126
139
|
}
|
|
127
140
|
/** Only the fields hostOf reads, as JSON. */
|
|
128
141
|
const INFO_FORMAT = '{"Architecture":{{json .Architecture}},"SecurityOptions":{{json .SecurityOptions}},"MemoryLimit":{{json .MemoryLimit}},' +
|
|
@@ -148,10 +161,14 @@ export class DockerProvider {
|
|
|
148
161
|
/** The volume option: the daemon's staged directory and a run folder are its subpaths (src/docker/volume.ts). */
|
|
149
162
|
#volume;
|
|
150
163
|
#docker;
|
|
164
|
+
/** Every docker CLI call's whole environment (dockerEnv of the env option). */
|
|
165
|
+
#env;
|
|
151
166
|
#user;
|
|
152
167
|
#desktop;
|
|
153
168
|
#image;
|
|
154
169
|
#egress;
|
|
170
|
+
/** The settleMs and settleQuietMs options: #settle's bounds; settleMs also bounds each removal #gone waits for. */
|
|
171
|
+
#settleBounds;
|
|
155
172
|
/** Each create in flight, and the names of the computers this provider deleted (create-requests.ts). */
|
|
156
173
|
#requests = new CreateRequests();
|
|
157
174
|
/** Why this provider's own interfaces are not the Docker host's, in words, or none: read once, for the first allowlist
|
|
@@ -178,7 +195,7 @@ export class DockerProvider {
|
|
|
178
195
|
}
|
|
179
196
|
/** The host as docker info first read it: a host's enforcement does not change under a running provider. */
|
|
180
197
|
#host;
|
|
181
|
-
constructor({ daemonPath, daemonCache, docker = "docker", user, desktop, egress, image = { recipe: DOCKER_RECIPE }, volume }) {
|
|
198
|
+
constructor({ daemonPath, daemonCache, docker = "docker", user, desktop, egress, image = { recipe: DOCKER_RECIPE }, volume, env, settleMs, settleQuietMs }) {
|
|
182
199
|
this.#daemonPath = resolve(daemonPath);
|
|
183
200
|
this.#daemonCache = resolve(daemonCache ?? defaultDaemonCache());
|
|
184
201
|
this.#volume = volume === undefined ? undefined : volumeOf(volume);
|
|
@@ -187,12 +204,14 @@ export class DockerProvider {
|
|
|
187
204
|
throw new Error(`${outsideWords(this.#volume, this.#daemonCache, "the provider's daemonCache")}: pass a daemonCache below it`);
|
|
188
205
|
}
|
|
189
206
|
this.#docker = docker;
|
|
207
|
+
this.#env = dockerEnv(env);
|
|
190
208
|
const unusable = imageSourceProblem(image);
|
|
191
209
|
if (unusable !== undefined)
|
|
192
210
|
throw new Error(`the provider's image: ${unusable}`);
|
|
193
211
|
this.#image = image;
|
|
194
212
|
this.#desktop = desktop === undefined ? undefined : desktopOf(desktop);
|
|
195
213
|
this.#egress = egressOptionsOf(egress ?? {});
|
|
214
|
+
this.#settleBounds = settleBoundsOf({ settleMs, settleQuietMs });
|
|
196
215
|
const given = user === undefined ? defaultUser() : userOf(user);
|
|
197
216
|
if (given === undefined)
|
|
198
217
|
throw new Error(`the provider's user ${JSON.stringify(user)} must be ${USER_FORM}`);
|
|
@@ -230,7 +249,7 @@ export class DockerProvider {
|
|
|
230
249
|
* Docker has none; one inspect when it has. Concurrent calls in one process share one build (ensureImage).
|
|
231
250
|
*/
|
|
232
251
|
image(options = {}) {
|
|
233
|
-
return ensureImage(this.#image, { ...options, docker: this.#docker });
|
|
252
|
+
return ensureImage(this.#image, { ...options, docker: this.#docker, env: this.#env });
|
|
234
253
|
}
|
|
235
254
|
/** The provider contract's prepareImage (its descriptor declares it): image(), its recipe built or its image pulled. */
|
|
236
255
|
prepareImage(context = {}) {
|
|
@@ -533,6 +552,7 @@ export class DockerProvider {
|
|
|
533
552
|
args.push("--user", user, "--env", `HOME=${WORK}`);
|
|
534
553
|
if (this.#desktop)
|
|
535
554
|
args.push("--env", `DISPLAY=${this.#desktop.display}`);
|
|
555
|
+
args.push(...NO_CONFIG_PROXY);
|
|
536
556
|
for (const [path, options] of Object.entries(tmpfsOf(user, memoryMb)))
|
|
537
557
|
args.push("--tmpfs", `${path}:${options}`);
|
|
538
558
|
args.push("--cap-drop", "ALL", "--security-opt", "no-new-privileges", "--pids-limit", String(spec.pids ?? DEFAULT_PIDS));
|
|
@@ -643,14 +663,14 @@ export class DockerProvider {
|
|
|
643
663
|
* After a `docker run` that did not end with an exit of the CLI's own (it was aborted, or the CLI could not be run):
|
|
644
664
|
* the CLI client is gone, but the Docker daemon may still finish making the container a moment later, after a single
|
|
645
665
|
* `docker rm` found nothing, and leave it Created. So the containers and volumes named are removed by name, then
|
|
646
|
-
* inspected, again and again SETTLE_EVERY_MS apart, until the looks have found none of them for
|
|
647
|
-
* row (a create that lands a second after the abort is still seen), on a
|
|
648
|
-
* caller's signal, which has already ended. Undefined when
|
|
649
|
-
* confirmed gone, in words (settleWords). A create later than
|
|
650
|
-
* next sweep, past #leftoverGraceMs, which stays the backstop.
|
|
666
|
+
* inspected, again and again SETTLE_EVERY_MS apart, until the looks have found none of them for the quiet window
|
|
667
|
+
* (settleQuietMs, default SETTLE_QUIET_MS) in a row (a create that lands a second after the abort is still seen), on a
|
|
668
|
+
* bound of their own (settleMs, default SETTLE_MS), never the caller's signal, which has already ended. Undefined when
|
|
669
|
+
* they are gone; else what is still there, or could not be confirmed gone, in words (settleWords). A create later than
|
|
670
|
+
* that is the janitor's: sweepLeftovers takes it at the next sweep, past #leftoverGraceMs, which stays the backstop.
|
|
651
671
|
*/
|
|
652
672
|
async #settle(containers, volumes, attempt) {
|
|
653
|
-
const bound = AbortSignal.timeout(
|
|
673
|
+
const bound = AbortSignal.timeout(this.#settleBounds.settleMs);
|
|
654
674
|
// Only what that create made (ATTEMPT_LABEL) is removed and waited for: a container or a volume another create of the
|
|
655
675
|
// request made under the name is not this create's leftover.
|
|
656
676
|
const mine = (reports) => reports.filter((one) => one.Config?.Labels?.[ATTEMPT_LABEL] === attempt);
|
|
@@ -686,12 +706,12 @@ export class DockerProvider {
|
|
|
686
706
|
quietSince = undefined;
|
|
687
707
|
else {
|
|
688
708
|
quietSince ??= Date.now();
|
|
689
|
-
if (Date.now() - quietSince >=
|
|
709
|
+
if (Date.now() - quietSince >= this.#settleBounds.quietMs)
|
|
690
710
|
return undefined;
|
|
691
711
|
}
|
|
692
712
|
await sleep(SETTLE_EVERY_MS, undefined, { signal: bound }).catch(() => undefined);
|
|
693
713
|
}
|
|
694
|
-
return settleWords(checked, there);
|
|
714
|
+
return settleWords(checked, there, this.#settleBounds);
|
|
695
715
|
}
|
|
696
716
|
/** Deletes a computer whose create was aborted after docker run; the delete itself is not signalled. */
|
|
697
717
|
async #abandon(ref) {
|
|
@@ -1024,7 +1044,7 @@ export class DockerProvider {
|
|
|
1024
1044
|
}
|
|
1025
1045
|
/** One connection to the computer's daemon, after hello, unchecked. */
|
|
1026
1046
|
async #open(ref, signal) {
|
|
1027
|
-
const child = spawn(this.#docker, ["exec", "-i", ref.name, DAEMON_IN_COMPUTER, "stdio"], { stdio: ["pipe", "pipe", "pipe"] });
|
|
1047
|
+
const child = spawn(this.#docker, ["exec", "-i", ref.name, DAEMON_IN_COMPUTER, "stdio"], { env: this.#env, stdio: ["pipe", "pipe", "pipe"] });
|
|
1028
1048
|
let stderr = "";
|
|
1029
1049
|
child.stderr.on("data", (chunk) => {
|
|
1030
1050
|
stderr = (stderr + chunk.toString("utf8")).slice(-4096);
|
|
@@ -1150,37 +1170,52 @@ export class DockerProvider {
|
|
|
1150
1170
|
}
|
|
1151
1171
|
/**
|
|
1152
1172
|
* The janitor's second pass (sweep calls it after the computers): every egress proxy container and egress volume
|
|
1153
|
-
* labelled EGRESS_LABEL, and with all of `labels`, whose
|
|
1154
|
-
*
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1157
|
-
* volume
|
|
1173
|
+
* labelled EGRESS_LABEL, and with all of `labels`, whose computer is not there, read by its name right before that
|
|
1174
|
+
* part's removal, and that is past its deadline label (or the label is missing or unreadable, fail closed) or older
|
|
1175
|
+
* than a create could take (#leftoverGraceMs). Per part, in this order: its labels and age; then `mine`, when given
|
|
1176
|
+
* (serve's: a run of its own store that no claim holds); then its computer, by name (there, or a read that fails,
|
|
1177
|
+
* keeps the part); then its removal by what its label found, a proxy before its volume, never by a name alone.
|
|
1178
|
+
* `mine` comes before the computer so a create under the caller's claim that finishes between the two reads is seen:
|
|
1179
|
+
* once the caller says no claim holds the run, nothing at that claim makes the computer, and a later claim's computer
|
|
1180
|
+
* has another name. A part with an owner label is never removed: Docker makes no agent's computer (no persistence),
|
|
1181
|
+
* so that label is a caller's, never a run's leftover. Returns the names removed, a volume's as "<name> (volume)".
|
|
1158
1182
|
*/
|
|
1159
|
-
async sweepLeftovers({ labels = {}, now = new Date(), signal } = {}) {
|
|
1183
|
+
async sweepLeftovers({ labels = {}, now = new Date(), signal, mine } = {}) {
|
|
1160
1184
|
const problem = filterProblem(labels);
|
|
1161
1185
|
if (problem)
|
|
1162
1186
|
return fail("invalid", problem);
|
|
1163
1187
|
const filters = [`label=${EGRESS_LABEL}`, ...Object.entries(labels).map(([key, value]) => `label=${key}=${value}`)].flatMap((filter) => ["--filter", filter]);
|
|
1164
1188
|
const lines = (stdout) => stdout.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
1165
|
-
const alive = await this.#run(["ps", "-a", "--no-trunc", "--filter", `label=${COMPUTER_LABEL}=1`, "--format", "{{.Names}}"], signal);
|
|
1166
|
-
if (!alive.ok)
|
|
1167
|
-
return alive;
|
|
1168
|
-
if (alive.value.exitCode !== 0)
|
|
1169
|
-
return vendorFail("docker", `docker ps failed: ${alive.value.stderr.trim()}`);
|
|
1170
|
-
const computers = new Set(lines(alive.value.stdout).filter((name) => NAME.test(name)));
|
|
1171
1189
|
const at = now.getTime();
|
|
1172
1190
|
const grace = this.#leftoverGraceMs();
|
|
1173
|
-
|
|
1191
|
+
// The computer a part was made for, when its labels and age allow it to be a leftover at all.
|
|
1192
|
+
const candidate = (labelsOf, created) => {
|
|
1174
1193
|
const owner = labelsOf?.[EGRESS_LABEL];
|
|
1175
|
-
const deadline = Date.parse(labelsOf?.[DEADLINE_LABEL] ?? "");
|
|
1176
1194
|
if (typeof owner !== "string" || !NAME.test(owner))
|
|
1177
|
-
return
|
|
1195
|
+
return undefined;
|
|
1196
|
+
if (labelsOf?.[OWNER_LABEL] !== undefined || labelsOf?.[OWNER_SERVER_LABEL] !== undefined)
|
|
1197
|
+
return undefined;
|
|
1198
|
+
const deadline = Date.parse(labelsOf?.[DEADLINE_LABEL] ?? "");
|
|
1178
1199
|
if (Number.isNaN(deadline) || deadline <= at)
|
|
1179
|
-
return
|
|
1180
|
-
if (computers.has(owner))
|
|
1181
|
-
return false;
|
|
1200
|
+
return owner;
|
|
1182
1201
|
const made = typeof created === "string" ? Date.parse(created) : Number.NaN;
|
|
1183
|
-
return Number.isNaN(made) || at - made > grace;
|
|
1202
|
+
return Number.isNaN(made) || at - made > grace ? owner : undefined;
|
|
1203
|
+
};
|
|
1204
|
+
// The caller's, when it says whose are its own: by the labels the leftover carries.
|
|
1205
|
+
const owned = async (labelsOf) => mine === undefined || (await mine({ ...(labelsOf ?? {}) })) === true;
|
|
1206
|
+
// Whether computer `name` is gone, read now: a container of that name, or a read that fails, says it is not.
|
|
1207
|
+
const gone = async (name) => {
|
|
1208
|
+
const found = await this.#inspect([name], signal);
|
|
1209
|
+
if (!found.ok)
|
|
1210
|
+
return signal?.aborted ? found : ok(false);
|
|
1211
|
+
return ok(found.value.length === 0);
|
|
1212
|
+
};
|
|
1213
|
+
// A part to remove: a candidate, the caller's, and its computer gone, read in that order.
|
|
1214
|
+
const removable = async (labelsOf, created) => {
|
|
1215
|
+
const computer = candidate(labelsOf, created);
|
|
1216
|
+
if (computer === undefined || !(await owned(labelsOf)))
|
|
1217
|
+
return ok(false);
|
|
1218
|
+
return gone(computer);
|
|
1184
1219
|
};
|
|
1185
1220
|
const removed = [];
|
|
1186
1221
|
const ps = await this.#run(["ps", "-a", "--no-trunc", ...filters, "--format", "{{.ID}}"], signal);
|
|
@@ -1194,12 +1229,17 @@ export class DockerProvider {
|
|
|
1194
1229
|
if (!found.ok)
|
|
1195
1230
|
return found;
|
|
1196
1231
|
for (const proxy of found.value) {
|
|
1197
|
-
if (
|
|
1232
|
+
if (typeof proxy.Id !== "string")
|
|
1233
|
+
continue;
|
|
1234
|
+
const take = await removable(proxy.Config?.Labels, proxy.Created);
|
|
1235
|
+
if (!take.ok)
|
|
1236
|
+
return take;
|
|
1237
|
+
if (!take.value)
|
|
1198
1238
|
continue;
|
|
1199
1239
|
const ran = await this.#run(["rm", "--force", proxy.Id], signal);
|
|
1200
1240
|
if (!ran.ok)
|
|
1201
1241
|
return ran;
|
|
1202
|
-
const gone = await this.#gone(ran.value, proxy.Id, `docker rm of the egress proxy ${nameOf(proxy)}`, AbortSignal.timeout(
|
|
1242
|
+
const gone = await this.#gone(ran.value, proxy.Id, `docker rm of the egress proxy ${nameOf(proxy)}`, AbortSignal.timeout(this.#settleBounds.settleMs), signal);
|
|
1203
1243
|
if (!gone.ok)
|
|
1204
1244
|
return gone;
|
|
1205
1245
|
removed.push(nameOf(proxy));
|
|
@@ -1223,7 +1263,12 @@ export class DockerProvider {
|
|
|
1223
1263
|
catch {
|
|
1224
1264
|
return vendorFail("docker", `docker volume inspect wrote a line that is not JSON: ${line.slice(0, 200)}`);
|
|
1225
1265
|
}
|
|
1226
|
-
if (typeof volume.Name !== "string"
|
|
1266
|
+
if (typeof volume.Name !== "string")
|
|
1267
|
+
continue;
|
|
1268
|
+
const take = await removable(volume.Labels, volume.CreatedAt);
|
|
1269
|
+
if (!take.ok)
|
|
1270
|
+
return take;
|
|
1271
|
+
if (!take.value)
|
|
1227
1272
|
continue;
|
|
1228
1273
|
const ran = await this.#run(["volume", "rm", "--force", volume.Name], signal);
|
|
1229
1274
|
if (!ran.ok)
|
|
@@ -1287,12 +1332,12 @@ export class DockerProvider {
|
|
|
1287
1332
|
/**
|
|
1288
1333
|
* An allowlist proxy and its volume that one create made for a computer it never ran: each only when it carries that
|
|
1289
1334
|
* create's attempt (ATTEMPT_LABEL) with the computer's egress label, found by both as release finds a proxy, the
|
|
1290
|
-
* proxy removed by its id. One another create of the request made stays. Bounded by
|
|
1335
|
+
* proxy removed by its id. One another create of the request made stays. Bounded by settleMs, never the caller's
|
|
1291
1336
|
* signal, which may have ended.
|
|
1292
1337
|
*/
|
|
1293
1338
|
async #removeProxy(name, attempt) {
|
|
1294
1339
|
const proxy = egressNameOf(name);
|
|
1295
|
-
const bound = AbortSignal.timeout(
|
|
1340
|
+
const bound = AbortSignal.timeout(this.#settleBounds.settleMs);
|
|
1296
1341
|
const filters = ["--filter", `label=${EGRESS_LABEL}=${name}`, "--filter", `label=${ATTEMPT_LABEL}=${attempt}`];
|
|
1297
1342
|
const lines = (text) => text.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
1298
1343
|
const found = await this.#run(["ps", "-a", "--no-trunc", ...filters, "--format", "{{.ID}}"], bound);
|
|
@@ -1350,78 +1395,104 @@ export class DockerProvider {
|
|
|
1350
1395
|
* What one create made under the name, removed after its computer's docker run failed or was cut off: the container
|
|
1351
1396
|
* that carries its attempt (ATTEMPT_LABEL), and the allowlist proxy and volume it made (#removeProxy). A container
|
|
1352
1397
|
* another create of the request made under the name, in another process or before this one, is left as it is, with
|
|
1353
|
-
* its proxy and volume: true then. The look is bounded (
|
|
1398
|
+
* its proxy and volume: true then. The look is bounded (settleMs), never the caller's signal, which may have ended.
|
|
1354
1399
|
*/
|
|
1355
1400
|
async #removeAttempt(name, attempt) {
|
|
1356
|
-
const found = await this.#inspect([name], AbortSignal.timeout(
|
|
1401
|
+
const found = await this.#inspect([name], AbortSignal.timeout(this.#settleBounds.settleMs));
|
|
1357
1402
|
if (!found.ok)
|
|
1358
1403
|
return found;
|
|
1359
1404
|
const report = found.value.find((one) => nameOf(one) === name);
|
|
1360
1405
|
const mine = report?.Config?.Labels?.[ATTEMPT_LABEL] === attempt;
|
|
1361
1406
|
// By the id looked at, never by the name, which another create may hold by the time rm runs.
|
|
1407
|
+
// The proxy and volume go whether or not the computer could be removed: the computer's failure is the answer.
|
|
1408
|
+
let computer = ok(undefined);
|
|
1362
1409
|
if (mine) {
|
|
1363
|
-
const bound = AbortSignal.timeout(
|
|
1410
|
+
const bound = AbortSignal.timeout(this.#settleBounds.settleMs);
|
|
1364
1411
|
const removed = await this.#run(["rm", "--force", "--volumes", String(report.Id)], bound);
|
|
1365
|
-
|
|
1366
|
-
return removed;
|
|
1367
|
-
const gone = await this.#gone(removed.value, String(report.Id), `docker rm ${name}`, bound);
|
|
1368
|
-
if (!gone.ok)
|
|
1369
|
-
return gone;
|
|
1412
|
+
computer = removed.ok ? await this.#gone(removed.value, String(report.Id), `docker rm ${name}`, bound) : removed;
|
|
1370
1413
|
}
|
|
1371
1414
|
const proxy = await this.#removeProxy(name, attempt);
|
|
1415
|
+
if (!computer.ok)
|
|
1416
|
+
return computer;
|
|
1372
1417
|
return proxy.ok ? ok(report !== undefined && !mine) : proxy;
|
|
1373
1418
|
}
|
|
1374
|
-
/**
|
|
1419
|
+
/**
|
|
1420
|
+
* release's work, which create also does for what it made before its computer ran (its request is not spent). Its
|
|
1421
|
+
* egress proxies are found by their label first, and a delete removes the computer and them in one docker rm, which
|
|
1422
|
+
* Docker's CLI sends together: a teardown cut off once that call is made (its process ended) leaves no proxy running
|
|
1423
|
+
* without its computer, and one cut off before it leaves both, for the janitor. A container that call did not remove
|
|
1424
|
+
* is asked again alone and waited for (#gone). Neither part's failure keeps the other from being removed (a computer
|
|
1425
|
+
* whose removal fails still has its proxy and volume removed): the first failure, the computer's before its proxy's,
|
|
1426
|
+
* is the answer. A stop stops the computer, then its proxies, the same way.
|
|
1427
|
+
*/
|
|
1375
1428
|
async #remove(ref, how) {
|
|
1376
|
-
const args = how === "stop" ? ["stop", ref.name] : ["rm", "--force", "--volumes", ref.name];
|
|
1377
|
-
const ran = await this.#run(args);
|
|
1378
|
-
if (!ran.ok)
|
|
1379
|
-
return ran;
|
|
1380
|
-
const gone = await this.#gone(ran.value, ref.name, `docker ${args[0]} ${ref.name}`, AbortSignal.timeout(SETTLE_MS));
|
|
1381
|
-
if (!gone.ok)
|
|
1382
|
-
return gone;
|
|
1383
1429
|
const label = `label=${EGRESS_LABEL}=${ref.name}`;
|
|
1430
|
+
const lines = (text) => text.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
1384
1431
|
const proxies = await this.#run(["ps", "-a", "--no-trunc", "--filter", label, "--format", "{{.ID}}"]);
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
if (!
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1432
|
+
const listed = !proxies.ok ? proxies : proxies.value.exitCode !== 0 ? vendorFail("docker", `docker ps for ${ref.name}'s egress proxy failed: ${proxies.value.stderr.trim()}`) : ok(lines(proxies.value.stdout));
|
|
1433
|
+
const ids = listed.ok ? listed.value : [];
|
|
1434
|
+
const proxyWords = `${ref.name}'s egress proxy`;
|
|
1435
|
+
// Every failure, in the order met: the first is the answer.
|
|
1436
|
+
const failures = [];
|
|
1437
|
+
const add = (result) => {
|
|
1438
|
+
if (!result.ok)
|
|
1439
|
+
failures.push(result.error);
|
|
1440
|
+
};
|
|
1441
|
+
const parts = (verb) => [[ref.name, `docker ${verb} ${ref.name}`], ...ids.map((id) => [id, `docker ${verb} of ${proxyWords}`])];
|
|
1442
|
+
if (how === "delete") {
|
|
1443
|
+
const all = await this.#run(["rm", "--force", "--volumes", ref.name, ...ids]);
|
|
1444
|
+
if (!all.ok)
|
|
1445
|
+
add(all);
|
|
1446
|
+
// Each one that call did not remove, asked again alone: one gone answers No such container, one whose removal is
|
|
1447
|
+
// under way is waited for, and any other answer is its failure in words.
|
|
1448
|
+
else if (all.value.exitCode !== 0) {
|
|
1449
|
+
for (const [key, what] of parts("rm")) {
|
|
1450
|
+
const again = await this.#run(["rm", "--force", ...(key === ref.name ? ["--volumes"] : []), key]);
|
|
1451
|
+
const gone = again.ok ? await this.#gone(again.value, key, what, AbortSignal.timeout(this.#settleBounds.settleMs)) : again;
|
|
1452
|
+
add(gone);
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1396
1455
|
}
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
return vendorFail("docker", `docker volume ls for ${ref.name}'s egress volume failed: ${volumes.value.stderr.trim()}`);
|
|
1404
|
-
for (const volume of volumes.value.stdout.split("\n").map((line) => line.trim()).filter(Boolean)) {
|
|
1405
|
-
const removed = await this.#run(["volume", "rm", "--force", volume]);
|
|
1406
|
-
if (!removed.ok)
|
|
1407
|
-
return removed;
|
|
1408
|
-
if (removed.value.exitCode !== 0)
|
|
1409
|
-
return vendorFail("docker", `docker volume rm ${volume} failed: ${removed.value.stderr.trim()}`);
|
|
1456
|
+
else {
|
|
1457
|
+
for (const [key, what] of parts("stop")) {
|
|
1458
|
+
const ran = await this.#run(["stop", key]);
|
|
1459
|
+
const gone = ran.ok ? await this.#gone(ran.value, key, what, AbortSignal.timeout(this.#settleBounds.settleMs)) : ran;
|
|
1460
|
+
add(gone);
|
|
1461
|
+
}
|
|
1410
1462
|
}
|
|
1411
|
-
|
|
1463
|
+
add(listed);
|
|
1464
|
+
if (how === "delete") {
|
|
1465
|
+
const volumes = await this.#run(["volume", "ls", "--filter", label, "--format", "{{.Name}}"]);
|
|
1466
|
+
if (!volumes.ok)
|
|
1467
|
+
add(volumes);
|
|
1468
|
+
else if (volumes.value.exitCode !== 0)
|
|
1469
|
+
add(vendorFail("docker", `docker volume ls for ${ref.name}'s egress volume failed: ${volumes.value.stderr.trim()}`));
|
|
1470
|
+
else {
|
|
1471
|
+
for (const volume of lines(volumes.value.stdout)) {
|
|
1472
|
+
const removed = await this.#run(["volume", "rm", "--force", volume]);
|
|
1473
|
+
if (!removed.ok)
|
|
1474
|
+
add(removed);
|
|
1475
|
+
else if (removed.value.exitCode !== 0)
|
|
1476
|
+
add(vendorFail("docker", `docker volume rm ${volume} failed: ${removed.value.stderr.trim()}`));
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
const [first] = failures;
|
|
1481
|
+
return first === undefined ? ok(undefined) : { ok: false, error: first };
|
|
1412
1482
|
}
|
|
1413
1483
|
/**
|
|
1414
1484
|
* Whether the docker rm (or stop) that answered `ran` left container `key` gone, `what` naming the call: ok on exit 0
|
|
1415
1485
|
* or "No such container". "Removal of container ... is already in progress" means another removal of it is under way,
|
|
1416
1486
|
* so it is going away: it is looked for, SETTLE_EVERY_MS apart, until it is gone (ok), the caller's `signal` aborts
|
|
1417
1487
|
* (aborted), or `bound` runs out with it still there (a failure that names it). Every other answer is the failure it is.
|
|
1488
|
+
* `bound` is the settleMs bound every caller passes (default SETTLE_MS), which the failure's words name: never a time
|
|
1489
|
+
* measured here, which a late wake-up would overstate.
|
|
1418
1490
|
*/
|
|
1419
1491
|
async #gone(ran, key, what, bound, signal) {
|
|
1420
1492
|
if (ran.exitCode === 0 || noSuchContainer(ran.stderr))
|
|
1421
1493
|
return ok(undefined);
|
|
1422
1494
|
if (!removalUnderWay(ran.stderr))
|
|
1423
1495
|
return vendorFail("docker", `${what} failed: ${ran.stderr.trim()}`);
|
|
1424
|
-
const from = Date.now();
|
|
1425
1496
|
const either = signal ? AbortSignal.any([signal, bound]) : bound;
|
|
1426
1497
|
for (;;) {
|
|
1427
1498
|
const look = await this.#inspect([key], either, "{{json .Id}}");
|
|
@@ -1430,7 +1501,7 @@ export class DockerProvider {
|
|
|
1430
1501
|
if (signal?.aborted)
|
|
1431
1502
|
return fail("aborted", `${what} was aborted while docker was still removing ${key}`);
|
|
1432
1503
|
if (bound.aborted)
|
|
1433
|
-
return vendorFail("docker", `${what} failed: docker answered that the removal of ${key} was already in progress, and it was still there ${
|
|
1504
|
+
return vendorFail("docker", `${what} failed: docker answered that the removal of ${key} was already in progress, and it was still there when the ${this.#settleBounds.settleMs / 1000} s bound ran out`);
|
|
1434
1505
|
if (!look.ok)
|
|
1435
1506
|
return look;
|
|
1436
1507
|
await sleep(SETTLE_EVERY_MS, undefined, { signal: either }).catch(() => undefined);
|
|
@@ -1458,7 +1529,7 @@ export class DockerProvider {
|
|
|
1458
1529
|
}
|
|
1459
1530
|
#run(args, signal) {
|
|
1460
1531
|
return new Promise((done) => {
|
|
1461
|
-
execFile(this.#docker, args, { signal, encoding: "utf8", maxBuffer: 16 * 1024 * 1024 }, (error, stdout, stderr) => {
|
|
1532
|
+
execFile(this.#docker, args, { env: this.#env, signal, encoding: "utf8", maxBuffer: 16 * 1024 * 1024 }, (error, stdout, stderr) => {
|
|
1462
1533
|
if (error === null)
|
|
1463
1534
|
return done(ok({ exitCode: 0, stdout, stderr }));
|
|
1464
1535
|
if (error.name === "AbortError")
|
|
@@ -1510,6 +1581,18 @@ function infoOf(report, proxy, code, local, volume) {
|
|
|
1510
1581
|
}
|
|
1511
1582
|
/** The longest delay Node's timers, and so AbortSignal.timeout, hold: 2^31 - 1 ms. */
|
|
1512
1583
|
const MAX_TIMER_MS = 2_147_483_647;
|
|
1584
|
+
/**
|
|
1585
|
+
* The settleMs and settleQuietMs options as #settle's bounds, with their defaults (SETTLE_MS, SETTLE_QUIET_MS), or a throw
|
|
1586
|
+
* in words: each is a whole number of milliseconds above 0 that a timer can hold. The one place the defaults are applied:
|
|
1587
|
+
* the constructor and settleWords both read it. Exported for its test, which reads the defaults instead of waiting them out.
|
|
1588
|
+
*/
|
|
1589
|
+
export function settleBoundsOf({ settleMs = SETTLE_MS, settleQuietMs = SETTLE_QUIET_MS }) {
|
|
1590
|
+
for (const [name, ms] of [["settleMs", settleMs], ["settleQuietMs", settleQuietMs]]) {
|
|
1591
|
+
if (!Number.isSafeInteger(ms) || ms <= 0 || ms > MAX_TIMER_MS)
|
|
1592
|
+
throw new Error(`the provider's ${name} must be a whole number of milliseconds above 0 and at most ${MAX_TIMER_MS}, not ${ms}`);
|
|
1593
|
+
}
|
|
1594
|
+
return { settleMs, quietMs: settleQuietMs };
|
|
1595
|
+
}
|
|
1513
1596
|
/** The egress options with their defaults, or a throw in words. */
|
|
1514
1597
|
function egressOptionsOf({ image = EGRESS_IMAGE, hint, readyMs = EGRESS_READY_MS, hostAddresses: given, hostRoot = "/" }) {
|
|
1515
1598
|
if (typeof hostRoot !== "string" || !hostRoot.startsWith("/"))
|
package/dist/drift.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The drift checks every provider shares: the daemon's hello against what the provider declares, and the report of
|
|
2
2
|
// computerd probe from inside a computer. Pure: no vendor call. Each mismatch is one sentence; none is an empty list.
|
|
3
3
|
// Docker's own read-back (docker info, docker inspect) is docker/inspect.ts's.
|
|
4
|
-
import {
|
|
4
|
+
import { helloProblem, NETWORK_FENCES } from "./protocol.js";
|
|
5
5
|
/** Where the daemon is mounted in each computer, read-only. */
|
|
6
6
|
export const DAEMON_IN_COMPUTER = "/opt/agentrun/computerd";
|
|
7
7
|
export const COMPUTER_LABEL = "agentrun.computer";
|
|
@@ -64,11 +64,11 @@ export function probeNotes(probe, network) {
|
|
|
64
64
|
/** Every way hello differs from what the provider expects. */
|
|
65
65
|
export function helloDrift(hello, expected) {
|
|
66
66
|
const found = [];
|
|
67
|
-
//
|
|
68
|
-
// daemon version,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
// spec/computer/README.md, "Versioning": a protocol helloProblem refuses is another wire, in its words, and the
|
|
68
|
+
// daemon's own version, which pins the build the provider ships, must match exactly.
|
|
69
|
+
const protocol = helloProblem(hello?.protocol, "provider");
|
|
70
|
+
if (protocol)
|
|
71
|
+
found.push(`hello: the daemon ${protocol}`);
|
|
72
72
|
if (hello?.version !== expected.version)
|
|
73
73
|
found.push(`hello: the daemon reports version ${text(hello?.version)}, expected ${expected.version}`);
|
|
74
74
|
if (hello?.os !== "linux")
|
package/dist/e2b.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { type Result } from "./result.js";
|
|
|
7
7
|
* process-wide proxy doesn't reach, and it sends every call, the API's and each sandbox's envd's, through the one `proxy`
|
|
8
8
|
* it is given. So it is given that one unless its NO_PROXY exempts the whole domain (proxyForDomain).
|
|
9
9
|
* The SDK's types below are `import type`: erased at build, so nothing loads the SDK from here and the published types
|
|
10
|
-
* name none of it (
|
|
10
|
+
* name none of it (e2b is only an optional dependency).
|
|
11
11
|
*/
|
|
12
12
|
export interface E2BConnectionOptions {
|
|
13
13
|
apiKey: string;
|
|
@@ -45,7 +45,7 @@ export interface E2BProviderOptions extends Omit<HostedOptions, "maxLifetimeMs">
|
|
|
45
45
|
* Not SandboxOpts, which is the SDK's own Sandbox.create options.
|
|
46
46
|
*/
|
|
47
47
|
export interface E2BOptions extends Omit<E2BProviderOptions, "Sandbox"> {
|
|
48
|
-
/** The SDK's Sandbox class;
|
|
48
|
+
/** The SDK's Sandbox class; the e2b package's by default. */
|
|
49
49
|
Sandbox?: E2BSandboxClass;
|
|
50
50
|
}
|
|
51
51
|
/** The connection options every SDK call is given. Exported for the test that hands them to the real SDK. */
|
package/dist/e2b.js
CHANGED
|
@@ -9,8 +9,7 @@ import { connectOf } from "./descriptor.js";
|
|
|
9
9
|
import { dateOf, DOMAIN, isWhole, sizeRefusals } from "./hosted/values.js";
|
|
10
10
|
import { PassThrough } from "node:stream";
|
|
11
11
|
import { ok } from "./result.js";
|
|
12
|
-
|
|
13
|
-
const E2B_PACKAGE = "e2b";
|
|
12
|
+
import { vendorSdk } from "./vendor-sdk.js";
|
|
14
13
|
const DEFAULT_DOMAIN = "e2b.app";
|
|
15
14
|
/** The connection options every SDK call is given. Exported for the test that hands them to the real SDK. */
|
|
16
15
|
export function connectionOptions({ apiKey, domain }, env = installedProxy()) {
|
|
@@ -37,7 +36,7 @@ function ambientProblem() {
|
|
|
37
36
|
*/
|
|
38
37
|
export async function create(options) {
|
|
39
38
|
const { Sandbox: given, ...rest } = options ?? {};
|
|
40
|
-
const Sandbox = given ?? (await
|
|
39
|
+
const Sandbox = given ?? (await vendorSdk(E2B.label, "e2b")).Sandbox;
|
|
41
40
|
return new E2BProvider({ ...rest, Sandbox });
|
|
42
41
|
}
|
|
43
42
|
/** The conformance CLI's module for E2B: its live switch, the run's 30-minute cap, its template and the drifted twin. */
|
package/dist/groundbox.js
CHANGED
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
// it, so kill is the shared pid kill as root. Labels are the sandbox's metadata, which the listing filters by. The
|
|
11
11
|
// lifetime is the janitor's, by the deadline label, and Groundbox's own timer (timeout_minutes) is set to the request's
|
|
12
12
|
// backstop. Kind desktop is the box image's Xvfb and xfwm4, started through the daemon as on E2B and boxd. The rest of
|
|
13
|
-
// the computer is the shared machine-host adapter's (./hosted/provider.ts).
|
|
14
|
-
// the README's Groundbox section.
|
|
13
|
+
// the computer is the shared machine-host adapter's (./hosted/provider.ts).
|
|
15
14
|
import { randomBytes } from "node:crypto";
|
|
16
15
|
import { boxImageRef } from "./box-image.js";
|
|
17
16
|
import { GROUNDBOX, GROUNDBOX_OWN_IMAGE } from "./descriptors/groundbox.js";
|
|
@@ -21,7 +20,7 @@ import { framedExec } from "./hosted/framed-exec.js";
|
|
|
21
20
|
import { boundOf, orThrow, pause, seconds } from "./hosted/process.js";
|
|
22
21
|
import { HostedProvider } from "./hosted/provider.js";
|
|
23
22
|
import { allPages, httpsBase, jsonOf, rest } from "./hosted/rest.js";
|
|
24
|
-
import { PID_KILL } from "./hosted/scripts.js";
|
|
23
|
+
import { PID_ECHO, PID_KILL, ROOT } from "./hosted/scripts.js";
|
|
25
24
|
import { dateOf, isWhole } from "./hosted/values.js";
|
|
26
25
|
import { ok } from "./result.js";
|
|
27
26
|
export async function create(options) {
|
|
@@ -102,8 +101,9 @@ const DIR_PREFIX = "/tmp/.agentrun-exec-";
|
|
|
102
101
|
const START_SCRIPT = [
|
|
103
102
|
"d=$1; shift",
|
|
104
103
|
'mkdir -m 700 "$d" 2>/dev/null || { echo "agentrun: $d is already there, so it is not one this command made: the command did not start" >&2; exit 126; }',
|
|
105
|
-
|
|
106
|
-
'
|
|
104
|
+
// `command exec`: a failed redirection of a bare exec ends a non-interactive sh with status 2, past the refusal.
|
|
105
|
+
'mkfifo -m 600 "$d/in" && command exec 3<>"$d/in" || { rm -rf "$d"; exit 126; }',
|
|
106
|
+
`${PID_ECHO} >"$d/pid.new" && mv -f "$d/pid.new" "$d/pid" || { rm -rf "$d"; exit 126; }`,
|
|
107
107
|
'echo "agentrun-ready:${d##*-}" >&2',
|
|
108
108
|
'"$@" <&3 3<&-; c=$?',
|
|
109
109
|
'rm -rf "$d"; exit $c',
|
|
@@ -150,7 +150,7 @@ const KILL_SCRIPT = [
|
|
|
150
150
|
OWN_DIR,
|
|
151
151
|
ownFile("pid"),
|
|
152
152
|
"read -r pid start 2>/dev/null <pid || exit 0",
|
|
153
|
-
|
|
153
|
+
ROOT,
|
|
154
154
|
'$p sh -c "$2" sh "$pid" "$start"',
|
|
155
155
|
'cd / && rm -rf "$d"',
|
|
156
156
|
].join("\n");
|