@ship.zone/runner 0.2.4 → 1.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.
@@ -5,8 +5,8 @@ import type {
5
5
  IExecutionContext,
6
6
  IExecutionResult,
7
7
  IJobExecutor,
8
- IJobLease,
9
8
  IOciExecutorConfig,
9
+ IOciJobLease,
10
10
  IOciRuntimeFacts,
11
11
  IPreparedOciLease,
12
12
  IPrepareOciLeaseContext,
@@ -161,7 +161,7 @@ export interface IOciRunCommand {
161
161
  export interface IOciStepCommandInput {
162
162
  runnerId: string;
163
163
  sessionId: string;
164
- lease: IJobLease;
164
+ lease: IOciJobLease;
165
165
  step: ICompiledStep;
166
166
  containerName: string;
167
167
  volumeName: string;
@@ -586,10 +586,18 @@ const validateHostMountPath = (path: string, name: string): string => {
586
586
  return path;
587
587
  };
588
588
 
589
- const validateResources = (
590
- config: IRunnerConfig,
591
- lease: IJobLease,
592
- ): { memoryBytes: number; cpus: number; pids: number } => {
589
+ interface IStepResources {
590
+ memoryBytes: number;
591
+ cpus: number;
592
+ pids: number;
593
+ sharedMemoryBytes: number;
594
+ }
595
+
596
+ /**
597
+ * Resolves the attempt's resource ceilings: the job's declared values, or the runner defaults for
598
+ * omitted values, each bounded by the runner maximum it advertises.
599
+ */
600
+ const validateResources = (config: IRunnerConfig, lease: IOciJobLease): IStepResources => {
593
601
  const bounded = (
594
602
  requested: number | undefined,
595
603
  fallback: number,
@@ -627,9 +635,28 @@ const validateResources = (
627
635
  'PID limit',
628
636
  true,
629
637
  ),
638
+ sharedMemoryBytes: bounded(
639
+ lease.job.resources?.sharedMemoryBytes,
640
+ config.oci.defaultSharedMemoryBytes,
641
+ config.oci.maximumSharedMemoryBytes,
642
+ 'shared memory limit',
643
+ true,
644
+ ),
630
645
  };
631
646
  };
632
647
 
648
+ /**
649
+ * The only network mode this executor enforces: `none` gives every step container a new network
650
+ * namespace whose only interface is loopback, private to that container.
651
+ */
652
+ const requireNoNetwork = (config: IRunnerConfig, lease: IOciJobLease): 'none' => {
653
+ const mode: string = lease.job.network.mode;
654
+ if (mode !== 'none' || !config.oci.allowedNetworks.includes('none')) {
655
+ throw new ProtocolError(`Job network ${mode} is not enforced by this runner`);
656
+ }
657
+ return 'none';
658
+ };
659
+
633
660
  const labels = (
634
661
  runnerId: string,
635
662
  sessionId: string,
@@ -653,7 +680,7 @@ const isolatedContainerArgs = (
653
680
  attemptId: string;
654
681
  containerName: string;
655
682
  user: string;
656
- network: 'none' | 'bridge';
683
+ network: 'none';
657
684
  workdir: string;
658
685
  memoryBytes: number;
659
686
  cpus: number;
@@ -750,11 +777,8 @@ export const buildOciRunCommand = (
750
777
  validateGeneratedName(input.volumeName, 'volume');
751
778
  validateImage(input.lease.job.execution.image);
752
779
  validateStepCommand(input.step.command);
753
- const network = input.lease.job.execution.network;
754
- if (!config.oci.allowedNetworks.includes(network)) {
755
- throw new ProtocolError(`Job network ${network} is not allowed by runner policy`);
756
- }
757
- const resources = validateResources(config, input.lease);
780
+ const network = requireNoNetwork(config, input.lease);
781
+ const { sharedMemoryBytes, ...resources } = validateResources(config, input.lease);
758
782
  const environment = collectStepEnvironment(config, input);
759
783
  const volumeMountOptions = config.oci.runtime === 'docker'
760
784
  ? 'volume-subpath=workspace,volume-nocopy'
@@ -770,6 +794,8 @@ export const buildOciRunCommand = (
770
794
  ...resources,
771
795
  });
772
796
  args.push(
797
+ '--shm-size',
798
+ String(sharedMemoryBytes),
773
799
  '--mount',
774
800
  `type=volume,source=${input.volumeName},target=/workspace,${volumeMountOptions}`,
775
801
  );
@@ -785,11 +811,7 @@ const validateLeasePolicy = (
785
811
  parseContainerUser(config.oci.containerUser);
786
812
  validateImage(context.lease.job.execution.image);
787
813
  validateWorkingDirectory(context.lease.job.execution.workingDirectory);
788
- if (!config.oci.allowedNetworks.includes(context.lease.job.execution.network)) {
789
- throw new ProtocolError(
790
- `Job network ${context.lease.job.execution.network} is not allowed by runner policy`,
791
- );
792
- }
814
+ requireNoNetwork(config, context.lease);
793
815
  if (
794
816
  !Number.isSafeInteger(context.lease.job.timeoutMs) ||
795
817
  context.lease.job.timeoutMs <= 0 ||
@@ -1421,7 +1443,10 @@ export class OciExecutor implements IJobExecutor {
1421
1443
  const activeContainers = new Set<string>();
1422
1444
  const lifetimeContainers = new Set<string>();
1423
1445
  const exportPaths = new Set<string>();
1424
- const deadline = this.now() + context.lease.job.timeoutMs;
1446
+ if (!Number.isSafeInteger(context.timeoutMs) || context.timeoutMs < 0) {
1447
+ throw new RunnerError('Execution requires a non-negative remaining attempt timeout');
1448
+ }
1449
+ const deadline = this.now() + context.timeoutMs;
1425
1450
  let stopReason: TExecutionStopReason | undefined;
1426
1451
  let activeContainer: string | undefined;
1427
1452
  const stopPromises = new Map<string, Promise<void>>();
@@ -1456,7 +1481,7 @@ export class OciExecutor implements IJobExecutor {
1456
1481
  const abortListener = (): void =>
1457
1482
  stopActive(isStopReason(context.signal.reason) ? context.signal.reason : 'runner_shutdown');
1458
1483
  context.signal.addEventListener('abort', abortListener, { once: true });
1459
- const timeout = setTimeout(() => stopActive('job_timeout'), context.lease.job.timeoutMs);
1484
+ const timeout = setTimeout(() => stopActive('job_timeout'), context.timeoutMs);
1460
1485
  const setActive = (name: string | undefined): boolean => {
1461
1486
  activeContainer = name;
1462
1487
  if (name && stopReason) stopActive(stopReason);
@@ -1816,7 +1841,7 @@ export class OciExecutor implements IJobExecutor {
1816
1841
  return this.runtimeFacts;
1817
1842
  }
1818
1843
 
1819
- private validateLeaseIdentity(runnerId: string, sessionId: string, lease: IJobLease): void {
1844
+ private validateLeaseIdentity(runnerId: string, sessionId: string, lease: IOciJobLease): void {
1820
1845
  validateIdentifier(runnerId, 'runnerId');
1821
1846
  validateIdentifier(sessionId, 'sessionId');
1822
1847
  validateIdentifier(lease.jobId, 'jobId');
@@ -2960,7 +2985,8 @@ export class OciExecutor implements IJobExecutor {
2960
2985
  deadline?: () => number | undefined,
2961
2986
  signal?: AbortSignal,
2962
2987
  ): Promise<void> {
2963
- const defaultDeadline = this.now() + this.config.oci.stopTimeoutSeconds * 1000;
2988
+ const stopRequestedAt = this.now();
2989
+ const defaultDeadline = stopRequestedAt + this.config.oci.stopTimeoutSeconds * 1000;
2964
2990
  let forceAt = Number.POSITIVE_INFINITY;
2965
2991
  let forceTimer: ReturnType<typeof setTimeout> | undefined;
2966
2992
  let forcePromise: Promise<void> | undefined;
@@ -2988,7 +3014,7 @@ export class OciExecutor implements IJobExecutor {
2988
3014
  signal?.addEventListener('abort', deadlineChanged, { once: true });
2989
3015
  scheduleForceRemoval();
2990
3016
  if (signal?.aborted) deadlineChanged();
2991
- const remainingMs = Math.max(0, forceAt - this.now());
3017
+ const remainingMs = Math.max(0, forceAt - stopRequestedAt);
2992
3018
  const graceSeconds = Math.max(0, Math.floor(remainingMs / 1000));
2993
3019
  let stopError: unknown;
2994
3020
  try {
package/ts/plugins.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  export {
2
2
  ciSpecStatus,
3
+ ciSpecVersion,
4
+ executionProfileIdentifiers,
3
5
  maximumArchivePathMetadataBytes,
4
6
  runnerProtocolBasePath,
5
- runnerProtocolIdentifier,
6
7
  } from '@foss.global/ci-spec';
7
8
 
8
9
  export const loadCiSpecArchiveCases = async (): Promise<unknown> =>
@@ -13,3 +14,6 @@ export { Ajv2020 };
13
14
 
14
15
  import runnerJobSchema from '@foss.global/ci-spec/runner-job.schema.json' with { type: 'json' };
15
16
  export { runnerJobSchema };
17
+
18
+ import runnerOpenApi from '@foss.global/ci-spec/runner.openapi.json' with { type: 'json' };
19
+ export { runnerOpenApi };