@ship.zone/runner 2.1.0 → 4.0.0
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/.smartconfig.json +118 -3
- package/changelog.md +101 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl +0 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.json +679 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.txt +15719 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl.tsrust-build.json +5 -5
- package/dist_rust/runnerworkspace_linux_arm64_musl +0 -0
- package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.json +679 -0
- package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.txt +15719 -0
- package/dist_rust/runnerworkspace_linux_arm64_musl.tsrust-build.json +5 -5
- package/dist_ts/00_commitinfo_data.d.ts +8 -0
- package/dist_ts/00_commitinfo_data.js +9 -0
- package/dist_ts/api-client.d.ts +47 -0
- package/dist_ts/api-client.js +600 -0
- package/dist_ts/artifact-manager.d.ts +11 -0
- package/dist_ts/artifact-manager.js +140 -0
- package/dist_ts/attempt-state.d.ts +18 -0
- package/dist_ts/attempt-state.js +151 -0
- package/dist_ts/cache-manager.d.ts +13 -0
- package/dist_ts/cache-manager.js +300 -0
- package/dist_ts/cli-entry.d.ts +2 -0
- package/dist_ts/cli-entry.js +18 -0
- package/dist_ts/cli.d.ts +14 -0
- package/dist_ts/cli.js +243 -0
- package/dist_ts/config.d.ts +8 -0
- package/dist_ts/config.js +495 -0
- package/dist_ts/egress-proxy.d.ts +99 -0
- package/dist_ts/egress-proxy.js +607 -0
- package/dist_ts/errors.d.ts +41 -0
- package/dist_ts/errors.js +90 -0
- package/dist_ts/filesystem.d.ts +73 -0
- package/dist_ts/filesystem.js +207 -0
- package/dist_ts/index.d.ts +20 -0
- package/dist_ts/index.js +21 -0
- package/dist_ts/interfaces.d.ts +685 -0
- package/dist_ts/interfaces.js +3 -0
- package/dist_ts/log-sender.d.ts +26 -0
- package/dist_ts/log-sender.js +124 -0
- package/dist_ts/microvm-executor.d.ts +90 -0
- package/dist_ts/microvm-executor.js +1045 -0
- package/dist_ts/node-version.d.ts +11 -0
- package/dist_ts/node-version.js +43 -0
- package/dist_ts/npm-grants.d.ts +9 -0
- package/dist_ts/npm-grants.js +44 -0
- package/dist_ts/oci-registry.d.ts +73 -0
- package/dist_ts/oci-registry.js +508 -0
- package/dist_ts/plugins.d.ts +23 -0
- package/dist_ts/plugins.js +27 -0
- package/dist_ts/protocol-validator.d.ts +39 -0
- package/dist_ts/protocol-validator.js +488 -0
- package/dist_ts/redactor.d.ts +78 -0
- package/dist_ts/redactor.js +235 -0
- package/dist_ts/registration-state.d.ts +16 -0
- package/dist_ts/registration-state.js +171 -0
- package/dist_ts/runner.d.ts +65 -0
- package/dist_ts/runner.js +912 -0
- package/dist_ts/source-workspace.d.ts +10 -0
- package/dist_ts/source-workspace.js +125 -0
- package/dist_ts/spec-version.d.ts +11 -0
- package/dist_ts/spec-version.js +41 -0
- package/dist_ts/staging-scavenger.d.ts +7 -0
- package/dist_ts/staging-scavenger.js +63 -0
- package/dist_ts/state-owner.d.ts +74 -0
- package/dist_ts/state-owner.js +291 -0
- package/dist_ts/transfer-archive.d.ts +78 -0
- package/dist_ts/transfer-archive.js +1619 -0
- package/dist_ts/validation.d.ts +11 -0
- package/dist_ts/validation.js +79 -0
- package/dist_ts/vsock-protocol.d.ts +130 -0
- package/dist_ts/vsock-protocol.js +336 -0
- package/dist_ts/wire-schema.d.ts +10 -0
- package/dist_ts/wire-schema.js +114 -0
- package/native-notices/crates/bitflags-2.13.1/license-apache +201 -0
- package/native-notices/crates/bitflags-2.13.1/license-mit +25 -0
- package/native-notices/crates/cc-1.8.0/license-apache +201 -0
- package/native-notices/crates/cc-1.8.0/license-mit +25 -0
- package/native-notices/crates/cfg-if-1.0.4/license-apache +201 -0
- package/native-notices/crates/cfg-if-1.0.4/license-mit +25 -0
- package/native-notices/crates/cfg_aliases-0.2.2/license +9 -0
- package/native-notices/crates/cfg_aliases-0.2.2/notices.md +26 -0
- package/native-notices/crates/find-msvc-tools-0.1.14/license-apache +201 -0
- package/native-notices/crates/find-msvc-tools-0.1.14/license-mit +25 -0
- package/native-notices/crates/itoa-1.0.18/license-apache +176 -0
- package/native-notices/crates/itoa-1.0.18/license-mit +23 -0
- package/native-notices/crates/libc-0.2.189/license-apache +176 -0
- package/native-notices/crates/libc-0.2.189/license-mit +25 -0
- package/native-notices/crates/memchr-2.8.3/copying +3 -0
- package/native-notices/crates/memchr-2.8.3/license-mit +21 -0
- package/native-notices/crates/memchr-2.8.3/unlicense +24 -0
- package/native-notices/crates/nix-0.30.1/license +21 -0
- package/native-notices/crates/proc-macro2-1.0.107/license-apache +176 -0
- package/native-notices/crates/proc-macro2-1.0.107/license-mit +23 -0
- package/native-notices/crates/quote-1.0.47/license-apache +176 -0
- package/native-notices/crates/quote-1.0.47/license-mit +23 -0
- package/native-notices/crates/serde-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_core-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde_core-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_derive-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde_derive-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_json-1.0.151/license-apache +176 -0
- package/native-notices/crates/serde_json-1.0.151/license-mit +23 -0
- package/native-notices/crates/shlex-2.0.1/license-apache +13 -0
- package/native-notices/crates/shlex-2.0.1/license-mit +21 -0
- package/native-notices/crates/syn-3.0.3/license-apache +176 -0
- package/native-notices/crates/syn-3.0.3/license-mit +23 -0
- package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-apache +201 -0
- package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-mit +25 -0
- package/native-notices/crates/tikv-jemallocator-0.7.0/license-apache +201 -0
- package/native-notices/crates/tikv-jemallocator-0.7.0/license-mit +25 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-apache +176 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-mit +23 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-unicode +39 -0
- package/native-notices/crates/zmij-1.0.23/license-mit +23 -0
- package/native-notices/manifest.json +763 -0
- package/native-notices/native/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/jemalloc-5.3.1/jemalloc-copying +27 -0
- package/native-notices/readme.md +46 -0
- package/native-notices/runtime/gcc/gpl-3.0.txt +674 -0
- package/native-notices/runtime/gcc/runtime-library-exception-3.1.txt +73 -0
- package/native-notices/runtime/libunwind-22.1.2/license.txt +311 -0
- package/native-notices/runtime/musl-1.2.5/copyright +193 -0
- package/native-notices/rust/compiler-builtins-license.txt +275 -0
- package/native-notices/rust/copyright-library.html +8266 -0
- package/native-notices/rust/crates/addr2line-0.25.1/license-apache +201 -0
- package/native-notices/rust/crates/addr2line-0.25.1/license-mit +25 -0
- package/native-notices/rust/crates/adler2-2.0.1/license-0bsd +12 -0
- package/native-notices/rust/crates/adler2-2.0.1/license-apache +201 -0
- package/native-notices/rust/crates/adler2-2.0.1/license-mit +23 -0
- package/native-notices/rust/crates/memchr-2.7.6/copying +3 -0
- package/native-notices/rust/crates/memchr-2.7.6/license-mit +21 -0
- package/native-notices/rust/crates/memchr-2.7.6/unlicense +24 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license +25 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license-apache.md +177 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license-mit.md +24 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license-zlib.md +14 -0
- package/native-notices/rust/crates/object-0.37.3/license-apache +201 -0
- package/native-notices/rust/crates/object-0.37.3/license-mit +25 -0
- package/native-notices/rust/licenses/apache-2.0.txt +73 -0
- package/native-notices/rust/licenses/bsd-2-clause.txt +9 -0
- package/native-notices/rust/licenses/cc-by-sa-4.0.txt +427 -0
- package/native-notices/rust/licenses/gcc-exception-3.1.txt +30 -0
- package/native-notices/rust/licenses/gpl-2.0-only.txt +133 -0
- package/native-notices/rust/licenses/gpl-3.0-or-later.txt +202 -0
- package/native-notices/rust/licenses/isc.txt +7 -0
- package/native-notices/rust/licenses/llvm-exception.txt +15 -0
- package/native-notices/rust/licenses/mit.txt +9 -0
- package/native-notices/rust/licenses/ncsa.txt +29 -0
- package/native-notices/rust/licenses/ofl-1.1.txt +43 -0
- package/native-notices/rust/licenses/unicode-3.0.txt +39 -0
- package/package.json +31 -26
- package/readme.md +157 -95
- package/rust/.cargo/config.toml +1 -1
- package/rust/Cargo.lock +1 -0
- package/rust/Cargo.toml +3 -2
- package/rust/src/cpio.rs +147 -0
- package/rust/src/extfs.rs +747 -0
- package/rust/src/guest.rs +2411 -0
- package/rust/src/lib.rs +197 -1
- package/rust/src/main.rs +7 -2
- package/rust/src/oci_tar.rs +842 -0
- package/rust-toolchain.toml +4 -0
- package/ts/00_commitinfo_data.ts +2 -2
- package/ts/api-client.ts +29 -8
- package/ts/artifact-manager.ts +9 -7
- package/ts/attempt-state.ts +75 -84
- package/ts/cache-manager.ts +22 -28
- package/ts/cli-entry.ts +17 -0
- package/ts/cli.ts +86 -53
- package/ts/config.ts +146 -62
- package/ts/egress-proxy.ts +649 -0
- package/ts/errors.ts +19 -0
- package/ts/filesystem.ts +316 -0
- package/ts/index.ts +20 -15
- package/ts/interfaces.ts +105 -23
- package/ts/log-sender.ts +4 -4
- package/ts/microvm-executor.ts +1265 -0
- package/ts/node-version.ts +49 -0
- package/ts/npm-grants.ts +49 -0
- package/ts/oci-registry.ts +649 -0
- package/ts/plugins.ts +25 -3
- package/ts/protocol-validator.ts +34 -30
- package/ts/redactor.ts +2 -2
- package/ts/registration-state.ts +82 -90
- package/ts/runner.ts +81 -34
- package/ts/source-workspace.ts +11 -8
- package/ts/spec-version.ts +2 -2
- package/ts/staging-scavenger.ts +37 -26
- package/ts/state-owner.ts +353 -0
- package/ts/transfer-archive.ts +214 -243
- package/ts/validation.ts +1 -1
- package/ts/vsock-protocol.ts +437 -0
- package/ts/wire-schema.ts +3 -3
- package/deno.json +0 -56
- package/deno.lock +0 -1495
- package/dist_npm/mod.d.ts +0 -967
- package/dist_npm/mod.js +0 -10058
- package/mod.ts +0 -8
- package/musl-copyright.md +0 -81
- package/third-party-licenses.md +0 -187
- package/ts/oci-executor.ts +0 -3137
package/ts/validation.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigurationError, ProtocolError } from './errors.
|
|
1
|
+
import { ConfigurationError, ProtocolError } from './errors.js';
|
|
2
2
|
|
|
3
3
|
export const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
4
4
|
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { RunnerError } from './errors.js';
|
|
3
|
+
|
|
4
|
+
export const GUEST_VSOCK_PORT = 1024;
|
|
5
|
+
|
|
6
|
+
export const FRAME_JSON_REQ = 0x01;
|
|
7
|
+
export const FRAME_JSON_RES = 0x02;
|
|
8
|
+
export const FRAME_DATA = 0x03;
|
|
9
|
+
export const FRAME_DATA_EOF = 0x04;
|
|
10
|
+
export const FRAME_STDOUT = 0x05;
|
|
11
|
+
export const FRAME_STDERR = 0x06;
|
|
12
|
+
export const FRAME_CANCEL = 0x07;
|
|
13
|
+
|
|
14
|
+
const MAXIMUM_FRAME_BYTES = 4 * 1024 * 1024;
|
|
15
|
+
const STREAM_CHUNK_BYTES = 32 * 1024;
|
|
16
|
+
|
|
17
|
+
export interface IGuestFrame {
|
|
18
|
+
kind: number;
|
|
19
|
+
payload: Buffer;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface IGuestHello {
|
|
23
|
+
ok: true;
|
|
24
|
+
version: string;
|
|
25
|
+
os: string;
|
|
26
|
+
architecture: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface IGuestTransferResult {
|
|
30
|
+
ok: true;
|
|
31
|
+
bytes: number;
|
|
32
|
+
entries: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface IGuestStepRequest {
|
|
36
|
+
command: string[];
|
|
37
|
+
env: Record<string, string>;
|
|
38
|
+
workingDirectory: string;
|
|
39
|
+
uid: number;
|
|
40
|
+
gid: number;
|
|
41
|
+
rootMode?: boolean;
|
|
42
|
+
timeoutMs: number;
|
|
43
|
+
memoryBytes: number;
|
|
44
|
+
cpus: number;
|
|
45
|
+
pids: number;
|
|
46
|
+
sharedMemoryBytes: number;
|
|
47
|
+
temporarySizeBytes: number;
|
|
48
|
+
maximumWorkspaceBytes: number;
|
|
49
|
+
maximumWorkspaceEntries: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface IGuestImageBuildRequest {
|
|
53
|
+
context: string;
|
|
54
|
+
dockerfile: string;
|
|
55
|
+
target?: string;
|
|
56
|
+
platform: string;
|
|
57
|
+
buildArgs: Record<string, string>;
|
|
58
|
+
secrets: Record<string, string>;
|
|
59
|
+
labels: Record<string, string>;
|
|
60
|
+
baseImages: Array<{ name: string; image: string }>;
|
|
61
|
+
npmrcContent?: string;
|
|
62
|
+
pushRegistry: string;
|
|
63
|
+
pushRepository: string;
|
|
64
|
+
grants: Array<{ registry: string; username: string; secret: string }>;
|
|
65
|
+
timeoutMs: number;
|
|
66
|
+
importCacheDir?: string;
|
|
67
|
+
exportCacheDir?: string;
|
|
68
|
+
buildctlPath?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface IGuestImageBuildResult {
|
|
72
|
+
ok: true;
|
|
73
|
+
exitCode: number | null;
|
|
74
|
+
timedOut: boolean;
|
|
75
|
+
canceled: boolean;
|
|
76
|
+
manifestDigest: string | null;
|
|
77
|
+
mediaType: string | null;
|
|
78
|
+
sizeBytes: number | null;
|
|
79
|
+
cacheExported: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface IGuestStepResult {
|
|
83
|
+
ok: true;
|
|
84
|
+
exitCode: number | null;
|
|
85
|
+
signal: number | null;
|
|
86
|
+
timedOut: boolean;
|
|
87
|
+
canceled: boolean;
|
|
88
|
+
oomKilled: boolean;
|
|
89
|
+
workspaceBytes: number;
|
|
90
|
+
workspaceEntries: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface IGuestRunStepCallbacks {
|
|
94
|
+
onStdout?: (chunk: Uint8Array) => Promise<void>;
|
|
95
|
+
onStderr?: (chunk: Uint8Array) => Promise<void>;
|
|
96
|
+
signal?: AbortSignal;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
class FrameReader {
|
|
100
|
+
private chunks: Buffer[] = [];
|
|
101
|
+
private buffered = 0;
|
|
102
|
+
private ended = false;
|
|
103
|
+
private failure?: Error;
|
|
104
|
+
private waiters: Array<() => void> = [];
|
|
105
|
+
|
|
106
|
+
constructor(private readonly socket: plugins.net.Socket) {
|
|
107
|
+
socket.on('data', (chunk: Buffer) => {
|
|
108
|
+
this.chunks.push(chunk);
|
|
109
|
+
this.buffered += chunk.length;
|
|
110
|
+
this.wake();
|
|
111
|
+
});
|
|
112
|
+
socket.on('end', () => {
|
|
113
|
+
this.ended = true;
|
|
114
|
+
this.wake();
|
|
115
|
+
});
|
|
116
|
+
socket.on('close', () => {
|
|
117
|
+
this.ended = true;
|
|
118
|
+
this.wake();
|
|
119
|
+
});
|
|
120
|
+
socket.on('error', (error: Error) => {
|
|
121
|
+
this.failure = error;
|
|
122
|
+
this.ended = true;
|
|
123
|
+
this.wake();
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private wake(): void {
|
|
128
|
+
const list = this.waiters;
|
|
129
|
+
this.waiters = [];
|
|
130
|
+
for (const resolve of list) resolve();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private async ensure(bytes: number): Promise<boolean> {
|
|
134
|
+
while (this.buffered < bytes) {
|
|
135
|
+
if (this.failure) throw new RunnerError(`Guest vsock stream error: ${this.failure.message}`, { cause: this.failure });
|
|
136
|
+
if (this.ended) return false;
|
|
137
|
+
await new Promise<void>((resolve) => {
|
|
138
|
+
this.waiters.push(resolve);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private take(bytes: number): Buffer {
|
|
145
|
+
const parts: Buffer[] = [];
|
|
146
|
+
let remaining = bytes;
|
|
147
|
+
while (remaining > 0) {
|
|
148
|
+
const head = this.chunks[0];
|
|
149
|
+
if (head.length <= remaining) {
|
|
150
|
+
parts.push(head);
|
|
151
|
+
this.chunks.shift();
|
|
152
|
+
remaining -= head.length;
|
|
153
|
+
} else {
|
|
154
|
+
parts.push(head.subarray(0, remaining));
|
|
155
|
+
this.chunks[0] = head.subarray(remaining);
|
|
156
|
+
remaining = 0;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
this.buffered -= bytes;
|
|
160
|
+
return parts.length === 1 ? parts[0] : Buffer.concat(parts, bytes);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async nextFrame(): Promise<IGuestFrame | null> {
|
|
164
|
+
const hasHeader = await this.ensure(5);
|
|
165
|
+
if (!hasHeader) {
|
|
166
|
+
if (this.buffered > 0) {
|
|
167
|
+
throw new RunnerError('Guest vsock stream closed mid-frame');
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
const header = this.take(5);
|
|
172
|
+
const length = header.readUInt32BE(0);
|
|
173
|
+
const kind = header[4];
|
|
174
|
+
if (length > MAXIMUM_FRAME_BYTES) {
|
|
175
|
+
throw new RunnerError('Guest vsock frame exceeds maximum allowed size');
|
|
176
|
+
}
|
|
177
|
+
if (length === 0) return { kind, payload: Buffer.alloc(0) };
|
|
178
|
+
const hasPayload = await this.ensure(length);
|
|
179
|
+
if (!hasPayload) throw new RunnerError('Guest vsock stream closed before frame payload completed');
|
|
180
|
+
return { kind, payload: this.take(length) };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const writeAllSocket = (socket: plugins.net.Socket, data: Uint8Array): Promise<void> =>
|
|
185
|
+
new Promise((resolve, reject) => {
|
|
186
|
+
if (socket.destroyed) {
|
|
187
|
+
reject(new RunnerError('Guest vsock socket is closed'));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
socket.write(data, (error?: Error | null) => {
|
|
191
|
+
if (error) reject(new RunnerError(`Guest vsock write failed: ${error.message}`, { cause: error }));
|
|
192
|
+
else resolve();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const encodeFrame = (kind: number, payload: Uint8Array): Buffer => {
|
|
197
|
+
if (payload.byteLength > MAXIMUM_FRAME_BYTES) {
|
|
198
|
+
throw new RunnerError('Outbound vsock frame exceeds maximum allowed size');
|
|
199
|
+
}
|
|
200
|
+
const buf = Buffer.allocUnsafe(5 + payload.byteLength);
|
|
201
|
+
buf.writeUInt32BE(payload.byteLength, 0);
|
|
202
|
+
buf[4] = kind;
|
|
203
|
+
if (payload.byteLength > 0) buf.set(payload, 5);
|
|
204
|
+
return buf;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Framed binary/JSON RPC client talking to `runnerworkspace guest-init` inside a Firecracker
|
|
209
|
+
* microVM over vsock (or over a Unix socket in unit tests).
|
|
210
|
+
*/
|
|
211
|
+
export class GuestVsockClient {
|
|
212
|
+
private readonly reader: FrameReader;
|
|
213
|
+
|
|
214
|
+
constructor(private readonly socket: plugins.net.Socket) {
|
|
215
|
+
this.reader = new FrameReader(socket);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
close(): void {
|
|
219
|
+
if (!this.socket.destroyed) this.socket.destroy();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private async sendJson(request: Record<string, unknown>): Promise<void> {
|
|
223
|
+
const payload = Buffer.from(JSON.stringify(request), 'utf8');
|
|
224
|
+
await writeAllSocket(this.socket, encodeFrame(FRAME_JSON_REQ, payload));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private async readJsonResponse<T extends { ok: true }>(): Promise<T> {
|
|
228
|
+
const frame = await this.reader.nextFrame();
|
|
229
|
+
if (!frame) throw new RunnerError('Guest closed vsock connection before responding');
|
|
230
|
+
if (frame.kind !== FRAME_JSON_RES) {
|
|
231
|
+
throw new RunnerError(`Guest returned unexpected frame type ${frame.kind}`);
|
|
232
|
+
}
|
|
233
|
+
let parsed: unknown;
|
|
234
|
+
try {
|
|
235
|
+
parsed = JSON.parse(frame.payload.toString('utf8'));
|
|
236
|
+
} catch (error) {
|
|
237
|
+
throw new RunnerError('Guest returned malformed JSON response', { cause: error });
|
|
238
|
+
}
|
|
239
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
240
|
+
throw new RunnerError('Guest returned non-object JSON response');
|
|
241
|
+
}
|
|
242
|
+
const record = parsed as Record<string, unknown>;
|
|
243
|
+
if (record.ok !== true) {
|
|
244
|
+
const message = typeof record.error === 'string' ? record.error : 'Unknown guest error';
|
|
245
|
+
throw new RunnerError(`Guest operation failed: ${message}`);
|
|
246
|
+
}
|
|
247
|
+
return record as T;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async hello(): Promise<IGuestHello> {
|
|
251
|
+
await this.sendJson({ op: 'hello' });
|
|
252
|
+
return await this.readJsonResponse<IGuestHello>();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async prepareWorkspace(options: {
|
|
256
|
+
workspaceSizeBytes: number;
|
|
257
|
+
maximumWorkspaceEntries: number;
|
|
258
|
+
uid: number;
|
|
259
|
+
gid: number;
|
|
260
|
+
mode?: 'oci' | 'vm' | 'oci-image';
|
|
261
|
+
npmrcContent?: string;
|
|
262
|
+
}): Promise<void> {
|
|
263
|
+
await this.sendJson({ op: 'prepare_workspace', ...options });
|
|
264
|
+
await this.readJsonResponse<{ ok: true }>();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async importTar(
|
|
268
|
+
tarBytes: Uint8Array,
|
|
269
|
+
options: { maximumBytes: number; maximumEntries: number; uid: number; gid: number },
|
|
270
|
+
): Promise<IGuestTransferResult> {
|
|
271
|
+
await this.sendJson({ op: 'import_tar', ...options });
|
|
272
|
+
for (let offset = 0; offset < tarBytes.byteLength; offset += STREAM_CHUNK_BYTES) {
|
|
273
|
+
const slice = tarBytes.subarray(offset, Math.min(tarBytes.byteLength, offset + STREAM_CHUNK_BYTES));
|
|
274
|
+
await writeAllSocket(this.socket, encodeFrame(FRAME_DATA, slice));
|
|
275
|
+
}
|
|
276
|
+
await writeAllSocket(this.socket, encodeFrame(FRAME_DATA_EOF, Buffer.alloc(0)));
|
|
277
|
+
return await this.readJsonResponse<IGuestTransferResult>();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async runStep(
|
|
281
|
+
spec: IGuestStepRequest,
|
|
282
|
+
callbacks: IGuestRunStepCallbacks = {},
|
|
283
|
+
): Promise<IGuestStepResult> {
|
|
284
|
+
let cancelSent = false;
|
|
285
|
+
const sendCancel = (): void => {
|
|
286
|
+
if (cancelSent || this.socket.destroyed) return;
|
|
287
|
+
cancelSent = true;
|
|
288
|
+
void writeAllSocket(this.socket, encodeFrame(FRAME_CANCEL, Buffer.alloc(0))).catch(() => {});
|
|
289
|
+
};
|
|
290
|
+
const onAbort = (): void => sendCancel();
|
|
291
|
+
callbacks.signal?.addEventListener('abort', onAbort, { once: true });
|
|
292
|
+
try {
|
|
293
|
+
await this.sendJson({ op: 'run_step', ...spec });
|
|
294
|
+
if (callbacks.signal?.aborted) sendCancel();
|
|
295
|
+
|
|
296
|
+
for (;;) {
|
|
297
|
+
const frame = await this.reader.nextFrame();
|
|
298
|
+
if (!frame) throw new RunnerError('Guest closed vsock connection while step was running');
|
|
299
|
+
if (frame.kind === FRAME_STDOUT) {
|
|
300
|
+
if (callbacks.onStdout && frame.payload.byteLength > 0) {
|
|
301
|
+
await callbacks.onStdout(frame.payload);
|
|
302
|
+
}
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (frame.kind === FRAME_STDERR) {
|
|
306
|
+
if (callbacks.onStderr && frame.payload.byteLength > 0) {
|
|
307
|
+
await callbacks.onStderr(frame.payload);
|
|
308
|
+
}
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (frame.kind === FRAME_JSON_RES) {
|
|
312
|
+
let parsed: unknown;
|
|
313
|
+
try {
|
|
314
|
+
parsed = JSON.parse(frame.payload.toString('utf8'));
|
|
315
|
+
} catch (error) {
|
|
316
|
+
throw new RunnerError('Guest returned malformed step JSON response', { cause: error });
|
|
317
|
+
}
|
|
318
|
+
const record = parsed as Record<string, unknown>;
|
|
319
|
+
if (record.ok !== true) {
|
|
320
|
+
const message = typeof record.error === 'string' ? record.error : 'Step failed in guest';
|
|
321
|
+
throw new RunnerError(`Guest step execution failed: ${message}`);
|
|
322
|
+
}
|
|
323
|
+
return record as unknown as IGuestStepResult;
|
|
324
|
+
}
|
|
325
|
+
throw new RunnerError(`Guest sent unexpected frame ${frame.kind} during step execution`);
|
|
326
|
+
}
|
|
327
|
+
} finally {
|
|
328
|
+
callbacks.signal?.removeEventListener('abort', onAbort);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
async exportTar(options: {
|
|
333
|
+
selections: string[];
|
|
334
|
+
maximumBytes: number;
|
|
335
|
+
maximumEntries: number;
|
|
336
|
+
maximumStreamBytes?: number;
|
|
337
|
+
}): Promise<{ tarBytes: Buffer; bytes: number; entries: number }> {
|
|
338
|
+
const maximumStreamBytes = options.maximumStreamBytes ??
|
|
339
|
+
options.maximumBytes + options.maximumEntries * 1024 + 1024 * 1024;
|
|
340
|
+
await this.sendJson({
|
|
341
|
+
op: 'export_tar',
|
|
342
|
+
selections: options.selections,
|
|
343
|
+
maximumBytes: options.maximumBytes,
|
|
344
|
+
maximumEntries: options.maximumEntries,
|
|
345
|
+
});
|
|
346
|
+
const chunks: Buffer[] = [];
|
|
347
|
+
let total = 0;
|
|
348
|
+
for (;;) {
|
|
349
|
+
const frame = await this.reader.nextFrame();
|
|
350
|
+
if (!frame) throw new RunnerError('Guest closed vsock connection during workspace export');
|
|
351
|
+
if (frame.kind === FRAME_DATA) {
|
|
352
|
+
total += frame.payload.byteLength;
|
|
353
|
+
if (total > maximumStreamBytes) {
|
|
354
|
+
throw new RunnerError('Exported workspace stream exceeds maximum allowed size');
|
|
355
|
+
}
|
|
356
|
+
chunks.push(frame.payload);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
if (frame.kind === FRAME_DATA_EOF) {
|
|
360
|
+
const result = await this.readJsonResponse<IGuestTransferResult>();
|
|
361
|
+
return {
|
|
362
|
+
tarBytes: chunks.length === 1 ? chunks[0] : Buffer.concat(chunks, total),
|
|
363
|
+
bytes: result.bytes,
|
|
364
|
+
entries: result.entries,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
if (frame.kind === FRAME_JSON_RES) {
|
|
368
|
+
// Guest returned an error before streaming any data frames.
|
|
369
|
+
const parsed = JSON.parse(frame.payload.toString('utf8')) as Record<string, unknown>;
|
|
370
|
+
const message = typeof parsed.error === 'string' ? parsed.error : 'Workspace export failed';
|
|
371
|
+
throw new RunnerError(`Guest workspace export failed: ${message}`);
|
|
372
|
+
}
|
|
373
|
+
throw new RunnerError(`Guest sent unexpected frame ${frame.kind} during workspace export`);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
async runImageBuild(
|
|
378
|
+
spec: IGuestImageBuildRequest,
|
|
379
|
+
callbacks: IGuestRunStepCallbacks = {},
|
|
380
|
+
): Promise<IGuestImageBuildResult> {
|
|
381
|
+
let cancelSent = false;
|
|
382
|
+
const sendCancel = (): void => {
|
|
383
|
+
if (cancelSent || this.socket.destroyed) return;
|
|
384
|
+
cancelSent = true;
|
|
385
|
+
void writeAllSocket(this.socket, encodeFrame(FRAME_CANCEL, Buffer.alloc(0))).catch(() => {});
|
|
386
|
+
};
|
|
387
|
+
const onAbort = (): void => sendCancel();
|
|
388
|
+
callbacks.signal?.addEventListener('abort', onAbort, { once: true });
|
|
389
|
+
try {
|
|
390
|
+
await this.sendJson({ op: 'run_image_build', ...spec });
|
|
391
|
+
if (callbacks.signal?.aborted) sendCancel();
|
|
392
|
+
|
|
393
|
+
for (;;) {
|
|
394
|
+
const frame = await this.reader.nextFrame();
|
|
395
|
+
if (!frame) throw new RunnerError('Guest closed vsock connection during image build');
|
|
396
|
+
if (frame.kind === FRAME_STDOUT) {
|
|
397
|
+
if (callbacks.onStdout && frame.payload.byteLength > 0) {
|
|
398
|
+
await callbacks.onStdout(frame.payload);
|
|
399
|
+
}
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (frame.kind === FRAME_STDERR) {
|
|
403
|
+
if (callbacks.onStderr && frame.payload.byteLength > 0) {
|
|
404
|
+
await callbacks.onStderr(frame.payload);
|
|
405
|
+
}
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
if (frame.kind === FRAME_JSON_RES) {
|
|
409
|
+
let parsed: unknown;
|
|
410
|
+
try {
|
|
411
|
+
parsed = JSON.parse(frame.payload.toString('utf8'));
|
|
412
|
+
} catch (error) {
|
|
413
|
+
throw new RunnerError('Guest returned malformed image build JSON response', {
|
|
414
|
+
cause: error,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
const record = parsed as Record<string, unknown>;
|
|
418
|
+
if (record.ok !== true) {
|
|
419
|
+
const message = typeof record.error === 'string'
|
|
420
|
+
? record.error
|
|
421
|
+
: 'Image build failed in guest';
|
|
422
|
+
throw new RunnerError(`Guest image build failed: ${message}`);
|
|
423
|
+
}
|
|
424
|
+
return record as unknown as IGuestImageBuildResult;
|
|
425
|
+
}
|
|
426
|
+
throw new RunnerError(`Guest sent unexpected frame ${frame.kind} during image build`);
|
|
427
|
+
}
|
|
428
|
+
} finally {
|
|
429
|
+
callbacks.signal?.removeEventListener('abort', onAbort);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
async shutdown(): Promise<void> {
|
|
434
|
+
await this.sendJson({ op: 'shutdown' });
|
|
435
|
+
await this.readJsonResponse<{ ok: true }>();
|
|
436
|
+
}
|
|
437
|
+
}
|
package/ts/wire-schema.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ProtocolError } from './errors.
|
|
2
|
-
import * as plugins from './plugins.
|
|
3
|
-
import { isProtocolTimestamp, isRecord } from './validation.
|
|
1
|
+
import { ProtocolError } from './errors.js';
|
|
2
|
+
import * as plugins from './plugins.js';
|
|
3
|
+
import { isProtocolTimestamp, isRecord } from './validation.js';
|
|
4
4
|
|
|
5
5
|
/** OpenAPI component schemas of the published runner protocol that this runner validates. */
|
|
6
6
|
export const wireSchemaNames = [
|
package/deno.json
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@ship.zone/runner",
|
|
3
|
-
"version": "2.1.0",
|
|
4
|
-
"exports": "./mod.ts",
|
|
5
|
-
"nodeModulesDir": "none",
|
|
6
|
-
"minimumDependencyAge": {
|
|
7
|
-
"age": "P1D",
|
|
8
|
-
"exclude": [
|
|
9
|
-
"npm:@git.zone/*",
|
|
10
|
-
"npm:@push.rocks/*",
|
|
11
|
-
"npm:@ship.zone/*"
|
|
12
|
-
]
|
|
13
|
-
},
|
|
14
|
-
"tasks": {
|
|
15
|
-
"dev": "deno run --allow-all mod.ts",
|
|
16
|
-
"bundle": "deno bundle --frozen --check --platform=deno --keep-names --external '@ship.zone/ci-spec' --external '@ship.zone/ci-spec/*' --external 'ajv/*' --declaration --outdir dist_npm mod.ts",
|
|
17
|
-
"test": "deno test --allow-env --allow-net --allow-read --allow-write --allow-run test/",
|
|
18
|
-
"check": "deno check mod.ts test/ scripts/",
|
|
19
|
-
"fmt": "deno fmt",
|
|
20
|
-
"lint": "deno lint"
|
|
21
|
-
},
|
|
22
|
-
"lint": {
|
|
23
|
-
"rules": {
|
|
24
|
-
"tags": [
|
|
25
|
-
"recommended"
|
|
26
|
-
]
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
"fmt": {
|
|
30
|
-
"useTabs": false,
|
|
31
|
-
"lineWidth": 100,
|
|
32
|
-
"indentWidth": 2,
|
|
33
|
-
"semiColons": true,
|
|
34
|
-
"singleQuote": true
|
|
35
|
-
},
|
|
36
|
-
"compilerOptions": {
|
|
37
|
-
"lib": [
|
|
38
|
-
"deno.window"
|
|
39
|
-
],
|
|
40
|
-
"strict": true
|
|
41
|
-
},
|
|
42
|
-
"imports": {
|
|
43
|
-
"@ship.zone/ci-spec": "npm:@ship.zone/ci-spec@2.0.0",
|
|
44
|
-
"@ship.zone/ci-spec/archive-cases.json": "npm:@ship.zone/ci-spec@2.0.0/archive-cases.json",
|
|
45
|
-
"@ship.zone/ci-spec/digest-cases.json": "npm:@ship.zone/ci-spec@2.0.0/digest-cases.json",
|
|
46
|
-
"@ship.zone/ci-spec/runner-cases.json": "npm:@ship.zone/ci-spec@2.0.0/runner-cases.json",
|
|
47
|
-
"@ship.zone/ci-spec/runner-job.schema.json": "npm:@ship.zone/ci-spec@2.0.0/runner-job.schema.json",
|
|
48
|
-
"@ship.zone/ci-spec/runner-messages.json": "npm:@ship.zone/ci-spec@2.0.0/runner-messages.json",
|
|
49
|
-
"@ship.zone/ci-spec/runner.openapi.json": "npm:@ship.zone/ci-spec@2.0.0/runner.openapi.json",
|
|
50
|
-
"@ship.zone/ci-spec/version-cases.json": "npm:@ship.zone/ci-spec@2.0.0/version-cases.json",
|
|
51
|
-
"@ship.zone/ci-spec/conformance/runner-jobs/": "npm:/@ship.zone/ci-spec@2.0.0/conformance/runner-jobs/",
|
|
52
|
-
"@std/assert": "jsr:@std/assert@^1.0.14",
|
|
53
|
-
"@std/path": "jsr:@std/path@^1.1.2",
|
|
54
|
-
"ajv/dist/2020.js": "npm:ajv@8.20.0/dist/2020.js"
|
|
55
|
-
}
|
|
56
|
-
}
|