@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/filesystem.ts
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { ResourceCleanupError, RunnerError } from './errors.js';
|
|
3
|
+
|
|
4
|
+
export type TFileHandle = plugins.fs.FileHandle;
|
|
5
|
+
|
|
6
|
+
/** Open flags for a new private file that must not exist yet. */
|
|
7
|
+
export const createNewWriteFlags = 'wx';
|
|
8
|
+
/** Open flags for an existing file that is rewritten from its start without being created. */
|
|
9
|
+
export const truncateExistingWriteFlags = (): number =>
|
|
10
|
+
plugins.fs.constants.O_WRONLY | plugins.fs.constants.O_TRUNC;
|
|
11
|
+
|
|
12
|
+
export interface IMakeTempOptions {
|
|
13
|
+
dir?: string;
|
|
14
|
+
prefix?: string;
|
|
15
|
+
suffix?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IRemoveOptions {
|
|
19
|
+
recursive?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const errorCode = (error: unknown): string | undefined => {
|
|
23
|
+
if (!(error instanceof Error)) return undefined;
|
|
24
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
25
|
+
return typeof code === 'string' ? code : undefined;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const isNotFound = (error: unknown): boolean => errorCode(error) === 'ENOENT';
|
|
29
|
+
|
|
30
|
+
export const isAlreadyExists = (error: unknown): boolean => errorCode(error) === 'EEXIST';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Runs an operation on an open file handle and always closes the handle afterwards.
|
|
34
|
+
*
|
|
35
|
+
* A failed close is never hidden: it becomes a `ResourceCleanupError` that also carries the
|
|
36
|
+
* operation's failure, if any. Every file descriptor the runner opens goes through this helper.
|
|
37
|
+
*/
|
|
38
|
+
export const withFileHandle = async <T>(
|
|
39
|
+
handle: TFileHandle,
|
|
40
|
+
operation: (handle: TFileHandle) => Promise<T>,
|
|
41
|
+
closeFailureMessage: string,
|
|
42
|
+
): Promise<T> => {
|
|
43
|
+
let result: T | undefined;
|
|
44
|
+
let operationError: unknown;
|
|
45
|
+
let hasOperationError = false;
|
|
46
|
+
try {
|
|
47
|
+
result = await operation(handle);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
operationError = error;
|
|
50
|
+
hasOperationError = true;
|
|
51
|
+
}
|
|
52
|
+
await closeAfterOperation(handle, hasOperationError, operationError, closeFailureMessage);
|
|
53
|
+
return result as T;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The async-generator form of `withFileHandle`: yields what `generate` yields and closes the
|
|
58
|
+
* handle when the generator completes, fails, or is ended early by its consumer.
|
|
59
|
+
*/
|
|
60
|
+
export async function* withFileHandleChunks<T>(
|
|
61
|
+
handle: TFileHandle,
|
|
62
|
+
generate: (handle: TFileHandle) => AsyncGenerator<T>,
|
|
63
|
+
closeFailureMessage: string,
|
|
64
|
+
): AsyncGenerator<T> {
|
|
65
|
+
let operationError: unknown;
|
|
66
|
+
let hasOperationError = false;
|
|
67
|
+
try {
|
|
68
|
+
yield* generate(handle);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
operationError = error;
|
|
71
|
+
hasOperationError = true;
|
|
72
|
+
} finally {
|
|
73
|
+
await closeAfterOperation(handle, hasOperationError, operationError, closeFailureMessage);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const closeAfterOperation = async (
|
|
78
|
+
handle: TFileHandle,
|
|
79
|
+
hasOperationError: boolean,
|
|
80
|
+
operationError: unknown,
|
|
81
|
+
closeFailureMessage: string,
|
|
82
|
+
): Promise<void> => {
|
|
83
|
+
let closeError: unknown;
|
|
84
|
+
let hasCloseError = false;
|
|
85
|
+
try {
|
|
86
|
+
await handle.close();
|
|
87
|
+
} catch (error) {
|
|
88
|
+
closeError = error;
|
|
89
|
+
hasCloseError = true;
|
|
90
|
+
}
|
|
91
|
+
if (hasCloseError) {
|
|
92
|
+
throw new ResourceCleanupError(closeFailureMessage, [
|
|
93
|
+
...(hasOperationError ? [operationError] : []),
|
|
94
|
+
closeError,
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
if (hasOperationError) throw operationError;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** Opens `path` and runs `operation` on the handle through `withFileHandle`. */
|
|
101
|
+
export const withOpenFile = async <T>(
|
|
102
|
+
path: string,
|
|
103
|
+
flags: string | number,
|
|
104
|
+
mode: number | undefined,
|
|
105
|
+
operation: (handle: TFileHandle) => Promise<T>,
|
|
106
|
+
closeFailureMessage: string,
|
|
107
|
+
): Promise<T> =>
|
|
108
|
+
await withFileHandle(
|
|
109
|
+
await plugins.fs.open(path, flags, mode),
|
|
110
|
+
operation,
|
|
111
|
+
closeFailureMessage,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
/** Writes every byte, failing when the kernel reports no progress. */
|
|
115
|
+
export const writeAll = async (
|
|
116
|
+
handle: TFileHandle,
|
|
117
|
+
bytes: Uint8Array,
|
|
118
|
+
noProgressMessage: string,
|
|
119
|
+
): Promise<void> => {
|
|
120
|
+
let offset = 0;
|
|
121
|
+
while (offset < bytes.byteLength) {
|
|
122
|
+
const { bytesWritten } = await handle.write(bytes, offset, bytes.byteLength - offset);
|
|
123
|
+
if (bytesWritten <= 0) throw new RunnerError(noProgressMessage);
|
|
124
|
+
offset += bytesWritten;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** Reads into `buffer` from the current position; returns `null` at end of file. */
|
|
129
|
+
export const readInto = async (
|
|
130
|
+
handle: TFileHandle,
|
|
131
|
+
buffer: Uint8Array,
|
|
132
|
+
): Promise<number | null> => {
|
|
133
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.byteLength, null);
|
|
134
|
+
return bytesRead === 0 && buffer.byteLength > 0 ? null : bytesRead;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/** Flushes a directory entry change to stable storage by fsyncing the directory itself. */
|
|
138
|
+
export const syncDirectory = async (path: string, closeFailureMessage: string): Promise<void> =>
|
|
139
|
+
await withOpenFile(
|
|
140
|
+
path,
|
|
141
|
+
'r',
|
|
142
|
+
undefined,
|
|
143
|
+
async (handle) => await handle.sync(),
|
|
144
|
+
closeFailureMessage,
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
export const lstatIfPresent = async (path: string): Promise<plugins.Stats | undefined> => {
|
|
148
|
+
try {
|
|
149
|
+
return await plugins.fs.lstat(path);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (isNotFound(error)) return undefined;
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/** Creates a private directory with a random name; `mkdtemp` creates it with mode 0700. */
|
|
157
|
+
export const makeTempDir = async (options: IMakeTempOptions = {}): Promise<string> =>
|
|
158
|
+
await plugins.fs.mkdtemp(
|
|
159
|
+
`${plugins.path.resolve(options.dir ?? plugins.os.tmpdir())}${plugins.path.sep}${
|
|
160
|
+
options.prefix ?? ''
|
|
161
|
+
}`,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Creates an empty mode-0600 file with a random name through an exclusive create, so an existing
|
|
166
|
+
* path (including a planted symbolic link) is never reused.
|
|
167
|
+
*/
|
|
168
|
+
export const makeTempFile = async (options: IMakeTempOptions = {}): Promise<string> => {
|
|
169
|
+
const path = plugins.path.join(
|
|
170
|
+
options.dir ?? plugins.os.tmpdir(),
|
|
171
|
+
`${options.prefix ?? ''}${plugins.crypto.randomBytes(16).toString('hex')}${
|
|
172
|
+
options.suffix ?? ''
|
|
173
|
+
}`,
|
|
174
|
+
);
|
|
175
|
+
await withOpenFile(
|
|
176
|
+
path,
|
|
177
|
+
createNewWriteFlags,
|
|
178
|
+
0o600,
|
|
179
|
+
async () => undefined,
|
|
180
|
+
'Temporary file creation and close failed',
|
|
181
|
+
);
|
|
182
|
+
return path;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Removes a file, a symbolic link or an empty directory, or a whole tree when `recursive` is set.
|
|
187
|
+
* A missing path is reported as `ENOENT`.
|
|
188
|
+
*/
|
|
189
|
+
export const removePath = async (path: string, options: IRemoveOptions = {}): Promise<void> => {
|
|
190
|
+
if (options.recursive) {
|
|
191
|
+
await plugins.fs.rm(path, { recursive: true });
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
await plugins.fs.unlink(path);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
if (errorCode(error) !== 'EISDIR') throw error;
|
|
198
|
+
await plugins.fs.rmdir(path);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/** True when both stats describe the same inode on the same device. */
|
|
203
|
+
export const sameFileIdentity = (first: plugins.Stats, second: plugins.Stats): boolean =>
|
|
204
|
+
second.dev === first.dev && second.ino === first.ino;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Reads a bounded regular file through one pinned descriptor and verifies that neither the path
|
|
208
|
+
* nor the descriptor changed while the exact bytes were read.
|
|
209
|
+
*/
|
|
210
|
+
export const readBoundedRegularFile = async (
|
|
211
|
+
path: string,
|
|
212
|
+
maximumBytes: number,
|
|
213
|
+
label: string,
|
|
214
|
+
): Promise<{ bytes: Uint8Array<ArrayBuffer>; stat: plugins.Stats }> => {
|
|
215
|
+
const pathStat = await plugins.fs.lstat(path);
|
|
216
|
+
if (
|
|
217
|
+
!pathStat.isFile() || pathStat.isSymbolicLink() || pathStat.size < 1 ||
|
|
218
|
+
pathStat.size > maximumBytes
|
|
219
|
+
) {
|
|
220
|
+
throw new RunnerError(`${label} must be a bounded regular file`);
|
|
221
|
+
}
|
|
222
|
+
return await withOpenFile(
|
|
223
|
+
path,
|
|
224
|
+
'r',
|
|
225
|
+
undefined,
|
|
226
|
+
async (handle) => {
|
|
227
|
+
const before = await handle.stat();
|
|
228
|
+
if (
|
|
229
|
+
!before.isFile() || before.size < 1 || before.size > maximumBytes ||
|
|
230
|
+
before.size !== pathStat.size || !sameFileIdentity(pathStat, before)
|
|
231
|
+
) {
|
|
232
|
+
throw new RunnerError(`${label} changed while it was opened`);
|
|
233
|
+
}
|
|
234
|
+
const bytes = new Uint8Array(before.size);
|
|
235
|
+
let offset = 0;
|
|
236
|
+
while (offset < bytes.byteLength) {
|
|
237
|
+
const read = await readInto(handle, bytes.subarray(offset));
|
|
238
|
+
if (read === null || read <= 0) {
|
|
239
|
+
throw new RunnerError(`${label} changed while it was read`);
|
|
240
|
+
}
|
|
241
|
+
offset += read;
|
|
242
|
+
}
|
|
243
|
+
const overflow = await readInto(handle, new Uint8Array(1));
|
|
244
|
+
const after = await handle.stat();
|
|
245
|
+
const currentPathStat = await plugins.fs.lstat(path);
|
|
246
|
+
if (
|
|
247
|
+
overflow !== null || !after.isFile() || after.size !== before.size ||
|
|
248
|
+
!currentPathStat.isFile() || currentPathStat.isSymbolicLink() ||
|
|
249
|
+
currentPathStat.size !== before.size || !sameFileIdentity(before, after) ||
|
|
250
|
+
!sameFileIdentity(after, currentPathStat)
|
|
251
|
+
) {
|
|
252
|
+
throw new RunnerError(`${label} changed while it was read`);
|
|
253
|
+
}
|
|
254
|
+
return { bytes, stat: after };
|
|
255
|
+
},
|
|
256
|
+
`${label} read and close failed`,
|
|
257
|
+
);
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/** Returns the lowercase hexadecimal SHA-256 digest of `bytes`. */
|
|
261
|
+
export const sha256Hex = (bytes: Uint8Array): string =>
|
|
262
|
+
plugins.crypto.createHash('sha256').update(bytes).digest('hex');
|
|
263
|
+
|
|
264
|
+
/** Yields copies of the file content from the handle's current position until end of file. */
|
|
265
|
+
export async function* readFileChunks(
|
|
266
|
+
handle: TFileHandle,
|
|
267
|
+
chunkBytes: number,
|
|
268
|
+
signal?: AbortSignal,
|
|
269
|
+
): AsyncGenerator<Uint8Array> {
|
|
270
|
+
const buffer = new Uint8Array(chunkBytes);
|
|
271
|
+
while (true) {
|
|
272
|
+
if (signal?.aborted) throw signal.reason;
|
|
273
|
+
const read = await readInto(handle, buffer);
|
|
274
|
+
if (read === null) return;
|
|
275
|
+
yield buffer.slice(0, read);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* A pull-based byte stream over an async generator; canceling the stream ends the generator.
|
|
281
|
+
*
|
|
282
|
+
* The generator is started when the stream is created, so a stream canceled before its first read
|
|
283
|
+
* still runs the generator's cleanup instead of leaving a generator that never started.
|
|
284
|
+
*/
|
|
285
|
+
export const asyncIteratorStream = (
|
|
286
|
+
iterator: AsyncGenerator<Uint8Array>,
|
|
287
|
+
): ReadableStream<Uint8Array> => {
|
|
288
|
+
const forward = async (
|
|
289
|
+
controller: ReadableStreamDefaultController<Uint8Array>,
|
|
290
|
+
): Promise<void> => {
|
|
291
|
+
const result = await iterator.next();
|
|
292
|
+
if (result.done) controller.close();
|
|
293
|
+
else controller.enqueue(result.value);
|
|
294
|
+
};
|
|
295
|
+
return new ReadableStream<Uint8Array>({
|
|
296
|
+
start: forward,
|
|
297
|
+
pull: forward,
|
|
298
|
+
async cancel() {
|
|
299
|
+
await iterator.return(undefined);
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/** Opens `path` for reading as a byte stream that closes its descriptor when it ends. */
|
|
305
|
+
export const openReadableFile = async (
|
|
306
|
+
path: string,
|
|
307
|
+
chunkBytes: number,
|
|
308
|
+
closeFailureMessage: string,
|
|
309
|
+
): Promise<ReadableStream<Uint8Array>> =>
|
|
310
|
+
asyncIteratorStream(
|
|
311
|
+
withFileHandleChunks(
|
|
312
|
+
await plugins.fs.open(path, 'r'),
|
|
313
|
+
(handle) => readFileChunks(handle, chunkBytes),
|
|
314
|
+
closeFailureMessage,
|
|
315
|
+
),
|
|
316
|
+
);
|
package/ts/index.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
export * from './api-client.
|
|
2
|
-
export * from './artifact-manager.
|
|
3
|
-
export * from './cache-manager.
|
|
4
|
-
export * from './config.
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
1
|
+
export * from './api-client.js';
|
|
2
|
+
export * from './artifact-manager.js';
|
|
3
|
+
export * from './cache-manager.js';
|
|
4
|
+
export * from './config.js';
|
|
5
|
+
export * from './egress-proxy.js';
|
|
6
|
+
export * from './errors.js';
|
|
7
|
+
export * from './interfaces.js';
|
|
8
|
+
export * from './log-sender.js';
|
|
9
|
+
export * from './microvm-executor.js';
|
|
10
|
+
export * from './npm-grants.js';
|
|
11
|
+
export * from './oci-registry.js';
|
|
12
|
+
export * from './protocol-validator.js';
|
|
13
|
+
export * from './redactor.js';
|
|
14
|
+
export * from './runner.js';
|
|
15
|
+
export * from './source-workspace.js';
|
|
16
|
+
export * from './spec-version.js';
|
|
17
|
+
export * from './staging-scavenger.js';
|
|
18
|
+
export * from './state-owner.js';
|
|
19
|
+
export * from './vsock-protocol.js';
|
|
20
|
+
export * from './wire-schema.js';
|
package/ts/interfaces.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { commitinfo } from './00_commitinfo_data.js';
|
|
2
2
|
|
|
3
|
-
export const runnerVersion: string =
|
|
3
|
+
export const runnerVersion: string = commitinfo.version;
|
|
4
4
|
|
|
5
5
|
export type TExecutionProfile = 'oci' | 'oci-image' | 'vm';
|
|
6
|
+
export type TRunnerRole = 'workload' | 'builder';
|
|
6
7
|
export type TIsolation = 'container' | 'microvm';
|
|
7
8
|
export type TRunnerFeature = 'source.tar-gz' | 'artifacts' | 'caches';
|
|
8
9
|
export type TLeaseFeature = 'image-pull-grants' | 'candidate-bindings' | 'npm-read-grants';
|
|
9
10
|
export type TNetworkMode = 'none' | 'egress';
|
|
10
11
|
export type TSourceFormat = 'tar.gz';
|
|
11
|
-
export type TOciRuntime = 'docker' | 'podman';
|
|
12
12
|
export type TArtifactPermission = 'none' | 'write';
|
|
13
13
|
export type TCachePermission = 'none' | 'read' | 'read-write';
|
|
14
14
|
export type TImagePermission = 'none' | 'push';
|
|
@@ -192,13 +192,11 @@ export interface IJobLease {
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
/**
|
|
195
|
-
* A lease this runner executes
|
|
196
|
-
*
|
|
195
|
+
* A lease this runner executes in Firecracker `microvm` isolation (`oci`, `vm`, or `oci-image`),
|
|
196
|
+
* including optional attempt-scoped image grants, candidate bindings, and npm read grants.
|
|
197
197
|
*/
|
|
198
|
-
export interface IOciJobLease extends Omit<IJobLease, 'job'
|
|
199
|
-
job:
|
|
200
|
-
grants: [];
|
|
201
|
-
bindings: [];
|
|
198
|
+
export interface IOciJobLease extends Omit<IJobLease, 'job'> {
|
|
199
|
+
job: TExecutableRunnerJob;
|
|
202
200
|
}
|
|
203
201
|
|
|
204
202
|
export interface IJobIdentity {
|
|
@@ -278,6 +276,32 @@ export interface IRecoverAttemptRequest {
|
|
|
278
276
|
reason: 'runner_restarted';
|
|
279
277
|
}
|
|
280
278
|
|
|
279
|
+
export interface IRecordImageRequest {
|
|
280
|
+
recordRequestId: string;
|
|
281
|
+
identity: IJobIdentity;
|
|
282
|
+
manifestDigest: string;
|
|
283
|
+
mediaType: 'application/vnd.oci.image.manifest.v1+json';
|
|
284
|
+
sizeBytes: number;
|
|
285
|
+
platform: string;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export interface IImageRecord {
|
|
289
|
+
registry: string;
|
|
290
|
+
repository: string;
|
|
291
|
+
manifestDigest: string;
|
|
292
|
+
mediaType: 'application/vnd.oci.image.manifest.v1+json';
|
|
293
|
+
sizeBytes: number;
|
|
294
|
+
platform: string;
|
|
295
|
+
createdAt: string;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface IProducedImageManifest {
|
|
299
|
+
readonly manifestDigest: string;
|
|
300
|
+
readonly mediaType: 'application/vnd.oci.image.manifest.v1+json';
|
|
301
|
+
readonly sizeBytes: number;
|
|
302
|
+
readonly platform: string;
|
|
303
|
+
}
|
|
304
|
+
|
|
281
305
|
export interface ITransferRecord {
|
|
282
306
|
name: string;
|
|
283
307
|
format: 'tar.gz';
|
|
@@ -456,13 +480,31 @@ export interface IImageBuildRunnerJob extends ICompiledRunnerJobBase {
|
|
|
456
480
|
/** Every compiled job shape the published runner job schema admits. */
|
|
457
481
|
export type TCompiledRunnerJob = IContainerRunnerJob | IVmRunnerJob | IImageBuildRunnerJob;
|
|
458
482
|
|
|
459
|
-
/** An `oci` job this runner executes
|
|
483
|
+
/** An `oci` job this runner executes in Firecracker `microvm` isolation. */
|
|
460
484
|
export interface IOciRunnerJob extends IContainerRunnerJob {
|
|
461
|
-
requirements: IJobRequirements & { executionProfile: 'oci'; isolation: '
|
|
462
|
-
|
|
463
|
-
|
|
485
|
+
requirements: IJobRequirements & { executionProfile: 'oci'; isolation: 'microvm' };
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/** A `vm` job this runner executes in Firecracker `microvm` isolation. */
|
|
489
|
+
export interface IVmExecutableRunnerJob extends IVmRunnerJob {
|
|
490
|
+
requirements: IJobRequirements & { executionProfile: 'vm'; isolation: 'microvm'; platform: string };
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/** An `oci-image` job this runner executes in a dedicated builder Firecracker microVM. */
|
|
494
|
+
export interface IImageBuildExecutableRunnerJob extends IImageBuildRunnerJob {
|
|
495
|
+
requirements: IJobRequirements & {
|
|
496
|
+
executionProfile: 'oci-image';
|
|
497
|
+
isolation: 'microvm';
|
|
498
|
+
platform: string;
|
|
499
|
+
};
|
|
464
500
|
}
|
|
465
501
|
|
|
502
|
+
/** Every compiled job shape this Firecracker runner can execute across workload and builder roles. */
|
|
503
|
+
export type TExecutableRunnerJob =
|
|
504
|
+
| IOciRunnerJob
|
|
505
|
+
| IVmExecutableRunnerJob
|
|
506
|
+
| IImageBuildExecutableRunnerJob;
|
|
507
|
+
|
|
466
508
|
export interface ITransferMetadata {
|
|
467
509
|
sha256: string;
|
|
468
510
|
sizeBytes: number;
|
|
@@ -519,10 +561,33 @@ export type TOciArchitecture = 'amd64' | 'arm64';
|
|
|
519
561
|
export type TOciHelperTarget = 'linux_amd64' | 'linux_arm64';
|
|
520
562
|
|
|
521
563
|
export interface IOciExecutorConfig {
|
|
522
|
-
|
|
523
|
-
|
|
564
|
+
/**
|
|
565
|
+
* Dedicated runner role per `@ship.zone/ci-spec`:
|
|
566
|
+
* - `'workload'`: executes `oci` and `vm` jobs (never `oci-image`).
|
|
567
|
+
* - `'builder'`: executes `oci-image` container builds exclusively (never `oci` or `vm`).
|
|
568
|
+
*/
|
|
569
|
+
runnerProfile: TRunnerRole;
|
|
570
|
+
/** Pinned Linux vmlinux kernel path for Firecracker microVMs. */
|
|
571
|
+
kernelPath: string;
|
|
572
|
+
/** Pinned ext2 guest rootfs containing rootless BuildKit (`buildkitd` + `buildctl`) for `builder` runners. */
|
|
573
|
+
builderRootfsPath?: string;
|
|
574
|
+
/** Optional override for the `buildctl` binary path inside the builder guest. */
|
|
575
|
+
buildctlPath?: string;
|
|
576
|
+
/** Optional smartvm-helper Unix socket path (defaults to `/run/smartvm/helper.sock`). */
|
|
577
|
+
smartvmSocketPath?: string;
|
|
578
|
+
/** Optional smartvm-bridge runtime directory for vsock relay sockets. */
|
|
579
|
+
smartvmRuntimeDir?: string;
|
|
580
|
+
/** Optional explicit path to the smartvm-bridge binary. */
|
|
581
|
+
smartvmBridgePath?: string;
|
|
582
|
+
/** Kernel boot arguments passed to Firecracker. */
|
|
583
|
+
bootArgs: string;
|
|
584
|
+
/** Maximum extracted OCI rootfs image bytes accepted during image materialization. */
|
|
585
|
+
maximumRootfsBytes: number;
|
|
586
|
+
/** Guest memory headroom reserved for the guest kernel and init agent on top of step memory. */
|
|
587
|
+
guestMemoryOverheadBytes: number;
|
|
588
|
+
/** Extra internal CIDRs blocked by the host egress proxy (e.g. coordinator network ranges). */
|
|
589
|
+
egressBlockedCidrs: string[];
|
|
524
590
|
workspaceHelperPath?: string;
|
|
525
|
-
requireRootless: boolean;
|
|
526
591
|
allowedNetworks: TNetworkMode[];
|
|
527
592
|
containerUser: string;
|
|
528
593
|
defaultTimeoutMs: number;
|
|
@@ -583,16 +648,24 @@ export interface IExecutionContext {
|
|
|
583
648
|
onLog: (stream: 'stdout' | 'stderr', data: string) => Promise<void>;
|
|
584
649
|
}
|
|
585
650
|
|
|
651
|
+
export interface IMicroVmShapeInfo {
|
|
652
|
+
readonly id: string;
|
|
653
|
+
readonly vcpus: number;
|
|
654
|
+
readonly memMib: number;
|
|
655
|
+
}
|
|
656
|
+
|
|
586
657
|
export interface IOciRuntimeFacts {
|
|
587
|
-
readonly
|
|
658
|
+
readonly engine: 'firecracker';
|
|
659
|
+
readonly firecrackerVersion: string;
|
|
588
660
|
readonly endpoint: string;
|
|
589
|
-
readonly rootless: boolean;
|
|
590
661
|
readonly os: 'linux';
|
|
591
662
|
readonly architecture: TOciArchitecture;
|
|
592
663
|
readonly helperTarget: TOciHelperTarget;
|
|
593
664
|
readonly helperPath: string;
|
|
594
665
|
readonly helperSha256: string;
|
|
595
|
-
readonly
|
|
666
|
+
readonly initrdPath: string;
|
|
667
|
+
readonly kernelPath: string;
|
|
668
|
+
readonly shapes: readonly IMicroVmShapeInfo[];
|
|
596
669
|
}
|
|
597
670
|
|
|
598
671
|
export interface IPrepareOciLeaseContext {
|
|
@@ -607,6 +680,11 @@ export interface IPreparedOciLease {
|
|
|
607
680
|
readonly attemptId: string;
|
|
608
681
|
readonly image: string;
|
|
609
682
|
readonly imageArchitecture: TOciArchitecture;
|
|
683
|
+
readonly rootfsPath?: string;
|
|
684
|
+
readonly imageDigest?: string;
|
|
685
|
+
readonly shapeId?: string;
|
|
686
|
+
readonly defaultEnv?: Record<string, string>;
|
|
687
|
+
readonly defaultWorkingDir?: string;
|
|
610
688
|
cleanup(): Promise<void>;
|
|
611
689
|
}
|
|
612
690
|
|
|
@@ -636,6 +714,7 @@ export interface IRuntimeWorkspaceExporter {
|
|
|
636
714
|
export interface IExecutionResult {
|
|
637
715
|
exitCode: number | null;
|
|
638
716
|
stopReason?: TExecutionStopReason;
|
|
717
|
+
producedImage?: IProducedImageManifest;
|
|
639
718
|
workspace?: IRuntimeWorkspaceExporter;
|
|
640
719
|
}
|
|
641
720
|
|
|
@@ -655,7 +734,7 @@ export interface IPreparedWorkspace {
|
|
|
655
734
|
|
|
656
735
|
export interface ISourcePrepareContext {
|
|
657
736
|
identity: IJobIdentity;
|
|
658
|
-
job: Pick<
|
|
737
|
+
job: Pick<TExecutableRunnerJob, 'source' | 'permissions' | 'requirements'>;
|
|
659
738
|
signal: AbortSignal;
|
|
660
739
|
}
|
|
661
740
|
|
|
@@ -679,7 +758,7 @@ export interface ISecretRedactionSet {
|
|
|
679
758
|
|
|
680
759
|
export interface IArtifactUploadContext {
|
|
681
760
|
workspace: IRuntimeWorkspaceExporter;
|
|
682
|
-
job: Pick<IOciRunnerJob, 'artifacts' | 'permissions' | 'requirements'>;
|
|
761
|
+
job: Pick<IOciRunnerJob | IVmExecutableRunnerJob, 'artifacts' | 'permissions' | 'requirements'>;
|
|
683
762
|
status: TJobCompletionStatus;
|
|
684
763
|
redactionSet: ISecretRedactionSet;
|
|
685
764
|
identity: IJobIdentity;
|
|
@@ -693,14 +772,17 @@ export interface IArtifactManager {
|
|
|
693
772
|
export interface ICacheRestoreContext {
|
|
694
773
|
workspacePath: string;
|
|
695
774
|
workspaceEntryCount: number;
|
|
696
|
-
job: Pick<
|
|
775
|
+
job: Pick<
|
|
776
|
+
IOciRunnerJob | IVmExecutableRunnerJob,
|
|
777
|
+
'caches' | 'permissions' | 'requirements' | 'source'
|
|
778
|
+
>;
|
|
697
779
|
identity: IJobIdentity;
|
|
698
780
|
signal: AbortSignal;
|
|
699
781
|
}
|
|
700
782
|
|
|
701
783
|
export interface ICacheSaveContext {
|
|
702
784
|
workspace: IRuntimeWorkspaceExporter;
|
|
703
|
-
job: Pick<IOciRunnerJob, 'caches' | 'permissions' | 'requirements'>;
|
|
785
|
+
job: Pick<IOciRunnerJob | IVmExecutableRunnerJob, 'caches' | 'permissions' | 'requirements'>;
|
|
704
786
|
status: TJobCompletionStatus;
|
|
705
787
|
redactionSet: ISecretRedactionSet;
|
|
706
788
|
identity: IJobIdentity;
|
package/ts/log-sender.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ProtocolError } from './errors.
|
|
2
|
-
import type { IJobIdentity, ILogAcknowledgement, ILogChunk, TLogStream } from './interfaces.
|
|
1
|
+
import { ProtocolError } from './errors.js';
|
|
2
|
+
import type { IJobIdentity, ILogAcknowledgement, ILogChunk, TLogStream } from './interfaces.js';
|
|
3
3
|
import {
|
|
4
4
|
LogSequenceRedactor,
|
|
5
5
|
type SecretRedactionSet,
|
|
6
6
|
StreamingSecretRedactor,
|
|
7
|
-
} from './redactor.
|
|
8
|
-
import { utf8Length } from './validation.
|
|
7
|
+
} from './redactor.js';
|
|
8
|
+
import { utf8Length } from './validation.js';
|
|
9
9
|
|
|
10
10
|
export interface ILogApi {
|
|
11
11
|
appendLog(chunk: ILogChunk, signal?: AbortSignal): Promise<ILogAcknowledgement>;
|