@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/cli.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RunnerApiClient } from './api-client.
|
|
2
|
-
import { ArtifactManager } from './artifact-manager.
|
|
3
|
-
import { CacheManager } from './cache-manager.
|
|
1
|
+
import { RunnerApiClient } from './api-client.js';
|
|
2
|
+
import { ArtifactManager } from './artifact-manager.js';
|
|
3
|
+
import { CacheManager } from './cache-manager.js';
|
|
4
4
|
import {
|
|
5
5
|
defaultRunnerConfig,
|
|
6
6
|
loadRunnerConfig,
|
|
@@ -8,37 +8,38 @@ import {
|
|
|
8
8
|
saveRunnerConfig,
|
|
9
9
|
validateRunnerConfig,
|
|
10
10
|
withRunnerCredential,
|
|
11
|
-
} from './config.
|
|
12
|
-
import { ConfigurationError } from './errors.
|
|
11
|
+
} from './config.js';
|
|
12
|
+
import { ConfigurationError } from './errors.js';
|
|
13
13
|
import type {
|
|
14
14
|
IRegisterRunnerRequest,
|
|
15
15
|
IRegisterRunnerResponse,
|
|
16
16
|
IRunnerCapabilities,
|
|
17
17
|
IRunnerConfig,
|
|
18
|
-
} from './interfaces.
|
|
19
|
-
import { runnerVersion } from './interfaces.
|
|
20
|
-
import {
|
|
21
|
-
import { RegistrationStateStore } from './registration-state.
|
|
22
|
-
import { reconcileProtocolLimits, runnerCapabilities, ShipRunner } from './runner.
|
|
23
|
-
import { runnerSpecVersion } from './spec-version.
|
|
24
|
-
import { SourceWorkspaceManager } from './source-workspace.
|
|
18
|
+
} from './interfaces.js';
|
|
19
|
+
import { runnerVersion } from './interfaces.js';
|
|
20
|
+
import { MicroVmExecutor } from './microvm-executor.js';
|
|
21
|
+
import { RegistrationStateStore } from './registration-state.js';
|
|
22
|
+
import { reconcileProtocolLimits, runnerCapabilities, ShipRunner } from './runner.js';
|
|
23
|
+
import { runnerSpecVersion } from './spec-version.js';
|
|
24
|
+
import { SourceWorkspaceManager } from './source-workspace.js';
|
|
25
|
+
import { RunnerStateOwner } from './state-owner.js';
|
|
25
26
|
|
|
26
27
|
interface IParsedArguments {
|
|
27
28
|
command: string;
|
|
28
29
|
options: Map<string, string | true>;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
const cliInvocation = '
|
|
32
|
+
const cliInvocation = 'ship-zone-runner';
|
|
32
33
|
|
|
33
|
-
const usage = `ship.zone runner ${runnerVersion}
|
|
34
|
+
const usage = `ship.zone runner ${runnerVersion} (Firecracker microVM)
|
|
34
35
|
|
|
35
36
|
Usage:
|
|
36
|
-
${cliInvocation} init --control-plane <url> [--config <path>] [--name <name>]
|
|
37
|
+
${cliInvocation} init --control-plane <url> [--profile workload|builder] [--config <path>] [--name <name>] [--kernel-path <path>] [--builder-rootfs-path <path>] [--smartvm-socket <path>] [--allow-egress]
|
|
37
38
|
${cliInvocation} register [--config <path>]
|
|
38
39
|
${cliInvocation} run [--config <path>]
|
|
39
40
|
${cliInvocation} once [--config <path>]
|
|
40
41
|
${cliInvocation} config [--config <path>]
|
|
41
|
-
${cliInvocation} version
|
|
42
|
+
${cliInvocation} version | --version
|
|
42
43
|
|
|
43
44
|
Bootstrap credentials must be supplied through SHIP_RUNNER_BOOTSTRAP_TOKEN or the
|
|
44
45
|
0600 config file. Secret values are intentionally not accepted as command arguments.
|
|
@@ -73,7 +74,7 @@ const stringOption = (
|
|
|
73
74
|
};
|
|
74
75
|
|
|
75
76
|
const configPath = (options: Map<string, string | true>): string =>
|
|
76
|
-
stringOption(options, 'config') ??
|
|
77
|
+
stringOption(options, 'config') ?? process.env.SHIP_RUNNER_CONFIG ?? './runner.config.json';
|
|
77
78
|
|
|
78
79
|
const apiFor = (config: IRunnerConfig): RunnerApiClient =>
|
|
79
80
|
new RunnerApiClient({
|
|
@@ -97,15 +98,14 @@ export const registerRunnerDurably = async (options: {
|
|
|
97
98
|
bootstrapToken: string,
|
|
98
99
|
): Promise<IRegisterRunnerResponse>;
|
|
99
100
|
};
|
|
100
|
-
stateStore
|
|
101
|
+
stateStore: RegistrationStateStore;
|
|
101
102
|
createRequestId?: () => string;
|
|
102
103
|
persistConfig?: (path: string, config: IRunnerConfig) => Promise<void>;
|
|
103
104
|
}): Promise<IRunnerConfig> => {
|
|
104
105
|
if (!options.config.bootstrapToken) {
|
|
105
106
|
throw new ConfigurationError('SHIP_RUNNER_BOOTSTRAP_TOKEN is required for registration');
|
|
106
107
|
}
|
|
107
|
-
const stateStore = options.stateStore
|
|
108
|
-
new RegistrationStateStore(options.config.stateDirectory);
|
|
108
|
+
const stateStore = options.stateStore;
|
|
109
109
|
const request = await stateStore.loadOrCreate({
|
|
110
110
|
spec: runnerSpecVersion,
|
|
111
111
|
runnerVersion,
|
|
@@ -123,17 +123,37 @@ const runInit = async (options: Map<string, string | true>): Promise<void> => {
|
|
|
123
123
|
const config = defaultRunnerConfig();
|
|
124
124
|
config.controlPlaneUrl = stringOption(options, 'control-plane') ?? '';
|
|
125
125
|
config.name = stringOption(options, 'name') ?? config.name;
|
|
126
|
+
const profile = stringOption(options, 'profile');
|
|
127
|
+
if (profile !== undefined) {
|
|
128
|
+
if (profile !== 'workload' && profile !== 'builder') {
|
|
129
|
+
throw new ConfigurationError('--profile must be "workload" or "builder"');
|
|
130
|
+
}
|
|
131
|
+
config.oci.runnerProfile = profile;
|
|
132
|
+
}
|
|
126
133
|
const labels = stringOption(options, 'labels');
|
|
127
134
|
if (labels) config.labels = labels.split(',').map((entry) => entry.trim()).filter(Boolean);
|
|
128
|
-
const
|
|
129
|
-
if (
|
|
135
|
+
const kernelPath = stringOption(options, 'kernel-path');
|
|
136
|
+
if (kernelPath) config.oci.kernelPath = kernelPath;
|
|
137
|
+
const builderRootfsPath = stringOption(options, 'builder-rootfs-path');
|
|
138
|
+
if (builderRootfsPath) config.oci.builderRootfsPath = builderRootfsPath;
|
|
139
|
+
const smartvmSocket = stringOption(options, 'smartvm-socket');
|
|
140
|
+
if (smartvmSocket) config.oci.smartvmSocketPath = smartvmSocket;
|
|
141
|
+
const smartvmRuntimeDir = stringOption(options, 'smartvm-runtime-dir');
|
|
142
|
+
if (smartvmRuntimeDir) config.oci.smartvmRuntimeDir = smartvmRuntimeDir;
|
|
143
|
+
const smartvmBridgePath = stringOption(options, 'smartvm-bridge-path');
|
|
144
|
+
if (smartvmBridgePath) config.oci.smartvmBridgePath = smartvmBridgePath;
|
|
130
145
|
const helperPath = stringOption(options, 'workspace-helper-path');
|
|
131
146
|
if (helperPath) config.oci.workspaceHelperPath = helperPath;
|
|
132
147
|
if (options.has('allow-insecure-loopback')) config.allowInsecureLoopback = true;
|
|
133
|
-
if (options.has('allow-network')) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
148
|
+
if (options.has('allow-egress') || options.has('allow-network')) {
|
|
149
|
+
config.oci.allowedNetworks = ['none', 'egress'];
|
|
150
|
+
}
|
|
151
|
+
const blockedCidr = stringOption(options, 'egress-blocked-cidr');
|
|
152
|
+
if (blockedCidr) {
|
|
153
|
+
config.oci.egressBlockedCidrs = blockedCidr
|
|
154
|
+
.split(',')
|
|
155
|
+
.map((entry) => entry.trim())
|
|
156
|
+
.filter(Boolean);
|
|
137
157
|
}
|
|
138
158
|
validateRunnerConfig(config);
|
|
139
159
|
const path = configPath(options);
|
|
@@ -147,44 +167,54 @@ const runRegister = async (options: Map<string, string | true>): Promise<void> =
|
|
|
147
167
|
if (!config.bootstrapToken) {
|
|
148
168
|
throw new ConfigurationError('SHIP_RUNNER_BOOTSTRAP_TOKEN is required for registration');
|
|
149
169
|
}
|
|
150
|
-
const
|
|
151
|
-
const executor = new
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
170
|
+
const stateOwner = await acquireStateOwner(config);
|
|
171
|
+
const executor = new MicroVmExecutor(config, stateOwner);
|
|
172
|
+
try {
|
|
173
|
+
const api = apiFor(config);
|
|
174
|
+
const runtime = await executor.verifyRuntime();
|
|
175
|
+
const discovery = await api.discover();
|
|
176
|
+
const capabilities = runnerCapabilities(config, runtime);
|
|
177
|
+
reconcileProtocolLimits(config, discovery, capabilities);
|
|
178
|
+
const registered = await registerRunnerDurably({
|
|
179
|
+
configPath: path,
|
|
180
|
+
config,
|
|
181
|
+
capabilities,
|
|
182
|
+
api,
|
|
183
|
+
stateStore: new RegistrationStateStore(stateOwner),
|
|
184
|
+
});
|
|
185
|
+
console.log(`Registered runner ${registered.runnerId}`);
|
|
186
|
+
} finally {
|
|
187
|
+
await executor.close().catch(() => {});
|
|
188
|
+
await stateOwner.release();
|
|
189
|
+
}
|
|
163
190
|
};
|
|
164
191
|
|
|
192
|
+
/** Takes the exclusive lock of the configured state directory before anything else uses it. */
|
|
193
|
+
const acquireStateOwner = async (config: IRunnerConfig): Promise<RunnerStateOwner> =>
|
|
194
|
+
await RunnerStateOwner.acquire({
|
|
195
|
+
stateDirectory: config.stateDirectory,
|
|
196
|
+
...(config.oci.workspaceHelperPath
|
|
197
|
+
? { helperSourcePath: config.oci.workspaceHelperPath }
|
|
198
|
+
: {}),
|
|
199
|
+
});
|
|
200
|
+
|
|
165
201
|
const runDaemon = async (
|
|
166
202
|
options: Map<string, string | true>,
|
|
167
203
|
once: boolean,
|
|
168
204
|
): Promise<void> => {
|
|
169
205
|
const path = configPath(options);
|
|
170
206
|
let config = await loadRunnerConfig(path);
|
|
171
|
-
const
|
|
172
|
-
const executor = new OciExecutor(config);
|
|
173
|
-
await executor.verifyRuntime();
|
|
207
|
+
const stateOwner = await acquireStateOwner(config);
|
|
174
208
|
const shutdown = new AbortController();
|
|
175
209
|
const shutdownListener = (): void => shutdown.abort('runner_shutdown');
|
|
176
|
-
const
|
|
177
|
-
for (const signal of
|
|
178
|
-
|
|
179
|
-
Deno.addSignalListener(signal, shutdownListener);
|
|
180
|
-
installedSignals.push(signal);
|
|
181
|
-
} catch {
|
|
182
|
-
// Signal listeners are unavailable on some supported hosts.
|
|
183
|
-
}
|
|
184
|
-
}
|
|
210
|
+
const signals = ['SIGINT', 'SIGTERM'] as const;
|
|
211
|
+
for (const signal of signals) process.on(signal, shutdownListener);
|
|
212
|
+
const executor = new MicroVmExecutor(config, stateOwner);
|
|
185
213
|
try {
|
|
214
|
+
const api = apiFor(config);
|
|
186
215
|
const reportMessage = (message: string): void => console.error(message);
|
|
187
216
|
const runner = new ShipRunner(config, {
|
|
217
|
+
stateOwner,
|
|
188
218
|
api,
|
|
189
219
|
executor,
|
|
190
220
|
workspaceManager: new SourceWorkspaceManager(config, api),
|
|
@@ -200,7 +230,9 @@ const runDaemon = async (
|
|
|
200
230
|
const result = await runner.run({ once, signal: shutdown.signal });
|
|
201
231
|
if (once) console.log(result.claimed ? `Job ${result.status}` : 'No job available');
|
|
202
232
|
} finally {
|
|
203
|
-
for (const signal of
|
|
233
|
+
for (const signal of signals) process.off(signal, shutdownListener);
|
|
234
|
+
await executor.close().catch(() => {});
|
|
235
|
+
await stateOwner.release();
|
|
204
236
|
}
|
|
205
237
|
};
|
|
206
238
|
|
|
@@ -226,6 +258,7 @@ export const runCli = async (arguments_: string[]): Promise<void> => {
|
|
|
226
258
|
break;
|
|
227
259
|
}
|
|
228
260
|
case 'version':
|
|
261
|
+
case '--version':
|
|
229
262
|
console.log(runnerVersion);
|
|
230
263
|
break;
|
|
231
264
|
case 'help':
|
|
@@ -238,6 +271,6 @@ export const runCli = async (arguments_: string[]): Promise<void> => {
|
|
|
238
271
|
}
|
|
239
272
|
} catch (error) {
|
|
240
273
|
console.error(error instanceof Error ? error.message : 'Runner failed');
|
|
241
|
-
|
|
274
|
+
process.exitCode = 1;
|
|
242
275
|
}
|
|
243
276
|
};
|
package/ts/config.ts
CHANGED
|
@@ -1,16 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { parseCidr } from './egress-proxy.js';
|
|
3
|
+
import { ConfigurationError } from './errors.js';
|
|
4
|
+
import {
|
|
5
|
+
createNewWriteFlags,
|
|
6
|
+
isNotFound,
|
|
7
|
+
removePath,
|
|
8
|
+
syncDirectory,
|
|
9
|
+
withOpenFile,
|
|
10
|
+
writeAll,
|
|
11
|
+
} from './filesystem.js';
|
|
12
|
+
import type { IOciExecutorConfig, IRunnerConfig, IRunnerCredential } from './interfaces.js';
|
|
13
|
+
import { isRecord, validateHttpUrl } from './validation.js';
|
|
14
|
+
|
|
15
|
+
const { dirname, isAbsolute, join } = plugins.path;
|
|
16
|
+
|
|
17
|
+
/** The host architecture label in the spelling of the runner's original default (`uname -m`). */
|
|
18
|
+
const hostArchitectureLabel = (): string => {
|
|
19
|
+
switch (process.arch) {
|
|
20
|
+
case 'x64':
|
|
21
|
+
return 'x86_64';
|
|
22
|
+
case 'arm64':
|
|
23
|
+
return 'aarch64';
|
|
24
|
+
default:
|
|
25
|
+
return process.arch;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
5
28
|
|
|
6
29
|
const identifierPattern = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
7
30
|
const timestampPattern =
|
|
8
31
|
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|[+-](\d{2}):(\d{2}))$/;
|
|
9
32
|
|
|
10
33
|
const defaultOciConfig: IOciExecutorConfig = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
34
|
+
runnerProfile: 'workload',
|
|
35
|
+
kernelPath: '/var/lib/ship-zone-runner/vmlinux',
|
|
36
|
+
bootArgs: 'console=ttyS0 reboot=k panic=1 pci=off rdinit=/init',
|
|
37
|
+
maximumRootfsBytes: 4 * 1024 * 1024 * 1024,
|
|
38
|
+
guestMemoryOverheadBytes: 128 * 1024 * 1024,
|
|
39
|
+
egressBlockedCidrs: [],
|
|
14
40
|
allowedNetworks: ['none'],
|
|
15
41
|
containerUser: '65532:65532',
|
|
16
42
|
defaultTimeoutMs: 30 * 60 * 1000,
|
|
@@ -31,8 +57,8 @@ const defaultOciConfig: IOciExecutorConfig = {
|
|
|
31
57
|
export const defaultRunnerConfig = (): IRunnerConfig => ({
|
|
32
58
|
controlPlaneUrl: '',
|
|
33
59
|
allowInsecureLoopback: false,
|
|
34
|
-
name: `runner-${
|
|
35
|
-
labels: ['linux',
|
|
60
|
+
name: `runner-${process.env.HOSTNAME ?? 'local'}`,
|
|
61
|
+
labels: ['linux', hostArchitectureLabel(), 'oci'],
|
|
36
62
|
stateDirectory: './.runner-state',
|
|
37
63
|
transferStagingReserveBytes: 1024 * 1024 * 1024,
|
|
38
64
|
transferStagingReserveInodes: 10_000,
|
|
@@ -160,28 +186,51 @@ const validTimestamp = (value: string): boolean => {
|
|
|
160
186
|
};
|
|
161
187
|
|
|
162
188
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* advertised.
|
|
189
|
+
* Network modes enforceable by the Firecracker microVM runner:
|
|
190
|
+
* - `none` (always required): isolated guest namespace with loopback only.
|
|
191
|
+
* - `egress` (opt-in): host-enforced DNS/SNI/Host allowlist proxy with non-global IP blocking.
|
|
167
192
|
*/
|
|
168
193
|
const requireEnforceableNetworks = (networks: readonly string[]): void => {
|
|
169
|
-
if (
|
|
194
|
+
if (
|
|
195
|
+
networks.length === 0 ||
|
|
196
|
+
!networks.includes('none') ||
|
|
197
|
+
networks.some((mode) => mode !== 'none' && mode !== 'egress')
|
|
198
|
+
) {
|
|
170
199
|
throw new ConfigurationError(
|
|
171
|
-
'oci.allowedNetworks must
|
|
200
|
+
'oci.allowedNetworks must include "none" and contain only "none" or "egress"',
|
|
172
201
|
);
|
|
173
202
|
}
|
|
174
203
|
};
|
|
175
204
|
|
|
205
|
+
const parseBlockedCidrs = (value: unknown, fallback: string[]): string[] => {
|
|
206
|
+
if (value === undefined) return [...fallback];
|
|
207
|
+
if (!Array.isArray(value) || value.length > 64 || value.some((entry) => typeof entry !== 'string')) {
|
|
208
|
+
throw new ConfigurationError('oci.egressBlockedCidrs must be an array of at most 64 CIDR strings');
|
|
209
|
+
}
|
|
210
|
+
for (const cidr of value) {
|
|
211
|
+
try {
|
|
212
|
+
parseCidr(cidr);
|
|
213
|
+
} catch {
|
|
214
|
+
throw new ConfigurationError(`oci.egressBlockedCidrs contains invalid CIDR: ${cidr}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return [...value];
|
|
218
|
+
};
|
|
219
|
+
|
|
176
220
|
const parseOciConfig = (input: unknown, fallback: IOciExecutorConfig): IOciExecutorConfig => {
|
|
177
221
|
const value = input === undefined ? {} : input;
|
|
178
222
|
if (!isRecord(value)) throw new ConfigurationError('oci must be an object');
|
|
179
223
|
if (Object.hasOwn(value, 'allowMutableImages')) {
|
|
180
224
|
throw new ConfigurationError('oci.allowMutableImages is not supported by the runner protocol');
|
|
181
225
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
226
|
+
if (Object.hasOwn(value, 'runtime') || Object.hasOwn(value, 'runtimePath')) {
|
|
227
|
+
throw new ConfigurationError(
|
|
228
|
+
'oci.runtime and oci.runtimePath were removed in 4.0.0; this runner uses Firecracker microVMs exclusively',
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
const runnerProfile = value.runnerProfile ?? fallback.runnerProfile;
|
|
232
|
+
if (runnerProfile !== 'workload' && runnerProfile !== 'builder') {
|
|
233
|
+
throw new ConfigurationError('oci.runnerProfile must be "workload" or "builder"');
|
|
185
234
|
}
|
|
186
235
|
const allowedNetworks = stringArray(
|
|
187
236
|
value.allowedNetworks,
|
|
@@ -191,14 +240,30 @@ const parseOciConfig = (input: unknown, fallback: IOciExecutorConfig): IOciExecu
|
|
|
191
240
|
);
|
|
192
241
|
requireEnforceableNetworks(allowedNetworks);
|
|
193
242
|
return {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
243
|
+
runnerProfile,
|
|
244
|
+
kernelPath: stringValue(value.kernelPath, fallback.kernelPath, 'oci.kernelPath'),
|
|
245
|
+
builderRootfsPath: optionalString(value.builderRootfsPath, 'oci.builderRootfsPath'),
|
|
246
|
+
buildctlPath: optionalString(value.buildctlPath, 'oci.buildctlPath'),
|
|
247
|
+
smartvmSocketPath: optionalString(value.smartvmSocketPath, 'oci.smartvmSocketPath'),
|
|
248
|
+
smartvmRuntimeDir: optionalString(value.smartvmRuntimeDir, 'oci.smartvmRuntimeDir'),
|
|
249
|
+
smartvmBridgePath: optionalString(value.smartvmBridgePath, 'oci.smartvmBridgePath'),
|
|
250
|
+
bootArgs: stringValue(value.bootArgs, fallback.bootArgs, 'oci.bootArgs', 1024),
|
|
251
|
+
maximumRootfsBytes: integerValue(
|
|
252
|
+
value.maximumRootfsBytes,
|
|
253
|
+
fallback.maximumRootfsBytes,
|
|
254
|
+
'oci.maximumRootfsBytes',
|
|
255
|
+
16_777_216,
|
|
256
|
+
1_099_511_627_776,
|
|
257
|
+
),
|
|
258
|
+
guestMemoryOverheadBytes: integerValue(
|
|
259
|
+
value.guestMemoryOverheadBytes,
|
|
260
|
+
fallback.guestMemoryOverheadBytes,
|
|
261
|
+
'oci.guestMemoryOverheadBytes',
|
|
262
|
+
16_777_216,
|
|
263
|
+
1_073_741_824,
|
|
201
264
|
),
|
|
265
|
+
egressBlockedCidrs: parseBlockedCidrs(value.egressBlockedCidrs, fallback.egressBlockedCidrs),
|
|
266
|
+
workspaceHelperPath: optionalString(value.workspaceHelperPath, 'oci.workspaceHelperPath'),
|
|
202
267
|
allowedNetworks: allowedNetworks as IOciExecutorConfig['allowedNetworks'],
|
|
203
268
|
containerUser: stringValue(value.containerUser, fallback.containerUser, 'oci.containerUser'),
|
|
204
269
|
defaultTimeoutMs: integerValue(
|
|
@@ -605,16 +670,46 @@ export const validateRunnerConfig = (config: IRunnerConfig): void => {
|
|
|
605
670
|
}
|
|
606
671
|
numberValue(config.oci.defaultCpus, config.oci.defaultCpus, 'oci.defaultCpus', 0, 1024);
|
|
607
672
|
numberValue(config.oci.maximumCpus, config.oci.maximumCpus, 'oci.maximumCpus', 0, 1024);
|
|
608
|
-
if (config.oci.
|
|
609
|
-
throw new ConfigurationError('oci.
|
|
673
|
+
if (config.oci.runnerProfile !== 'workload' && config.oci.runnerProfile !== 'builder') {
|
|
674
|
+
throw new ConfigurationError('oci.runnerProfile must be "workload" or "builder"');
|
|
610
675
|
}
|
|
611
676
|
requireEnforceableNetworks(config.oci.allowedNetworks);
|
|
612
|
-
|
|
613
|
-
|
|
677
|
+
parseBlockedCidrs(config.oci.egressBlockedCidrs, []);
|
|
678
|
+
if (!isAbsolute(config.oci.kernelPath)) {
|
|
679
|
+
throw new ConfigurationError('oci.kernelPath must be absolute');
|
|
680
|
+
}
|
|
681
|
+
if (config.oci.builderRootfsPath && !isAbsolute(config.oci.builderRootfsPath)) {
|
|
682
|
+
throw new ConfigurationError('oci.builderRootfsPath must be absolute');
|
|
683
|
+
}
|
|
684
|
+
if (config.oci.buildctlPath && !isAbsolute(config.oci.buildctlPath)) {
|
|
685
|
+
throw new ConfigurationError('oci.buildctlPath must be absolute');
|
|
686
|
+
}
|
|
687
|
+
if (config.oci.smartvmSocketPath && !isAbsolute(config.oci.smartvmSocketPath)) {
|
|
688
|
+
throw new ConfigurationError('oci.smartvmSocketPath must be absolute');
|
|
689
|
+
}
|
|
690
|
+
if (config.oci.smartvmRuntimeDir && !isAbsolute(config.oci.smartvmRuntimeDir)) {
|
|
691
|
+
throw new ConfigurationError('oci.smartvmRuntimeDir must be absolute');
|
|
692
|
+
}
|
|
693
|
+
if (config.oci.smartvmBridgePath && !isAbsolute(config.oci.smartvmBridgePath)) {
|
|
694
|
+
throw new ConfigurationError('oci.smartvmBridgePath must be absolute');
|
|
614
695
|
}
|
|
615
696
|
if (config.oci.workspaceHelperPath && !isAbsolute(config.oci.workspaceHelperPath)) {
|
|
616
697
|
throw new ConfigurationError('oci.workspaceHelperPath must be absolute');
|
|
617
698
|
}
|
|
699
|
+
integerValue(
|
|
700
|
+
config.oci.maximumRootfsBytes,
|
|
701
|
+
config.oci.maximumRootfsBytes,
|
|
702
|
+
'oci.maximumRootfsBytes',
|
|
703
|
+
16_777_216,
|
|
704
|
+
1_099_511_627_776,
|
|
705
|
+
);
|
|
706
|
+
integerValue(
|
|
707
|
+
config.oci.guestMemoryOverheadBytes,
|
|
708
|
+
config.oci.guestMemoryOverheadBytes,
|
|
709
|
+
'oci.guestMemoryOverheadBytes',
|
|
710
|
+
16_777_216,
|
|
711
|
+
1_073_741_824,
|
|
712
|
+
);
|
|
618
713
|
const user = /^([1-9][0-9]*)(?::([1-9][0-9]*))?$/.exec(config.oci.containerUser);
|
|
619
714
|
if (!user || [user[1], user[2] ?? user[1]].some((entry) => Number(entry) > 4_294_967_294)) {
|
|
620
715
|
throw new ConfigurationError('oci.containerUser must be a numeric non-root UID[:GID]');
|
|
@@ -673,10 +768,10 @@ const applyEnvironment = (value: Record<string, unknown>): Record<string, unknow
|
|
|
673
768
|
['SHIP_RUNNER_STATE_DIRECTORY', 'stateDirectory'],
|
|
674
769
|
];
|
|
675
770
|
for (const [environmentName, field] of mappings) {
|
|
676
|
-
const environmentValue =
|
|
771
|
+
const environmentValue = process.env[environmentName];
|
|
677
772
|
if (environmentValue) result[field] = environmentValue;
|
|
678
773
|
}
|
|
679
|
-
const labels =
|
|
774
|
+
const labels = process.env.SHIP_RUNNER_LABELS;
|
|
680
775
|
if (labels) result.labels = labels.split(',').map((entry) => entry.trim()).filter(Boolean);
|
|
681
776
|
return result;
|
|
682
777
|
};
|
|
@@ -684,11 +779,11 @@ const applyEnvironment = (value: Record<string, unknown>): Record<string, unknow
|
|
|
684
779
|
export const loadRunnerConfig = async (path: string): Promise<IRunnerConfig> => {
|
|
685
780
|
let input: Record<string, unknown> = {};
|
|
686
781
|
try {
|
|
687
|
-
const parsed: unknown = JSON.parse(await
|
|
782
|
+
const parsed: unknown = JSON.parse(await plugins.fs.readFile(path, 'utf8'));
|
|
688
783
|
if (!isRecord(parsed)) throw new ConfigurationError('Runner config must be a JSON object');
|
|
689
784
|
input = parsed;
|
|
690
785
|
} catch (error) {
|
|
691
|
-
if (!(error
|
|
786
|
+
if (!isNotFound(error)) throw error;
|
|
692
787
|
}
|
|
693
788
|
return parseRunnerConfig(applyEnvironment(input));
|
|
694
789
|
};
|
|
@@ -696,40 +791,29 @@ export const loadRunnerConfig = async (path: string): Promise<IRunnerConfig> =>
|
|
|
696
791
|
export const saveRunnerConfig = async (path: string, config: IRunnerConfig): Promise<void> => {
|
|
697
792
|
validateRunnerConfig(config);
|
|
698
793
|
const parent = dirname(path);
|
|
699
|
-
await
|
|
700
|
-
const temporaryPath = join(parent, `.${crypto.randomUUID()}.runner-config.tmp`);
|
|
794
|
+
await plugins.fs.mkdir(parent, { recursive: true, mode: 0o700 });
|
|
795
|
+
const temporaryPath = join(parent, `.${plugins.crypto.randomUUID()}.runner-config.tmp`);
|
|
701
796
|
const bytes = new TextEncoder().encode(`${JSON.stringify(config, null, 2)}\n`);
|
|
702
|
-
let file: Deno.FsFile | undefined;
|
|
703
797
|
try {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
await
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
await Deno.chmod(temporaryPath, 0o600);
|
|
719
|
-
await Deno.rename(temporaryPath, path);
|
|
720
|
-
await Deno.chmod(path, 0o600);
|
|
721
|
-
const directory = await Deno.open(parent, { read: true });
|
|
722
|
-
try {
|
|
723
|
-
await directory.sync();
|
|
724
|
-
} finally {
|
|
725
|
-
directory.close();
|
|
726
|
-
}
|
|
798
|
+
await withOpenFile(
|
|
799
|
+
temporaryPath,
|
|
800
|
+
createNewWriteFlags,
|
|
801
|
+
0o600,
|
|
802
|
+
async (file) => {
|
|
803
|
+
await writeAll(file, bytes, 'Runner config write made no progress');
|
|
804
|
+
await file.sync();
|
|
805
|
+
},
|
|
806
|
+
'Runner config write and close failed',
|
|
807
|
+
);
|
|
808
|
+
await plugins.fs.chmod(temporaryPath, 0o600);
|
|
809
|
+
await plugins.fs.rename(temporaryPath, path);
|
|
810
|
+
await plugins.fs.chmod(path, 0o600);
|
|
811
|
+
await syncDirectory(parent, 'Runner config directory sync and close failed');
|
|
727
812
|
} catch (error) {
|
|
728
|
-
file?.close();
|
|
729
813
|
try {
|
|
730
|
-
await
|
|
814
|
+
await removePath(temporaryPath);
|
|
731
815
|
} catch (cleanupError) {
|
|
732
|
-
if (!(cleanupError
|
|
816
|
+
if (!isNotFound(cleanupError)) {
|
|
733
817
|
throw new AggregateError([error, cleanupError], 'Config write and cleanup failed');
|
|
734
818
|
}
|
|
735
819
|
}
|