@ship.zone/runner 2.0.0 → 3.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 (180) hide show
  1. package/.smartconfig.json +101 -3
  2. package/changelog.md +69 -0
  3. package/dist_rust/runnerworkspace_linux_amd64_musl +0 -0
  4. package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.json +679 -0
  5. package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.txt +15719 -0
  6. package/dist_rust/runnerworkspace_linux_amd64_musl.tsrust-build.json +5 -5
  7. package/dist_rust/runnerworkspace_linux_arm64_musl +0 -0
  8. package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.json +679 -0
  9. package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.txt +15719 -0
  10. package/dist_rust/runnerworkspace_linux_arm64_musl.tsrust-build.json +5 -5
  11. package/dist_ts/00_commitinfo_data.d.ts +8 -0
  12. package/dist_ts/00_commitinfo_data.js +9 -0
  13. package/dist_ts/api-client.d.ts +46 -0
  14. package/dist_ts/api-client.js +592 -0
  15. package/dist_ts/artifact-manager.d.ts +11 -0
  16. package/dist_ts/artifact-manager.js +140 -0
  17. package/dist_ts/attempt-state.d.ts +18 -0
  18. package/dist_ts/attempt-state.js +151 -0
  19. package/dist_ts/cache-manager.d.ts +13 -0
  20. package/dist_ts/cache-manager.js +300 -0
  21. package/dist_ts/cli-entry.d.ts +2 -0
  22. package/dist_ts/cli-entry.js +4 -0
  23. package/dist_ts/cli.d.ts +14 -0
  24. package/dist_ts/cli.js +215 -0
  25. package/dist_ts/config.d.ts +8 -0
  26. package/dist_ts/config.js +445 -0
  27. package/dist_ts/errors.d.ts +41 -0
  28. package/dist_ts/errors.js +90 -0
  29. package/dist_ts/filesystem.d.ts +73 -0
  30. package/dist_ts/filesystem.js +207 -0
  31. package/dist_ts/index.d.ts +16 -0
  32. package/dist_ts/index.js +17 -0
  33. package/dist_ts/interfaces.d.ts +614 -0
  34. package/dist_ts/interfaces.js +3 -0
  35. package/dist_ts/log-sender.d.ts +26 -0
  36. package/dist_ts/log-sender.js +124 -0
  37. package/dist_ts/oci-executor.d.ts +155 -0
  38. package/dist_ts/oci-executor.js +2238 -0
  39. package/dist_ts/plugins.d.ts +19 -0
  40. package/dist_ts/plugins.js +23 -0
  41. package/dist_ts/protocol-validator.d.ts +39 -0
  42. package/dist_ts/protocol-validator.js +483 -0
  43. package/dist_ts/redactor.d.ts +78 -0
  44. package/dist_ts/redactor.js +235 -0
  45. package/dist_ts/registration-state.d.ts +16 -0
  46. package/dist_ts/registration-state.js +171 -0
  47. package/dist_ts/runner.d.ts +64 -0
  48. package/dist_ts/runner.js +882 -0
  49. package/dist_ts/source-workspace.d.ts +10 -0
  50. package/dist_ts/source-workspace.js +125 -0
  51. package/dist_ts/spec-version.d.ts +11 -0
  52. package/dist_ts/spec-version.js +41 -0
  53. package/dist_ts/staging-scavenger.d.ts +7 -0
  54. package/dist_ts/staging-scavenger.js +63 -0
  55. package/dist_ts/state-owner.d.ts +74 -0
  56. package/dist_ts/state-owner.js +289 -0
  57. package/dist_ts/transfer-archive.d.ts +78 -0
  58. package/dist_ts/transfer-archive.js +1619 -0
  59. package/dist_ts/validation.d.ts +11 -0
  60. package/dist_ts/validation.js +79 -0
  61. package/dist_ts/wire-schema.d.ts +10 -0
  62. package/dist_ts/wire-schema.js +114 -0
  63. package/native-notices/crates/bitflags-2.13.1/license-apache +201 -0
  64. package/native-notices/crates/bitflags-2.13.1/license-mit +25 -0
  65. package/native-notices/crates/cc-1.8.0/license-apache +201 -0
  66. package/native-notices/crates/cc-1.8.0/license-mit +25 -0
  67. package/native-notices/crates/cfg-if-1.0.4/license-apache +201 -0
  68. package/native-notices/crates/cfg-if-1.0.4/license-mit +25 -0
  69. package/native-notices/crates/cfg_aliases-0.2.2/license +9 -0
  70. package/native-notices/crates/cfg_aliases-0.2.2/notices.md +26 -0
  71. package/native-notices/crates/find-msvc-tools-0.1.14/license-apache +201 -0
  72. package/native-notices/crates/find-msvc-tools-0.1.14/license-mit +25 -0
  73. package/native-notices/crates/itoa-1.0.18/license-apache +176 -0
  74. package/native-notices/crates/itoa-1.0.18/license-mit +23 -0
  75. package/native-notices/crates/libc-0.2.189/license-apache +176 -0
  76. package/native-notices/crates/libc-0.2.189/license-mit +25 -0
  77. package/native-notices/crates/memchr-2.8.3/copying +3 -0
  78. package/native-notices/crates/memchr-2.8.3/license-mit +21 -0
  79. package/native-notices/crates/memchr-2.8.3/unlicense +24 -0
  80. package/native-notices/crates/nix-0.30.1/license +21 -0
  81. package/native-notices/crates/proc-macro2-1.0.107/license-apache +176 -0
  82. package/native-notices/crates/proc-macro2-1.0.107/license-mit +23 -0
  83. package/native-notices/crates/quote-1.0.47/license-apache +176 -0
  84. package/native-notices/crates/quote-1.0.47/license-mit +23 -0
  85. package/native-notices/crates/serde-1.0.229/license-apache +176 -0
  86. package/native-notices/crates/serde-1.0.229/license-mit +23 -0
  87. package/native-notices/crates/serde_core-1.0.229/license-apache +176 -0
  88. package/native-notices/crates/serde_core-1.0.229/license-mit +23 -0
  89. package/native-notices/crates/serde_derive-1.0.229/license-apache +176 -0
  90. package/native-notices/crates/serde_derive-1.0.229/license-mit +23 -0
  91. package/native-notices/crates/serde_json-1.0.151/license-apache +176 -0
  92. package/native-notices/crates/serde_json-1.0.151/license-mit +23 -0
  93. package/native-notices/crates/shlex-2.0.1/license-apache +13 -0
  94. package/native-notices/crates/shlex-2.0.1/license-mit +21 -0
  95. package/native-notices/crates/syn-3.0.3/license-apache +176 -0
  96. package/native-notices/crates/syn-3.0.3/license-mit +23 -0
  97. package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-apache +201 -0
  98. package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-mit +25 -0
  99. package/native-notices/crates/tikv-jemallocator-0.7.0/license-apache +201 -0
  100. package/native-notices/crates/tikv-jemallocator-0.7.0/license-mit +25 -0
  101. package/native-notices/crates/unicode-ident-1.0.24/license-apache +176 -0
  102. package/native-notices/crates/unicode-ident-1.0.24/license-mit +23 -0
  103. package/native-notices/crates/unicode-ident-1.0.24/license-unicode +39 -0
  104. package/native-notices/crates/zmij-1.0.23/license-mit +23 -0
  105. package/native-notices/manifest.json +763 -0
  106. package/native-notices/native/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/jemalloc-5.3.1/jemalloc-copying +27 -0
  107. package/native-notices/readme.md +46 -0
  108. package/native-notices/runtime/gcc/gpl-3.0.txt +674 -0
  109. package/native-notices/runtime/gcc/runtime-library-exception-3.1.txt +73 -0
  110. package/native-notices/runtime/libunwind-22.1.2/license.txt +311 -0
  111. package/native-notices/runtime/musl-1.2.5/copyright +193 -0
  112. package/native-notices/rust/compiler-builtins-license.txt +275 -0
  113. package/native-notices/rust/copyright-library.html +8266 -0
  114. package/native-notices/rust/crates/addr2line-0.25.1/license-apache +201 -0
  115. package/native-notices/rust/crates/addr2line-0.25.1/license-mit +25 -0
  116. package/native-notices/rust/crates/adler2-2.0.1/license-0bsd +12 -0
  117. package/native-notices/rust/crates/adler2-2.0.1/license-apache +201 -0
  118. package/native-notices/rust/crates/adler2-2.0.1/license-mit +23 -0
  119. package/native-notices/rust/crates/memchr-2.7.6/copying +3 -0
  120. package/native-notices/rust/crates/memchr-2.7.6/license-mit +21 -0
  121. package/native-notices/rust/crates/memchr-2.7.6/unlicense +24 -0
  122. package/native-notices/rust/crates/miniz_oxide-0.8.9/license +25 -0
  123. package/native-notices/rust/crates/miniz_oxide-0.8.9/license-apache.md +177 -0
  124. package/native-notices/rust/crates/miniz_oxide-0.8.9/license-mit.md +24 -0
  125. package/native-notices/rust/crates/miniz_oxide-0.8.9/license-zlib.md +14 -0
  126. package/native-notices/rust/crates/object-0.37.3/license-apache +201 -0
  127. package/native-notices/rust/crates/object-0.37.3/license-mit +25 -0
  128. package/native-notices/rust/licenses/apache-2.0.txt +73 -0
  129. package/native-notices/rust/licenses/bsd-2-clause.txt +9 -0
  130. package/native-notices/rust/licenses/cc-by-sa-4.0.txt +427 -0
  131. package/native-notices/rust/licenses/gcc-exception-3.1.txt +30 -0
  132. package/native-notices/rust/licenses/gpl-2.0-only.txt +133 -0
  133. package/native-notices/rust/licenses/gpl-3.0-or-later.txt +202 -0
  134. package/native-notices/rust/licenses/isc.txt +7 -0
  135. package/native-notices/rust/licenses/llvm-exception.txt +15 -0
  136. package/native-notices/rust/licenses/mit.txt +9 -0
  137. package/native-notices/rust/licenses/ncsa.txt +29 -0
  138. package/native-notices/rust/licenses/ofl-1.1.txt +43 -0
  139. package/native-notices/rust/licenses/unicode-3.0.txt +39 -0
  140. package/package.json +24 -21
  141. package/readme.md +91 -40
  142. package/rust/.cargo/config.toml +1 -1
  143. package/rust/Cargo.lock +43 -0
  144. package/rust/Cargo.toml +4 -1
  145. package/rust/src/lib.rs +156 -1
  146. package/rust/src/main.rs +5 -1
  147. package/rust-toolchain.toml +4 -0
  148. package/ts/00_commitinfo_data.ts +1 -1
  149. package/ts/api-client.ts +10 -7
  150. package/ts/artifact-manager.ts +9 -7
  151. package/ts/attempt-state.ts +75 -84
  152. package/ts/cache-manager.ts +22 -28
  153. package/ts/cli-entry.ts +4 -0
  154. package/ts/cli.ts +56 -45
  155. package/ts/config.ts +50 -39
  156. package/ts/errors.ts +19 -0
  157. package/ts/filesystem.ts +316 -0
  158. package/ts/index.ts +16 -15
  159. package/ts/interfaces.ts +2 -2
  160. package/ts/log-sender.ts +4 -4
  161. package/ts/oci-executor.ts +235 -383
  162. package/ts/plugins.ts +21 -3
  163. package/ts/protocol-validator.ts +5 -5
  164. package/ts/redactor.ts +2 -2
  165. package/ts/registration-state.ts +82 -90
  166. package/ts/runner.ts +30 -17
  167. package/ts/source-workspace.ts +11 -8
  168. package/ts/spec-version.ts +2 -2
  169. package/ts/staging-scavenger.ts +37 -26
  170. package/ts/state-owner.ts +346 -0
  171. package/ts/transfer-archive.ts +214 -243
  172. package/ts/validation.ts +1 -1
  173. package/ts/wire-schema.ts +3 -3
  174. package/deno.json +0 -56
  175. package/deno.lock +0 -1762
  176. package/dist_npm/mod.d.ts +0 -967
  177. package/dist_npm/mod.js +0 -10058
  178. package/mod.ts +0 -8
  179. package/musl-copyright.md +0 -81
  180. package/third-party-licenses.md +0 -95
