@ship.zone/runner 3.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.
Files changed (80) hide show
  1. package/.smartconfig.json +19 -1
  2. package/changelog.md +61 -0
  3. package/dist_rust/runnerworkspace_linux_amd64_musl +0 -0
  4. package/dist_rust/runnerworkspace_linux_amd64_musl.tsrust-build.json +4 -4
  5. package/dist_rust/runnerworkspace_linux_arm64_musl +0 -0
  6. package/dist_rust/runnerworkspace_linux_arm64_musl.tsrust-build.json +4 -4
  7. package/dist_ts/00_commitinfo_data.js +3 -3
  8. package/dist_ts/api-client.d.ts +2 -1
  9. package/dist_ts/api-client.js +10 -2
  10. package/dist_ts/artifact-manager.js +1 -1
  11. package/dist_ts/attempt-state.js +1 -1
  12. package/dist_ts/cache-manager.js +1 -1
  13. package/dist_ts/cli-entry.js +17 -3
  14. package/dist_ts/cli.d.ts +7 -0
  15. package/dist_ts/cli.js +155 -35
  16. package/dist_ts/config.js +75 -22
  17. package/dist_ts/egress-proxy.d.ts +99 -0
  18. package/dist_ts/egress-proxy.js +607 -0
  19. package/dist_ts/errors.js +1 -1
  20. package/dist_ts/filesystem.js +1 -1
  21. package/dist_ts/index.d.ts +5 -1
  22. package/dist_ts/index.js +6 -2
  23. package/dist_ts/interfaces.d.ts +85 -31
  24. package/dist_ts/interfaces.js +1 -1
  25. package/dist_ts/log-sender.js +1 -1
  26. package/dist_ts/microvm-executor.d.ts +90 -0
  27. package/dist_ts/microvm-executor.js +1078 -0
  28. package/dist_ts/node-version.d.ts +11 -0
  29. package/dist_ts/node-version.js +43 -0
  30. package/dist_ts/npm-grants.d.ts +9 -0
  31. package/dist_ts/npm-grants.js +44 -0
  32. package/dist_ts/oci-registry.d.ts +73 -0
  33. package/dist_ts/oci-registry.js +508 -0
  34. package/dist_ts/plugins.d.ts +6 -2
  35. package/dist_ts/plugins.js +7 -3
  36. package/dist_ts/protocol-validator.d.ts +3 -5
  37. package/dist_ts/protocol-validator.js +27 -51
  38. package/dist_ts/redactor.js +1 -1
  39. package/dist_ts/registration-state.js +1 -1
  40. package/dist_ts/runner.d.ts +5 -5
  41. package/dist_ts/runner.js +47 -22
  42. package/dist_ts/source-workspace.js +1 -1
  43. package/dist_ts/spec-version.js +1 -1
  44. package/dist_ts/staging-scavenger.js +1 -1
  45. package/dist_ts/state-owner.js +4 -2
  46. package/dist_ts/transfer-archive.js +1 -1
  47. package/dist_ts/validation.js +1 -1
  48. package/dist_ts/vsock-protocol.d.ts +130 -0
  49. package/dist_ts/vsock-protocol.js +336 -0
  50. package/dist_ts/wire-schema.js +1 -1
  51. package/package.json +19 -15
  52. package/readme.md +106 -108
  53. package/rust/Cargo.lock +1 -0
  54. package/rust/Cargo.toml +2 -1
  55. package/rust/src/cpio.rs +147 -0
  56. package/rust/src/extfs.rs +747 -0
  57. package/rust/src/guest.rs +2411 -0
  58. package/rust/src/lib.rs +41 -0
  59. package/rust/src/main.rs +6 -1
  60. package/rust/src/oci_tar.rs +842 -0
  61. package/ts/00_commitinfo_data.ts +2 -2
  62. package/ts/api-client.ts +19 -1
  63. package/ts/cli-entry.ts +15 -2
  64. package/ts/cli.ts +172 -40
  65. package/ts/config.ts +100 -25
  66. package/ts/egress-proxy.ts +649 -0
  67. package/ts/index.ts +5 -1
  68. package/ts/interfaces.ts +97 -30
  69. package/ts/microvm-executor.ts +1310 -0
  70. package/ts/node-version.ts +49 -0
  71. package/ts/npm-grants.ts +49 -0
  72. package/ts/oci-registry.ts +649 -0
  73. package/ts/plugins.ts +6 -2
  74. package/ts/protocol-validator.ts +29 -58
  75. package/ts/runner.ts +48 -21
  76. package/ts/state-owner.ts +8 -1
  77. package/ts/vsock-protocol.ts +437 -0
  78. package/dist_ts/oci-executor.d.ts +0 -155
  79. package/dist_ts/oci-executor.js +0 -2238
  80. package/ts/oci-executor.ts +0 -2989
