@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.
Files changed (200) hide show
  1. package/.smartconfig.json +118 -3
  2. package/changelog.md +101 -0
  3. package/dist_rust/runnerworkspace_linux_amd64_musl +0 -0
  4. package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.json +679 -0
  5. package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.txt +15719 -0
  6. package/dist_rust/runnerworkspace_linux_amd64_musl.tsrust-build.json +5 -5
  7. package/dist_rust/runnerworkspace_linux_arm64_musl +0 -0
  8. package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.json +679 -0
  9. package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.txt +15719 -0
  10. package/dist_rust/runnerworkspace_linux_arm64_musl.tsrust-build.json +5 -5
  11. package/dist_ts/00_commitinfo_data.d.ts +8 -0
  12. package/dist_ts/00_commitinfo_data.js +9 -0
  13. package/dist_ts/api-client.d.ts +47 -0
  14. package/dist_ts/api-client.js +600 -0
  15. package/dist_ts/artifact-manager.d.ts +11 -0
  16. package/dist_ts/artifact-manager.js +140 -0
  17. package/dist_ts/attempt-state.d.ts +18 -0
  18. package/dist_ts/attempt-state.js +151 -0
  19. package/dist_ts/cache-manager.d.ts +13 -0
  20. package/dist_ts/cache-manager.js +300 -0
  21. package/dist_ts/cli-entry.d.ts +2 -0
  22. package/dist_ts/cli-entry.js +18 -0
  23. package/dist_ts/cli.d.ts +14 -0
  24. package/dist_ts/cli.js +243 -0
  25. package/dist_ts/config.d.ts +8 -0
  26. package/dist_ts/config.js +495 -0
  27. package/dist_ts/egress-proxy.d.ts +99 -0
  28. package/dist_ts/egress-proxy.js +607 -0
  29. package/dist_ts/errors.d.ts +41 -0
  30. package/dist_ts/errors.js +90 -0
  31. package/dist_ts/filesystem.d.ts +73 -0
  32. package/dist_ts/filesystem.js +207 -0
  33. package/dist_ts/index.d.ts +20 -0
  34. package/dist_ts/index.js +21 -0
  35. package/dist_ts/interfaces.d.ts +685 -0
  36. package/dist_ts/interfaces.js +3 -0
  37. package/dist_ts/log-sender.d.ts +26 -0
  38. package/dist_ts/log-sender.js +124 -0
  39. package/dist_ts/microvm-executor.d.ts +90 -0
  40. package/dist_ts/microvm-executor.js +1045 -0
  41. package/dist_ts/node-version.d.ts +11 -0
  42. package/dist_ts/node-version.js +43 -0
  43. package/dist_ts/npm-grants.d.ts +9 -0
  44. package/dist_ts/npm-grants.js +44 -0
  45. package/dist_ts/oci-registry.d.ts +73 -0
  46. package/dist_ts/oci-registry.js +508 -0
  47. package/dist_ts/plugins.d.ts +23 -0
  48. package/dist_ts/plugins.js +27 -0
  49. package/dist_ts/protocol-validator.d.ts +39 -0
  50. package/dist_ts/protocol-validator.js +488 -0
  51. package/dist_ts/redactor.d.ts +78 -0
  52. package/dist_ts/redactor.js +235 -0
  53. package/dist_ts/registration-state.d.ts +16 -0
  54. package/dist_ts/registration-state.js +171 -0
  55. package/dist_ts/runner.d.ts +65 -0
  56. package/dist_ts/runner.js +912 -0
  57. package/dist_ts/source-workspace.d.ts +10 -0
  58. package/dist_ts/source-workspace.js +125 -0
  59. package/dist_ts/spec-version.d.ts +11 -0
  60. package/dist_ts/spec-version.js +41 -0
  61. package/dist_ts/staging-scavenger.d.ts +7 -0
  62. package/dist_ts/staging-scavenger.js +63 -0
  63. package/dist_ts/state-owner.d.ts +74 -0
  64. package/dist_ts/state-owner.js +291 -0
  65. package/dist_ts/transfer-archive.d.ts +78 -0
  66. package/dist_ts/transfer-archive.js +1619 -0
  67. package/dist_ts/validation.d.ts +11 -0
  68. package/dist_ts/validation.js +79 -0
  69. package/dist_ts/vsock-protocol.d.ts +130 -0
  70. package/dist_ts/vsock-protocol.js +336 -0
  71. package/dist_ts/wire-schema.d.ts +10 -0
  72. package/dist_ts/wire-schema.js +114 -0
  73. package/native-notices/crates/bitflags-2.13.1/license-apache +201 -0
  74. package/native-notices/crates/bitflags-2.13.1/license-mit +25 -0
  75. package/native-notices/crates/cc-1.8.0/license-apache +201 -0
  76. package/native-notices/crates/cc-1.8.0/license-mit +25 -0
  77. package/native-notices/crates/cfg-if-1.0.4/license-apache +201 -0
  78. package/native-notices/crates/cfg-if-1.0.4/license-mit +25 -0
  79. package/native-notices/crates/cfg_aliases-0.2.2/license +9 -0
  80. package/native-notices/crates/cfg_aliases-0.2.2/notices.md +26 -0
  81. package/native-notices/crates/find-msvc-tools-0.1.14/license-apache +201 -0
  82. package/native-notices/crates/find-msvc-tools-0.1.14/license-mit +25 -0
  83. package/native-notices/crates/itoa-1.0.18/license-apache +176 -0
  84. package/native-notices/crates/itoa-1.0.18/license-mit +23 -0
  85. package/native-notices/crates/libc-0.2.189/license-apache +176 -0
  86. package/native-notices/crates/libc-0.2.189/license-mit +25 -0
  87. package/native-notices/crates/memchr-2.8.3/copying +3 -0
  88. package/native-notices/crates/memchr-2.8.3/license-mit +21 -0
  89. package/native-notices/crates/memchr-2.8.3/unlicense +24 -0
  90. package/native-notices/crates/nix-0.30.1/license +21 -0
  91. package/native-notices/crates/proc-macro2-1.0.107/license-apache +176 -0
  92. package/native-notices/crates/proc-macro2-1.0.107/license-mit +23 -0
  93. package/native-notices/crates/quote-1.0.47/license-apache +176 -0
  94. package/native-notices/crates/quote-1.0.47/license-mit +23 -0
  95. package/native-notices/crates/serde-1.0.229/license-apache +176 -0
  96. package/native-notices/crates/serde-1.0.229/license-mit +23 -0
  97. package/native-notices/crates/serde_core-1.0.229/license-apache +176 -0
  98. package/native-notices/crates/serde_core-1.0.229/license-mit +23 -0
  99. package/native-notices/crates/serde_derive-1.0.229/license-apache +176 -0
  100. package/native-notices/crates/serde_derive-1.0.229/license-mit +23 -0
  101. package/native-notices/crates/serde_json-1.0.151/license-apache +176 -0
  102. package/native-notices/crates/serde_json-1.0.151/license-mit +23 -0
  103. package/native-notices/crates/shlex-2.0.1/license-apache +13 -0
  104. package/native-notices/crates/shlex-2.0.1/license-mit +21 -0
  105. package/native-notices/crates/syn-3.0.3/license-apache +176 -0
  106. package/native-notices/crates/syn-3.0.3/license-mit +23 -0
  107. package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-apache +201 -0
  108. package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-mit +25 -0
  109. package/native-notices/crates/tikv-jemallocator-0.7.0/license-apache +201 -0
  110. package/native-notices/crates/tikv-jemallocator-0.7.0/license-mit +25 -0
  111. package/native-notices/crates/unicode-ident-1.0.24/license-apache +176 -0
  112. package/native-notices/crates/unicode-ident-1.0.24/license-mit +23 -0
  113. package/native-notices/crates/unicode-ident-1.0.24/license-unicode +39 -0
  114. package/native-notices/crates/zmij-1.0.23/license-mit +23 -0
  115. package/native-notices/manifest.json +763 -0
  116. package/native-notices/native/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/jemalloc-5.3.1/jemalloc-copying +27 -0
  117. package/native-notices/readme.md +46 -0
  118. package/native-notices/runtime/gcc/gpl-3.0.txt +674 -0
  119. package/native-notices/runtime/gcc/runtime-library-exception-3.1.txt +73 -0
  120. package/native-notices/runtime/libunwind-22.1.2/license.txt +311 -0
  121. package/native-notices/runtime/musl-1.2.5/copyright +193 -0
  122. package/native-notices/rust/compiler-builtins-license.txt +275 -0
  123. package/native-notices/rust/copyright-library.html +8266 -0
  124. package/native-notices/rust/crates/addr2line-0.25.1/license-apache +201 -0
  125. package/native-notices/rust/crates/addr2line-0.25.1/license-mit +25 -0
  126. package/native-notices/rust/crates/adler2-2.0.1/license-0bsd +12 -0
  127. package/native-notices/rust/crates/adler2-2.0.1/license-apache +201 -0
  128. package/native-notices/rust/crates/adler2-2.0.1/license-mit +23 -0
  129. package/native-notices/rust/crates/memchr-2.7.6/copying +3 -0
  130. package/native-notices/rust/crates/memchr-2.7.6/license-mit +21 -0
  131. package/native-notices/rust/crates/memchr-2.7.6/unlicense +24 -0
  132. package/native-notices/rust/crates/miniz_oxide-0.8.9/license +25 -0
  133. package/native-notices/rust/crates/miniz_oxide-0.8.9/license-apache.md +177 -0
  134. package/native-notices/rust/crates/miniz_oxide-0.8.9/license-mit.md +24 -0
  135. package/native-notices/rust/crates/miniz_oxide-0.8.9/license-zlib.md +14 -0
  136. package/native-notices/rust/crates/object-0.37.3/license-apache +201 -0
  137. package/native-notices/rust/crates/object-0.37.3/license-mit +25 -0
  138. package/native-notices/rust/licenses/apache-2.0.txt +73 -0
  139. package/native-notices/rust/licenses/bsd-2-clause.txt +9 -0
  140. package/native-notices/rust/licenses/cc-by-sa-4.0.txt +427 -0
  141. package/native-notices/rust/licenses/gcc-exception-3.1.txt +30 -0
  142. package/native-notices/rust/licenses/gpl-2.0-only.txt +133 -0
  143. package/native-notices/rust/licenses/gpl-3.0-or-later.txt +202 -0
  144. package/native-notices/rust/licenses/isc.txt +7 -0
  145. package/native-notices/rust/licenses/llvm-exception.txt +15 -0
  146. package/native-notices/rust/licenses/mit.txt +9 -0
  147. package/native-notices/rust/licenses/ncsa.txt +29 -0
  148. package/native-notices/rust/licenses/ofl-1.1.txt +43 -0
  149. package/native-notices/rust/licenses/unicode-3.0.txt +39 -0
  150. package/package.json +31 -26
  151. package/readme.md +157 -95
  152. package/rust/.cargo/config.toml +1 -1
  153. package/rust/Cargo.lock +1 -0
  154. package/rust/Cargo.toml +3 -2
  155. package/rust/src/cpio.rs +147 -0
  156. package/rust/src/extfs.rs +747 -0
  157. package/rust/src/guest.rs +2411 -0
  158. package/rust/src/lib.rs +197 -1
  159. package/rust/src/main.rs +7 -2
  160. package/rust/src/oci_tar.rs +842 -0
  161. package/rust-toolchain.toml +4 -0
  162. package/ts/00_commitinfo_data.ts +2 -2
  163. package/ts/api-client.ts +29 -8
  164. package/ts/artifact-manager.ts +9 -7
  165. package/ts/attempt-state.ts +75 -84
  166. package/ts/cache-manager.ts +22 -28
  167. package/ts/cli-entry.ts +17 -0
  168. package/ts/cli.ts +86 -53
  169. package/ts/config.ts +146 -62
  170. package/ts/egress-proxy.ts +649 -0
  171. package/ts/errors.ts +19 -0
  172. package/ts/filesystem.ts +316 -0
  173. package/ts/index.ts +20 -15
  174. package/ts/interfaces.ts +105 -23
  175. package/ts/log-sender.ts +4 -4
  176. package/ts/microvm-executor.ts +1265 -0
  177. package/ts/node-version.ts +49 -0
  178. package/ts/npm-grants.ts +49 -0
  179. package/ts/oci-registry.ts +649 -0
  180. package/ts/plugins.ts +25 -3
  181. package/ts/protocol-validator.ts +34 -30
  182. package/ts/redactor.ts +2 -2
  183. package/ts/registration-state.ts +82 -90
  184. package/ts/runner.ts +81 -34
  185. package/ts/source-workspace.ts +11 -8
  186. package/ts/spec-version.ts +2 -2
  187. package/ts/staging-scavenger.ts +37 -26
  188. package/ts/state-owner.ts +353 -0
  189. package/ts/transfer-archive.ts +214 -243
  190. package/ts/validation.ts +1 -1
  191. package/ts/vsock-protocol.ts +437 -0
  192. package/ts/wire-schema.ts +3 -3
  193. package/deno.json +0 -56
  194. package/deno.lock +0 -1495
  195. package/dist_npm/mod.d.ts +0 -967
  196. package/dist_npm/mod.js +0 -10058
  197. package/mod.ts +0 -8
  198. package/musl-copyright.md +0 -81
  199. package/third-party-licenses.md +0 -187
  200. package/ts/oci-executor.ts +0 -3137