package/readme.md CHANGED
@@ -55,35 +55,54 @@ Requests directly.
55
55
 
56
56
  ## Requirements
57
57
 
58
- - Deno 2
59
- - pnpm 11
58
+ - Linux on x64 or arm64
59
+ - For the npm package: Node.js 26.1 or later; the staging capacity check reads the filesystem
60
+ fragment size, `statfs` `frsize`, which Node.js provides from 26.1 on. The executables embed
61
+ Node.js 26.11.1.
62
+ - pnpm 12
60
63
  - Docker or Podman on Linux
61
64
  - A rootless runtime by default
62
65
  - Rust and configured cross-compilers when building the packaged helpers from source
63
66
 
64
67
  ## Install
65
68
 
66
- Add the published source package to a Deno project:
69
+ Install the `ship-zone-runner` executable on a Linux host:
67
70
 
68
71
  ```sh
69
- deno add npm:@ship.zone/runner
72
+ curl -fsSL https://code.foss.global/ship.zone/runner/releases/download/latest/install.sh | sudo bash
70
73
  ```
71
74
 
72
- Then import the package through the generated import-map name. The npm export resolves to the
73
- prebuilt Deno JavaScript bundle and its rolled-up TypeScript declarations:
75
+ The installer is an asset of every release from 3.0.0 on. It downloads the executable of the newest
76
+ release for the host's architecture (`ship-zone-runner-linux-x64` or `ship-zone-runner-linux-arm64`)
77
+ with its third-party notices, verifies them against the release's `SHA256SUMS.txt`, and runs the
78
+ executable with `--version` before it changes anything. It installs to
79
+ `/opt/ship-zone-runner/ship-zone-runner` and links `/usr/local/bin/ship-zone-runner`. Pass
80
+ `--version vX.Y.Z` for a given release, `--install-dir <dir>` for another directory, or `--dry-run`
81
+ to check the release assets without changing anything:
74
82
 
