@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
@@ -0,0 +1,49 @@
1
+ // The bundle of the single executables inlines package.json; dist_ts and ts read it from the
2
+ // package root.
3
+ import packageJson from '../package.json' with { type: 'json' };
4
+ import { RunnerError } from './errors.js';
5
+
6
+ type TNodeVersion = readonly [major: number, minor: number, patch: number];
7
+
8
+ const releaseVersionPattern = /^(\d+)\.(\d+)\.(\d+)$/;
9
+ const enginesRangePattern = /^>=\s*(\d+\.\d+\.\d+)$/;
10
+
11
+ const parseReleaseVersion = (version: string, label: string): TNodeVersion => {
12
+ const match = releaseVersionPattern.exec(version);
13
+ if (!match) throw new RunnerError(`${label} ${version} is not a major.minor.patch version`);
14
+ return [Number(match[1]), Number(match[2]), Number(match[3])];
15
+ };
16
+
17
+ const isAtLeast = (version: TNodeVersion, minimum: TNodeVersion): boolean => {
18
+ for (let index = 0; index < version.length; index++) {
19
+ if (version[index] !== minimum[index]) return version[index] > minimum[index];
20
+ }
21
+ return true;
22
+ };
23
+
24
+ /**
25
+ * The minimum Node.js version of the runner: `engines.node` of its `package.json`, which must have
26
+ * the form `>=major.minor.patch`.
27
+ */
28
+ export const nodeEnginesMinimum = (): string => {
29
+ const match = enginesRangePattern.exec(packageJson.engines.node);
30
+ if (!match) {
31
+ throw new RunnerError('The runner package.json engines.node must be ">=major.minor.patch"');
32
+ }
33
+ return match[1];
34
+ };
35
+
36
+ /**
37
+ * Refuses a Node.js release older than the `engines.node` minimum before the runner starts: on
38
+ * such a release the runner would fail deep inside, for example because `fs.statfs` does not
39
+ * report the fragment size.
40
+ */
41
+ export const assertSupportedNodeVersion = (nodeVersion: string): void => {
42
+ const minimum = nodeEnginesMinimum();
43
+ const version = parseReleaseVersion(nodeVersion, 'Node.js');
44
+ if (!isAtLeast(version, parseReleaseVersion(minimum, 'The engines.node minimum'))) {
45
+ throw new RunnerError(
46
+ `The runner needs Node.js ${minimum} or later, and this is Node.js ${nodeVersion}`,
47
+ );
48
+ }
49
+ };
@@ -0,0 +1,49 @@
1
+ import { ProtocolError } from './errors.js';
2
+ import type { INpmGrant } from './interfaces.js';
3
+
4
+ /** Fixed guest path where the runner mounts the read-only attempt-scoped npm config file. */
5
+ export const GUEST_NPMRC_PATH = '/run/shipzone-npmrc/npmrc';
6
+
7
+ const ensureTrailingSlash = (value: string): string => (value.endsWith('/') ? value : `${value}/`);
8
+
9
+ /**
10
+ * Renders the attempt-scoped `.npmrc` file from `npmGrants` per `@ship.zone/ci-spec`
11
+ * (npm Read Grants): maps every scope to its registry and binds each attempt-scoped read token
12
+ * without placing the token anywhere else.
13
+ */
14
+ export const buildNpmrcContent = (grants: readonly INpmGrant[]): string => {
15
+ if (grants.length === 0) return '';
16
+ const lines: string[] = [];
17
+ const emittedTokens = new Set<string>();
18
+
19
+ for (const grant of grants) {
20
+ if (grant.secret.includes('\n') || grant.secret.includes('\r')) {
21
+ throw new ProtocolError('npm grant secret must not contain line terminators');
22
+ }
23
+ let parsed: URL;
24
+ try {
25
+ parsed = new URL(grant.registry);
26
+ } catch (error) {
27
+ throw new ProtocolError(`Invalid npm grant registry URL: ${grant.registry}`, { cause: error });
28
+ }
29
+ if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
30
+ throw new ProtocolError(`Unsupported npm grant registry protocol: ${parsed.protocol}`);
31
+ }
32
+ const registryUrl = ensureTrailingSlash(parsed.toString());
33
+ const authKey = `//${parsed.host}${ensureTrailingSlash(parsed.pathname)}:_authToken`;
34
+
35
+ for (const scope of grant.scopes) {
36
+ if (!scope.startsWith('@') || scope.includes('=') || scope.includes('\n') || scope.includes('\r')) {
37
+ throw new ProtocolError(`Invalid npm grant scope: ${scope}`);
38
+ }
39
+ lines.push(`${scope}:registry=${registryUrl}`);
40
+ }
41
+
42
+ if (!emittedTokens.has(authKey)) {
43
+ emittedTokens.add(authKey);
44
+ lines.push(`${authKey}=${grant.secret}`);
45
+ }
46
+ }
47
+
48
+ return `${lines.join('\n')}\n`;
49
+ };