package/ts/cli.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { RunnerApiClient } from './api-client.ts';
2
- import { ArtifactManager } from './artifact-manager.ts';
3
- import { CacheManager } from './cache-manager.ts';
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.ts';
12
- import { ConfigurationError } from './errors.ts';
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.ts';
19
- import { runnerVersion } from './interfaces.ts';
20
- import { OciExecutor } from './oci-executor.ts';
21
- import { RegistrationStateStore } from './registration-state.ts';
22
- import { reconcileProtocolLimits, runnerCapabilities, ShipRunner } from './runner.ts';
23
- import { runnerSpecVersion } from './spec-version.ts';
24
- import { SourceWorkspaceManager } from './source-workspace.ts';
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 = 'deno run --allow-all npm:@ship.zone/runner';
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') ?? Deno.env.get('SHIP_RUNNER_CONFIG') ?? './runner.config.json';
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?: RegistrationStateStore;
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 runtimePath = stringOption(options, 'runtime-path');
129
- if (runtimePath) config.oci.runtimePath = runtimePath;
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
- throw new ConfigurationError(
135
- '--allow-network is not supported: this runner does not enforce egress allowlists',
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 api = apiFor(config);
151
- const executor = new OciExecutor(config);
152
- const runtime = await executor.verifyRuntime();
153
- const discovery = await api.discover();
154
- const capabilities = runnerCapabilities(config, runtime);
155
- reconcileProtocolLimits(config, discovery, capabilities);
156
- const registered = await registerRunnerDurably({
157
- configPath: path,
158
- config,
159
- capabilities,
160
- api,
161
- });
162
- console.log(`Registered runner ${registered.runnerId}`);
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 api = apiFor(config);
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 installedSignals: Array<'SIGINT' | 'SIGTERM'> = [];
177
- for (const signal of ['SIGINT', 'SIGTERM'] as const) {
178
- try {
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 installedSignals) Deno.removeSignalListener(signal, shutdownListener);
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
- Deno.exitCode = 1;
274
+ process.exitCode = 1;
242
275
  }
243
276
  };
