@ship.zone/runner 4.0.0 → 5.0.1

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/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@ship.zone/runner",
3
- "version": "4.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "The Firecracker microVM OCI job runner for ship.zone CI/CD",
5
- "homepage": "https://code.foss.global/ship.zone/runner",
5
+ "homepage": "https://foss.global/ship.zone/runner",
6
6
  "bugs": {
7
- "url": "https://code.foss.global/ship.zone/runner/issues"
7
+ "url": "https://foss.global/ship.zone/runner/issues"
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://code.foss.global/ship.zone/runner.git"
11
+ "url": "git+https://foss.global/ship.zone/runner.git"
12
12
  },
13
13
  "author": "Task Venture Capital GmbH",
14
14
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "dependencies": {
31
31
  "@push.rocks/smartsea": "^1.1.0",
32
32
  "@push.rocks/smartvm": "^2.0.0",
33
- "@ship.zone/ci-spec": "2.0.0",
33
+ "@ship.zone/ci-spec": "3.0.0",
34
34
  "ajv": "^8.20.0"
35
35
  },
36
36
  "devDependencies": {
package/readme.md CHANGED
@@ -1,18 +1,18 @@
1
1
  # @ship.zone/runner
2
2
 
3
3
  `@ship.zone/runner` is the outbound-only Firecracker microVM execution agent for ship.zone CI/CD.
4
- It implements the runner protocol of `@ship.zone/ci-spec` (2.0.0) with `microvm` isolation for
5
- `oci`, `vm`, and dedicated-builder `oci-image` execution profiles, validates leases and compiled
6
- jobs against the published schemas, and runs one fenced attempt at a time inside a dedicated
7
- Firecracker microVM managed via `@push.rocks/smartvm`.
4
+ It implements the runner protocol of `@ship.zone/ci-spec` (3.0.0) across all three execution profiles
5
+ (`oci`, `vm`, and `oci-image`) on one unified runner, validates leases and compiled jobs against the
6
+ published schemas, and runs one fenced attempt at a time inside a fresh disposable Firecracker
7
+ microVM managed via `@push.rocks/smartvm`.
8
8
 
9
9
  No host Docker or Podman daemon is required or supported. Jobs still choose any digest-pinned
10
10
  Linux Docker/OCI image; the runner pulls and verifies the image layers directly via OCI
11
11
  Distribution v2, builds a deterministic read-only ext2 rootfs image, and boots a fresh Firecracker
12
12
  microVM with that image attached read-only (`/dev/vda`) and the static Rust `runnerworkspace` guest
13
- agent as PID 1 (`/init`). Dedicated builder runners (`--profile builder`) execute `oci-image`
14
- builds via BuildKit (`buildctl`) inside a dedicated Firecracker microVM and record the produced
15
- image digest with the coordinator.
13
+ agent as PID 1 (`/init`). When configured with `--builder-rootfs-path` or `--builder-image`, the
14
+ exact same runner also advertises and executes `oci-image` builds via BuildKit (`buildctl`) inside
15
+ a fresh Firecracker microVM and records the produced image digest with the coordinator.
16
16
 
17
17
  The control plane owns workflow compilation, scheduling, authorization, secrets policy, and
18
18
  canonical run state. This package owns runner registration, lease handling, isolated execution,
@@ -39,14 +39,12 @@ Requests directly.
39
39
  private namespaces, and bounded vCPU, memory, PID, shared-memory (`/dev/shm`), time, and
40
40
  writable-storage limits. In `vm` profile, steps run inside the microVM over an ephemeral writable
41
41
  overlayfs above the read-only OCI rootfs and are torn down between steps via cgroup v2 kill.
42
- - Dedicated builder runners (`--profile builder`) advertise only `oci-image` (never `oci` or `vm`),
43
- run BuildKit inside a fresh Firecracker microVM with source-policy digest pinning, scoped `0400`
44
- secrets and push credentials, attestations disabled, and digest-only push before calling
45
- `PUT /jobs/{jobId}/attempts/{attemptId}/image`.
46
- - By default the network mode is `none` (Firecracker microVM with no external connectivity). When
47
- `--allow-egress` is enabled, the runner advertises `['none', 'egress']` and enforces `egress`
48
- allowlists on the host via `EgressProxy` (DNS `A`/`AAAA`-only allowlist, private/link-local/
49
- non-global/IPv4-mapped and custom CIDR blocking, TTL bindings, TLS SNI on 443, HTTP `Host` on 80).
42
+ - `oci-image` builds run on the same unified runner inside a fresh Firecracker microVM with
43
+ source-policy digest pinning, scoped `0400` secrets and push credentials, attestations disabled,
44
+ and digest-only push before calling `PUT /jobs/{jobId}/attempts/{attemptId}/image`.
45
+ - Network mode is `none` (Firecracker microVM with no external connectivity). The host egress policy
46
+ controller (`EgressAllowlistController`) is tested and ready for future guest network transport;
47
+ until that transport is wired into Firecracker/smartvm, the runner advertises `['none']` only.
50
48
  - MicroVMs receive no host paths, runtime sockets, devices, or host namespaces. Their only
51
49
  persistent writable workspace is `/workspace`, imported/exported by the static Rust
52
50
  `runnerworkspace` guest PID 1 agent over vsock.
@@ -78,7 +76,7 @@ Requests directly.
78
76
  Install the `ship-zone-runner` executable on a Linux host:
79
77
 
80
78
  ```sh
81
- curl -fsSL https://code.foss.global/ship.zone/runner/releases/download/latest/install.sh | sudo bash
79
+ curl -fsSL https://foss.global/ship.zone/runner/releases/download/latest/install.sh | sudo bash
82
80
  ```
83
81
 
84
82
  The installer is an asset of every release from 3.0.0 on. It downloads the executable of the newest
@@ -90,7 +88,7 @@ executable with `--version` before it changes anything. It installs to
90
88
  to check the release assets without changing anything:
91
89
 
92
90
  ```sh
93
- curl -fsSL https://code.foss.global/ship.zone/runner/releases/download/latest/install.sh | sudo bash -s -- --version vX.Y.Z
91
+ curl -fsSL https://foss.global/ship.zone/runner/releases/download/latest/install.sh | sudo bash -s -- --version vX.Y.Z
94
92
  ```
95
93
 
96
94
  Running it again updates the executable. The installer never touches the runner's configuration
@@ -125,25 +123,11 @@ explicit absolute helper path for development or controlled deployments.
125
123
 
126
124
  Configured, packaged, and dependency-injected helper resolver paths are source files. Runtime
127
125
  verification reads the bounded regular source through one pinned file descriptor, hashes those exact
128
- bytes, and materializes an executable mode-`0755` copy below the private mode-`0700` runner state
129
- subdirectory as `workspace-helpers/runnerworkspace_<target>_musl_<sha256>`. Source permissions are
130
- not changed, so package managers may install the source without executable bits. The private parent
131
- directory is the host access boundary; mode `0755` lets capability-dropped helper containers execute
132
- the host-owned read-only bind mount. `IOciRuntimeFacts.helperPath` reports the validated
133
- materialized path used by host probes and OCI bind mounts, while `helperSha256` reports its content
134
- digest. Existing digest paths are reused only
135
- after their type, single-link status, mode, and digest are revalidated without mutating them; the
136
- runner retains a bounded set for rollback, reclaims stale incomplete temporary copies, and rejects
137
- excessive recent temporary residue. The sole immediate-recovery exception is a validated temporary
138
- name and exact digest destination that still reference the same two-link inode after interruption;
139
- the runner removes the temporary name, verifies the destination became single-link, and then reuses
140
- it. The advisory `.workspace-helper.lock` file of runner 2.x is no longer used and is removed.
141
-
142
- Runtime verification creates one private `.runtime-probe-owner_<id>` marker in the helper state.
143
- Host tmpfs probes include that owner in their exact directory names, and OCI runtime probe volumes
144
- carry the same `ship.zone.runner.runtime-probe-owner` label. This lets interrupted verification be
145
- cleaned by the same state owner without touching unowned probes or probes from another runner. The
146
- runner syncs both the helper-directory entry and a newly created owner marker before using them.
126
+ bytes, materializes an executable mode-`0755` copy below the private mode-`0700` runner state
127
+ subdirectory as `workspace-helpers/runnerworkspace_<target>_musl_<sha256>`, and packages it into a
128
+ deterministic initramfs (`initrd_<target>_<sha256>.cpio`) booted as PID 1 (`/init`) inside every
129
+ Firecracker microVM. `IOciRuntimeFacts.helperPath` reports the materialized host helper path while
130
+ `initrdPath` and `helperSha256` report the generated initrd and helper digest.
147
131
 
148
132
  ## State Directory Ownership
149
133
 
@@ -168,48 +152,54 @@ single in-process chain.
168
152
 
169
153
  ## Configure And Run
170
154
 
171
- Create a private runner configuration:
155
+ Enroll in a single step using a one-time bootstrap token minted on `console.ship.zone`, then start
156
+ the daemon:
172
157
 
173
158
  ```sh
174
- ship-zone-runner init \
175
- --control-plane https://foss.global \
176
- --kernel-path /var/lib/ship-zone-runner/vmlinux
159
+ SHIP_RUNNER_BOOTSTRAP_TOKEN='<one-time token>' ship-zone-runner enroll \
160
+ --control-plane https://console.ship.zone
161
+ ship-zone-runner run
177
162
  ```
178
163
 
179
- Optional flags for `init`:
180
-
181
- - `--profile workload|builder`: `workload` (default) advertises `['oci', 'vm']`; `builder`
182
- advertises only `['oci-image']` and requires `--builder-rootfs-path <path>`.
183
- - `--allow-egress`: enable host-enforced `egress` allowlist proxy and advertise `['none', 'egress']`.
184
- - `--egress-blocked-cidr <cidr>` (repeatable): block additional destination CIDRs in `egress` mode.
185
-
186
- Register with a one-time bootstrap token, then start the daemon:
164
+ Or initialize and register in two separate steps (`init` + `register`):
187
165
 
188
166
  ```sh
167
+ ship-zone-runner init \
168
+ --control-plane https://console.ship.zone \
169
+ --kernel-path /var/lib/ship-zone-runner/vmlinux
189
170
  SHIP_RUNNER_BOOTSTRAP_TOKEN='<one-time token>' ship-zone-runner register
190
171
  ship-zone-runner run
191
172
  ```
192
173
 
193
- The runner uses `/dev/shm` for fail-closed host tmpfs verification before registration and talks to
194
- `smartvm-helper` (`@push.rocks/smartvm`) to boot per-attempt Firecracker microVMs.
174
+ Optional flags for `enroll` / `init`:
175
+
176
+ - `--builder-rootfs-path <path>` or `--builder-image <ref@sha256:...>`: enable `oci-image`
177
+ BuildKit image builds alongside `oci` and `vm` on the same unified runner (`['oci', 'vm', 'oci-image']`).
178
+ - `--labels <a,b>` (repeatable): customize advertised runner labels.
179
+ - `--name <name>`: override the default `runner-<hostname>` runner name.
180
+ - `--smartvm-socket <path>`: override the default `/run/smartvm/helper.sock` helper socket.
181
+
182
+ The runner verifies the Firecracker kernel and `smartvm-helper` (`@push.rocks/smartvm`) before
183
+ registration and boots a fresh per-attempt Firecracker microVM for every job.
195
184
 
196
185
  Replace `run` with `once` to claim at most one job or `config` to print the effective configuration
197
186
  with credentials masked. Within this repository, `pnpm build` followed by
198
187
  `node dist_ts/cli-entry.js <command>` is the equivalent development invocation.
199
188
  `SHIP_RUNNER_CONFIG` selects a config path; the default is `./runner.config.json`.
200
189
 
201
- `init` writes the config with mode `0600`. Registration verifies the runtime and protocol discovery
202
- document before advertising capabilities, durably journals the exact registration request without
203
- the bootstrap token, then atomically replaces the bootstrap token with the returned runner
204
- credential. An interrupted registration replays the journaled request and rejects configuration
205
- drift. Credential rotation from session and runner-heartbeat responses is persisted before the new
206
- credential becomes active.
190
+ `init` and `enroll` write the config with mode `0600`. Registration verifies the runtime and
191
+ protocol discovery document before advertising capabilities, durably journals the exact registration
192
+ request without the bootstrap token, then atomically replaces the bootstrap token with the returned
193
+ runner credential. An interrupted registration replays the journaled request and rejects
194
+ configuration drift. Credential rotation from session and runner-heartbeat responses is persisted
195
+ before the new credential becomes active.
207
196
 
208
197
  The default policy includes:
209
198
 
210
- - Firecracker microVM isolation via `@push.rocks/smartvm` (`workload` profile: `oci` and `vm`);
211
- - labels for Linux, the current architecture, and microVM;
212
- - network `none` only (add `--allow-egress` to enable host-enforced `egress`);
199
+ - Firecracker microVM isolation via `@push.rocks/smartvm` (`oci` and `vm`, plus `oci-image` when a
200
+ builder rootfs or pinned builder image is configured);
201
+ - labels for Linux, the current architecture, and `microvm`;
202
+ - network `none` only;
213
203
  - job user `65532:65532` (for `oci` steps);
214
204
  - a 4 GiB maximum logical workspace and 100,000 entries;
215
205
  - bounded source, artifact, cache, log, environment, and staging limits;
@@ -225,30 +215,27 @@ For each claim, the runner:
225
215
  job schema and the specification version acceptance rule, the RFC 8785 `compiledPlanDigest`,
226
216
  internal job coherence, the lease coherence of `grants`, `bindings`, and `npmGrants`, fit against
227
217
  the immutable advertised capability snapshot, and all runner execution policy before image
228
- inspection or pull. A lease that fails any check, or that this runner does not execute, is
218
+ materialization. A lease that fails any check, or that this runner does not execute, is
229
219
  abandoned as `runner_error` before acceptance.
230
- 2. Pulls or locates the exact image digest, validates its Linux architecture, and probes it with the
231
- inert helper.
220
+ 2. Materializes the exact digest-pinned OCI image (or configured builder rootfs/image) into a
221
+ deterministic ext2 rootfs and validates its Linux architecture.
232
222
  3. Writes a private interrupted-attempt journal and sends the explicit fenced acceptance request.
233
223
  Source transfer and execution do not start before HTTP 204.
234
224
  4. Downloads and validates the source `tar.gz`, then restores readable caches in declaration order
235
225
  into private host staging.
236
- 5. Imports staging into the bounded tmpfs and runs compiled steps in declaration order, stopping at
237
- the first non-zero exit.
238
- 6. Publishes successful read-write caches and artifacts selected by their `when` policy as
239
- deterministic, replayable `tar.gz` transfers.
240
- 7. Cleans staging, helper/step containers, and the tmpfs volume before sending the idempotent
241
- terminal completion, then clears the recovery journal after the coordinator accepts it.
242
-
243
- An attempt-scoped inert holder container keeps Docker's local-driver tmpfs mounted while fresh step
244
- and helper containers come and go. It runs no image-provided command and is removed with the
245
- workspace.
246
-
247
- On restart, the runner first scavenges only its known host-staging directories, journal temporary
248
- files, and stale private copies of the state owner helper, right after it owns the state directory
249
- and before it verifies the runtime. A new session then removes stale labeled containers and volumes
250
- locally, reads the secret-free journal, and calls the recovery endpoint to revoke and reconcile the
251
- interrupted attempt. Work is never resumed, and a coordinator outage cannot retain prior staging.
226
+ 5. Boots a fresh Firecracker microVM, transfers the workspace over vsock into the guest's bounded
227
+ `/workspace`, and executes compiled steps (or `oci-image` BuildKit build) in order.
228
+ 6. Exports artifacts and read-write caches over vsock and publishes them as deterministic,
229
+ replayable `tar.gz` transfers.
230
+ 7. Destroys the Firecracker microVM and cleans host staging before sending the idempotent terminal
231
+ completion, then clears the recovery journal after the coordinator accepts it.
232
+
233
+ On restart, the runner first scavenges its known host-staging directories, journal temporary files,
234
+ and stale private copies of the state owner helper, right after it owns the state directory and
235
+ before it verifies the runtime. A new session then destroys any orphaned Firecracker VMs recorded
236
+ in `active-vms.json`, reads the secret-free journal, and calls the recovery endpoint to revoke and
237
+ reconcile the interrupted attempt. Work is never resumed, and a coordinator outage cannot retain
238
+ prior staging.
252
239
 
253
240
  ## Job Timeout
254
241
 
@@ -340,7 +327,7 @@ import {
340
327
  ArtifactManager,
341
328
  CacheManager,
342
329
  defaultRunnerConfig,
343
- EgressProxy,
330
+ EgressAllowlistController,
344
331
  MicroVmExecutor,
345
332
  RunnerApiClient,
346
333
  ShipRunner,
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@ship.zone/runner',
6
- version: '4.0.0',
6
+ version: '5.0.1',
7
7
  description: 'The Firecracker microVM OCI job runner for ship.zone CI/CD'
8
8
  }
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 | true>;
29
+ options: Map<string, string[]>;
30
+ flags: Set<string>;
30
31
  }
