@ship.zone/runner 4.0.0 → 5.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/changelog.md +18 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl.tsrust-build.json +3 -3
- package/dist_rust/runnerworkspace_linux_arm64_musl.tsrust-build.json +3 -3
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/cli-entry.js +0 -0
- package/dist_ts/cli.d.ts +7 -0
- package/dist_ts/cli.js +140 -48
- package/dist_ts/config.js +20 -17
- package/dist_ts/interfaces.d.ts +7 -24
- package/dist_ts/microvm-executor.js +58 -25
- package/dist_ts/protocol-validator.d.ts +3 -5
- package/dist_ts/protocol-validator.js +7 -36
- package/dist_ts/runner.d.ts +3 -4
- package/dist_ts/runner.js +9 -14
- package/package.json +11 -10
- package/readme.md +64 -77
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/cli.ts +162 -52
- package/ts/config.ts +20 -18
- package/ts/interfaces.ts +9 -24
- package/ts/microvm-executor.ts +73 -28
- package/ts/protocol-validator.ts +6 -39
- package/ts/runner.ts +6 -13
package/ts/cli.ts
CHANGED
|
@@ -26,15 +26,35 @@ import { RunnerStateOwner } from './state-owner.js';
|
|
|
26
26
|
|
|
27
27
|
interface IParsedArguments {
|
|
28
28
|
command: string;
|
|
29
|
-
options: Map<string, string
|
|
29
|
+
options: Map<string, string[]>;
|
|
30
|
+
flags: Set<string>;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
const cliInvocation = 'ship-zone-runner';
|
|
33
34
|
|
|
34
|
-
const
|
|
35
|
+
const BOOLEAN_FLAGS = new Set<string>(['allow-insecure-loopback']);
|
|
36
|
+
const VALUE_OPTIONS = new Set<string>([
|
|
37
|
+
'config',
|
|
38
|
+
'control-plane',
|
|
39
|
+
'name',
|
|
40
|
+
'labels',
|
|
41
|
+
'state-directory',
|
|
42
|
+
'kernel-path',
|
|
43
|
+
'builder-rootfs-path',
|
|
44
|
+
'builder-image',
|
|
45
|
+
'buildctl-path',
|
|
46
|
+
'smartvm-socket',
|
|
47
|
+
'smartvm-runtime-dir',
|
|
48
|
+
'smartvm-bridge-path',
|
|
49
|
+
'workspace-helper-path',
|
|
50
|
+
'egress-blocked-cidr',
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
const usage = `ship.zone runner ${runnerVersion} (Firecracker microVM · ci-spec ${runnerSpecVersion})
|
|
35
54
|
|
|
36
55
|
Usage:
|
|
37
|
-
${cliInvocation}
|
|
56
|
+
${cliInvocation} enroll --control-plane <url> [--config <path>] [--name <name>] [--labels <a,b>] [--kernel-path <path>] [--builder-rootfs-path <path> | --builder-image <ref@sha256:...>] [--smartvm-socket <path>]
|
|
57
|
+
${cliInvocation} init --control-plane <url> [--config <path>] [--name <name>] [--labels <a,b>] [--kernel-path <path>] [--builder-rootfs-path <path> | --builder-image <ref@sha256:...>] [--smartvm-socket <path>]
|
|
38
58
|
${cliInvocation} register [--config <path>]
|
|
39
59
|
${cliInvocation} run [--config <path>]
|
|
40
60
|
${cliInvocation} once [--config <path>]
|
|
@@ -45,36 +65,88 @@ Bootstrap credentials must be supplied through SHIP_RUNNER_BOOTSTRAP_TOKEN or th
|
|
|
45
65
|
0600 config file. Secret values are intentionally not accepted as command arguments.
|
|
46
66
|
`;
|
|
47
67
|
|
|
48
|
-
const parseArguments = (arguments_: string[]): IParsedArguments => {
|
|
68
|
+
export const parseArguments = (arguments_: string[]): IParsedArguments => {
|
|
49
69
|
const normalizedArguments = arguments_[0] === '--' ? arguments_.slice(1) : arguments_;
|
|
50
70
|
const [command = 'help', ...rest] = normalizedArguments;
|
|
51
|
-
const options = new Map<string, string
|
|
71
|
+
const options = new Map<string, string[]>();
|
|
72
|
+
const flags = new Set<string>();
|
|
73
|
+
|
|
52
74
|
for (let index = 0; index < rest.length; index++) {
|
|
53
75
|
const entry = rest[index];
|
|
54
76
|
if (!entry.startsWith('--')) throw new ConfigurationError(`Unexpected argument: ${entry}`);
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
77
|
+
const eqIndex = entry.indexOf('=');
|
|
78
|
+
const name = eqIndex >= 0 ? entry.slice(2, eqIndex) : entry.slice(2);
|
|
79
|
+
const inlineValue = eqIndex >= 0 ? entry.slice(eqIndex + 1) : undefined;
|
|
80
|
+
|
|
81
|
+
if (BOOLEAN_FLAGS.has(name)) {
|
|
82
|
+
if (inlineValue !== undefined) {
|
|
83
|
+
throw new ConfigurationError(`--${name} does not accept a value`);
|
|
84
|
+
}
|
|
85
|
+
flags.add(name);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!VALUE_OPTIONS.has(name)) {
|
|
90
|
+
if (name === 'profile') {
|
|
91
|
+
throw new ConfigurationError(
|
|
92
|
+
'--profile was removed in 5.0.0; one unified microVM runner executes oci, vm, and oci-image jobs',
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (name === 'allow-egress' || name === 'allow-network') {
|
|
96
|
+
throw new ConfigurationError(
|
|
97
|
+
`--${name} is not supported yet; Firecracker guest egress transport is not wired`,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
throw new ConfigurationError(`Unknown option: --${name}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let value: string | undefined;
|
|
104
|
+
if (inlineValue !== undefined) {
|
|
105
|
+
value = inlineValue;
|
|
106
|
+
} else {
|
|
107
|
+
const next = rest[index + 1];
|
|
108
|
+
if (!next || next.startsWith('--')) {
|
|
109
|
+
throw new ConfigurationError(`--${name} requires a value`);
|
|
110
|
+
}
|
|
111
|
+
value = next;
|
|
60
112
|
index++;
|
|
61
113
|
}
|
|
114
|
+
if (value.length === 0) {
|
|
115
|
+
throw new ConfigurationError(`--${name} requires a non-empty value`);
|
|
116
|
+
}
|
|
117
|
+
const existing = options.get(name);
|
|
118
|
+
if (existing) existing.push(value);
|
|
119
|
+
else options.set(name, [value]);
|
|
62
120
|
}
|
|
63
|
-
return { command, options };
|
|
121
|
+
return { command, options, flags };
|
|
64
122
|
};
|
|
65
123
|
|
|
66
|
-
const
|
|
67
|
-
options: Map<string, string
|
|
124
|
+
const singleOption = (
|
|
125
|
+
options: Map<string, string[]>,
|
|
68
126
|
name: string,
|
|
69
127
|
): string | undefined => {
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
if (
|
|
73
|
-
|
|
128
|
+
const values = options.get(name);
|
|
129
|
+
if (!values || values.length === 0) return undefined;
|
|
130
|
+
if (values.length > 1) {
|
|
131
|
+
throw new ConfigurationError(`--${name} may only be specified once`);
|
|
132
|
+
}
|
|
133
|
+
return values[0];
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const listOption = (
|
|
137
|
+
options: Map<string, string[]>,
|
|
138
|
+
name: string,
|
|
139
|
+
): string[] | undefined => {
|
|
140
|
+
const values = options.get(name);
|
|
141
|
+
if (!values || values.length === 0) return undefined;
|
|
142
|
+
return values
|
|
143
|
+
.flatMap((entry) => entry.split(','))
|
|
144
|
+
.map((entry) => entry.trim())
|
|
145
|
+
.filter(Boolean);
|
|
74
146
|
};
|
|
75
147
|
|
|
76
|
-
const configPath = (options: Map<string, string
|
|
77
|
-
|
|
148
|
+
const configPath = (options: Map<string, string[]>): string =>
|
|
149
|
+
singleOption(options, 'config') ?? process.env.SHIP_RUNNER_CONFIG ?? './runner.config.json';
|
|
78
150
|
|
|
79
151
|
const apiFor = (config: IRunnerConfig): RunnerApiClient =>
|
|
80
152
|
new RunnerApiClient({
|
|
@@ -119,49 +191,84 @@ export const registerRunnerDurably = async (options: {
|
|
|
119
191
|
return registered;
|
|
120
192
|
};
|
|
121
193
|
|
|
122
|
-
const
|
|
194
|
+
const buildConfigFromOptions = (
|
|
195
|
+
options: Map<string, string[]>,
|
|
196
|
+
flags: Set<string>,
|
|
197
|
+
): IRunnerConfig => {
|
|
123
198
|
const config = defaultRunnerConfig();
|
|
124
|
-
config.controlPlaneUrl =
|
|
125
|
-
config.name =
|
|
126
|
-
const
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
config.oci.runnerProfile = profile;
|
|
132
|
-
}
|
|
133
|
-
const labels = stringOption(options, 'labels');
|
|
134
|
-
if (labels) config.labels = labels.split(',').map((entry) => entry.trim()).filter(Boolean);
|
|
135
|
-
const kernelPath = stringOption(options, 'kernel-path');
|
|
199
|
+
config.controlPlaneUrl = singleOption(options, 'control-plane') ?? '';
|
|
200
|
+
config.name = singleOption(options, 'name') ?? config.name;
|
|
201
|
+
const stateDirectory = singleOption(options, 'state-directory');
|
|
202
|
+
if (stateDirectory) config.stateDirectory = stateDirectory;
|
|
203
|
+
const labels = listOption(options, 'labels');
|
|
204
|
+
if (labels) config.labels = labels;
|
|
205
|
+
const kernelPath = singleOption(options, 'kernel-path');
|
|
136
206
|
if (kernelPath) config.oci.kernelPath = kernelPath;
|
|
137
|
-
const builderRootfsPath =
|
|
207
|
+
const builderRootfsPath = singleOption(options, 'builder-rootfs-path');
|
|
138
208
|
if (builderRootfsPath) config.oci.builderRootfsPath = builderRootfsPath;
|
|
139
|
-
const
|
|
209
|
+
const builderImage = singleOption(options, 'builder-image');
|
|
210
|
+
if (builderImage) config.oci.builderImage = builderImage;
|
|
211
|
+
const buildctlPath = singleOption(options, 'buildctl-path');
|
|
212
|
+
if (buildctlPath) config.oci.buildctlPath = buildctlPath;
|
|
213
|
+
const smartvmSocket = singleOption(options, 'smartvm-socket');
|
|
140
214
|
if (smartvmSocket) config.oci.smartvmSocketPath = smartvmSocket;
|
|
141
|
-
const smartvmRuntimeDir =
|
|
215
|
+
const smartvmRuntimeDir = singleOption(options, 'smartvm-runtime-dir');
|
|
142
216
|
if (smartvmRuntimeDir) config.oci.smartvmRuntimeDir = smartvmRuntimeDir;
|
|
143
|
-
const smartvmBridgePath =
|
|
217
|
+
const smartvmBridgePath = singleOption(options, 'smartvm-bridge-path');
|
|
144
218
|
if (smartvmBridgePath) config.oci.smartvmBridgePath = smartvmBridgePath;
|
|
145
|
-
const helperPath =
|
|
219
|
+
const helperPath = singleOption(options, 'workspace-helper-path');
|
|
146
220
|
if (helperPath) config.oci.workspaceHelperPath = helperPath;
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
|
|
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);
|
|
157
|
-
}
|
|
221
|
+
if (flags.has('allow-insecure-loopback')) config.allowInsecureLoopback = true;
|
|
222
|
+
const blockedCidrs = listOption(options, 'egress-blocked-cidr');
|
|
223
|
+
if (blockedCidrs) config.oci.egressBlockedCidrs = blockedCidrs;
|
|
158
224
|
validateRunnerConfig(config);
|
|
225
|
+
return config;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const runInit = async (
|
|
229
|
+
options: Map<string, string[]>,
|
|
230
|
+
flags: Set<string>,
|
|
231
|
+
): Promise<void> => {
|
|
232
|
+
const config = buildConfigFromOptions(options, flags);
|
|
159
233
|
const path = configPath(options);
|
|
160
234
|
await saveRunnerConfig(path, config);
|
|
161
235
|
console.log(`Created ${path}`);
|
|
162
236
|
};
|
|
163
237
|
|
|
164
|
-
const
|
|
238
|
+
const runEnroll = async (
|
|
239
|
+
options: Map<string, string[]>,
|
|
240
|
+
flags: Set<string>,
|
|
241
|
+
): Promise<void> => {
|
|
242
|
+
const bootstrapToken = process.env.SHIP_RUNNER_BOOTSTRAP_TOKEN?.trim();
|
|
243
|
+
if (!bootstrapToken) {
|
|
244
|
+
throw new ConfigurationError('SHIP_RUNNER_BOOTSTRAP_TOKEN is required for enrollment');
|
|
245
|
+
}
|
|
246
|
+
const config = buildConfigFromOptions(options, flags);
|
|
247
|
+
config.bootstrapToken = bootstrapToken;
|
|
248
|
+
const path = configPath(options);
|
|
249
|
+
const stateOwner = await acquireStateOwner(config);
|
|
250
|
+
const executor = new MicroVmExecutor(config, stateOwner);
|
|
251
|
+
try {
|
|
252
|
+
const api = apiFor(config);
|
|
253
|
+
const runtime = await executor.verifyRuntime();
|
|
254
|
+
const discovery = await api.discover();
|
|
255
|
+
const capabilities = runnerCapabilities(config, runtime);
|
|
256
|
+
reconcileProtocolLimits(config, discovery, capabilities);
|
|
257
|
+
const registered = await registerRunnerDurably({
|
|
258
|
+
configPath: path,
|
|
259
|
+
config,
|
|
260
|
+
capabilities,
|
|
261
|
+
api,
|
|
262
|
+
stateStore: new RegistrationStateStore(stateOwner),
|
|
263
|
+
});
|
|
264
|
+
console.log(`Enrolled runner ${registered.runnerId} (${path})`);
|
|
265
|
+
} finally {
|
|
266
|
+
await executor.close().catch(() => {});
|
|
267
|
+
await stateOwner.release();
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
const runRegister = async (options: Map<string, string[]>): Promise<void> => {
|
|
165
272
|
const path = configPath(options);
|
|
166
273
|
const config = await loadRunnerConfig(path);
|
|
167
274
|
if (!config.bootstrapToken) {
|
|
@@ -199,7 +306,7 @@ const acquireStateOwner = async (config: IRunnerConfig): Promise<RunnerStateOwne
|
|
|
199
306
|
});
|
|
200
307
|
|
|
201
308
|
const runDaemon = async (
|
|
202
|
-
options: Map<string, string
|
|
309
|
+
options: Map<string, string[]>,
|
|
203
310
|
once: boolean,
|
|
204
311
|
): Promise<void> => {
|
|
205
312
|
const path = configPath(options);
|
|
@@ -238,10 +345,13 @@ const runDaemon = async (
|
|
|
238
345
|
|
|
239
346
|
export const runCli = async (arguments_: string[]): Promise<void> => {
|
|
240
347
|
try {
|
|
241
|
-
const { command, options } = parseArguments(arguments_);
|
|
348
|
+
const { command, options, flags } = parseArguments(arguments_);
|
|
242
349
|
switch (command) {
|
|
350
|
+
case 'enroll':
|
|
351
|
+
await runEnroll(options, flags);
|
|
352
|
+
break;
|
|
243
353
|
case 'init':
|
|
244
|
-
await runInit(options);
|
|
354
|
+
await runInit(options, flags);
|
|
245
355
|
break;
|
|
246
356
|
case 'register':
|
|
247
357
|
await runRegister(options);
|
package/ts/config.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
writeAll,
|
|
11
11
|
} from './filesystem.js';
|
|
12
12
|
import type { IOciExecutorConfig, IRunnerConfig, IRunnerCredential } from './interfaces.js';
|
|
13
|
+
import { parseDigestPinnedImageReference } from './oci-registry.js';
|
|
13
14
|
import { isRecord, validateHttpUrl } from './validation.js';
|
|
14
15
|
|
|
15
16
|
const { dirname, isAbsolute, join } = plugins.path;
|
|
@@ -31,7 +32,6 @@ const timestampPattern =
|
|
|
31
32
|
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|[+-](\d{2}):(\d{2}))$/;
|
|
32
33
|
|
|
33
34
|
const defaultOciConfig: IOciExecutorConfig = {
|
|
34
|
-
runnerProfile: 'workload',
|
|
35
35
|
kernelPath: '/var/lib/ship-zone-runner/vmlinux',
|
|
36
36
|
bootArgs: 'console=ttyS0 reboot=k panic=1 pci=off rdinit=/init',
|
|
37
37
|
maximumRootfsBytes: 4 * 1024 * 1024 * 1024,
|
|
@@ -57,8 +57,8 @@ const defaultOciConfig: IOciExecutorConfig = {
|
|
|
57
57
|
export const defaultRunnerConfig = (): IRunnerConfig => ({
|
|
58
58
|
controlPlaneUrl: '',
|
|
59
59
|
allowInsecureLoopback: false,
|
|
60
|
-
name: `runner-${
|
|
61
|
-
labels: ['linux', hostArchitectureLabel(), '
|
|
60
|
+
name: `runner-${plugins.os.hostname() || 'local'}`,
|
|
61
|
+
labels: ['linux', hostArchitectureLabel(), 'microvm'],
|
|
62
62
|
stateDirectory: './.runner-state',
|
|
63
63
|
transferStagingReserveBytes: 1024 * 1024 * 1024,
|
|
64
64
|
transferStagingReserveInodes: 10_000,
|
|
@@ -187,17 +187,14 @@ const validTimestamp = (value: string): boolean => {
|
|
|
187
187
|
|
|
188
188
|
/**
|
|
189
189
|
* Network modes enforceable by the Firecracker microVM runner:
|
|
190
|
-
* - `none
|
|
191
|
-
* - `egress`
|
|
190
|
+
* - `none`: isolated guest namespace with loopback only.
|
|
191
|
+
* Host-enforced `egress` guest transport is not yet wired into Firecracker/smartvm, so
|
|
192
|
+
* advertising `egress` is rejected fail-closed instead of silently running egress jobs offline.
|
|
192
193
|
*/
|
|
193
194
|
const requireEnforceableNetworks = (networks: readonly string[]): void => {
|
|
194
|
-
if (
|
|
195
|
-
networks.length === 0 ||
|
|
196
|
-
!networks.includes('none') ||
|
|
197
|
-
networks.some((mode) => mode !== 'none' && mode !== 'egress')
|
|
198
|
-
) {
|
|
195
|
+
if (networks.length !== 1 || networks[0] !== 'none') {
|
|
199
196
|
throw new ConfigurationError(
|
|
200
|
-
'oci.allowedNetworks must
|
|
197
|
+
'oci.allowedNetworks must be ["none"]; Firecracker guest egress transport is not yet wired',
|
|
201
198
|
);
|
|
202
199
|
}
|
|
203
200
|
};
|
|
@@ -228,9 +225,10 @@ const parseOciConfig = (input: unknown, fallback: IOciExecutorConfig): IOciExecu
|
|
|
228
225
|
'oci.runtime and oci.runtimePath were removed in 4.0.0; this runner uses Firecracker microVMs exclusively',
|
|
229
226
|
);
|
|
230
227
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
228
|
+
if (Object.hasOwn(value, 'runnerProfile')) {
|
|
229
|
+
throw new ConfigurationError(
|
|
230
|
+
'oci.runnerProfile was removed in 5.0.0; one unified microVM runner executes oci, vm, and oci-image jobs',
|
|
231
|
+
);
|
|
234
232
|
}
|
|
235
233
|
const allowedNetworks = stringArray(
|
|
236
234
|
value.allowedNetworks,
|
|
@@ -240,9 +238,9 @@ const parseOciConfig = (input: unknown, fallback: IOciExecutorConfig): IOciExecu
|
|
|
240
238
|
);
|
|
241
239
|
requireEnforceableNetworks(allowedNetworks);
|
|
242
240
|
return {
|
|
243
|
-
runnerProfile,
|
|
244
241
|
kernelPath: stringValue(value.kernelPath, fallback.kernelPath, 'oci.kernelPath'),
|
|
245
242
|
builderRootfsPath: optionalString(value.builderRootfsPath, 'oci.builderRootfsPath'),
|
|
243
|
+
builderImage: optionalString(value.builderImage, 'oci.builderImage'),
|
|
246
244
|
buildctlPath: optionalString(value.buildctlPath, 'oci.buildctlPath'),
|
|
247
245
|
smartvmSocketPath: optionalString(value.smartvmSocketPath, 'oci.smartvmSocketPath'),
|
|
248
246
|
smartvmRuntimeDir: optionalString(value.smartvmRuntimeDir, 'oci.smartvmRuntimeDir'),
|
|
@@ -670,9 +668,6 @@ export const validateRunnerConfig = (config: IRunnerConfig): void => {
|
|
|
670
668
|
}
|
|
671
669
|
numberValue(config.oci.defaultCpus, config.oci.defaultCpus, 'oci.defaultCpus', 0, 1024);
|
|
672
670
|
numberValue(config.oci.maximumCpus, config.oci.maximumCpus, 'oci.maximumCpus', 0, 1024);
|
|
673
|
-
if (config.oci.runnerProfile !== 'workload' && config.oci.runnerProfile !== 'builder') {
|
|
674
|
-
throw new ConfigurationError('oci.runnerProfile must be "workload" or "builder"');
|
|
675
|
-
}
|
|
676
671
|
requireEnforceableNetworks(config.oci.allowedNetworks);
|
|
677
672
|
parseBlockedCidrs(config.oci.egressBlockedCidrs, []);
|
|
678
673
|
if (!isAbsolute(config.oci.kernelPath)) {
|
|
@@ -681,6 +676,13 @@ export const validateRunnerConfig = (config: IRunnerConfig): void => {
|
|
|
681
676
|
if (config.oci.builderRootfsPath && !isAbsolute(config.oci.builderRootfsPath)) {
|
|
682
677
|
throw new ConfigurationError('oci.builderRootfsPath must be absolute');
|
|
683
678
|
}
|
|
679
|
+
if (config.oci.builderImage) {
|
|
680
|
+
try {
|
|
681
|
+
parseDigestPinnedImageReference(config.oci.builderImage);
|
|
682
|
+
} catch {
|
|
683
|
+
throw new ConfigurationError('oci.builderImage must be a digest-pinned OCI image reference');
|
|
684
|
+
}
|
|
685
|
+
}
|
|
684
686
|
if (config.oci.buildctlPath && !isAbsolute(config.oci.buildctlPath)) {
|
|
685
687
|
throw new ConfigurationError('oci.buildctlPath must be absolute');
|
|
686
688
|
}
|
package/ts/interfaces.ts
CHANGED
|
@@ -3,12 +3,8 @@ import { commitinfo } from './00_commitinfo_data.js';
|
|
|
3
3
|
export const runnerVersion: string = commitinfo.version;
|
|
4
4
|
|
|
5
5
|
export type TExecutionProfile = 'oci' | 'oci-image' | 'vm';
|
|
6
|
-
export type TRunnerRole = 'workload' | 'builder';
|
|
7
|
-
export type TIsolation = 'container' | 'microvm';
|
|
8
6
|
export type TRunnerFeature = 'source.tar-gz' | 'artifacts' | 'caches';
|
|
9
|
-
export type TLeaseFeature = 'image-pull-grants' | 'candidate-bindings' | 'npm-read-grants';
|
|
10
7
|
export type TNetworkMode = 'none' | 'egress';
|
|
11
|
-
export type TSourceFormat = 'tar.gz';
|
|
12
8
|
export type TArtifactPermission = 'none' | 'write';
|
|
13
9
|
export type TCachePermission = 'none' | 'read' | 'read-write';
|
|
14
10
|
export type TImagePermission = 'none' | 'push';
|
|
@@ -83,17 +79,13 @@ export interface IResourceLimits {
|
|
|
83
79
|
|
|
84
80
|
export interface IRunnerCapabilities {
|
|
85
81
|
executionProfiles: TExecutionProfile[];
|
|
86
|
-
isolation: TIsolation[];
|
|
87
82
|
platforms: string[];
|
|
88
83
|
labels: string[];
|
|
89
84
|
features: TRunnerFeature[];
|
|
90
85
|
networks: TNetworkMode[];
|
|
91
|
-
sourceFormats: TSourceFormat[];
|
|
92
86
|
limits: ITransferLimits;
|
|
93
87
|
/** The largest resource ceilings the runner enforces per attempt. */
|
|
94
88
|
resources?: IResourceLimits;
|
|
95
|
-
/** The lease contents the runner uses. */
|
|
96
|
-
leaseFeatures?: TLeaseFeature[];
|
|
97
89
|
/** The largest job `timeoutMs` the runner executes. */
|
|
98
90
|
maximumTimeoutMs?: number;
|
|
99
91
|
}
|
|
@@ -143,7 +135,6 @@ export interface IClaimJobRequest {
|
|
|
143
135
|
claimRequestId: string;
|
|
144
136
|
runnerId: string;
|
|
145
137
|
sessionId: string;
|
|
146
|
-
capabilities: IRunnerCapabilities;
|
|
147
138
|
}
|
|
148
139
|
|
|
149
140
|
export interface IClaimJobResponse {
|
|
@@ -321,7 +312,6 @@ export interface IErrorResponse {
|
|
|
321
312
|
|
|
322
313
|
export interface IJobRequirements {
|
|
323
314
|
executionProfile: TExecutionProfile;
|
|
324
|
-
isolation: TIsolation;
|
|
325
315
|
platform?: string;
|
|
326
316
|
labels: string[];
|
|
327
317
|
features: TRunnerFeature[];
|
|
@@ -480,26 +470,25 @@ export interface IImageBuildRunnerJob extends ICompiledRunnerJobBase {
|
|
|
480
470
|
/** Every compiled job shape the published runner job schema admits. */
|
|
481
471
|
export type TCompiledRunnerJob = IContainerRunnerJob | IVmRunnerJob | IImageBuildRunnerJob;
|
|
482
472
|
|
|
483
|
-
/** An `oci` job this runner executes in Firecracker
|
|
473
|
+
/** An `oci` job this runner executes in a Firecracker microVM. */
|
|
484
474
|
export interface IOciRunnerJob extends IContainerRunnerJob {
|
|
485
|
-
requirements: IJobRequirements & { executionProfile: 'oci'
|
|
475
|
+
requirements: IJobRequirements & { executionProfile: 'oci' };
|
|
486
476
|
}
|
|
487
477
|
|
|
488
|
-
/** A `vm` job this runner executes in Firecracker
|
|
478
|
+
/** A `vm` job this runner executes in a Firecracker microVM. */
|
|
489
479
|
export interface IVmExecutableRunnerJob extends IVmRunnerJob {
|
|
490
|
-
requirements: IJobRequirements & { executionProfile: 'vm';
|
|
480
|
+
requirements: IJobRequirements & { executionProfile: 'vm'; platform: string };
|
|
491
481
|
}
|
|
492
482
|
|
|
493
|
-
/** An `oci-image` job this runner executes in a
|
|
483
|
+
/** An `oci-image` job this runner executes in a Firecracker microVM. */
|
|
494
484
|
export interface IImageBuildExecutableRunnerJob extends IImageBuildRunnerJob {
|
|
495
485
|
requirements: IJobRequirements & {
|
|
496
486
|
executionProfile: 'oci-image';
|
|
497
|
-
isolation: 'microvm';
|
|
498
487
|
platform: string;
|
|
499
488
|
};
|
|
500
489
|
}
|
|
501
490
|
|
|
502
|
-
/** Every compiled job shape this Firecracker runner
|
|
491
|
+
/** Every compiled job shape this unified Firecracker runner executes. */
|
|
503
492
|
export type TExecutableRunnerJob =
|
|
504
493
|
| IOciRunnerJob
|
|
505
494
|
| IVmExecutableRunnerJob
|
|
@@ -561,16 +550,12 @@ export type TOciArchitecture = 'amd64' | 'arm64';
|
|
|
561
550
|
export type TOciHelperTarget = 'linux_amd64' | 'linux_arm64';
|
|
562
551
|
|
|
563
552
|
export interface IOciExecutorConfig {
|
|
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
553
|
/** Pinned Linux vmlinux kernel path for Firecracker microVMs. */
|
|
571
554
|
kernelPath: string;
|
|
572
|
-
/**
|
|
555
|
+
/** Optional pinned ext2 guest rootfs containing rootless BuildKit (`buildkitd` + `buildctl`) for `oci-image` jobs. */
|
|
573
556
|
builderRootfsPath?: string;
|
|
557
|
+
/** Optional digest-pinned OCI image containing rootless BuildKit (pulled on demand when `builderRootfsPath` is not set). */
|
|
558
|
+
builderImage?: string;
|
|
574
559
|
/** Optional override for the `buildctl` binary path inside the builder guest. */
|
|
575
560
|
buildctlPath?: string;
|
|
576
561
|
/** Optional smartvm-helper Unix socket path (defaults to `/run/smartvm/helper.sock`). */
|
package/ts/microvm-executor.ts
CHANGED
|
@@ -594,6 +594,14 @@ export class MicroVmExecutor implements IJobExecutor {
|
|
|
594
594
|
if (this.runtimeFacts) return this.runtimeFacts;
|
|
595
595
|
this.stateOwner.assertHeld();
|
|
596
596
|
await this.verifyKernelFile(this.config.oci.kernelPath);
|
|
597
|
+
if (this.config.oci.builderRootfsPath) {
|
|
598
|
+
const builderStat = await lstatIfPresent(this.config.oci.builderRootfsPath);
|
|
599
|
+
if (!builderStat || !builderStat.isFile() || builderStat.size === 0) {
|
|
600
|
+
throw new RunnerError(
|
|
601
|
+
`Firecracker builder rootfs is missing or invalid: ${this.config.oci.builderRootfsPath}`,
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
597
605
|
const smartvm = await this.getSmartVm();
|
|
598
606
|
const report = await smartvm.checkHost();
|
|
599
607
|
if (!report.ok) {
|
|
@@ -653,39 +661,76 @@ export class MicroVmExecutor implements IJobExecutor {
|
|
|
653
661
|
const smartvm = await this.getSmartVm();
|
|
654
662
|
|
|
655
663
|
if ('build' in job) {
|
|
656
|
-
const builderRootfsPath = this.config.oci.builderRootfsPath;
|
|
657
|
-
if (!builderRootfsPath) {
|
|
658
|
-
throw new RunnerError(
|
|
659
|
-
'oci.builderRootfsPath must be configured to execute oci-image builds',
|
|
660
|
-
);
|
|
661
|
-
}
|
|
662
|
-
const stat = await lstatIfPresent(builderRootfsPath);
|
|
663
|
-
if (!stat || !stat.isFile() || stat.size === 0) {
|
|
664
|
-
throw new RunnerError(
|
|
665
|
-
`Firecracker builder rootfs is missing or invalid: ${builderRootfsPath}`,
|
|
666
|
-
);
|
|
667
|
-
}
|
|
668
664
|
// Verify every base image reference resolves to an exact digest-pinned image.
|
|
669
665
|
for (const base of job.build.baseImages) {
|
|
670
666
|
const resolved = resolveImageReference(base.image, context.lease.bindings);
|
|
671
667
|
parseDigestPinnedImageReference(resolved);
|
|
672
668
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
669
|
+
|
|
670
|
+
const builderRootfsPath = this.config.oci.builderRootfsPath;
|
|
671
|
+
const builderImage = this.config.oci.builderImage;
|
|
672
|
+
|
|
673
|
+
if (builderRootfsPath) {
|
|
674
|
+
const stat = await lstatIfPresent(builderRootfsPath);
|
|
675
|
+
if (!stat || !stat.isFile() || stat.size === 0) {
|
|
676
|
+
throw new RunnerError(
|
|
677
|
+
`Firecracker builder rootfs is missing or invalid: ${builderRootfsPath}`,
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
const { imageDigest } = await smartvm.computeImageDigest({
|
|
681
|
+
kernelPath: runtime.kernelPath,
|
|
682
|
+
rootfsPath: builderRootfsPath,
|
|
683
|
+
initrdPath: runtime.initrdPath,
|
|
684
|
+
bootArgs: this.config.oci.bootArgs,
|
|
685
|
+
});
|
|
686
|
+
return {
|
|
687
|
+
preparationId: plugins.crypto.randomUUID(),
|
|
688
|
+
attemptId: context.lease.attemptId,
|
|
689
|
+
image: builderRootfsPath,
|
|
690
|
+
imageArchitecture: runtime.architecture,
|
|
691
|
+
rootfsPath: builderRootfsPath,
|
|
692
|
+
imageDigest,
|
|
693
|
+
shapeId: shape.id,
|
|
694
|
+
cleanup: async () => {},
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
if (builderImage) {
|
|
699
|
+
parseDigestPinnedImageReference(builderImage);
|
|
700
|
+
const materialized = this.dependencies.materializeImage
|
|
701
|
+
? await this.dependencies.materializeImage(builderImage, runtime.architecture, context.signal)
|
|
702
|
+
: await this.getRegistryClient(runtime.helperPath).materializeImage(
|
|
703
|
+
builderImage,
|
|
704
|
+
runtime.architecture,
|
|
705
|
+
context.signal,
|
|
706
|
+
);
|
|
707
|
+
if (materialized.os !== 'linux' || materialized.architecture !== runtime.architecture) {
|
|
708
|
+
await materialized.cleanup().catch(() => {});
|
|
709
|
+
throw new ProtocolError(
|
|
710
|
+
`Materialized builder image platform ${materialized.os}/${materialized.architecture} does not match linux/${runtime.architecture}`,
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
const { imageDigest } = await smartvm.computeImageDigest({
|
|
714
|
+
kernelPath: runtime.kernelPath,
|
|
715
|
+
rootfsPath: materialized.rootfsPath,
|
|
716
|
+
initrdPath: runtime.initrdPath,
|
|
717
|
+
bootArgs: this.config.oci.bootArgs,
|
|
718
|
+
});
|
|
719
|
+
return {
|
|
720
|
+
preparationId: plugins.crypto.randomUUID(),
|
|
721
|
+
attemptId: context.lease.attemptId,
|
|
722
|
+
image: builderImage,
|
|
723
|
+
imageArchitecture: materialized.architecture,
|
|
724
|
+
rootfsPath: materialized.rootfsPath,
|
|
725
|
+
imageDigest,
|
|
726
|
+
shapeId: shape.id,
|
|
727
|
+
cleanup: () => materialized.cleanup(),
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
throw new RunnerError(
|
|
732
|
+
'oci.builderRootfsPath or oci.builderImage must be configured to execute oci-image builds',
|
|
733
|
+
);
|
|
689
734
|
}
|
|
690
735
|
|
|
691
736
|
const image = resolveImageReference(job.execution.image, context.lease.bindings);
|