package/ts/config.ts CHANGED
@@ -1,16 +1,42 @@
1
- import { dirname, isAbsolute, join } from '@std/path';
2
- import { ConfigurationError } from './errors.ts';
3
- import type { IOciExecutorConfig, IRunnerConfig, IRunnerCredential } from './interfaces.ts';
4
- import { isRecord, validateHttpUrl } from './validation.ts';
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
- runtime: 'docker',
12
- runtimePath: '/usr/bin/docker',
13
- requireRootless: true,
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-${Deno.env.get('HOSTNAME') ?? 'local'}`,
35
- labels: ['linux', Deno.build.arch, 'oci'],
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
- * The OCI executor enforces only the `none` network mode: every step container gets a new network
164
- * namespace with loopback only. `egress` needs a runner-provided resolver and per-attempt
165
- * connection filtering that this executor does not implement, so it can be neither configured nor
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 (networks.length !== 1 || networks[0] !== 'none') {
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 be ["none"]: this runner does not enforce egress allowlists',
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
- const runtime = value.runtime ?? fallback.runtime;
183
- if (runtime !== 'docker' && runtime !== 'podman') {
184
- throw new ConfigurationError('oci.runtime must be docker or podman');
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
- runtime,
195
- runtimePath: stringValue(value.runtimePath, fallback.runtimePath, 'oci.runtimePath'),
196
- workspaceHelperPath: optionalString(value.workspaceHelperPath, 'oci.workspaceHelperPath'),
197
- requireRootless: booleanValue(
198
- value.requireRootless,
199
- fallback.requireRootless,
200
- 'oci.requireRootless',
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.runtime !== 'docker' && config.oci.runtime !== 'podman') {
609
- throw new ConfigurationError('oci.runtime must be docker or podman');
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
- if (!isAbsolute(config.oci.runtimePath)) {
613
- throw new ConfigurationError('oci.runtimePath must be absolute');
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 = Deno.env.get(environmentName);
771
+ const environmentValue = process.env[environmentName];
677
772
  if (environmentValue) result[field] = environmentValue;
678
773
  }
679
- const labels = Deno.env.get('SHIP_RUNNER_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 Deno.readTextFile(path));
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 instanceof Deno.errors.NotFound)) throw 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 Deno.mkdir(parent, { recursive: true, mode: 0o700 });
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
- file = await Deno.open(temporaryPath, {
705
- write: true,
706
- createNew: true,
707
- mode: 0o600,
708
- });
709
- let offset = 0;
710
- while (offset < bytes.byteLength) {
711
- const written = await file.write(bytes.subarray(offset));
712
- if (written <= 0) throw new ConfigurationError('Runner config write made no progress');
713
- offset += written;
714
- }
715
- await file.sync();
716
- file.close();
717
- file = undefined;
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 Deno.remove(temporaryPath);
814
+ await removePath(temporaryPath);
731
815
  } catch (cleanupError) {
732
- if (!(cleanupError instanceof Deno.errors.NotFound)) {
816
+ if (!isNotFound(cleanupError)) {
733
817
  throw new AggregateError([error, cleanupError], 'Config write and cleanup failed');
734
818
  }
735
819
  }