@@ -3,14 +3,12 @@ import type {
3
3
  ICompiledStep,
4
4
  IJobLease,
5
5
  IOciJobLease,
6
- IOciRunnerJob,
7
6
  IRunnerCapabilities,
8
7
  ITransferLimits,
9
8
  TCompiledRunnerJob,
10
9
  TImageReference,
11
10
  TJsonObject,
12
11
  TJsonValue,
13
- TLeaseFeature,
14
12
  } from './interfaces.js';
15
13
  import { acceptSpecVersion, runnerSpecVersion } from './spec-version.js';
16
14
  import { isRecord } from './validation.js';
@@ -169,9 +167,6 @@ const requireCapabilityFit = (
169
167
  if (!capabilities.executionProfiles.includes(requirements.executionProfile)) {
170
168
  throw new ProtocolError('Job execution profile is not supported by this runner');
171
169
  }
172
- if (!capabilities.isolation.includes(requirements.isolation)) {
173
- throw new ProtocolError('Job isolation is not supported by this runner');
174
- }
175
170
  if (requirements.platform !== undefined) {
176
171
  if (!capabilities.platforms.includes(requirements.platform)) {
177
172
  throw new ProtocolError('Job platform is not executed natively by this runner');
@@ -192,9 +187,6 @@ const requireCapabilityFit = (
192
187
  if (!capabilities.networks.includes(job.network.mode)) {
193
188
  throw new ProtocolError('Job network mode is not supported by this runner');
194
189
  }
195
- if (!capabilities.sourceFormats.includes(job.source.format)) {
196
- throw new ProtocolError('Job source format is not supported by this runner');
197
- }
198
190
  for (const name of transferLimitNames) {
199
191
  if (requirements.limits[name] > capabilities.limits[name]) {
200
192
  throw new ProtocolError(`Job requirement ${name} exceeds runner capability`);
@@ -222,28 +214,6 @@ const requireCapabilityFit = (
222
214
  }
223
215
  };
224
216
 
225
- /**
226
- * Checks that a lease uses only the lease features of the capability snapshot: a pull grant
227
- * requires `image-pull-grants`, a binding `candidate-bindings`, and `npmGrants`
228
- * `npm-read-grants`. A snapshot without `leaseFeatures` imposes no such condition.
229
- */
230
- const requireLeaseFeatureFit = (lease: IJobLease, capabilities: IRunnerCapabilities): void => {
231
- const advertised = capabilities.leaseFeatures;
232
- if (advertised === undefined) return;
233
- const used: Array<[boolean, TLeaseFeature]> = [
234
- [lease.grants.some((grant) => grant.access === 'pull'), 'image-pull-grants'],
235
- [lease.bindings.length > 0, 'candidate-bindings'],
236
- [lease.npmGrants !== undefined, 'npm-read-grants'],
237
- ];
238
- for (const [uses, feature] of used) {
239
- if (uses && !advertised.includes(feature)) {
240
- throw new ProtocolError(
241
- `Lease uses ${feature}, a lease feature this runner does not advertise`,
242
- );
243
- }
244
- }
245
- };
246
-
247
217
  const requireTransferCoherence = (job: TCompiledRunnerJob): void => {
248
218
  const limits = job.requirements.limits;
249
219
  if (!job.requirements.features.includes('source.tar-gz')) {
@@ -464,34 +434,36 @@ const requireLeaseCoherence = (lease: IJobLease): void => {
464
434
  };
465
435
 
466
436
  /**
467
- * Narrows a coherent lease to the one shape this runner executes and refuses every other shape:
468
- * the `vm` and `oci-image` profiles, `microvm` isolation, egress networking, candidate images and
469
- * image grants, and npm read grants.
437
+ * Narrows a coherent lease to an executable Firecracker microVM lease (`oci`, `vm`, or
438
+ * `oci-image`).
470
439
  */
471
440
  export const requireExecutableLease = (lease: IJobLease): IOciJobLease => {
472
441
  const job = lease.job;
473
- if (job.requirements.executionProfile !== 'oci' || !hasSteps(job)) {
442
+ if (job.requirements.platform && !job.requirements.platform.startsWith('linux/')) {
474
443
  throw new UnsupportedJobError(
475
- `Execution profile ${job.requirements.executionProfile} is not supported by this runner`,
444
+ `Platform ${job.requirements.platform} is not supported by this Linux Firecracker runner`,
476
445
  );
477
446
  }
478
- if (job.execution.profile !== 'oci') {
479
- throw new UnsupportedJobError('Job execution does not match the oci profile');
480
- }
481
- if (job.requirements.isolation !== 'container') {
482
- throw new UnsupportedJobError('microvm isolation is not supported by this runner');
483
- }
484
- if (job.network.mode !== 'none') {
485
- throw new UnsupportedJobError('egress networking is not enforced by this runner');
486
- }
487
- if (typeof job.execution.image !== 'string' || lease.bindings.length > 0) {
488
- throw new UnsupportedJobError('Candidate image bindings are not supported by this runner');
489
- }
490
- if (lease.grants.length > 0) {
491
- throw new UnsupportedJobError('Image grants are not supported by this runner');
492
- }
493
- if (job.npmRead !== undefined || lease.npmGrants !== undefined) {
494
- throw new UnsupportedJobError('npm read grants are not delivered by this runner');
447
+ const profile = job.requirements.executionProfile;
448
+ if (profile === 'oci') {
449
+ if (!hasSteps(job) || job.execution.profile !== 'oci') {
450
+ throw new UnsupportedJobError('Job execution does not match the oci profile');
451
+ }
452
+ } else if (profile === 'vm') {
453
+ if (!hasSteps(job) || job.execution.profile !== 'vm') {
454
+ throw new UnsupportedJobError('Job execution does not match the vm profile');
455
+ }
456
+ } else if (profile === 'oci-image') {
457
+ if (!('build' in job)) {
458
+ throw new UnsupportedJobError('Job does not match the oci-image build profile');
459
+ }
460
+ if (job.caches.length > 0) {
461
+ throw new UnsupportedJobError('oci-image build caches are not supported by this runner');
462
+ }
463
+ } else {
464
+ throw new UnsupportedJobError(
465
+ `Execution profile ${String(profile)} is not supported by this runner`,
466
+ );
495
467
  }
496
468
  return {
497
469
  jobId: lease.jobId,
@@ -499,9 +471,10 @@ export const requireExecutableLease = (lease: IJobLease): IOciJobLease => {
499
471
  leaseId: lease.leaseId,
500
472
  fencingToken: lease.fencingToken,
501
473
  leaseExpiresAt: lease.leaseExpiresAt,
502
- job: job as IOciRunnerJob,
503
- grants: [],
504
- bindings: [],
474
+ job: job as IOciJobLease['job'],
475
+ grants: lease.grants,
476
+ bindings: lease.bindings,
477
+ ...(lease.npmGrants !== undefined ? { npmGrants: lease.npmGrants } : {}),
505
478
  };
506
479
  };
507
480
 
@@ -546,8 +519,7 @@ export class RunnerProtocolValidator {
546
519
  }
547
520
 
548
521
  /**
549
- * Validates a lease against the published `JobLease` schema, its job, lease coherence, and the
550
- * lease features of the capability snapshot.
522
+ * Validates a lease against the published `JobLease` schema, its job, and lease coherence.
551
523
  */
552
524
  public async validateJobLease(leaseUnknown: unknown): Promise<IJobLease> {
553
525
  if (!isRecord(leaseUnknown)) throw new ProtocolError('Invalid job lease');
@@ -555,7 +527,6 @@ export class RunnerProtocolValidator {
555
527
  const job = await this.validateJob(jobUnknown);
556
528
  const lease = validateWireMessage<IJobLease>('JobLease', { ...envelope, job });
557
529
  requireLeaseCoherence(lease);
558
- requireLeaseFeatureFit(lease, this.capabilities);
559
530
  return lease;
560
531
  }
561
532
 
package/ts/runner.ts CHANGED
@@ -19,6 +19,7 @@ import type {
19
19
  ICompleteJobRequest,
20
20
  ICompleteJobResponse,
21
21
  IDiscoveryResponse,
22
+ IImageRecord,
22
23
  IJobExecutor,
23
24
  IJobHeartbeatRequest,
24
25
  IJobHeartbeatResponse,
@@ -30,6 +31,7 @@ import type {
30
31
  IPreparedOciLease,
31
32
  IPreparedWorkspace,
32
33
  IProtocolLimits,
34
+ IRecordImageRequest,
33
35
  IRecoverAttemptRequest,
34
36
  IRunnerCapabilities,
35
37
  IRunnerConfig,
@@ -66,6 +68,7 @@ export interface IRunnerCoordinatorClient {
66
68
  signal?: AbortSignal,
67
69
  ): Promise<IJobHeartbeatResponse>;
68
70
  appendLog(chunk: ILogChunk, signal?: AbortSignal): Promise<ILogAcknowledgement>;
71
+ recordImage?(request: IRecordImageRequest, signal?: AbortSignal): Promise<IImageRecord>;
69
72
  completeJob(request: ICompleteJobRequest, signal?: AbortSignal): Promise<ICompleteJobResponse>;
70
73
  abandonJob(request: IAbandonJobRequest, signal?: AbortSignal): Promise<void>;
71
74
  recoverAttempt(request: IRecoverAttemptRequest, signal?: AbortSignal): Promise<void>;
@@ -210,22 +213,22 @@ class LeaseGuard {
210
213
  }
211
214
 
212
215
  /**
213
- * The capabilities this runner advertises: the `oci` profile in `container` isolation on the
214
- * native linux platform of its verified OCI engine, the `none` network mode, the configured
215
- * transfer limits, the resource ceilings it enforces per attempt, no lease features (it uses no
216
- * image grants, candidate bindings, or npm read grants), and its configured longest job timeout.
216
+ * The capabilities this unified Firecracker microVM runner advertises:
217
+ * - Always advertises `oci` and `vm`; adds `oci-image` whenever `builderRootfsPath` or
218
+ * `builderImage` is configured so one runner handles every profile in disposable microVMs.
217
219
  */
218
220
  export const runnerCapabilities = (
219
221
  config: IRunnerConfig,
220
222
  runtime: Pick<IOciRuntimeFacts, 'os' | 'architecture'>,
221
223
  ): IRunnerCapabilities => {
222
- const artifactEnabled = config.maximumArtifacts > 0 && config.maximumArtifactBytes > 0 &&
223
- config.maximumArtifactExtractedBytes > 0 && config.maximumArtifactEntries > 0;
224
+ const hasBuilder = Boolean(config.oci.builderRootfsPath || config.oci.builderImage);
225
+ const artifactEnabled = config.maximumArtifacts > 0 &&
226
+ config.maximumArtifactBytes > 0 && config.maximumArtifactExtractedBytes > 0 &&
227
+ config.maximumArtifactEntries > 0;
224
228
  const cacheEnabled = config.maximumCaches > 0 && config.maximumCacheArchiveBytes > 0 &&
225
229
  config.maximumCacheExtractedBytes > 0 && config.maximumCacheEntries > 0;
226
230
  return createRunnerCapabilitySnapshot({
227
- executionProfiles: ['oci'],
228
- isolation: ['container'],
231
+ executionProfiles: hasBuilder ? ['oci', 'vm', 'oci-image'] : ['oci', 'vm'],
229
232
  platforms: [`${runtime.os}/${runtime.architecture}`],
230
233
  labels: [...config.labels],
231
234
  features: [
@@ -234,7 +237,6 @@ export const runnerCapabilities = (
234
237
  ...(cacheEnabled ? ['caches' as const] : []),
235
238
  ],
236
239
  networks: [...config.oci.allowedNetworks],
237
- sourceFormats: ['tar.gz'],
238
240
  limits: {
239
241
  maximumSourceArchiveBytes: config.maximumSourceArchiveBytes,
240
242
  maximumSourceExtractedBytes: config.maximumSourceExtractedBytes,
@@ -258,7 +260,6 @@ export const runnerCapabilities = (
258
260
  maximumPids: config.oci.maximumPids,
259
261
  maximumSharedMemoryBytes: config.oci.maximumSharedMemoryBytes,
260
262
  },
261
- leaseFeatures: [],
262
263
  maximumTimeoutMs: config.oci.maximumTimeoutMs,
263
264
  });
264
265
  };
@@ -376,7 +377,6 @@ export class ShipRunner {
376
377
  lastResult = await this.runOnce(
377
378
  runnerId,
378
379
  session.sessionId,
379
- capabilities,
380
380
  validator,
381
381
  discovery.limits,
382
382
  journal,
@@ -436,7 +436,6 @@ export class ShipRunner {
436
436
  private async runOnce(
437
437
  runnerId: string,
438
438
  sessionId: string,
439
- capabilities: IRunnerCapabilities,
440
439
  validator: RunnerProtocolValidator,
441
440
  protocolLimits: IProtocolLimits,
442
441
  journal: AttemptStateStore,
@@ -447,7 +446,6 @@ export class ShipRunner {
447
446
  claimRequestId: plugins.crypto.randomUUID(),
448
447
  runnerId,
449
448
  sessionId,
450
- capabilities,
451
449
  }, runnerSignal);
452
450
  const claimElapsedMs = Math.max(0, this.now() - claimStartedAt);
453
451
  if (claim.lease === null) {
@@ -712,14 +710,18 @@ export class ShipRunner {
712
710
  recordFailure(error);
713
711
  };
714
712
 
713
+ const isImageBuild = lease.job.requirements.executionProfile === 'oci-image';
714
+ const hasArtifacts = !isImageBuild && 'artifacts' in lease.job && lease.job.artifacts.length > 0;
715
+ const hasStepCaches = !isImageBuild && lease.job.caches.length > 0;
716
+
715
717
  const deadlineTimer = setTimeout(() => {
716
718
  if (!executionAbort.signal.aborted) executionAbort.abort('job_timeout');
717
719
  }, Math.max(0, lease.job.timeoutMs - (this.monotonicNow() - acceptedAt)));
718
720
  try {
719
- if (lease.job.artifacts.length > 0 && !this.dependencies.artifactManager) {
721
+ if (hasArtifacts && !this.dependencies.artifactManager) {
720
722
  throw new RunnerError('Artifact manager is not configured');
721
723
  }
722
- if (lease.job.caches.length > 0 && !this.dependencies.cacheManager) {
724
+ if (hasStepCaches && !this.dependencies.cacheManager) {
723
725
  throw new RunnerError('Cache manager is not configured');
724
726
  }
725
727
  stagingWorkspace = await this.dependencies.workspaceManager.prepare({
@@ -727,7 +729,7 @@ export class ShipRunner {
727
729
  job: lease.job,
728
730
  signal: executionSignal,
729
731
  });
730
- if (lease.job.caches.length > 0) {
732
+ if (hasStepCaches && 'steps' in lease.job) {
731
733
  await this.dependencies.cacheManager!.restore({
732
734
  workspacePath: stagingWorkspace.path,
733
735
  workspaceEntryCount: stagingWorkspace.materializedEntryCount,
@@ -751,9 +753,34 @@ export class ShipRunner {
751
753
  onLog: (stream, data) => logs.write(stream, data),
752
754
  });
753
755
  runtimeWorkspace = result.workspace;
754
- exitCode = result.exitCode;
755
- status = this.completionStatus(result.stopReason, result.exitCode, heartbeatState);
756
- if (status !== 'succeeded' && status !== 'failed') exitCode = null;
756
+ if (isImageBuild) {
757
+ exitCode = null;
758
+ if (result.stopReason) {
759
+ status = this.completionStatus(result.stopReason, null, heartbeatState);
760
+ } else if (result.producedImage) {
761
+ if (!this.dependencies.api.recordImage) {
762
+ throw new RunnerError('Coordinator API client does not implement recordImage');
763
+ }
764
+ await this.dependencies.api.recordImage(
765
+ {
766
+ recordRequestId: plugins.crypto.randomUUID(),
767
+ identity,
768
+ manifestDigest: result.producedImage.manifestDigest,
769
+ mediaType: result.producedImage.mediaType,
770
+ sizeBytes: result.producedImage.sizeBytes,
771
+ platform: result.producedImage.platform,
772
+ },
773
+ executionSignal,
774
+ );
775
+ status = 'succeeded';
776
+ } else {
777
+ status = 'failed';
778
+ }
779
+ } else {
780
+ exitCode = result.exitCode;
781
+ status = this.completionStatus(result.stopReason, result.exitCode, heartbeatState);
782
+ if (status !== 'succeeded' && status !== 'failed') exitCode = null;
783
+ }
757
784
  } catch (error) {
758
785
  if (error instanceof ResourceCleanupError) recordCleanupFailure(error);
759
786
  else if (
@@ -798,7 +825,7 @@ export class ShipRunner {
798
825
  }
799
826
 
800
827
  if (runtimeWorkspace && !cleanupFailure && !transferSignal.aborted) {
801
- if (lease.job.caches.length > 0) {
828
+ if (hasStepCaches && 'steps' in lease.job) {
802
829
  try {
803
830
  await this.dependencies.cacheManager!.save({
804
831
  workspace: runtimeWorkspace,
@@ -814,7 +841,7 @@ export class ShipRunner {
814
841
  }
815
842
  }
816
843
  if (
817
- lease.job.artifacts.length > 0 && !cleanupFailure &&
844
+ hasArtifacts && 'steps' in lease.job && !cleanupFailure &&
818
845
  !transferSignal.aborted
819
846
  ) {
820
847
  try {
package/ts/state-owner.ts CHANGED
@@ -71,7 +71,14 @@ export const resolvePackagedWorkspaceHelperPath = async (
71
71
  `This executable embeds only the ${embeddedTarget} workspace helper, not ${target}`,
72
72
  );
73
73
  }
74
- return await plugins.smartsea.getSidecarPath(workspaceHelperSidecarName);
74
+ return await plugins.smartsea.getSidecarPath(workspaceHelperSidecarName).catch((error) => {
75
+ throw new RunnerError(
76
+ `The embedded ${embeddedTarget} workspace helper is unavailable: ${
77
+ error instanceof Error ? error.message : String(error)
78
+ }`,
79
+ { cause: error },
80
+ );
81
+ });
75
82
  }
76
83
  return plugins.url.fileURLToPath(
77
84
  new URL(`../dist_rust/runnerworkspace_${target}_musl`, import.meta.url),