75
- ```ts
76
- import { ShipRunner } from '@ship.zone/runner';
83
+ ```sh
84
+ curl -fsSL https://code.foss.global/ship.zone/runner/releases/download/latest/install.sh | sudo bash -s -- --version vX.Y.Z
77
85
  ```
78
86
 
79
- Without an import-map entry, use the npm package directly:
87
+ Running it again updates the executable. The installer never touches the runner's configuration
88
+ or state: the runner keeps reading `./runner.config.json` and `./.runner-state` relative to its
89
+ working directory (or the paths `--config`, `SHIP_RUNNER_CONFIG` and `stateDirectory` name). If a
90
+ systemd service named `ship-zone-runner` is running, the installer stops it for the update and
91
+ restarts it with the new version; it does not create a service. Each executable embeds the static workspace
92
+ helper of its architecture, which the runner copies into its private state as described below.
93
+
94
+ Or add the package to a Node.js project:
95
+
96
+ ```sh
97
+ pnpm add @ship.zone/runner
98
+ ```
80
99
 
81
100
  ```ts
82
- import { ShipRunner } from 'npm:@ship.zone/runner';
101
+ import { ShipRunner } from '@ship.zone/runner';
83
102
  ```
84
103
 
85
- For development in this repository, install dependencies and build the npm bundle plus the static
86
- musl-based `linux_amd64` and `linux_arm64` helpers:
104
+ For development in this repository, install dependencies, compile the TypeScript sources to
105
+ `dist_ts/`, and build the static musl-based helper for the host architecture:
87
106
 
88
107
  ```sh
89
108
  pnpm install
@@ -103,13 +122,13 @@ not changed, so package managers may install the source without executable bits.
103
122
  directory is the host access boundary; mode `0755` lets capability-dropped helper containers execute
104
123
  the host-owned read-only bind mount. `IOciRuntimeFacts.helperPath` reports the validated
105
124
  materialized path used by host probes and OCI bind mounts, while `helperSha256` reports its content
106
- digest. A private advisory lock serializes materialization. Existing digest paths are reused only
125
+ digest. Existing digest paths are reused only
107
126
  after their type, single-link status, mode, and digest are revalidated without mutating them; the
108
127
  runner retains a bounded set for rollback, reclaims stale incomplete temporary copies, and rejects
