@leitwerk-dev/worker-runners 0.1.9 → 0.2.1
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/dist/{chunk-6WACBFXN.js → chunk-2P3CWUP3.js} +16 -5
- package/dist/chunk-2P3CWUP3.js.map +1 -0
- package/dist/chunk-4F7EMXMU.js +119 -0
- package/dist/chunk-4F7EMXMU.js.map +1 -0
- package/dist/chunk-6UZ2REWV.js +90 -0
- package/dist/chunk-6UZ2REWV.js.map +1 -0
- package/dist/{chunk-DL3Y3R6E.js → chunk-A3XSYWA5.js} +74 -8
- package/dist/chunk-A3XSYWA5.js.map +1 -0
- package/dist/{chunk-2TSWMVLZ.js → chunk-BRIIMAZX.js} +158 -39
- package/dist/chunk-BRIIMAZX.js.map +1 -0
- package/dist/{chunk-IRFVGUXJ.js → chunk-DFPYUJIK.js} +10 -3
- package/dist/chunk-DFPYUJIK.js.map +1 -0
- package/dist/{chunk-HLTGLGUS.js → chunk-H4JEE3ZT.js} +70 -93
- package/dist/chunk-H4JEE3ZT.js.map +1 -0
- package/dist/chunk-ISH4647R.js +506 -0
- package/dist/chunk-ISH4647R.js.map +1 -0
- package/dist/chunk-UGKQOL5E.js +39 -0
- package/dist/chunk-UGKQOL5E.js.map +1 -0
- package/dist/chunk-V7TTFLGE.js +899 -0
- package/dist/chunk-V7TTFLGE.js.map +1 -0
- package/dist/chunk-YDYI3BD2.js +315 -0
- package/dist/chunk-YDYI3BD2.js.map +1 -0
- package/dist/chunk-ZGFD76I6.js +16 -0
- package/dist/chunk-ZGFD76I6.js.map +1 -0
- package/dist/docker-client-public.d.ts +2 -0
- package/dist/docker-client-public.d.ts.map +1 -0
- package/dist/docker-client-public.js +7 -0
- package/dist/docker-client-public.js.map +1 -0
- package/dist/{docker-engine-client-Cpmy2yma.d.ts → docker-engine-client-Btw6ZTXk.d.ts} +48 -34
- package/dist/docker-engine-client.d.ts +47 -33
- package/dist/docker-engine-client.d.ts.map +1 -1
- package/dist/docker-engine-http-client.d.ts +18 -9
- package/dist/docker-engine-http-client.d.ts.map +1 -1
- package/dist/docker-engine-http-client.js +12 -201
- package/dist/docker-engine-http-client.js.map +1 -1
- package/dist/docker-public.d.ts +2 -0
- package/dist/docker-public.d.ts.map +1 -0
- package/dist/docker-public.js +13 -0
- package/dist/docker-public.js.map +1 -0
- package/dist/docker-worker-runner.d.ts +25 -8
- package/dist/docker-worker-runner.d.ts.map +1 -1
- package/dist/docker-worker-runner.js +12 -235
- package/dist/docker-worker-runner.js.map +1 -1
- package/dist/fake-docker-engine-client.d.ts.map +1 -1
- package/dist/filesystem-process-state-exporter.d.ts +10 -0
- package/dist/filesystem-process-state-exporter.d.ts.map +1 -0
- package/dist/helper-process-state-exporter.d.ts +28 -0
- package/dist/helper-process-state-exporter.d.ts.map +1 -0
- package/dist/index.d.ts +2 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -9
- package/dist/index.js.map +1 -1
- package/dist/kubernetes-api-client-CEe7pHC4.d.ts +453 -0
- package/dist/kubernetes-api-client.d.ts +113 -6
- package/dist/kubernetes-api-client.d.ts.map +1 -1
- package/dist/kubernetes-client-public.d.ts +2 -0
- package/dist/kubernetes-client-public.d.ts.map +1 -0
- package/dist/kubernetes-client-public.js +9 -0
- package/dist/kubernetes-client-public.js.map +1 -0
- package/dist/kubernetes-http-client.d.ts +11 -0
- package/dist/kubernetes-http-client.d.ts.map +1 -1
- package/dist/kubernetes-http-client.js +10 -295
- package/dist/kubernetes-http-client.js.map +1 -1
- package/dist/kubernetes-manifests.d.ts +189 -83
- package/dist/kubernetes-manifests.d.ts.map +1 -1
- package/dist/kubernetes-public.d.ts +2 -0
- package/dist/kubernetes-public.d.ts.map +1 -0
- package/dist/kubernetes-public.js +13 -0
- package/dist/kubernetes-public.js.map +1 -0
- package/dist/kubernetes-startup-sampler.d.ts +14 -0
- package/dist/kubernetes-startup-sampler.d.ts.map +1 -0
- package/dist/kubernetes-volume-pool-api.d.ts +114 -0
- package/dist/kubernetes-volume-pool-api.d.ts.map +1 -0
- package/dist/kubernetes-volume-pool.d.ts +41 -0
- package/dist/kubernetes-volume-pool.d.ts.map +1 -0
- package/dist/kubernetes-worker-runner.d.ts +46 -6
- package/dist/kubernetes-worker-runner.d.ts.map +1 -1
- package/dist/kubernetes-worker-runner.js +12 -161
- package/dist/kubernetes-worker-runner.js.map +1 -1
- package/dist/local-public.d.ts +2 -0
- package/dist/local-public.d.ts.map +1 -0
- package/dist/local-public.js +11 -0
- package/dist/local-public.js.map +1 -0
- package/dist/local-worker-runner.d.ts +22 -5
- package/dist/local-worker-runner.d.ts.map +1 -1
- package/dist/local-worker-runner.js +14 -108
- package/dist/local-worker-runner.js.map +1 -1
- package/dist/process-volume-retention.d.ts +15 -0
- package/dist/process-volume-retention.d.ts.map +1 -1
- package/dist/runner-utils.d.ts +8 -1
- package/dist/runner-utils.d.ts.map +1 -1
- package/dist/session-transfer-helper-cli.d.ts +2 -0
- package/dist/session-transfer-helper-cli.d.ts.map +1 -0
- package/dist/session-transfer-helper-cli.js +9 -0
- package/dist/session-transfer-helper-cli.js.map +1 -0
- package/dist/session-transfer-helper.d.ts +7 -0
- package/dist/session-transfer-helper.d.ts.map +1 -0
- package/dist/session-transfer-helper.js +11 -0
- package/dist/session-transfer-helper.js.map +1 -0
- package/dist/types-public.d.ts +3 -0
- package/dist/types-public.d.ts.map +1 -0
- package/dist/types-public.js +7 -0
- package/dist/types-public.js.map +1 -0
- package/dist/types.d.ts +140 -39
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -11
- package/dist/types.js.map +1 -1
- package/dist/worker-labels.d.ts +36 -2
- package/dist/worker-labels.d.ts.map +1 -1
- package/package.json +26 -23
- package/src/docker-client-public.ts +1 -0
- package/src/docker-engine-client.ts +62 -36
- package/src/docker-engine-http-client.ts +90 -96
- package/src/docker-public.ts +1 -0
- package/src/docker-worker-runner.ts +194 -58
- package/src/fake-docker-engine-client.ts +13 -41
- package/src/filesystem-process-state-exporter.ts +42 -0
- package/src/helper-process-state-exporter.ts +149 -0
- package/src/index.ts +5 -94
- package/src/kubernetes-api-client.ts +179 -13
- package/src/kubernetes-client-public.ts +1 -0
- package/src/kubernetes-http-client.ts +239 -92
- package/src/kubernetes-manifests.ts +469 -345
- package/src/kubernetes-public.ts +1 -0
- package/src/kubernetes-startup-sampler.ts +191 -0
- package/src/kubernetes-volume-pool-api.ts +241 -0
- package/src/kubernetes-volume-pool.ts +375 -0
- package/src/kubernetes-worker-runner.ts +361 -44
- package/src/local-public.ts +1 -0
- package/src/local-worker-runner.ts +93 -10
- package/src/process-volume-retention.ts +15 -0
- package/src/runner-utils.ts +17 -2
- package/src/session-transfer-helper-cli.ts +5 -0
- package/src/session-transfer-helper.ts +108 -0
- package/src/types-public.ts +12 -0
- package/src/types.ts +169 -36
- package/src/worker-labels.ts +47 -2
- package/dist/chunk-2TSWMVLZ.js.map +0 -1
- package/dist/chunk-6WACBFXN.js.map +0 -1
- package/dist/chunk-DL3Y3R6E.js.map +0 -1
- package/dist/chunk-DUFA24LP.js +0 -401
- package/dist/chunk-DUFA24LP.js.map +0 -1
- package/dist/chunk-HLTGLGUS.js.map +0 -1
- package/dist/chunk-IRFVGUXJ.js.map +0 -1
- package/dist/chunk-P4DIFRBH.js +0 -187
- package/dist/chunk-P4DIFRBH.js.map +0 -1
- package/dist/docker-engine-client.js +0 -10
- package/dist/docker-engine-client.js.map +0 -1
- package/dist/fake-docker-engine-client.js +0 -131
- package/dist/fake-docker-engine-client.js.map +0 -1
- package/dist/kubernetes-api-client-BcwF2uon.d.ts +0 -286
- package/dist/kubernetes-api-client.js +0 -142
- package/dist/kubernetes-api-client.js.map +0 -1
- package/dist/kubernetes-manifests.js +0 -379
- package/dist/kubernetes-manifests.js.map +0 -1
- package/dist/process-volume-retention.js +0 -46
- package/dist/process-volume-retention.js.map +0 -1
- package/dist/runner-utils.js +0 -36
- package/dist/runner-utils.js.map +0 -1
- package/dist/worker-labels.js +0 -83
- package/dist/worker-labels.js.map +0 -1
|
@@ -1,86 +1,112 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal Docker Engine API port used by the Docker {@link WorkerRunner}.
|
|
3
|
-
*
|
|
4
|
-
* This is deliberately a narrow, leitwerk-shaped interface rather than the
|
|
5
|
-
* full dockerode surface so the runner can be unit-tested against a fake engine
|
|
6
|
-
* client with no daemon. A thin real adapter maps dockerode (or any
|
|
7
|
-
* Docker-compatible Engine API: Podman, OrbStack, nerdctl) onto these methods.
|
|
8
|
-
*/
|
|
1
|
+
/** Docker Engine operations used by workers and process exporters. */
|
|
9
2
|
|
|
3
|
+
/** @internal */
|
|
10
4
|
export interface DockerMountSpec {
|
|
11
|
-
/** Host path (bind) or named volume identifier. */
|
|
5
|
+
/** Host path (bind) or named volume identifier. @internal */
|
|
12
6
|
source: string;
|
|
13
|
-
/** Mount path inside the container. */
|
|
7
|
+
/** Mount path inside the container. @internal */
|
|
14
8
|
target: string;
|
|
15
|
-
/** Mount read-only inside the container. */
|
|
9
|
+
/** Mount read-only inside the container. @internal */
|
|
16
10
|
readOnly?: boolean;
|
|
11
|
+
/** Mount only this relative directory of a named volume, without copying image files into it. @internal */
|
|
12
|
+
volumeSubpath?: string;
|
|
17
13
|
}
|
|
18
14
|
|
|
15
|
+
/** @internal */
|
|
19
16
|
export interface DockerContainerSpec {
|
|
17
|
+
/** @internal */
|
|
20
18
|
name: string;
|
|
19
|
+
/** @internal */
|
|
21
20
|
image: string;
|
|
22
|
-
/** `KEY=value` env entries. */
|
|
21
|
+
/** `KEY=value` env entries. @internal */
|
|
23
22
|
env: string[];
|
|
23
|
+
/** Container command override. @internal */
|
|
24
|
+
command?: string[];
|
|
25
|
+
/** @internal */
|
|
24
26
|
labels: Record<string, string>;
|
|
27
|
+
/** @internal */
|
|
25
28
|
mounts: DockerMountSpec[];
|
|
26
|
-
/** Docker network the container attaches to (user-defined bridge). */
|
|
29
|
+
/** Docker network the container attaches to (user-defined bridge). @internal */
|
|
27
30
|
networkMode: string;
|
|
28
|
-
/** Maps to HostConfig.Privileged
|
|
31
|
+
/** Maps to HostConfig.Privileged for private-daemon isolation. @internal */
|
|
29
32
|
privileged: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* HostConfig.Runtime override. Set to the host's sysbox runtime for sysbox
|
|
32
|
-
* DinD so the worker gets a nested daemon without `--privileged`. Omitted for
|
|
33
|
-
* the default runtime.
|
|
34
|
-
*/
|
|
33
|
+
/** HostConfig.Runtime override. Set to `sysbox-runc` for private Docker. @internal */
|
|
35
34
|
runtime?: string;
|
|
36
|
-
/**
|
|
37
|
-
* Anonymous volumes Docker manages for the container (no host source). Used
|
|
38
|
-
* to back the inner `dockerd` storage (`/var/lib/docker`) under DinD so inner
|
|
39
|
-
* image/layer state never lands in the server-opaque process volume.
|
|
40
|
-
*/
|
|
41
|
-
anonymousVolumes?: string[];
|
|
42
|
-
/** NanoCPUs (1 CPU == 1e9). Omitted when no limit is configured. */
|
|
35
|
+
/** NanoCPUs (1 CPU == 1e9). Omitted when no limit is configured. @internal */
|
|
43
36
|
nanoCpus?: number;
|
|
44
|
-
/** Memory limit in bytes. Omitted when no limit is configured. */
|
|
37
|
+
/** Memory limit in bytes. Omitted when no limit is configured. @internal */
|
|
45
38
|
memoryBytes?: number;
|
|
46
39
|
}
|
|
47
40
|
|
|
41
|
+
/** @internal */
|
|
48
42
|
export interface DockerContainerExit {
|
|
43
|
+
/** @internal */
|
|
49
44
|
statusCode: number;
|
|
45
|
+
/** @internal */
|
|
50
46
|
oomKilled?: boolean;
|
|
51
|
-
/** Termination signal name when the runtime reports one. */
|
|
47
|
+
/** Termination signal name when the runtime reports one. @internal */
|
|
52
48
|
signal?: string;
|
|
53
|
-
/** Human-readable error surfaced by the runtime, if any. */
|
|
49
|
+
/** Human-readable error surfaced by the runtime, if any. @internal */
|
|
54
50
|
error?: string;
|
|
55
51
|
}
|
|
56
52
|
|
|
53
|
+
/** @internal */
|
|
57
54
|
export interface DockerContainerInspect {
|
|
55
|
+
/** @internal */
|
|
58
56
|
id: string;
|
|
57
|
+
/** @internal */
|
|
59
58
|
running: boolean;
|
|
59
|
+
/** @internal */
|
|
60
60
|
labels: Record<string, string>;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/** @internal */
|
|
63
64
|
export interface DockerContainerSummary {
|
|
65
|
+
/** @internal */
|
|
64
66
|
id: string;
|
|
67
|
+
/** @internal */
|
|
65
68
|
labels: Record<string, string>;
|
|
66
69
|
}
|
|
67
70
|
|
|
71
|
+
/** @internal */
|
|
68
72
|
export interface DockerListContainersFilter {
|
|
73
|
+
/** @internal */
|
|
69
74
|
labels: Record<string, string>;
|
|
70
75
|
}
|
|
71
76
|
|
|
77
|
+
/** @internal */
|
|
72
78
|
export interface DockerEngineClient {
|
|
73
|
-
|
|
79
|
+
/** @internal */
|
|
80
|
+
createContainer(spec: DockerContainerSpec): Promise<{
|
|
81
|
+
/** @internal */
|
|
82
|
+
id: string;
|
|
83
|
+
}>;
|
|
84
|
+
/** @internal */
|
|
74
85
|
startContainer(id: string): Promise<void>;
|
|
75
|
-
/** Graceful stop, escalating to SIGKILL after `timeoutSeconds`. */
|
|
76
|
-
stopContainer(
|
|
77
|
-
|
|
86
|
+
/** Graceful stop, escalating to SIGKILL after `timeoutSeconds`. @internal */
|
|
87
|
+
stopContainer(
|
|
88
|
+
id: string,
|
|
89
|
+
opts: {
|
|
90
|
+
/** @internal */
|
|
91
|
+
timeoutSeconds: number;
|
|
92
|
+
},
|
|
93
|
+
): Promise<void>;
|
|
94
|
+
/** @internal */
|
|
95
|
+
removeContainer(
|
|
96
|
+
id: string,
|
|
97
|
+
opts: {
|
|
98
|
+
/** @internal */
|
|
99
|
+
force?: boolean;
|
|
100
|
+
},
|
|
101
|
+
): Promise<void>;
|
|
102
|
+
/** @internal */
|
|
78
103
|
inspectContainer(id: string): Promise<DockerContainerInspect>;
|
|
104
|
+
/** @internal */
|
|
79
105
|
listContainers(filter: DockerListContainersFilter): Promise<DockerContainerSummary[]>;
|
|
80
|
-
/** Resolves when the container exits. Used to drive `onExit`. */
|
|
106
|
+
/** Resolves when the container exits. Used to drive `onExit`. @internal */
|
|
81
107
|
waitContainer(id: string): Promise<DockerContainerExit>;
|
|
82
|
-
/** Idempotently ensures a named volume exists (named_volume mode). */
|
|
108
|
+
/** Idempotently ensures a named volume exists (named_volume mode). @internal */
|
|
83
109
|
ensureVolume(name: string): Promise<void>;
|
|
84
|
-
/** Removes a named volume (retention cleanup only). */
|
|
110
|
+
/** Removes a named volume (retention cleanup only). @internal */
|
|
85
111
|
removeVolume(name: string): Promise<void>;
|
|
86
112
|
}
|
|
@@ -1,31 +1,40 @@
|
|
|
1
1
|
import http from "node:http";
|
|
2
|
+
import { text as readText } from "node:stream/consumers";
|
|
2
3
|
import type {
|
|
3
4
|
DockerContainerExit,
|
|
4
5
|
DockerContainerInspect,
|
|
5
6
|
DockerContainerSpec,
|
|
6
7
|
DockerEngineClient,
|
|
7
|
-
DockerListContainersFilter,
|
|
8
8
|
} from "./docker-engine-client.js";
|
|
9
9
|
|
|
10
|
+
/** @internal */
|
|
10
11
|
export class DockerEngineHttpError extends Error {
|
|
12
|
+
/** @internal */
|
|
11
13
|
constructor(
|
|
12
14
|
message: string,
|
|
15
|
+
/** @internal */
|
|
13
16
|
readonly statusCode: number,
|
|
17
|
+
/** @internal */
|
|
14
18
|
readonly body: string,
|
|
15
19
|
) {
|
|
16
20
|
super(message);
|
|
17
21
|
}
|
|
18
22
|
}
|
|
19
23
|
|
|
24
|
+
/** @internal */
|
|
20
25
|
export function isDockerEngineNotFoundError(error: unknown): boolean {
|
|
21
26
|
return error instanceof DockerEngineHttpError && error.statusCode === 404;
|
|
22
27
|
}
|
|
23
28
|
|
|
29
|
+
/** @internal */
|
|
24
30
|
export interface ParsedDockerEngineSocket {
|
|
31
|
+
/** @internal */
|
|
25
32
|
socketPath?: string;
|
|
33
|
+
/** @internal */
|
|
26
34
|
baseUrl?: URL;
|
|
27
35
|
}
|
|
28
36
|
|
|
37
|
+
/** @internal */
|
|
29
38
|
export function parseDockerEngineSocket(value: string): ParsedDockerEngineSocket {
|
|
30
39
|
if (value.startsWith("unix://")) {
|
|
31
40
|
const socketPath = value.slice("unix://".length);
|
|
@@ -45,8 +54,11 @@ export function parseDockerEngineSocket(value: string): ParsedDockerEngineSocket
|
|
|
45
54
|
);
|
|
46
55
|
}
|
|
47
56
|
|
|
57
|
+
/** @internal */
|
|
48
58
|
export interface DockerEngineHttpClientOptions {
|
|
59
|
+
/** @internal */
|
|
49
60
|
socket: string;
|
|
61
|
+
/** @internal */
|
|
50
62
|
apiVersion?: string;
|
|
51
63
|
}
|
|
52
64
|
|
|
@@ -64,27 +76,32 @@ function encodeQuery(query?: Record<string, string>): string {
|
|
|
64
76
|
return text ? `?${text}` : "";
|
|
65
77
|
}
|
|
66
78
|
|
|
67
|
-
function dockerPathComponent(value: string): string {
|
|
68
|
-
return encodeURIComponent(value).replaceAll("%2F", "%2F");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
79
|
function toMounts(spec: DockerContainerSpec): Array<Record<string, unknown>> {
|
|
72
80
|
return spec.mounts.map((mount) => ({
|
|
73
81
|
Type: mount.source.startsWith("/") ? "bind" : "volume",
|
|
74
82
|
Source: mount.source,
|
|
75
83
|
Target: mount.target,
|
|
76
84
|
ReadOnly: mount.readOnly ?? false,
|
|
85
|
+
...(mount.volumeSubpath !== undefined
|
|
86
|
+
? { VolumeOptions: { Subpath: mount.volumeSubpath, NoCopy: true } }
|
|
87
|
+
: {}),
|
|
77
88
|
}));
|
|
78
89
|
}
|
|
79
90
|
|
|
91
|
+
function requireVolumeSubpathApiVersion(value: unknown): string {
|
|
92
|
+
if (typeof value === "string" && /^\d+\.\d+$/.test(value)) {
|
|
93
|
+
const [major = 0, minor = 0] = value.split(".").map(Number);
|
|
94
|
+
if (major > 1 || (major === 1 && minor >= 45)) return value;
|
|
95
|
+
}
|
|
96
|
+
throw new Error("Scoped Docker volume mounts require Docker Engine 26.0 or newer (API 1.45+)");
|
|
97
|
+
}
|
|
98
|
+
|
|
80
99
|
function toContainerCreateBody(spec: DockerContainerSpec): Record<string, unknown> {
|
|
81
|
-
const volumes: Record<string, Record<string, never>> = {};
|
|
82
|
-
for (const target of spec.anonymousVolumes ?? []) volumes[target] = {};
|
|
83
100
|
return {
|
|
84
101
|
Image: spec.image,
|
|
85
102
|
Env: spec.env,
|
|
86
103
|
Labels: spec.labels,
|
|
87
|
-
|
|
104
|
+
...(spec.command ? { Cmd: spec.command } : {}),
|
|
88
105
|
HostConfig: {
|
|
89
106
|
Mounts: toMounts(spec),
|
|
90
107
|
NetworkMode: spec.networkMode,
|
|
@@ -131,71 +148,20 @@ function mapWait(raw: DockerWaitResponse): DockerContainerExit {
|
|
|
131
148
|
};
|
|
132
149
|
}
|
|
133
150
|
|
|
134
|
-
|
|
135
|
-
method: keyof DockerEngineClient,
|
|
136
|
-
args: unknown[],
|
|
137
|
-
): DockerApiRequest {
|
|
138
|
-
switch (method) {
|
|
139
|
-
case "createContainer": {
|
|
140
|
-
const spec = args[0] as DockerContainerSpec;
|
|
141
|
-
return {
|
|
142
|
-
method: "POST",
|
|
143
|
-
path: "/containers/create",
|
|
144
|
-
query: { name: spec.name },
|
|
145
|
-
body: toContainerCreateBody(spec),
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
case "startContainer":
|
|
149
|
-
return {
|
|
150
|
-
method: "POST",
|
|
151
|
-
path: `/containers/${dockerPathComponent(args[0] as string)}/start`,
|
|
152
|
-
};
|
|
153
|
-
case "stopContainer":
|
|
154
|
-
return {
|
|
155
|
-
method: "POST",
|
|
156
|
-
path: `/containers/${dockerPathComponent(args[0] as string)}/stop`,
|
|
157
|
-
query: { t: String((args[1] as { timeoutSeconds: number }).timeoutSeconds) },
|
|
158
|
-
};
|
|
159
|
-
case "removeContainer":
|
|
160
|
-
return {
|
|
161
|
-
method: "DELETE",
|
|
162
|
-
path: `/containers/${dockerPathComponent(args[0] as string)}`,
|
|
163
|
-
query: { force: (args[1] as { force?: boolean }).force ? "1" : "0", v: "1" },
|
|
164
|
-
};
|
|
165
|
-
case "inspectContainer":
|
|
166
|
-
return { method: "GET", path: `/containers/${dockerPathComponent(args[0] as string)}/json` };
|
|
167
|
-
case "listContainers": {
|
|
168
|
-
const filter = args[0] as DockerListContainersFilter;
|
|
169
|
-
return {
|
|
170
|
-
method: "GET",
|
|
171
|
-
path: "/containers/json",
|
|
172
|
-
query: {
|
|
173
|
-
filters: JSON.stringify({
|
|
174
|
-
label: Object.entries(filter.labels).map(([k, v]) => `${k}=${v}`),
|
|
175
|
-
}),
|
|
176
|
-
},
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
case "waitContainer":
|
|
180
|
-
return { method: "POST", path: `/containers/${dockerPathComponent(args[0] as string)}/wait` };
|
|
181
|
-
case "ensureVolume":
|
|
182
|
-
return { method: "POST", path: "/volumes/create", body: { Name: args[0] } };
|
|
183
|
-
case "removeVolume":
|
|
184
|
-
return { method: "DELETE", path: `/volumes/${dockerPathComponent(args[0] as string)}` };
|
|
185
|
-
default:
|
|
186
|
-
throw new Error(`No Docker Engine HTTP mapping for ${String(method)}`);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
151
|
+
/** @internal */
|
|
190
152
|
export function createDockerEngineHttpClient(
|
|
191
153
|
options: DockerEngineHttpClientOptions,
|
|
192
154
|
): DockerEngineClient {
|
|
193
155
|
const endpoint = parseDockerEngineSocket(options.socket);
|
|
194
|
-
const
|
|
195
|
-
async function request<T>(
|
|
156
|
+
const configuredApiVersion = options.apiVersion?.replace(/^v/, "");
|
|
157
|
+
async function request<T>(
|
|
158
|
+
apiReq: DockerApiRequest,
|
|
159
|
+
apiVersion = configuredApiVersion,
|
|
160
|
+
): Promise<T> {
|
|
161
|
+
const prefix = apiVersion ? `/v${apiVersion}` : "";
|
|
196
162
|
const path = `${prefix}${apiReq.path}${encodeQuery(apiReq.query)}`;
|
|
197
163
|
const body = apiReq.body === undefined ? undefined : JSON.stringify(apiReq.body);
|
|
198
|
-
|
|
164
|
+
const response = await new Promise<http.IncomingMessage>((resolve, reject) => {
|
|
199
165
|
const req = http.request(
|
|
200
166
|
{
|
|
201
167
|
method: apiReq.method,
|
|
@@ -207,66 +173,94 @@ export function createDockerEngineHttpClient(
|
|
|
207
173
|
? { "content-type": "application/json", "content-length": Buffer.byteLength(body) }
|
|
208
174
|
: undefined,
|
|
209
175
|
},
|
|
210
|
-
|
|
211
|
-
const chunks: Buffer[] = [];
|
|
212
|
-
res.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
|
213
|
-
res.on("end", () => {
|
|
214
|
-
const text = Buffer.concat(chunks).toString("utf8");
|
|
215
|
-
if ((res.statusCode ?? 500) >= 400)
|
|
216
|
-
return reject(
|
|
217
|
-
new DockerEngineHttpError(
|
|
218
|
-
`Docker Engine ${apiReq.method} ${apiReq.path} failed with ${res.statusCode}: ${text}`,
|
|
219
|
-
res.statusCode ?? 500,
|
|
220
|
-
text,
|
|
221
|
-
),
|
|
222
|
-
);
|
|
223
|
-
resolve((text ? JSON.parse(text) : undefined) as T);
|
|
224
|
-
});
|
|
225
|
-
},
|
|
176
|
+
resolve,
|
|
226
177
|
);
|
|
227
178
|
req.on("error", reject);
|
|
228
|
-
|
|
229
|
-
req.end();
|
|
179
|
+
req.end(body);
|
|
230
180
|
});
|
|
181
|
+
const text = await readText(response);
|
|
182
|
+
if ((response.statusCode ?? 500) >= 400) {
|
|
183
|
+
throw new DockerEngineHttpError(
|
|
184
|
+
`Docker Engine ${apiReq.method} ${apiReq.path} failed with ${response.statusCode}: ${text}`,
|
|
185
|
+
response.statusCode ?? 500,
|
|
186
|
+
text,
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
return (text ? JSON.parse(text) : undefined) as T;
|
|
231
190
|
}
|
|
232
191
|
return {
|
|
233
192
|
async createContainer(spec) {
|
|
193
|
+
let apiVersion = configuredApiVersion;
|
|
194
|
+
if (spec.mounts.some((mount) => mount.volumeSubpath !== undefined)) {
|
|
195
|
+
const version =
|
|
196
|
+
configuredApiVersion ??
|
|
197
|
+
(await request<{ ApiVersion?: string }>({ method: "GET", path: "/version" })).ApiVersion;
|
|
198
|
+
// Pin this request to an API that understands Subpath. An older daemon
|
|
199
|
+
// must reject the request, never ignore the option and mount the volume root.
|
|
200
|
+
apiVersion = requireVolumeSubpathApiVersion(version);
|
|
201
|
+
}
|
|
234
202
|
const raw = await request<DockerCreateResponse>(
|
|
235
|
-
|
|
203
|
+
{
|
|
204
|
+
method: "POST",
|
|
205
|
+
path: "/containers/create",
|
|
206
|
+
query: { name: spec.name },
|
|
207
|
+
body: toContainerCreateBody(spec),
|
|
208
|
+
},
|
|
209
|
+
apiVersion,
|
|
236
210
|
);
|
|
237
211
|
return { id: raw.Id };
|
|
238
212
|
},
|
|
239
213
|
async startContainer(id) {
|
|
240
|
-
await request(
|
|
214
|
+
await request({ method: "POST", path: `/containers/${encodeURIComponent(id)}/start` });
|
|
241
215
|
},
|
|
242
216
|
async stopContainer(id, opts) {
|
|
243
|
-
await request(
|
|
217
|
+
await request({
|
|
218
|
+
method: "POST",
|
|
219
|
+
path: `/containers/${encodeURIComponent(id)}/stop`,
|
|
220
|
+
query: { t: String(opts.timeoutSeconds) },
|
|
221
|
+
});
|
|
244
222
|
},
|
|
245
223
|
async removeContainer(id, opts) {
|
|
246
|
-
await request(
|
|
224
|
+
await request({
|
|
225
|
+
method: "DELETE",
|
|
226
|
+
path: `/containers/${encodeURIComponent(id)}`,
|
|
227
|
+
query: { force: opts.force ? "1" : "0", v: "1" },
|
|
228
|
+
});
|
|
247
229
|
},
|
|
248
230
|
async inspectContainer(id) {
|
|
249
231
|
return mapInspect(
|
|
250
|
-
await request<DockerInspectResponse>(
|
|
232
|
+
await request<DockerInspectResponse>({
|
|
233
|
+
method: "GET",
|
|
234
|
+
path: `/containers/${encodeURIComponent(id)}/json`,
|
|
235
|
+
}),
|
|
251
236
|
);
|
|
252
237
|
},
|
|
253
238
|
async listContainers(filter) {
|
|
254
|
-
const raw = await request<DockerListContainerResponse[]>(
|
|
255
|
-
|
|
256
|
-
|
|
239
|
+
const raw = await request<DockerListContainerResponse[]>({
|
|
240
|
+
method: "GET",
|
|
241
|
+
path: "/containers/json",
|
|
242
|
+
query: {
|
|
243
|
+
filters: JSON.stringify({
|
|
244
|
+
label: Object.entries(filter.labels).map(([key, value]) => `${key}=${value}`),
|
|
245
|
+
}),
|
|
246
|
+
},
|
|
247
|
+
});
|
|
257
248
|
return raw.map((c) => ({ id: c.Id, labels: c.Labels ?? {} }));
|
|
258
249
|
},
|
|
259
250
|
async waitContainer(id) {
|
|
260
251
|
return mapWait(
|
|
261
|
-
await request<DockerWaitResponse>(
|
|
252
|
+
await request<DockerWaitResponse>({
|
|
253
|
+
method: "POST",
|
|
254
|
+
path: `/containers/${encodeURIComponent(id)}/wait`,
|
|
255
|
+
}),
|
|
262
256
|
);
|
|
263
257
|
},
|
|
264
258
|
async ensureVolume(name) {
|
|
265
|
-
await request(
|
|
259
|
+
await request({ method: "POST", path: "/volumes/create", body: { Name: name } });
|
|
266
260
|
},
|
|
267
261
|
async removeVolume(name) {
|
|
268
262
|
try {
|
|
269
|
-
await request(
|
|
263
|
+
await request({ method: "DELETE", path: `/volumes/${encodeURIComponent(name)}` });
|
|
270
264
|
} catch (error) {
|
|
271
265
|
if (!isDockerEngineNotFoundError(error)) throw error;
|
|
272
266
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createDockerWorkerRunner } from "./docker-worker-runner.js";
|