@leitwerk-dev/worker-runners 0.1.0 → 0.1.2
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/docker-engine-http-client.d.ts +11 -10
- package/dist/docker-engine-http-client.js +14 -201
- package/dist/docker-engine-http-client.js.map +1 -1
- package/dist/docker-worker-runner.d.ts +9 -7
- package/dist/docker-worker-runner.js +9 -235
- package/dist/docker-worker-runner.js.map +1 -1
- package/dist/index.d.ts +96 -12
- package/dist/index.js +284 -9
- package/dist/index.js.map +1 -1
- package/dist/kubernetes-http-client.d.ts +8 -5
- package/dist/kubernetes-http-client.js +298 -287
- package/dist/kubernetes-http-client.js.map +1 -1
- package/dist/kubernetes-worker-runner.d.ts +7 -6
- package/dist/kubernetes-worker-runner.js +9 -161
- package/dist/kubernetes-worker-runner.js.map +1 -1
- package/dist/local-worker-runner.d.ts +9 -7
- package/dist/local-worker-runner.js +11 -108
- package/dist/local-worker-runner.js.map +1 -1
- package/dist/types.d.ts +16 -16
- package/dist/types.js +0 -11
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
- package/dist/docker-engine-client.d.ts +0 -86
- package/dist/docker-engine-client.d.ts.map +0 -1
- package/dist/docker-engine-client.js +0 -10
- package/dist/docker-engine-client.js.map +0 -1
- package/dist/docker-engine-http-client.d.ts.map +0 -1
- package/dist/docker-worker-runner.d.ts.map +0 -1
- package/dist/fake-docker-engine-client.d.ts +0 -40
- package/dist/fake-docker-engine-client.d.ts.map +0 -1
- package/dist/fake-docker-engine-client.js +0 -131
- package/dist/fake-docker-engine-client.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/kubernetes-api-client.d.ts +0 -71
- package/dist/kubernetes-api-client.d.ts.map +0 -1
- package/dist/kubernetes-api-client.js +0 -142
- package/dist/kubernetes-api-client.js.map +0 -1
- package/dist/kubernetes-http-client.d.ts.map +0 -1
- package/dist/kubernetes-manifests.d.ts +0 -232
- package/dist/kubernetes-manifests.d.ts.map +0 -1
- package/dist/kubernetes-manifests.js +0 -370
- package/dist/kubernetes-manifests.js.map +0 -1
- package/dist/kubernetes-worker-runner.d.ts.map +0 -1
- package/dist/local-worker-runner.d.ts.map +0 -1
- package/dist/process-volume-retention.d.ts +0 -21
- package/dist/process-volume-retention.d.ts.map +0 -1
- package/dist/process-volume-retention.js +0 -46
- package/dist/process-volume-retention.js.map +0 -1
- package/dist/runner-utils.d.ts +0 -16
- package/dist/runner-utils.d.ts.map +0 -1
- package/dist/runner-utils.js +0 -36
- package/dist/runner-utils.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/worker-labels.d.ts +0 -50
- package/dist/worker-labels.d.ts.map +0 -1
- package/dist/worker-labels.js +0 -83
- package/dist/worker-labels.js.map +0 -1
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { d as DockerEngineClient } from './docker-engine-client-Cpmy2yma.js';
|
|
2
|
+
|
|
3
|
+
declare class DockerEngineHttpError extends Error {
|
|
3
4
|
readonly statusCode: number;
|
|
4
5
|
readonly body: string;
|
|
5
6
|
constructor(message: string, statusCode: number, body: string);
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
declare function isDockerEngineNotFoundError(error: unknown): boolean;
|
|
9
|
+
interface ParsedDockerEngineSocket {
|
|
9
10
|
socketPath?: string;
|
|
10
11
|
baseUrl?: URL;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
declare function parseDockerEngineSocket(value: string): ParsedDockerEngineSocket;
|
|
14
|
+
interface DockerEngineHttpClientOptions {
|
|
14
15
|
socket: string;
|
|
15
16
|
apiVersion?: string;
|
|
16
17
|
}
|
|
@@ -20,7 +21,7 @@ interface DockerApiRequest {
|
|
|
20
21
|
query?: Record<string, string>;
|
|
21
22
|
body?: unknown;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
declare function dockerEngineRequestMapping(method: keyof DockerEngineClient, args: unknown[]): DockerApiRequest;
|
|
25
|
+
declare function createDockerEngineHttpClient(options: DockerEngineHttpClientOptions): DockerEngineClient;
|
|
26
|
+
|
|
27
|
+
export { type DockerEngineHttpClientOptions, DockerEngineHttpError, type ParsedDockerEngineSocket, createDockerEngineHttpClient, dockerEngineRequestMapping, isDockerEngineNotFoundError, parseDockerEngineSocket };
|
|
@@ -1,202 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (value.startsWith("unix://")) {
|
|
16
|
-
const socketPath = value.slice("unix://".length);
|
|
17
|
-
if (!socketPath.startsWith("/"))
|
|
18
|
-
throw new Error("docker.socket unix:// URL must contain an absolute path");
|
|
19
|
-
return { socketPath };
|
|
20
|
-
}
|
|
21
|
-
if (value.startsWith("http://"))
|
|
22
|
-
return { baseUrl: new URL(value) };
|
|
23
|
-
if (value.startsWith("https://")) {
|
|
24
|
-
throw new Error("docker.socket https:// is not supported by the built-in Docker adapter; use unix:// or http://");
|
|
25
|
-
}
|
|
26
|
-
if (value.startsWith("/"))
|
|
27
|
-
return { socketPath: value };
|
|
28
|
-
throw new Error(`Unsupported docker.socket value '${value}'; expected unix:///path/to/docker.sock`);
|
|
29
|
-
}
|
|
30
|
-
function encodeQuery(query) {
|
|
31
|
-
if (!query)
|
|
32
|
-
return "";
|
|
33
|
-
const params = new URLSearchParams(query);
|
|
34
|
-
const text = params.toString();
|
|
35
|
-
return text ? `?${text}` : "";
|
|
36
|
-
}
|
|
37
|
-
function dockerPathComponent(value) {
|
|
38
|
-
return encodeURIComponent(value).replaceAll("%2F", "%2F");
|
|
39
|
-
}
|
|
40
|
-
function toMounts(spec) {
|
|
41
|
-
return spec.mounts.map((mount) => ({
|
|
42
|
-
Type: mount.source.startsWith("/") ? "bind" : "volume",
|
|
43
|
-
Source: mount.source,
|
|
44
|
-
Target: mount.target,
|
|
45
|
-
ReadOnly: mount.readOnly ?? false,
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
function toContainerCreateBody(spec) {
|
|
49
|
-
const volumes = {};
|
|
50
|
-
for (const target of spec.anonymousVolumes ?? [])
|
|
51
|
-
volumes[target] = {};
|
|
52
|
-
return {
|
|
53
|
-
Image: spec.image,
|
|
54
|
-
Env: spec.env,
|
|
55
|
-
Labels: spec.labels,
|
|
56
|
-
Volumes: volumes,
|
|
57
|
-
HostConfig: {
|
|
58
|
-
Mounts: toMounts(spec),
|
|
59
|
-
NetworkMode: spec.networkMode,
|
|
60
|
-
Privileged: spec.privileged,
|
|
61
|
-
...(spec.runtime ? { Runtime: spec.runtime } : {}),
|
|
62
|
-
...(spec.nanoCpus ? { NanoCpus: spec.nanoCpus } : {}),
|
|
63
|
-
...(spec.memoryBytes ? { Memory: spec.memoryBytes } : {}),
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function mapInspect(raw) {
|
|
68
|
-
return {
|
|
69
|
-
id: raw.Id,
|
|
70
|
-
running: raw.State?.Running === true,
|
|
71
|
-
labels: raw.Config?.Labels ?? {},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function mapWait(raw) {
|
|
75
|
-
return {
|
|
76
|
-
statusCode: Number(raw.StatusCode ?? 0),
|
|
77
|
-
...(raw.Error?.Message ? { error: raw.Error.Message } : {}),
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
export function dockerEngineRequestMapping(method, args) {
|
|
81
|
-
switch (method) {
|
|
82
|
-
case "createContainer": {
|
|
83
|
-
const spec = args[0];
|
|
84
|
-
return {
|
|
85
|
-
method: "POST",
|
|
86
|
-
path: "/containers/create",
|
|
87
|
-
query: { name: spec.name },
|
|
88
|
-
body: toContainerCreateBody(spec),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
case "startContainer":
|
|
92
|
-
return {
|
|
93
|
-
method: "POST",
|
|
94
|
-
path: `/containers/${dockerPathComponent(args[0])}/start`,
|
|
95
|
-
};
|
|
96
|
-
case "stopContainer":
|
|
97
|
-
return {
|
|
98
|
-
method: "POST",
|
|
99
|
-
path: `/containers/${dockerPathComponent(args[0])}/stop`,
|
|
100
|
-
query: { t: String(args[1].timeoutSeconds) },
|
|
101
|
-
};
|
|
102
|
-
case "removeContainer":
|
|
103
|
-
return {
|
|
104
|
-
method: "DELETE",
|
|
105
|
-
path: `/containers/${dockerPathComponent(args[0])}`,
|
|
106
|
-
query: { force: args[1].force ? "1" : "0", v: "1" },
|
|
107
|
-
};
|
|
108
|
-
case "inspectContainer":
|
|
109
|
-
return { method: "GET", path: `/containers/${dockerPathComponent(args[0])}/json` };
|
|
110
|
-
case "listContainers": {
|
|
111
|
-
const filter = args[0];
|
|
112
|
-
return {
|
|
113
|
-
method: "GET",
|
|
114
|
-
path: "/containers/json",
|
|
115
|
-
query: {
|
|
116
|
-
filters: JSON.stringify({
|
|
117
|
-
label: Object.entries(filter.labels).map(([k, v]) => `${k}=${v}`),
|
|
118
|
-
}),
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
case "waitContainer":
|
|
123
|
-
return { method: "POST", path: `/containers/${dockerPathComponent(args[0])}/wait` };
|
|
124
|
-
case "ensureVolume":
|
|
125
|
-
return { method: "POST", path: "/volumes/create", body: { Name: args[0] } };
|
|
126
|
-
case "removeVolume":
|
|
127
|
-
return { method: "DELETE", path: `/volumes/${dockerPathComponent(args[0])}` };
|
|
128
|
-
default:
|
|
129
|
-
throw new Error(`No Docker Engine HTTP mapping for ${String(method)}`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
export function createDockerEngineHttpClient(options) {
|
|
133
|
-
const endpoint = parseDockerEngineSocket(options.socket);
|
|
134
|
-
const prefix = options.apiVersion ? `/v${options.apiVersion.replace(/^v/, "")}` : "";
|
|
135
|
-
async function request(apiReq) {
|
|
136
|
-
const path = `${prefix}${apiReq.path}${encodeQuery(apiReq.query)}`;
|
|
137
|
-
const body = apiReq.body === undefined ? undefined : JSON.stringify(apiReq.body);
|
|
138
|
-
return new Promise((resolve, reject) => {
|
|
139
|
-
const req = http.request({
|
|
140
|
-
method: apiReq.method,
|
|
141
|
-
path: endpoint.baseUrl ? `${endpoint.baseUrl.pathname.replace(/\/$/, "")}${path}` : path,
|
|
142
|
-
socketPath: endpoint.socketPath,
|
|
143
|
-
hostname: endpoint.baseUrl?.hostname,
|
|
144
|
-
port: endpoint.baseUrl?.port,
|
|
145
|
-
headers: body
|
|
146
|
-
? { "content-type": "application/json", "content-length": Buffer.byteLength(body) }
|
|
147
|
-
: undefined,
|
|
148
|
-
}, (res) => {
|
|
149
|
-
const chunks = [];
|
|
150
|
-
res.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
|
151
|
-
res.on("end", () => {
|
|
152
|
-
const text = Buffer.concat(chunks).toString("utf8");
|
|
153
|
-
if ((res.statusCode ?? 500) >= 400)
|
|
154
|
-
return reject(new DockerEngineHttpError(`Docker Engine ${apiReq.method} ${apiReq.path} failed with ${res.statusCode}: ${text}`, res.statusCode ?? 500, text));
|
|
155
|
-
resolve((text ? JSON.parse(text) : undefined));
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
req.on("error", reject);
|
|
159
|
-
if (body)
|
|
160
|
-
req.write(body);
|
|
161
|
-
req.end();
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
return {
|
|
165
|
-
async createContainer(spec) {
|
|
166
|
-
const raw = await request(dockerEngineRequestMapping("createContainer", [spec]));
|
|
167
|
-
return { id: raw.Id };
|
|
168
|
-
},
|
|
169
|
-
async startContainer(id) {
|
|
170
|
-
await request(dockerEngineRequestMapping("startContainer", [id]));
|
|
171
|
-
},
|
|
172
|
-
async stopContainer(id, opts) {
|
|
173
|
-
await request(dockerEngineRequestMapping("stopContainer", [id, opts]));
|
|
174
|
-
},
|
|
175
|
-
async removeContainer(id, opts) {
|
|
176
|
-
await request(dockerEngineRequestMapping("removeContainer", [id, opts]));
|
|
177
|
-
},
|
|
178
|
-
async inspectContainer(id) {
|
|
179
|
-
return mapInspect(await request(dockerEngineRequestMapping("inspectContainer", [id])));
|
|
180
|
-
},
|
|
181
|
-
async listContainers(filter) {
|
|
182
|
-
const raw = await request(dockerEngineRequestMapping("listContainers", [filter]));
|
|
183
|
-
return raw.map((c) => ({ id: c.Id, labels: c.Labels ?? {} }));
|
|
184
|
-
},
|
|
185
|
-
async waitContainer(id) {
|
|
186
|
-
return mapWait(await request(dockerEngineRequestMapping("waitContainer", [id])));
|
|
187
|
-
},
|
|
188
|
-
async ensureVolume(name) {
|
|
189
|
-
await request(dockerEngineRequestMapping("ensureVolume", [name]));
|
|
190
|
-
},
|
|
191
|
-
async removeVolume(name) {
|
|
192
|
-
try {
|
|
193
|
-
await request(dockerEngineRequestMapping("removeVolume", [name]));
|
|
194
|
-
}
|
|
195
|
-
catch (error) {
|
|
196
|
-
if (!isDockerEngineNotFoundError(error))
|
|
197
|
-
throw error;
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
};
|
|
201
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
DockerEngineHttpError,
|
|
3
|
+
createDockerEngineHttpClient,
|
|
4
|
+
dockerEngineRequestMapping,
|
|
5
|
+
isDockerEngineNotFoundError,
|
|
6
|
+
parseDockerEngineSocket
|
|
7
|
+
} from "./chunk-HLTGLGUS.js";
|
|
8
|
+
export {
|
|
9
|
+
DockerEngineHttpError,
|
|
10
|
+
createDockerEngineHttpClient,
|
|
11
|
+
dockerEngineRequestMapping,
|
|
12
|
+
isDockerEngineNotFoundError,
|
|
13
|
+
parseDockerEngineSocket
|
|
14
|
+
};
|
|
202
15
|
//# sourceMappingURL=docker-engine-http-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { d as DockerEngineClient } from './docker-engine-client-Cpmy2yma.js';
|
|
2
|
+
import { WorkerRunner, IsolatedStartWorkerInput, ProcessVolume } from './types.js';
|
|
3
|
+
|
|
4
|
+
type DockerProcessVolumeMode = "bind" | "named_volume";
|
|
5
|
+
interface DockerProcessVolumeOptions {
|
|
5
6
|
mode: DockerProcessVolumeMode;
|
|
6
7
|
/** Host root for per-process bind mounts (bind mode). */
|
|
7
8
|
hostRoot: string;
|
|
@@ -10,7 +11,7 @@ export interface DockerProcessVolumeOptions {
|
|
|
10
11
|
/** Prefix for named volumes (named_volume mode). */
|
|
11
12
|
namedVolumePrefix?: string;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
interface DockerWorkerRunnerOptions {
|
|
14
15
|
engine: DockerEngineClient;
|
|
15
16
|
volume: DockerProcessVolumeOptions;
|
|
16
17
|
/** Shared private network attached to every worker container. */
|
|
@@ -28,8 +29,9 @@ export interface DockerWorkerRunnerOptions {
|
|
|
28
29
|
* container exits are observed via the engine's wait call and mapped into the
|
|
29
30
|
* supervisor's existing failure paths through `onExit`.
|
|
30
31
|
*/
|
|
31
|
-
|
|
32
|
+
declare function createDockerWorkerRunner(options: DockerWorkerRunnerOptions): {
|
|
32
33
|
runner: WorkerRunner<IsolatedStartWorkerInput>;
|
|
33
34
|
volume: ProcessVolume;
|
|
34
35
|
};
|
|
35
|
-
|
|
36
|
+
|
|
37
|
+
export { type DockerProcessVolumeMode, type DockerProcessVolumeOptions, type DockerWorkerRunnerOptions, createDockerWorkerRunner };
|
|
@@ -1,236 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* Docker-managed volume so inner image/layer state never lands in the
|
|
11
|
-
* server-opaque process volume mounted at the worker's `mountPath`.
|
|
12
|
-
*/
|
|
13
|
-
const DIND_DAEMON_STORAGE_PATH = "/var/lib/docker";
|
|
14
|
-
const WORKER_SERVER_CA_MOUNT_PATH = "/leitwerk/server-ca.pem";
|
|
15
|
-
/** Replaces characters Docker rejects in container names. */
|
|
16
|
-
function sanitizeNameSegment(value) {
|
|
17
|
-
const cleaned = value.replace(/[^a-zA-Z0-9_.-]/g, "-");
|
|
18
|
-
return cleaned.length > 0 ? cleaned : "x";
|
|
19
|
-
}
|
|
20
|
-
function containerName(instanceId, workerId) {
|
|
21
|
-
return `leitwerk-worker-${sanitizeNameSegment(instanceId)}-${sanitizeNameSegment(workerId)}`;
|
|
22
|
-
}
|
|
23
|
-
function toEnvList(env) {
|
|
24
|
-
return Object.entries(env).map(([key, value]) => `${key}=${value}`);
|
|
25
|
-
}
|
|
26
|
-
function parseCpuToNanoCpus(cpu) {
|
|
27
|
-
if (cpu === undefined) {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
const parsed = Number.parseFloat(cpu);
|
|
31
|
-
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
return Math.round(parsed * NANO_CPUS_PER_CPU);
|
|
35
|
-
}
|
|
36
|
-
const MEMORY_SUFFIX_MULTIPLIERS = [
|
|
37
|
-
["Gi", 1024 ** 3],
|
|
38
|
-
["Mi", 1024 ** 2],
|
|
39
|
-
["Ki", 1024],
|
|
40
|
-
["G", 1000 ** 3],
|
|
41
|
-
["M", 1000 ** 2],
|
|
42
|
-
["K", 1000],
|
|
43
|
-
["g", 1024 ** 3],
|
|
44
|
-
["m", 1024 ** 2],
|
|
45
|
-
["k", 1024],
|
|
46
|
-
["b", 1],
|
|
47
|
-
["B", 1],
|
|
48
|
-
];
|
|
49
|
-
function parseMemoryToBytes(memory) {
|
|
50
|
-
if (memory === undefined) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
const trimmed = memory.trim();
|
|
54
|
-
for (const [suffix, multiplier] of MEMORY_SUFFIX_MULTIPLIERS) {
|
|
55
|
-
if (trimmed.endsWith(suffix)) {
|
|
56
|
-
const value = Number.parseFloat(trimmed.slice(0, -suffix.length));
|
|
57
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
return Math.round(value * multiplier);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const bytes = Number.parseInt(trimmed, 10);
|
|
64
|
-
return Number.isFinite(bytes) && bytes > 0 ? bytes : undefined;
|
|
65
|
-
}
|
|
66
|
-
function mapExit(info) {
|
|
67
|
-
return {
|
|
68
|
-
exitCode: Number.isFinite(info.statusCode) ? info.statusCode : null,
|
|
69
|
-
signal: info.signal ?? null,
|
|
70
|
-
...(info.oomKilled !== undefined ? { oomKilled: info.oomKilled } : {}),
|
|
71
|
-
...(info.error !== undefined ? { reason: info.error } : {}),
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Docker Engine API {@link ProcessVolume} / {@link WorkerRunner}.
|
|
76
|
-
*
|
|
77
|
-
* Container-per-process, labelled for adoption, bind- or named-volume backed.
|
|
78
|
-
* The server never reads the volume; it only injects the mount. Physical
|
|
79
|
-
* container exits are observed via the engine's wait call and mapped into the
|
|
80
|
-
* supervisor's existing failure paths through `onExit`.
|
|
81
|
-
*/
|
|
82
|
-
export function createDockerWorkerRunner(options) {
|
|
83
|
-
const { engine } = options;
|
|
84
|
-
const mountPath = options.volume.mountPath;
|
|
85
|
-
const namedVolumePrefix = options.volume.namedVolumePrefix ?? DEFAULT_NAMED_VOLUME_PREFIX;
|
|
86
|
-
function volumeId(instanceId) {
|
|
87
|
-
if (options.volume.mode === "named_volume") {
|
|
88
|
-
return `${namedVolumePrefix}${instanceId}`;
|
|
89
|
-
}
|
|
90
|
-
return path.join(options.volume.hostRoot, instanceId);
|
|
91
|
-
}
|
|
92
|
-
async function releaseManagedStorage(instanceId) {
|
|
93
|
-
if (options.volume.mode === "named_volume") {
|
|
94
|
-
await engine.removeVolume(volumeId(instanceId));
|
|
95
|
-
}
|
|
96
|
-
// Bind mounts are retained on the host filesystem; retention/GC of the
|
|
97
|
-
// host directory is an operator concern, not a runner action.
|
|
98
|
-
}
|
|
99
|
-
const volume = {
|
|
100
|
-
async ensure(instanceId) {
|
|
101
|
-
const id = volumeId(instanceId);
|
|
102
|
-
if (options.volume.mode === "named_volume") {
|
|
103
|
-
await engine.ensureVolume(id);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
mkdirSync(id, { recursive: true });
|
|
107
|
-
}
|
|
108
|
-
return { instanceId, id, mountPath };
|
|
109
|
-
},
|
|
110
|
-
release: releaseManagedStorage,
|
|
111
|
-
deleteProcessResources: releaseManagedStorage,
|
|
112
|
-
};
|
|
113
|
-
const exitNotifier = new UnitExitNotifier();
|
|
114
|
-
const watched = new Set();
|
|
115
|
-
function watchForExit(unitId) {
|
|
116
|
-
if (watched.has(unitId))
|
|
117
|
-
return;
|
|
118
|
-
watched.add(unitId);
|
|
119
|
-
engine
|
|
120
|
-
.waitContainer(unitId)
|
|
121
|
-
.then((exit) => exitNotifier.fireExit(unitId, mapExit(exit)))
|
|
122
|
-
.catch(() => exitNotifier.fireExit(unitId, { exitCode: null, signal: null, reason: "wait_failed" }))
|
|
123
|
-
.finally(() => watched.delete(unitId));
|
|
124
|
-
}
|
|
125
|
-
const runner = {
|
|
126
|
-
async start(input) {
|
|
127
|
-
const volume = input.volume;
|
|
128
|
-
const labels = buildWorkerUnitLabels({
|
|
129
|
-
instanceId: input.instanceId,
|
|
130
|
-
workerId: input.workerId,
|
|
131
|
-
serverEpoch: input.serverEpoch,
|
|
132
|
-
});
|
|
133
|
-
const mounts = [{ source: volume.id, target: volume.mountPath }];
|
|
134
|
-
const env = { ...input.env };
|
|
135
|
-
if (options.serverCaFile) {
|
|
136
|
-
mounts.push({
|
|
137
|
-
source: options.serverCaFile,
|
|
138
|
-
target: WORKER_SERVER_CA_MOUNT_PATH,
|
|
139
|
-
readOnly: true,
|
|
140
|
-
});
|
|
141
|
-
env.NODE_EXTRA_CA_CERTS = WORKER_SERVER_CA_MOUNT_PATH;
|
|
142
|
-
}
|
|
143
|
-
const privileged = input.isolation.dind === "privileged";
|
|
144
|
-
const dindMode = input.isolation.dind;
|
|
145
|
-
const sysbox = dindMode === "sysbox";
|
|
146
|
-
if (sysbox && !options.sysboxRuntime) {
|
|
147
|
-
throw new Error(`Cannot start worker for ${input.instanceId}: sysbox DinD requested but no host sysbox runtime is configured`);
|
|
148
|
-
}
|
|
149
|
-
// Under any DinD mode the inner dockerd needs its own storage. Back it with
|
|
150
|
-
// an anonymous Docker-managed volume so inner image/layer state stays out
|
|
151
|
-
// of the server-opaque process volume and is reclaimed when the worker
|
|
152
|
-
// container is removed.
|
|
153
|
-
const anonymousVolumes = dindMode === false ? undefined : [DIND_DAEMON_STORAGE_PATH];
|
|
154
|
-
const { id } = await engine.createContainer({
|
|
155
|
-
name: containerName(input.instanceId, input.workerId),
|
|
156
|
-
image: input.image.reference,
|
|
157
|
-
env: toEnvList(env),
|
|
158
|
-
labels,
|
|
159
|
-
mounts,
|
|
160
|
-
networkMode: options.defaultNetwork,
|
|
161
|
-
privileged,
|
|
162
|
-
...(sysbox ? { runtime: options.sysboxRuntime } : {}),
|
|
163
|
-
...(anonymousVolumes ? { anonymousVolumes } : {}),
|
|
164
|
-
nanoCpus: parseCpuToNanoCpus(input.resources?.cpu),
|
|
165
|
-
memoryBytes: parseMemoryToBytes(input.resources?.memory),
|
|
166
|
-
});
|
|
167
|
-
await engine.startContainer(id);
|
|
168
|
-
const ref = {
|
|
169
|
-
instanceId: input.instanceId,
|
|
170
|
-
workerId: input.workerId,
|
|
171
|
-
unitId: id,
|
|
172
|
-
};
|
|
173
|
-
watchForExit(id);
|
|
174
|
-
return exitNotifier.wrapUnit(ref, ref.unitId);
|
|
175
|
-
},
|
|
176
|
-
async stop(ref, opts) {
|
|
177
|
-
const timeoutSeconds = Math.max(0, Math.ceil(opts.graceMs / 1000));
|
|
178
|
-
try {
|
|
179
|
-
await engine.stopContainer(ref.unitId, { timeoutSeconds });
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
if (!isDockerEngineNotFoundError(error))
|
|
183
|
-
throw error;
|
|
184
|
-
}
|
|
185
|
-
try {
|
|
186
|
-
await engine.removeContainer(ref.unitId, { force: true });
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
if (!isDockerEngineNotFoundError(error))
|
|
190
|
-
throw error;
|
|
191
|
-
}
|
|
192
|
-
// The process volume is intentionally kept for resume; removing the ephemeral
|
|
193
|
-
// container reclaims Docker-managed anonymous volumes (including DinD storage).
|
|
194
|
-
},
|
|
195
|
-
async list() {
|
|
196
|
-
const summaries = await engine.listContainers({
|
|
197
|
-
labels: managedWorkerLabelSelector(),
|
|
198
|
-
});
|
|
199
|
-
const descriptors = [];
|
|
200
|
-
for (const summary of summaries) {
|
|
201
|
-
const identity = parseWorkerUnitIdentity(summary.labels);
|
|
202
|
-
if (!identity) {
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
descriptors.push({
|
|
206
|
-
instanceId: identity.instanceId,
|
|
207
|
-
workerId: identity.workerId,
|
|
208
|
-
unitId: summary.id,
|
|
209
|
-
observedState: "running",
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
return descriptors;
|
|
213
|
-
},
|
|
214
|
-
async adopt(descriptor) {
|
|
215
|
-
const inspect = await engine.inspectContainer(descriptor.unitId);
|
|
216
|
-
const identity = parseWorkerUnitIdentity(inspect.labels);
|
|
217
|
-
if (!identity ||
|
|
218
|
-
identity.instanceId !== descriptor.instanceId ||
|
|
219
|
-
identity.workerId !== descriptor.workerId) {
|
|
220
|
-
throw new Error(`Cannot adopt worker unit ${descriptor.unitId}: labels changed`);
|
|
221
|
-
}
|
|
222
|
-
if (!inspect.running) {
|
|
223
|
-
throw new Error(`Cannot adopt worker unit ${descriptor.unitId}: not running`);
|
|
224
|
-
}
|
|
225
|
-
const ref = {
|
|
226
|
-
instanceId: descriptor.instanceId,
|
|
227
|
-
workerId: descriptor.workerId,
|
|
228
|
-
unitId: descriptor.unitId,
|
|
229
|
-
};
|
|
230
|
-
watchForExit(descriptor.unitId);
|
|
231
|
-
return exitNotifier.wrapUnit(ref, ref.unitId);
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
return { runner, volume };
|
|
235
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createDockerWorkerRunner
|
|
3
|
+
} from "./chunk-2TSWMVLZ.js";
|
|
4
|
+
import "./chunk-HLTGLGUS.js";
|
|
5
|
+
import "./chunk-6WACBFXN.js";
|
|
6
|
+
import "./chunk-IRFVGUXJ.js";
|
|
7
|
+
export {
|
|
8
|
+
createDockerWorkerRunner
|
|
9
|
+
};
|
|
236
10
|
//# sourceMappingURL=docker-worker-runner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|