109
128
  excessive recent temporary residue. The sole immediate-recovery exception is a validated temporary
110
129
  name and exact digest destination that still reference the same two-link inode after interruption;
111
- the runner removes the temporary name under the lock, verifies the destination became single-link,
112
- and then reuses it.
130
+ the runner removes the temporary name, verifies the destination became single-link, and then reuses
131
+ it. The advisory `.workspace-helper.lock` file of runner 2.x is no longer used and is removed.
113
132
 
114
133
  Runtime verification creates one private `.runtime-probe-owner_<id>` marker in the helper state.
115
134
  Host tmpfs probes include that owner in their exact directory names, and OCI runtime probe volumes
@@ -117,13 +136,33 @@ carry the same `ship.zone.runner.runtime-probe-owner` label. This lets interrupt
117
136
  cleaned by the same state owner without touching unowned probes or probes from another runner. The
118
137
  runner syncs both the helper-directory entry and a newly created owner marker before using them.
119
138
 
139
+ ## State Directory Ownership
140
+
141
+ One runner owns a state directory at a time; many runners per host are still supported, each with
142
+ its own state directory. Before anything else touches the state directory, the runner starts its
143
+ own static helper as `runnerworkspace own-state <stateDirectory>`, which takes an exclusive kernel
144
+ `flock` on `<stateDirectory>/.runner-owner.lock` (mode `0600`, a single-link regular file owned by
145
+ the runner user). The lock lives exactly as long as that helper process: the helper prints `locked`,
146
+ then waits for end of input on stdin, which the runner closes when it releases the lock or exits, and
147
+ it carries a parent-death signal as a backstop. It ignores `SIGINT`, `SIGTERM`, and `SIGHUP`, so a
148
+ graceful shutdown keeps its ownership until the runner releases it.
149
+
150
+ A second runner on the same state directory is a configuration error: its helper exits at once with
151
+ exit code `3`, and the runner stops with `RunnerStateOwnedElsewhereError` instead of waiting. If the
152
+ helper exits while the runner is still live, ownership is lost and the runner shuts down with
153
+ `RunnerStateOwnershipLostError`.
154
+
155
+ The runner writes the verified helper bytes to a private exclusive mode-`0700` file in the state
156
+ directory, starts it, and removes the file as soon as the lock is held. Within the runner process,
157
+ helper materialization and the runtime probe owner marker run one after another on the owner's
158
+ single in-process chain.
159
+
120
160
  ## Configure And Run
121
161
 
122
162
  Create a private runner configuration:
123
163
 
124
164
  ```sh
125
- deno run --allow-all \
126
- npm:@ship.zone/runner init \
165
+ ship-zone-runner init \
127
166
  --control-plane https://foss.global \
128
167
  --runtime-path /usr/bin/docker
129
168
  ```
@@ -131,21 +170,17 @@ deno run --allow-all \
131
170
  Register with a one-time bootstrap token, then start the daemon:
132
171
 
133
172
  ```sh
134
- SHIP_RUNNER_BOOTSTRAP_TOKEN='<one-time token>' \
135
- deno run --allow-all \
136
- npm:@ship.zone/runner register
137
- deno run --allow-all \
138
- npm:@ship.zone/runner run
173
+ SHIP_RUNNER_BOOTSTRAP_TOKEN='<one-time token>' ship-zone-runner register
174
+ ship-zone-runner run
139
175
  ```
140
176
 
141
- `--allow-all` is required because Deno reserves direct `/dev/shm` access for that mode. The runner
142
- uses `/dev/shm` for fail-closed host tmpfs verification before registration and must already be
177
+ The runner uses `/dev/shm` for fail-closed host tmpfs verification before registration and must be
143
178
  trusted with unrestricted subprocess execution for the configured OCI runtime.
144
179
 
145
180
  Replace `run` with `once` to claim at most one job or `config` to print the effective configuration
146
- with credentials masked. Within this repository, `deno task dev -- <command>` is the equivalent
147
- development invocation. `SHIP_RUNNER_CONFIG` selects a config path; the default is
148
- `./runner.config.json`.
181
+ with credentials masked. Within this repository, `pnpm build` followed by
182
+ `node dist_ts/cli-entry.js <command>` is the equivalent development invocation.
183
+ `SHIP_RUNNER_CONFIG` selects a config path; the default is `./runner.config.json`.
149
184
 
150
185
  `init` writes the config with mode `0600`. Registration verifies the runtime and protocol discovery
151
186
  document before advertising capabilities, durably journals the exact registration request without
@@ -193,10 +228,11 @@ An attempt-scoped inert holder container keeps Docker's local-driver tmpfs mount
193
228
  and helper containers come and go. It runs no image-provided command and is removed with the
194
229
  workspace.
195
230
 
196
- On restart, a new session first removes stale labeled containers and volumes locally, scavenges only
197
- the runner's known host-staging directories and journal temporary files, then reads the secret-free
198
- journal and calls the recovery endpoint to revoke and reconcile the interrupted attempt. Work is
199
- never resumed, and a coordinator outage cannot retain prior staging.
231
+ On restart, the runner first scavenges only its known host-staging directories, journal temporary
232
+ files, and stale private copies of the state owner helper, right after it owns the state directory
233
+ and before it verifies the runtime. A new session then removes stale labeled containers and volumes
234
+ locally, reads the secret-free journal, and calls the recovery endpoint to revoke and reconcile the
235
+ interrupted attempt. Work is never resumed, and a coordinator outage cannot retain prior staging.
200
236
 
201
237
  ## Job Timeout