31
32
 
32
33
  const cliInvocation = 'ship-zone-runner';
33
34
 
34
- const usage = `ship.zone runner ${runnerVersion} (Firecracker microVM)
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} init --control-plane <url> [--profile workload|builder] [--config <path>] [--name <name>] [--kernel-path <path>] [--builder-rootfs-path <path>] [--smartvm-socket <path>] [--allow-egress]
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 | true>();
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 name = entry.slice(2);
56
- const next = rest[index + 1];
57
- if (!next || next.startsWith('--')) options.set(name, true);
58
- else {
59
- options.set(name, next);
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 stringOption = (
67
- options: Map<string, string | true>,
124
+ const singleOption = (
125
+ options: Map<string, string[]>,
68
126
  name: string,
69
127
  ): string | undefined => {
70
- const value = options.get(name);
71
- if (value === undefined) return undefined;
72
- if (value === true) throw new ConfigurationError(`--${name} requires a value`);
73
- return value;
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 | true>): string =>
77
- stringOption(options, 'config') ?? process.env.SHIP_RUNNER_CONFIG ?? './runner.config.json';
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 runInit = async (options: Map<string, string | true>): Promise<void> => {
194
+ const buildConfigFromOptions = (
195
+ options: Map<string, string[]>,
196
+ flags: Set<string>,
197
+ ): IRunnerConfig => {
123
198
  const config = defaultRunnerConfig();
124
- config.controlPlaneUrl = stringOption(options, 'control-plane') ?? '';
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
- }
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 = stringOption(options, 'builder-rootfs-path');
207
+ const builderRootfsPath = singleOption(options, 'builder-rootfs-path');
138
208
  if (builderRootfsPath) config.oci.builderRootfsPath = builderRootfsPath;
139
- const smartvmSocket = stringOption(options, 'smartvm-socket');
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 = stringOption(options, 'smartvm-runtime-dir');
215
+ const smartvmRuntimeDir = singleOption(options, 'smartvm-runtime-dir');
142
216
  if (smartvmRuntimeDir) config.oci.smartvmRuntimeDir = smartvmRuntimeDir;
143
- const smartvmBridgePath = stringOption(options, 'smartvm-bridge-path');
217
+ const smartvmBridgePath = singleOption(options, 'smartvm-bridge-path');
144
218
  if (smartvmBridgePath) config.oci.smartvmBridgePath = smartvmBridgePath;
145
- const helperPath = stringOption(options, 'workspace-helper-path');
219
+ const helperPath = singleOption(options, 'workspace-helper-path');
146
220
  if (helperPath) config.oci.workspaceHelperPath = helperPath;
147
- if (options.has('allow-insecure-loopback')) config.allowInsecureLoopback = true;
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);
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 runRegister = async (options: Map<string, string | true>): Promise<void> => {
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 | true>,
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);