202
238
 
@@ -294,25 +330,37 @@ import {
294
330
  ```
295
331
 
296
332
  The CLI is the supported complete assembly. Embedded callers must preserve the same runtime
297
- verification, discovery, lifecycle, fencing, cleanup, and credential-persistence ordering.
333
+ verification, discovery, lifecycle, fencing, cleanup, and credential-persistence ordering, and must
334
+ own the state directory first:
335
+
336
+ ```ts
337
+ import { OciExecutor, RunnerStateOwner, ShipRunner } from '@ship.zone/runner';
338
+
339
+ const stateOwner = await RunnerStateOwner.acquire({ stateDirectory: config.stateDirectory });
340
+ try {
341
+ const executor = new OciExecutor(config, stateOwner);
342
+ // new ShipRunner(config, { stateOwner, executor, ... }).run(...)
343
+ } finally {
344
+ await stateOwner.release();
345
+ }
346
+ ```
298
347
 
299
348
  ## Verification
300
349
 
301
350
  ```sh
302
- deno task fmt --check
303
- deno task lint
304
- deno task check
305
- pnpm test
306
351
  pnpm build
352
+ pnpm exec tsbuild check 'test/**/*'
353
+ pnpm test
307
354
  pnpm pack --dry-run
308
355
  ```
309
356
 
357
+ `pnpm test` builds first: the tests take real state ownership with the host helper in `dist_rust/`.
310
358
  The real Docker integration is opt-in and requires a locally available digest-pinned Linux image:
311
359
 
312
360
  ```sh
313
361
  SHIP_RUNNER_OCI_TEST=1 \
314
362
  SHIP_RUNNER_OCI_IMAGE='alpine@sha256:<digest>' \
315
- deno test --allow-all test/oci-executor.test.ts
363
+ pnpm exec tstest test/test.oci-executor.node.ts --verbose
316
364
  ```
317
365
 
318
366
  It verifies direct execution of an imported workspace file, shared multi-step state, helper
@@ -322,9 +370,12 @@ against the real runtime.
322
370
  ## License and Legal Information
323
371
 
324
372
  This repository contains open-source code licensed under the MIT License. A copy of the license can
325
- be found in the [repository license file](./license.md). Dependency notices for the npm bundle and
326
- the packaged static helper binaries are in [third-party-licenses.md](./third-party-licenses.md),
327
- with the complete applicable musl inventory in [musl-copyright.md](./musl-copyright.md).
373
+ be found in the [repository license file](./license.md). The third-party notices of the packaged
374
+ static helpers (Rust crates, jemalloc, the Rust standard library, musl and the other runtime
375
+ libraries) are generated into [native-notices/](./native-notices/readme.md), and every helper in
376
+ `dist_rust/` carries the notices of its target beside it. Every release executable comes with its
377
+ own `<executable>.third-party-notices.txt` and `.json`, which cover Node.js, the bundled JavaScript
378
+ dependencies and the embedded helper.
328
379
 
329
380
  **Please note:** The MIT License does not grant permission to use the trade names, trademarks,
330
381
  service marks, or product names of the project, except as required for reasonable and customary use
@@ -2,4 +2,4 @@
2
2
  linker = "aarch64-linux-gnu-gcc"
3
3
 
4
4
  [target.aarch64-unknown-linux-musl]
5
- linker = "aarch64-linux-gnu-gcc"
5
+ linker = "aarch64-linux-musl-gcc"
package/rust/Cargo.lock CHANGED
@@ -8,6 +8,16 @@ version = "2.13.1"
8
8
  source = "registry+https://github.com/rust-lang/crates.io-index"
9
9
  checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da"
10
10
 
11
+ [[package]]
12
+ name = "cc"
13
+ version = "1.8.0"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "6651c9ed80effdc7db0ff72512157f901af5e3549e341e24b1dd4887d836d838"
16
+ dependencies = [
17
+ "find-msvc-tools",
18
+ "shlex",
19
+ ]
20
+
11
21
  [[package]]
12
22
  name = "cfg-if"
13
23
  version = "1.0.4"
@@ -20,6 +30,12 @@ version = "0.2.2"
20
30
  source = "registry+https://github.com/rust-lang/crates.io-index"
21
31
  checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
22
32
 
33
+ [[package]]
34
+ name = "find-msvc-tools"
35
+ version = "0.1.14"
36
+ source = "registry+https://github.com/rust-lang/crates.io-index"
37
+ checksum = "aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484"
38
+
23
39
  [[package]]
24
40
  name = "itoa"
25
41
  version = "1.0.18"
@@ -75,6 +91,7 @@ dependencies = [
75
91
  "nix",
76
92
  "serde",
77
93
  "serde_json",
94
+ "tikv-jemallocator",
78
95
  ]
79
96
 
80
97
  [[package]]
@@ -120,6 +137,12 @@ dependencies = [
120
137
  "zmij",
121
138
  ]
122
139
 
140
+ [[package]]
141
+ name = "shlex"
142
+ version = "2.0.1"
143
+ source = "registry+https://github.com/rust-lang/crates.io-index"
144
+ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
145
+
123
146
  [[package]]
124
147
  name = "syn"
125
148
  version = "3.0.3"
@@ -131,6 +154,26 @@ dependencies = [
131
154
  "unicode-ident",
132
155
  ]
133
156
 
157
+ [[package]]
158
+ name = "tikv-jemalloc-sys"
159
+ version = "0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8"
160
+ source = "registry+https://github.com/rust-lang/crates.io-index"
161
+ checksum = "1a2825c78386b4ae0314074867860ba9577875de945f05992c38815cbec327f0"
162
+ dependencies = [
163
+ "cc",
164
+ "libc",
165
+ ]
166
+
167
+ [[package]]
168
+ name = "tikv-jemallocator"
169
+ version = "0.7.0"
170
+ source = "registry+https://github.com/rust-lang/crates.io-index"
171
+ checksum = "249f09e49ab1609436f34c776e84231bead18d6a955f119f939bdc1d847561bd"
172
+ dependencies = [
173
+ "libc",
174
+ "tikv-jemalloc-sys",
175
+ ]
176
+
134
177
  [[package]]
135
178
  name = "unicode-ident"
136
179
  version = "1.0.24"
package/rust/Cargo.toml CHANGED
@@ -6,10 +6,13 @@ license = "MIT"
6
6
  publish = false
7
7
 
8
8
  [dependencies]
9
- nix = { version = "0.30.1", default-features = false, features = ["fs", "signal"] }
9
+ nix = { version = "0.30.1", default-features = false, features = ["fs", "process", "signal", "user"] }
10
10
  serde = { version = "1.0.229", features = ["derive"] }
11
11
  serde_json = "1.0.149"
12
12
 
13
+ [target.'cfg(not(target_env = "msvc"))'.dependencies]
14
+ tikv-jemallocator = { version = "0.7.0", features = ["background_threads"] }
15
+
13
16
  [profile.release]
14
17
  strip = true
15
18
  lto = true
package/rust/src/lib.rs CHANGED
@@ -17,6 +17,8 @@ const COPY_BUFFER_SIZE: usize = 64 * 1024;
17
17
  const MAXIMUM_TRAVERSAL_DEPTH: usize = 256;
18
18
  const HOLD_PARK_INTERVAL: Duration = Duration::from_millis(100);
19
19
  const RESERVE_FILE_NAME: &str = ".runnerworkspace-reserve";
20
+ const STATE_OWNER_LOCK_NAME: &str = ".runner-owner.lock";
21
+ const STATE_OWNER_LOCK_MODE: u32 = 0o600;
20
22
  const DESTINATION_CLEANUP_FAILURE: &str = "unable to clean destination after failure";
21
23
  const RESERVE_CLEANUP_FAILURE: &str = "unable to clean volume after reserve failure";
22
24
 
@@ -24,14 +26,33 @@ static HOLD_TERMINATION_REQUESTED: AtomicBool = AtomicBool::new(false);
24
26
 
25
27
  type Result<T> = std::result::Result<T, Error>;
26
28
 
29
+ /// Exit code of `own-state` when another process already holds the runner state lock.
30
+ pub const STATE_OWNED_ELSEWHERE_EXIT_CODE: i32 = 3;
31
+
27
32
  #[derive(Debug, Clone, Copy, Eq, PartialEq)]
28
33
  pub struct Error {
29
34
  message: &'static str,
35
+ exit_code: i32,
30
36
  }
31
37
 
32
38
  impl Error {
33
39
  const fn new(message: &'static str) -> Self {
34
- Self { message }
40
+ Self {
41
+ message,
42
+ exit_code: 1,
43
+ }
44
+ }
45
+
46
+ const fn state_owned_elsewhere() -> Self {
47
+ Self {
48
+ message: "runner state is owned by another process",
49
+ exit_code: STATE_OWNED_ELSEWHERE_EXIT_CODE,
50
+ }
51
+ }
52
+
53
+ /// The process exit code that reports this error.
54
+ pub const fn exit_code(&self) -> i32 {
55
+ self.exit_code
35
56
  }
36
57
  }
37
58
 
@@ -630,10 +651,98 @@ where
630
651
  ownership,
631
652
  )?)
632
653
  }
654
+ "own-state" => {
655
+ let state_directory = PathBuf::from(
656
+ iterator
657
+ .next()
658
+ .ok_or_else(|| Error::new("own-state requires a state directory"))?,
659
+ );
660
+ if iterator.next().is_some() {
661
+ return Err(Error::new("own-state accepts only a state directory"));
662
+ }
663
+ own_state(&state_directory)
664
+ }
633
665
  _ => Err(Error::new("unknown command")),
634
666
  }
635
667
  }
636
668
 
669
+ /// Holds the exclusive runner state lock for the lifetime of the parent runner process.
670
+ ///
671
+ /// The lock is a kernel `flock` on `<state>/.runner-owner.lock`, so it ends with this process.
672
+ /// Once held, `locked` is printed and the helper waits for end of input on stdin, which the runner
673
+ /// closes on release or exit. The parent-death signal is a backstop for a parent that dies
674
+ /// without closing stdin. Interactive and service-manager termination signals are ignored, so
675
+ /// the lock outlives a graceful runner shutdown until the runner releases it.
676
+ fn own_state(state_directory: &Path) -> Result<()> {
677
+ use nix::sys::signal::{self, SigHandler, Signal};
678
+
679
+ let parent = std::os::unix::process::parent_id();
680
+ nix::sys::prctl::set_pdeathsig(Signal::SIGKILL)
681
+ .map_err(|_| Error::new("unable to set the parent-death signal"))?;
682
+ if std::os::unix::process::parent_id() != parent {
683
+ return Err(Error::new("runner exited before the state lock was taken"));
684
+ }
685
+ for ignored in [Signal::SIGINT, Signal::SIGTERM, Signal::SIGHUP] {
686
+ // Ignoring a signal installs no handler code, so no async-signal-safety rule applies.
687
+ unsafe { signal::signal(ignored, SigHandler::SigIgn) }
688
+ .map_err(|_| Error::new("unable to ignore termination signals"))?;
689
+ }
690
+ let lock = lock_state_directory(state_directory)?;
691
+ {
692
+ let stdout = io::stdout();
693
+ let mut output = stdout.lock();
694
+ output
695
+ .write_all(b"locked\n")
696
+ .and_then(|()| output.flush())
697
+ .map_err(|_| Error::new("unable to report the state lock"))?;
698
+ }
699
+ wait_for_end_of_input(io::stdin().lock())?;
700
+ drop(lock);
701
+ Ok(())
702
+ }
703
+
704
+ fn lock_state_directory(state_directory: &Path) -> Result<nix::fcntl::Flock<fs::File>> {
705
+ use nix::fcntl::{Flock, FlockArg};
706
+
707
+ require_absolute(state_directory)?;
708
+ let file = OpenOptions::new()
709
+ .read(true)
710
+ .write(true)
711
+ .create(true)
712
+ .mode(STATE_OWNER_LOCK_MODE)
713
+ .custom_flags(nix::libc::O_CLOEXEC | nix::libc::O_NOFOLLOW)
714
+ .open(state_directory.join(STATE_OWNER_LOCK_NAME))
715
+ .map_err(|_| Error::new("unable to open the runner state lock"))?;
716
+ let metadata = file
717
+ .metadata()
718
+ .map_err(|_| Error::new("unable to inspect the runner state lock"))?;
719
+ if !metadata.file_type().is_file()
720
+ || metadata.nlink() != 1
721
+ || metadata.uid() != nix::unistd::geteuid().as_raw()
722
+ {
723
+ return Err(Error::new(
724
+ "runner state lock must be a single-link regular file owned by the runner",
725
+ ));
726
+ }
727
+ match Flock::lock(file, FlockArg::LockExclusiveNonblock) {
728
+ Ok(lock) => Ok(lock),
729
+ Err((_, nix::errno::Errno::EWOULDBLOCK)) => Err(Error::state_owned_elsewhere()),
730
+ Err(_) => Err(Error::new("unable to lock the runner state")),
731
+ }
732
+ }
733
+
734
+ fn wait_for_end_of_input<R: Read>(mut input: R) -> Result<()> {
735
+ let mut buffer = [0_u8; 64];
736
+ loop {
737
+ match input.read(&mut buffer) {
738
+ Ok(0) => return Ok(()),
739
+ Ok(_) => {}
740
+ Err(error) if error.kind() == io::ErrorKind::Interrupted => {}
741
+ Err(_) => return Err(Error::new("unable to read the state owner input")),
742
+ }
743
+ }
744
+ }
745
+
637
746
  fn emit_json<T: Serialize>(value: &T) -> Result<()> {
638
747
  let stdout = io::stdout();
639
748
  let mut output = stdout.lock();
@@ -1730,6 +1839,52 @@ mod tests {
1730
1839
  assert!(termination_requested.load(Ordering::Relaxed));
1731
1840
  }
1732
1841
 
1842
+ #[test]
1843
+ fn state_lock_is_exclusive_and_released_with_its_holder() {
1844
+ let temporary = TestDirectory::new();
1845
+ let first = lock_state_directory(&temporary.path).expect("first lock");
1846
+ assert_eq!(
1847
+ lock_state_directory(&temporary.path).unwrap_err(),
1848
+ Error::state_owned_elsewhere()
1849
+ );
1850
+ assert_eq!(
1851
+ Error::state_owned_elsewhere().exit_code(),
1852
+ STATE_OWNED_ELSEWHERE_EXIT_CODE
1853
+ );
1854
+ drop(first);
1855
+ let second = lock_state_directory(&temporary.path).expect("lock after release");
1856
+ let metadata = fs::symlink_metadata(temporary.child(STATE_OWNER_LOCK_NAME)).unwrap();
1857
+ assert_eq!(metadata.permissions().mode() & 0o777, STATE_OWNER_LOCK_MODE);
1858
+ drop(second);
1859
+ }
1860
+
1861
+ #[test]
1862
+ fn state_lock_rejects_links_and_relative_directories() {
1863
+ let temporary = TestDirectory::new();
1864
+ let target = temporary.child("target");
1865
+ write_file(&target, b"");
1866
+ std::os::unix::fs::symlink(&target, temporary.child(STATE_OWNER_LOCK_NAME)).unwrap();
1867
+ assert_eq!(
1868
+ lock_state_directory(&temporary.path).unwrap_err(),
1869
+ Error::new("unable to open the runner state lock")
1870
+ );
1871
+ fs::remove_file(temporary.child(STATE_OWNER_LOCK_NAME)).unwrap();
1872
+ fs::hard_link(&target, temporary.child(STATE_OWNER_LOCK_NAME)).unwrap();
1873
+ assert_eq!(
1874
+ lock_state_directory(&temporary.path).unwrap_err(),
1875
+ Error::new("runner state lock must be a single-link regular file owned by the runner")
1876
+ );
1877
+ assert_eq!(
1878
+ lock_state_directory(Path::new("relative")).unwrap_err(),
1879
+ Error::new("root paths must be absolute")
1880
+ );
1881
+ }
1882
+
1883
+ #[test]
1884
+ fn state_owner_waits_for_end_of_input() {
1885
+ wait_for_end_of_input(&b"ignored input"[..]).expect("end of input");
1886
+ }
1887
+
1733
1888
  #[test]
1734
1889
  fn reports_statvfs_values() {
1735
1890
  let temporary = TestDirectory::new();
package/rust/src/main.rs CHANGED
@@ -1,6 +1,10 @@
1
+ #[cfg(not(target_env = "msvc"))]
2
+ #[global_allocator]
3
+ static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
4
+
1
5
  fn main() {
2
6
  if let Err(error) = runnerworkspace::run(std::env::args_os().skip(1)) {
3
7
  eprintln!("runnerworkspace: {error}");
4
- std::process::exit(1);
8
+ std::process::exit(error.exit_code());
5
9
  }
6
10
  }
@@ -0,0 +1,4 @@
1
+ [toolchain]
2
+ channel = "1.95.0"
3
+ components = ["rust-src"]
4
+ targets = ["x86_64-unknown-linux-musl", "aarch64-unknown-linux-musl"]
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@ship.zone/runner',
6
- version: '2.0.0',
6
+ version: '3.0.0',
7
7
  description: 'The isolated OCI job runner for ship.zone CI/CD'
8
8
  }
package/ts/api-client.ts CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  LeaseLostError,
5
5
  ProtocolError,
6
6
  ResourceCleanupError,
7
- } from './errors.ts';
7
+ } from './errors.js';
8
8
  import type {
9
9
  IAbandonJobRequest,
10
10
  IAcceptJobRequest,
@@ -33,14 +33,14 @@ import type {
33
33
  ITransferRecord,
34
34
  TCacheDownload,
35
35
  TOpenTransferBody,
36
- } from './interfaces.ts';
37
- import { runnerProtocolBasePath } from './plugins.ts';
38
- import { runnerSpecVersion, specMajorVersionsMatch } from './spec-version.ts';
39
- import { isProtocolTimestamp, isRecord, validateHttpUrl } from './validation.ts';
40
- import { isValidWireMessage, type TWireSchemaName, validateWireMessage } from './wire-schema.ts';
36
+ } from './interfaces.js';
37
+ import { runnerProtocolBasePath } from './plugins.js';
38
+ import { runnerSpecVersion, specMajorVersionsMatch } from './spec-version.js';
39
+ import { isProtocolTimestamp, isRecord, validateHttpUrl } from './validation.js';
40
+ import { isValidWireMessage, type TWireSchemaName, validateWireMessage } from './wire-schema.js';
41
41
 
42
42
  export type TRunnerFetch = (
43
- input: RequestInfo | URL,
43
+ input: string | URL | Request,
44
44
  init?: RequestInit,
45
45
  ) => Promise<Response>;
46
46
 
@@ -741,6 +741,9 @@ export class RunnerApiClient {
741
741
  method: 'PUT',
742
742
  headers,
743
743
  body,
744
+ // A streamed request body must be sent half-duplex: the request body is written before
745
+ // the response is read.
746
+ duplex: 'half',
744
747
  redirect: 'error',
745
748
  signal: requestSignal,
746
749
  });
@@ -1,11 +1,11 @@
1
- import { join } from '@std/path';
1
+ import * as plugins from './plugins.js';
2
2
  import {
3
3
  AuthenticationError,
4
4
  LeaseLostError,
5
5
  ProtocolError,
6
6
  ResourceCleanupError,
7
7
  SecretDisclosureError,
8
- } from './errors.ts';
8
+ } from './errors.js';
9
9
  import type {
10
10
  IArtifactDeclaration,
11
11
  IArtifactManager,
@@ -15,13 +15,15 @@ import type {
15
15
  ITransferMetadata,
16
16
  ITransferRecord,
17
17
  TOpenTransferBody,
18
- } from './interfaces.ts';
18
+ } from './interfaces.js';
19
19
  import {
20
20
  createTarGzipArchive,
21
21
  ensureStagingCapacity,
22
22
  validateRelativeSelections,
23
23
  validateTransferRecord,
24
- } from './transfer-archive.ts';
24
+ } from './transfer-archive.js';
25
+
26
+ const { join } = plugins.path;
25
27
 
26
28
  export interface IArtifactApiClient {
27
29
  uploadArtifact(
@@ -138,7 +140,7 @@ export class ArtifactManager implements IArtifactManager {
138
140
  let archive: Awaited<ReturnType<typeof createTarGzipArchive>> | undefined;
139
141
  let operationError: unknown;
140
142
  try {
141
- await Deno.mkdir(this.config.stateDirectory, { recursive: true, mode: 0o700 });
143
+ await plugins.fs.mkdir(this.config.stateDirectory, { recursive: true, mode: 0o700 });
142
144
  await ensureStagingCapacity(
143
145
  this.config.stateDirectory,
144
146
  artifact.maximumExtractedBytes,
@@ -153,7 +155,7 @@ export class ArtifactManager implements IArtifactManager {
153
155
  signal: context.signal,
154
156
  });
155
157
  const archiveRoot = join(this.config.stateDirectory, 'artifact-uploads');
156
- await Deno.mkdir(archiveRoot, { recursive: true, mode: 0o700 });
158
+ await plugins.fs.mkdir(archiveRoot, { recursive: true, mode: 0o700 });
157
159
  await ensureStagingCapacity(
158
160
  archiveRoot,
159
161
  artifact.maximumBytes,
@@ -174,7 +176,7 @@ export class ArtifactManager implements IArtifactManager {
174
176
  redactionSet: context.redactionSet,
175
177
  signal: context.signal,
176
178
  });
177
- const transferRequestId = crypto.randomUUID();
179
+ const transferRequestId = plugins.crypto.randomUUID();
178
180
  const record = await this.api.uploadArtifact(
179
181
  context.identity,
180
182
  artifact.name,