@ship.zone/runner 2.1.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.
- package/.smartconfig.json +99 -2
- package/changelog.md +58 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl +0 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.json +679 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl.third-party-notices.txt +15719 -0
- package/dist_rust/runnerworkspace_linux_amd64_musl.tsrust-build.json +5 -5
- package/dist_rust/runnerworkspace_linux_arm64_musl +0 -0
- package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.json +679 -0
- package/dist_rust/runnerworkspace_linux_arm64_musl.third-party-notices.txt +15719 -0
- package/dist_rust/runnerworkspace_linux_arm64_musl.tsrust-build.json +5 -5
- package/dist_ts/00_commitinfo_data.d.ts +8 -0
- package/dist_ts/00_commitinfo_data.js +9 -0
- package/dist_ts/api-client.d.ts +46 -0
- package/dist_ts/api-client.js +592 -0
- package/dist_ts/artifact-manager.d.ts +11 -0
- package/dist_ts/artifact-manager.js +140 -0
- package/dist_ts/attempt-state.d.ts +18 -0
- package/dist_ts/attempt-state.js +151 -0
- package/dist_ts/cache-manager.d.ts +13 -0
- package/dist_ts/cache-manager.js +300 -0
- package/dist_ts/cli-entry.d.ts +2 -0
- package/dist_ts/cli-entry.js +4 -0
- package/dist_ts/cli.d.ts +14 -0
- package/dist_ts/cli.js +215 -0
- package/dist_ts/config.d.ts +8 -0
- package/dist_ts/config.js +445 -0
- package/dist_ts/errors.d.ts +41 -0
- package/dist_ts/errors.js +90 -0
- package/dist_ts/filesystem.d.ts +73 -0
- package/dist_ts/filesystem.js +207 -0
- package/dist_ts/index.d.ts +16 -0
- package/dist_ts/index.js +17 -0
- package/dist_ts/interfaces.d.ts +614 -0
- package/dist_ts/interfaces.js +3 -0
- package/dist_ts/log-sender.d.ts +26 -0
- package/dist_ts/log-sender.js +124 -0
- package/dist_ts/oci-executor.d.ts +155 -0
- package/dist_ts/oci-executor.js +2238 -0
- package/dist_ts/plugins.d.ts +19 -0
- package/dist_ts/plugins.js +23 -0
- package/dist_ts/protocol-validator.d.ts +39 -0
- package/dist_ts/protocol-validator.js +483 -0
- package/dist_ts/redactor.d.ts +78 -0
- package/dist_ts/redactor.js +235 -0
- package/dist_ts/registration-state.d.ts +16 -0
- package/dist_ts/registration-state.js +171 -0
- package/dist_ts/runner.d.ts +64 -0
- package/dist_ts/runner.js +882 -0
- package/dist_ts/source-workspace.d.ts +10 -0
- package/dist_ts/source-workspace.js +125 -0
- package/dist_ts/spec-version.d.ts +11 -0
- package/dist_ts/spec-version.js +41 -0
- package/dist_ts/staging-scavenger.d.ts +7 -0
- package/dist_ts/staging-scavenger.js +63 -0
- package/dist_ts/state-owner.d.ts +74 -0
- package/dist_ts/state-owner.js +289 -0
- package/dist_ts/transfer-archive.d.ts +78 -0
- package/dist_ts/transfer-archive.js +1619 -0
- package/dist_ts/validation.d.ts +11 -0
- package/dist_ts/validation.js +79 -0
- package/dist_ts/wire-schema.d.ts +10 -0
- package/dist_ts/wire-schema.js +114 -0
- package/native-notices/crates/bitflags-2.13.1/license-apache +201 -0
- package/native-notices/crates/bitflags-2.13.1/license-mit +25 -0
- package/native-notices/crates/cc-1.8.0/license-apache +201 -0
- package/native-notices/crates/cc-1.8.0/license-mit +25 -0
- package/native-notices/crates/cfg-if-1.0.4/license-apache +201 -0
- package/native-notices/crates/cfg-if-1.0.4/license-mit +25 -0
- package/native-notices/crates/cfg_aliases-0.2.2/license +9 -0
- package/native-notices/crates/cfg_aliases-0.2.2/notices.md +26 -0
- package/native-notices/crates/find-msvc-tools-0.1.14/license-apache +201 -0
- package/native-notices/crates/find-msvc-tools-0.1.14/license-mit +25 -0
- package/native-notices/crates/itoa-1.0.18/license-apache +176 -0
- package/native-notices/crates/itoa-1.0.18/license-mit +23 -0
- package/native-notices/crates/libc-0.2.189/license-apache +176 -0
- package/native-notices/crates/libc-0.2.189/license-mit +25 -0
- package/native-notices/crates/memchr-2.8.3/copying +3 -0
- package/native-notices/crates/memchr-2.8.3/license-mit +21 -0
- package/native-notices/crates/memchr-2.8.3/unlicense +24 -0
- package/native-notices/crates/nix-0.30.1/license +21 -0
- package/native-notices/crates/proc-macro2-1.0.107/license-apache +176 -0
- package/native-notices/crates/proc-macro2-1.0.107/license-mit +23 -0
- package/native-notices/crates/quote-1.0.47/license-apache +176 -0
- package/native-notices/crates/quote-1.0.47/license-mit +23 -0
- package/native-notices/crates/serde-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_core-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde_core-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_derive-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde_derive-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_json-1.0.151/license-apache +176 -0
- package/native-notices/crates/serde_json-1.0.151/license-mit +23 -0
- package/native-notices/crates/shlex-2.0.1/license-apache +13 -0
- package/native-notices/crates/shlex-2.0.1/license-mit +21 -0
- package/native-notices/crates/syn-3.0.3/license-apache +176 -0
- package/native-notices/crates/syn-3.0.3/license-mit +23 -0
- package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-apache +201 -0
- package/native-notices/crates/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/license-mit +25 -0
- package/native-notices/crates/tikv-jemallocator-0.7.0/license-apache +201 -0
- package/native-notices/crates/tikv-jemallocator-0.7.0/license-mit +25 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-apache +176 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-mit +23 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-unicode +39 -0
- package/native-notices/crates/zmij-1.0.23/license-mit +23 -0
- package/native-notices/manifest.json +763 -0
- package/native-notices/native/tikv-jemalloc-sys-0.7.1+5.3.1-0-g81034ce1f1373e37dc865038e1bc8eeecf559ce8/jemalloc-5.3.1/jemalloc-copying +27 -0
- package/native-notices/readme.md +46 -0
- package/native-notices/runtime/gcc/gpl-3.0.txt +674 -0
- package/native-notices/runtime/gcc/runtime-library-exception-3.1.txt +73 -0
- package/native-notices/runtime/libunwind-22.1.2/license.txt +311 -0
- package/native-notices/runtime/musl-1.2.5/copyright +193 -0
- package/native-notices/rust/compiler-builtins-license.txt +275 -0
- package/native-notices/rust/copyright-library.html +8266 -0
- package/native-notices/rust/crates/addr2line-0.25.1/license-apache +201 -0
- package/native-notices/rust/crates/addr2line-0.25.1/license-mit +25 -0
- package/native-notices/rust/crates/adler2-2.0.1/license-0bsd +12 -0
- package/native-notices/rust/crates/adler2-2.0.1/license-apache +201 -0
- package/native-notices/rust/crates/adler2-2.0.1/license-mit +23 -0
- package/native-notices/rust/crates/memchr-2.7.6/copying +3 -0
- package/native-notices/rust/crates/memchr-2.7.6/license-mit +21 -0
- package/native-notices/rust/crates/memchr-2.7.6/unlicense +24 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license +25 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license-apache.md +177 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license-mit.md +24 -0
- package/native-notices/rust/crates/miniz_oxide-0.8.9/license-zlib.md +14 -0
- package/native-notices/rust/crates/object-0.37.3/license-apache +201 -0
- package/native-notices/rust/crates/object-0.37.3/license-mit +25 -0
- package/native-notices/rust/licenses/apache-2.0.txt +73 -0
- package/native-notices/rust/licenses/bsd-2-clause.txt +9 -0
- package/native-notices/rust/licenses/cc-by-sa-4.0.txt +427 -0
- package/native-notices/rust/licenses/gcc-exception-3.1.txt +30 -0
- package/native-notices/rust/licenses/gpl-2.0-only.txt +133 -0
- package/native-notices/rust/licenses/gpl-3.0-or-later.txt +202 -0
- package/native-notices/rust/licenses/isc.txt +7 -0
- package/native-notices/rust/licenses/llvm-exception.txt +15 -0
- package/native-notices/rust/licenses/mit.txt +9 -0
- package/native-notices/rust/licenses/ncsa.txt +29 -0
- package/native-notices/rust/licenses/ofl-1.1.txt +43 -0
- package/native-notices/rust/licenses/unicode-3.0.txt +39 -0
- package/package.json +24 -22
- package/readme.md +91 -40
- package/rust/.cargo/config.toml +1 -1
- package/rust/Cargo.toml +1 -1
- package/rust/src/lib.rs +156 -1
- package/rust/src/main.rs +1 -1
- package/rust-toolchain.toml +4 -0
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/api-client.ts +10 -7
- package/ts/artifact-manager.ts +9 -7
- package/ts/attempt-state.ts +75 -84
- package/ts/cache-manager.ts +22 -28
- package/ts/cli-entry.ts +4 -0
- package/ts/cli.ts +56 -45
- package/ts/config.ts +50 -39
- package/ts/errors.ts +19 -0
- package/ts/filesystem.ts +316 -0
- package/ts/index.ts +16 -15
- package/ts/interfaces.ts +2 -2
- package/ts/log-sender.ts +4 -4
- package/ts/oci-executor.ts +235 -383
- package/ts/plugins.ts +21 -3
- package/ts/protocol-validator.ts +5 -5
- package/ts/redactor.ts +2 -2
- package/ts/registration-state.ts +82 -90
- package/ts/runner.ts +30 -17
- package/ts/source-workspace.ts +11 -8
- package/ts/spec-version.ts +2 -2
- package/ts/staging-scavenger.ts +37 -26
- package/ts/state-owner.ts +346 -0
- package/ts/transfer-archive.ts +214 -243
- package/ts/validation.ts +1 -1
- package/ts/wire-schema.ts +3 -3
- package/deno.json +0 -56
- package/deno.lock +0 -1495
- package/dist_npm/mod.d.ts +0 -967
- package/dist_npm/mod.js +0 -10058
- package/mod.ts +0 -8
- package/musl-copyright.md +0 -81
- package/third-party-licenses.md +0 -187
package/ts/attempt-state.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { RunnerError } from './errors.
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { RunnerError } from './errors.js';
|
|
3
|
+
import {
|
|
4
|
+
createNewWriteFlags,
|
|
5
|
+
isNotFound,
|
|
6
|
+
readInto,
|
|
7
|
+
removePath,
|
|
8
|
+
sameFileIdentity,
|
|
9
|
+
syncDirectory,
|
|
10
|
+
withOpenFile,
|
|
11
|
+
writeAll,
|
|
12
|
+
} from './filesystem.js';
|
|
13
|
+
import { ensurePrivateStateDirectory, type RunnerStateOwner } from './state-owner.js';
|
|
14
|
+
|
|
15
|
+
const { join } = plugins.path;
|
|
3
16
|
|
|
4
17
|
export interface IAttemptJournal {
|
|
5
18
|
previousSessionId: string;
|
|
@@ -38,29 +51,20 @@ const validateJournal = (value: unknown): IAttemptJournal => {
|
|
|
38
51
|
};
|
|
39
52
|
};
|
|
40
53
|
|
|
41
|
-
const writeAll = async (file: Deno.FsFile, bytes: Uint8Array): Promise<void> => {
|
|
42
|
-
let offset = 0;
|
|
43
|
-
while (offset < bytes.byteLength) {
|
|
44
|
-
const written = await file.write(bytes.subarray(offset));
|
|
45
|
-
if (written <= 0) throw new RunnerError('Attempt journal write made no progress');
|
|
46
|
-
offset += written;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const isNotFound = (error: unknown): boolean => error instanceof Deno.errors.NotFound;
|
|
51
|
-
|
|
52
54
|
export class AttemptStateStore {
|
|
53
55
|
readonly path: string;
|
|
56
|
+
private readonly stateDirectory: string;
|
|
54
57
|
|
|
55
|
-
constructor(private readonly
|
|
56
|
-
this.
|
|
58
|
+
constructor(private readonly owner: RunnerStateOwner) {
|
|
59
|
+
this.stateDirectory = owner.stateDirectory;
|
|
60
|
+
this.path = join(this.stateDirectory, journalName);
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
async load(): Promise<IAttemptJournal | undefined> {
|
|
60
64
|
await this.ensureDirectory();
|
|
61
|
-
let pathStat:
|
|
65
|
+
let pathStat: plugins.Stats;
|
|
62
66
|
try {
|
|
63
|
-
pathStat = await
|
|
67
|
+
pathStat = await plugins.fs.lstat(this.path);
|
|
64
68
|
} catch (error) {
|
|
65
69
|
if (isNotFound(error)) return undefined;
|
|
66
70
|
throw error;
|
|
@@ -69,73 +73,71 @@ export class AttemptStateStore {
|
|
|
69
73
|
if (pathStat.size > maximumJournalBytes) {
|
|
70
74
|
throw new RunnerError('Attempt journal exceeds its size limit');
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
76
|
+
return await withOpenFile(
|
|
77
|
+
this.path,
|
|
78
|
+
'r',
|
|
79
|
+
undefined,
|
|
80
|
+
async (file) => {
|
|
81
|
+
const openStat = await file.stat();
|
|
82
|
+
if (!openStat.isFile() || !sameFileIdentity(pathStat, openStat)) {
|
|
83
|
+
throw new RunnerError('Attempt journal changed while it was opened');
|
|
84
|
+
}
|
|
85
|
+
const bytes = new Uint8Array(pathStat.size + 1);
|
|
86
|
+
let offset = 0;
|
|
87
|
+
while (offset < bytes.byteLength) {
|
|
88
|
+
const read = await readInto(file, bytes.subarray(offset));
|
|
89
|
+
if (read === null) break;
|
|
90
|
+
offset += read;
|
|
91
|
+
}
|
|
92
|
+
if (offset !== pathStat.size) {
|
|
93
|
+
throw new RunnerError('Attempt journal changed while it was read');
|
|
94
|
+
}
|
|
95
|
+
let parsed: unknown;
|
|
96
|
+
try {
|
|
97
|
+
parsed = JSON.parse(new TextDecoder().decode(bytes.subarray(0, offset)));
|
|
98
|
+
} catch (error) {
|
|
99
|
+
throw new RunnerError('Attempt journal is not valid JSON', { cause: error });
|
|
100
|
+
}
|
|
101
|
+
return validateJournal(parsed);
|
|
102
|
+
},
|
|
103
|
+
'Attempt journal read and close failed',
|
|
104
|
+
);
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
async save(journal: IAttemptJournal): Promise<void> {
|
|
105
108
|
const validated = validateJournal(journal);
|
|
106
109
|
await this.ensureDirectory();
|
|
107
110
|
try {
|
|
108
|
-
this.assertSafeJournalFile(await
|
|
111
|
+
this.assertSafeJournalFile(await plugins.fs.lstat(this.path));
|
|
109
112
|
} catch (error) {
|
|
110
113
|
if (!isNotFound(error)) throw error;
|
|
111
114
|
}
|
|
112
115
|
const temporaryPath = join(
|
|
113
116
|
this.stateDirectory,
|
|
114
|
-
`.${crypto.randomUUID()}.attempt-journal.tmp`,
|
|
117
|
+
`.${plugins.crypto.randomUUID()}.attempt-journal.tmp`,
|
|
115
118
|
);
|
|
116
119
|
const bytes = new TextEncoder().encode(`${JSON.stringify(validated)}\n`);
|
|
117
120
|
if (bytes.byteLength > maximumJournalBytes) {
|
|
118
121
|
throw new RunnerError('Attempt journal exceeds its size limit');
|
|
119
122
|
}
|
|
120
|
-
let file: Deno.FsFile | undefined;
|
|
121
123
|
try {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
await
|
|
133
|
-
await
|
|
124
|
+
await withOpenFile(
|
|
125
|
+
temporaryPath,
|
|
126
|
+
createNewWriteFlags,
|
|
127
|
+
0o600,
|
|
128
|
+
async (file) => {
|
|
129
|
+
await writeAll(file, bytes, 'Attempt journal write made no progress');
|
|
130
|
+
await file.sync();
|
|
131
|
+
},
|
|
132
|
+
'Attempt journal write and close failed',
|
|
133
|
+
);
|
|
134
|
+
await plugins.fs.chmod(temporaryPath, 0o600);
|
|
135
|
+
await plugins.fs.rename(temporaryPath, this.path);
|
|
136
|
+
await plugins.fs.chmod(this.path, 0o600);
|
|
134
137
|
await this.syncDirectory();
|
|
135
138
|
} catch (error) {
|
|
136
|
-
file?.close();
|
|
137
139
|
try {
|
|
138
|
-
await
|
|
140
|
+
await removePath(temporaryPath);
|
|
139
141
|
} catch (cleanupError) {
|
|
140
142
|
if (!isNotFound(cleanupError)) {
|
|
141
143
|
throw new AggregateError([error, cleanupError], 'Attempt journal write cleanup failed');
|
|
@@ -147,44 +149,33 @@ export class AttemptStateStore {
|
|
|
147
149
|
|
|
148
150
|
async clear(): Promise<void> {
|
|
149
151
|
await this.ensureDirectory();
|
|
150
|
-
let stat:
|
|
152
|
+
let stat: plugins.Stats;
|
|
151
153
|
try {
|
|
152
|
-
stat = await
|
|
154
|
+
stat = await plugins.fs.lstat(this.path);
|
|
153
155
|
} catch (error) {
|
|
154
156
|
if (isNotFound(error)) return;
|
|
155
157
|
throw error;
|
|
156
158
|
}
|
|
157
159
|
this.assertSafeJournalFile(stat);
|
|
158
|
-
await
|
|
160
|
+
await removePath(this.path);
|
|
159
161
|
await this.syncDirectory();
|
|
160
162
|
}
|
|
161
163
|
|
|
162
164
|
private async ensureDirectory(): Promise<void> {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (!stat.isDirectory || stat.isSymlink) {
|
|
166
|
-
throw new RunnerError('Runner state directory must be a real directory');
|
|
167
|
-
}
|
|
168
|
-
if (Deno.build.os !== 'windows' && stat.mode !== null && (stat.mode & 0o077) !== 0) {
|
|
169
|
-
throw new RunnerError('Runner state directory permissions are not private');
|
|
170
|
-
}
|
|
165
|
+
this.owner.assertHeld();
|
|
166
|
+
await ensurePrivateStateDirectory(this.stateDirectory);
|
|
171
167
|
}
|
|
172
168
|
|
|
173
|
-
private assertSafeJournalFile(stat:
|
|
174
|
-
if (!stat.isFile || stat.
|
|
169
|
+
private assertSafeJournalFile(stat: plugins.Stats): void {
|
|
170
|
+
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
175
171
|
throw new RunnerError('Attempt journal must be a regular file');
|
|
176
172
|
}
|
|
177
|
-
if (
|
|
173
|
+
if ((stat.mode & 0o777) !== 0o600) {
|
|
178
174
|
throw new RunnerError('Attempt journal permissions must be 0600');
|
|
179
175
|
}
|
|
180
176
|
}
|
|
181
177
|
|
|
182
178
|
private async syncDirectory(): Promise<void> {
|
|
183
|
-
|
|
184
|
-
try {
|
|
185
|
-
await directory.sync();
|
|
186
|
-
} finally {
|
|
187
|
-
directory.close();
|
|
188
|
-
}
|
|
179
|
+
await syncDirectory(this.stateDirectory, 'Runner state directory sync and close failed');
|
|
189
180
|
}
|
|
190
181
|
}
|
package/ts/cache-manager.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { lstatIfPresent, makeTempDir, removePath } from './filesystem.js';
|
|
3
|
+
import { ProtocolError, ResourceCleanupError, RunnerError } from './errors.js';
|
|
3
4
|
import type {
|
|
4
5
|
ICacheDeclaration,
|
|
5
6
|
ICacheManager,
|
|
@@ -11,7 +12,7 @@ import type {
|
|
|
11
12
|
ITransferRecord,
|
|
12
13
|
TCacheDownload,
|
|
13
14
|
TOpenTransferBody,
|
|
14
|
-
} from './interfaces.
|
|
15
|
+
} from './interfaces.js';
|
|
15
16
|
import {
|
|
16
17
|
createTarGzipArchive,
|
|
17
18
|
ensureStagingCapacity,
|
|
@@ -20,7 +21,9 @@ import {
|
|
|
20
21
|
stageTransferDownload,
|
|
21
22
|
validateRelativeSelections,
|
|
22
23
|
validateTransferRecord,
|
|
23
|
-
} from './transfer-archive.
|
|
24
|
+
} from './transfer-archive.js';
|
|
25
|
+
|
|
26
|
+
const { dirname, join, resolve } = plugins.path;
|
|
24
27
|
|
|
25
28
|
export interface ICacheApiClient {
|
|
26
29
|
downloadCache(
|
|
@@ -143,15 +146,6 @@ const validateCaches = (
|
|
|
143
146
|
return limits;
|
|
144
147
|
};
|
|
145
148
|
|
|
146
|
-
const lstatIfPresent = async (path: string): Promise<Deno.FileInfo | undefined> => {
|
|
147
|
-
try {
|
|
148
|
-
return await Deno.lstat(path);
|
|
149
|
-
} catch (error) {
|
|
150
|
-
if (error instanceof Deno.errors.NotFound) return undefined;
|
|
151
|
-
throw error;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
|
|
155
149
|
const assertSafeDestinationParents = async (workspacePath: string, path: string): Promise<void> => {
|
|
156
150
|
let current = resolve(workspacePath);
|
|
157
151
|
const segments = path.split('/');
|
|
@@ -159,7 +153,7 @@ const assertSafeDestinationParents = async (workspacePath: string, path: string)
|
|
|
159
153
|
current = join(current, segments[index]);
|
|
160
154
|
const stat = await lstatIfPresent(current);
|
|
161
155
|
if (!stat) return;
|
|
162
|
-
if (!stat.isDirectory || stat.
|
|
156
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
163
157
|
throw new RunnerError('Cache destination has an unsafe ancestor');
|
|
164
158
|
}
|
|
165
159
|
}
|
|
@@ -182,14 +176,14 @@ const restoreSelectedPaths = async (
|
|
|
182
176
|
await assertSafeDestinationParents(workspacePath, path);
|
|
183
177
|
const destination = join(resolve(workspacePath), ...path.split('/'));
|
|
184
178
|
const destinationStat = await lstatIfPresent(destination);
|
|
185
|
-
if (destinationStat?.
|
|
179
|
+
if (destinationStat?.isSymbolicLink()) {
|
|
186
180
|
throw new RunnerError('Cache destination is a symbolic link');
|
|
187
181
|
}
|
|
188
182
|
candidates.push({ source, destination, existed: destinationStat !== undefined });
|
|
189
183
|
}
|
|
190
184
|
|
|
191
185
|
const workspaceRoot = resolve(workspacePath);
|
|
192
|
-
const backupRoot = await
|
|
186
|
+
const backupRoot = await makeTempDir({
|
|
193
187
|
dir: dirname(workspaceRoot),
|
|
194
188
|
prefix: '.cache-restore-',
|
|
195
189
|
});
|
|
@@ -200,15 +194,15 @@ const restoreSelectedPaths = async (
|
|
|
200
194
|
const candidate = candidates[index];
|
|
201
195
|
if (!candidate.existed) continue;
|
|
202
196
|
const backup = join(backupRoot, String(index));
|
|
203
|
-
await
|
|
197
|
+
await plugins.fs.rename(candidate.destination, backup);
|
|
204
198
|
backedUp.push({ backup, destination: candidate.destination });
|
|
205
199
|
}
|
|
206
200
|
for (const candidate of candidates) {
|
|
207
|
-
await
|
|
208
|
-
await
|
|
201
|
+
await plugins.fs.mkdir(dirname(candidate.destination), { recursive: true, mode: 0o700 });
|
|
202
|
+
await plugins.fs.rename(candidate.source, candidate.destination);
|
|
209
203
|
installed.push(candidate.destination);
|
|
210
204
|
}
|
|
211
|
-
await
|
|
205
|
+
await removePath(backupRoot, { recursive: true });
|
|
212
206
|
} catch (error) {
|
|
213
207
|
const errors = [error];
|
|
214
208
|
for (const destination of installed.reverse()) {
|
|
@@ -220,8 +214,8 @@ const restoreSelectedPaths = async (
|
|
|
220
214
|
}
|
|
221
215
|
for (const entry of backedUp.reverse()) {
|
|
222
216
|
try {
|
|
223
|
-
await
|
|
224
|
-
await
|
|
217
|
+
await plugins.fs.mkdir(dirname(entry.destination), { recursive: true, mode: 0o700 });
|
|
218
|
+
await plugins.fs.rename(entry.backup, entry.destination);
|
|
225
219
|
} catch (rollbackError) {
|
|
226
220
|
errors.push(rollbackError);
|
|
227
221
|
}
|
|
@@ -316,12 +310,12 @@ export class CacheManager implements ICacheManager {
|
|
|
316
310
|
let restorePath: string | undefined;
|
|
317
311
|
let primaryError: unknown;
|
|
318
312
|
try {
|
|
319
|
-
await
|
|
320
|
-
restorePath = await
|
|
313
|
+
await plugins.fs.mkdir(restoreRoot, { recursive: true, mode: 0o700 });
|
|
314
|
+
restorePath = await makeTempDir({
|
|
321
315
|
dir: restoreRoot,
|
|
322
316
|
prefix: 'cache-',
|
|
323
317
|
});
|
|
324
|
-
await
|
|
318
|
+
await plugins.fs.chmod(restorePath, 0o700);
|
|
325
319
|
const extracted = await extractTarGzipArchive({
|
|
326
320
|
archivePath: staged.path,
|
|
327
321
|
destinationPath: restorePath,
|
|
@@ -368,7 +362,7 @@ export class CacheManager implements ICacheManager {
|
|
|
368
362
|
for (const cache of context.job.caches) {
|
|
369
363
|
if (cache.access !== 'read-write') continue;
|
|
370
364
|
if (context.signal.aborted) throw context.signal.reason;
|
|
371
|
-
await
|
|
365
|
+
await plugins.fs.mkdir(this.config.stateDirectory, { recursive: true, mode: 0o700 });
|
|
372
366
|
await ensureStagingCapacity(
|
|
373
367
|
this.config.stateDirectory,
|
|
374
368
|
cache.maximumExtractedBytes,
|
|
@@ -387,7 +381,7 @@ export class CacheManager implements ICacheManager {
|
|
|
387
381
|
signal: context.signal,
|
|
388
382
|
});
|
|
389
383
|
const archiveRoot = join(this.config.stateDirectory, 'cache-uploads');
|
|
390
|
-
await
|
|
384
|
+
await plugins.fs.mkdir(archiveRoot, { recursive: true, mode: 0o700 });
|
|
391
385
|
await ensureStagingCapacity(
|
|
392
386
|
archiveRoot,
|
|
393
387
|
cache.maximumBytes,
|
|
@@ -408,7 +402,7 @@ export class CacheManager implements ICacheManager {
|
|
|
408
402
|
redactionSet: context.redactionSet,
|
|
409
403
|
signal: context.signal,
|
|
410
404
|
});
|
|
411
|
-
const transferRequestId = crypto.randomUUID();
|
|
405
|
+
const transferRequestId = plugins.crypto.randomUUID();
|
|
412
406
|
const record = await this.api.uploadCache(
|
|
413
407
|
context.identity,
|
|
414
408
|
cache.name,
|
package/ts/cli-entry.ts
ADDED
package/ts/cli.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RunnerApiClient } from './api-client.
|
|
2
|
-
import { ArtifactManager } from './artifact-manager.
|
|
3
|
-
import { CacheManager } from './cache-manager.
|
|
1
|
+
import { RunnerApiClient } from './api-client.js';
|
|
2
|
+
import { ArtifactManager } from './artifact-manager.js';
|
|
3
|
+
import { CacheManager } from './cache-manager.js';
|
|
4
4
|
import {
|
|
5
5
|
defaultRunnerConfig,
|
|
6
6
|
loadRunnerConfig,
|
|
@@ -8,27 +8,28 @@ import {
|
|
|
8
8
|
saveRunnerConfig,
|
|
9
9
|
validateRunnerConfig,
|
|
10
10
|
withRunnerCredential,
|
|
11
|
-
} from './config.
|
|
12
|
-
import { ConfigurationError } from './errors.
|
|
11
|
+
} from './config.js';
|
|
12
|
+
import { ConfigurationError } from './errors.js';
|
|
13
13
|
import type {
|
|
14
14
|
IRegisterRunnerRequest,
|
|
15
15
|
IRegisterRunnerResponse,
|
|
16
16
|
IRunnerCapabilities,
|
|
17
17
|
IRunnerConfig,
|
|
18
|
-
} from './interfaces.
|
|
19
|
-
import { runnerVersion } from './interfaces.
|
|
20
|
-
import { OciExecutor } from './oci-executor.
|
|
21
|
-
import { RegistrationStateStore } from './registration-state.
|
|
22
|
-
import { reconcileProtocolLimits, runnerCapabilities, ShipRunner } from './runner.
|
|
23
|
-
import { runnerSpecVersion } from './spec-version.
|
|
24
|
-
import { SourceWorkspaceManager } from './source-workspace.
|
|
18
|
+
} from './interfaces.js';
|
|
19
|
+
import { runnerVersion } from './interfaces.js';
|
|
20
|
+
import { OciExecutor } from './oci-executor.js';
|
|
21
|
+
import { RegistrationStateStore } from './registration-state.js';
|
|
22
|
+
import { reconcileProtocolLimits, runnerCapabilities, ShipRunner } from './runner.js';
|
|
23
|
+
import { runnerSpecVersion } from './spec-version.js';
|
|
24
|
+
import { SourceWorkspaceManager } from './source-workspace.js';
|
|
25
|
+
import { RunnerStateOwner } from './state-owner.js';
|
|
25
26
|
|
|
26
27
|
interface IParsedArguments {
|
|
27
28
|
command: string;
|
|
28
29
|
options: Map<string, string | true>;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
const cliInvocation = '
|
|
32
|
+
const cliInvocation = 'ship-zone-runner';
|
|
32
33
|
|
|
33
34
|
const usage = `ship.zone runner ${runnerVersion}
|
|
34
35
|
|
|
@@ -38,7 +39,7 @@ Usage:
|
|
|
38
39
|
${cliInvocation} run [--config <path>]
|
|
39
40
|
${cliInvocation} once [--config <path>]
|
|
40
41
|
${cliInvocation} config [--config <path>]
|
|
41
|
-
${cliInvocation} version
|
|
42
|
+
${cliInvocation} version | --version
|
|
42
43
|
|
|
43
44
|
Bootstrap credentials must be supplied through SHIP_RUNNER_BOOTSTRAP_TOKEN or the
|
|
44
45
|
0600 config file. Secret values are intentionally not accepted as command arguments.
|
|
@@ -73,7 +74,7 @@ const stringOption = (
|
|
|
73
74
|
};
|
|
74
75
|
|
|
75
76
|
const configPath = (options: Map<string, string | true>): string =>
|
|
76
|
-
stringOption(options, 'config') ??
|
|
77
|
+
stringOption(options, 'config') ?? process.env.SHIP_RUNNER_CONFIG ?? './runner.config.json';
|
|
77
78
|
|
|
78
79
|
const apiFor = (config: IRunnerConfig): RunnerApiClient =>
|
|
79
80
|
new RunnerApiClient({
|
|
@@ -97,15 +98,14 @@ export const registerRunnerDurably = async (options: {
|
|
|
97
98
|
bootstrapToken: string,
|
|
98
99
|
): Promise<IRegisterRunnerResponse>;
|
|
99
100
|
};
|
|
100
|
-
stateStore
|
|
101
|
+
stateStore: RegistrationStateStore;
|
|
101
102
|
createRequestId?: () => string;
|
|
102
103
|
persistConfig?: (path: string, config: IRunnerConfig) => Promise<void>;
|
|
103
104
|
}): Promise<IRunnerConfig> => {
|
|
104
105
|
if (!options.config.bootstrapToken) {
|
|
105
106
|
throw new ConfigurationError('SHIP_RUNNER_BOOTSTRAP_TOKEN is required for registration');
|
|
106
107
|
}
|
|
107
|
-
const stateStore = options.stateStore
|
|
108
|
-
new RegistrationStateStore(options.config.stateDirectory);
|
|
108
|
+
const stateStore = options.stateStore;
|
|
109
109
|
const request = await stateStore.loadOrCreate({
|
|
110
110
|
spec: runnerSpecVersion,
|
|
111
111
|
runnerVersion,
|
|
@@ -147,44 +147,53 @@ const runRegister = async (options: Map<string, string | true>): Promise<void> =
|
|
|
147
147
|
if (!config.bootstrapToken) {
|
|
148
148
|
throw new ConfigurationError('SHIP_RUNNER_BOOTSTRAP_TOKEN is required for registration');
|
|
149
149
|
}
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
150
|
+
const stateOwner = await acquireStateOwner(config);
|
|
151
|
+
try {
|
|
152
|
+
const api = apiFor(config);
|
|
153
|
+
const executor = new OciExecutor(config, stateOwner);
|
|
154
|
+
const runtime = await executor.verifyRuntime();
|
|
155
|
+
const discovery = await api.discover();
|
|
156
|
+
const capabilities = runnerCapabilities(config, runtime);
|
|
157
|
+
reconcileProtocolLimits(config, discovery, capabilities);
|
|
158
|
+
const registered = await registerRunnerDurably({
|
|
159
|
+
configPath: path,
|
|
160
|
+
config,
|
|
161
|
+
capabilities,
|
|
162
|
+
api,
|
|
163
|
+
stateStore: new RegistrationStateStore(stateOwner),
|
|
164
|
+
});
|
|
165
|
+
console.log(`Registered runner ${registered.runnerId}`);
|
|
166
|
+
} finally {
|
|
167
|
+
await stateOwner.release();
|
|
168
|
+
}
|
|
163
169
|
};
|
|
164
170
|
|
|
171
|
+
/** Takes the exclusive lock of the configured state directory before anything else uses it. */
|
|
172
|
+
const acquireStateOwner = async (config: IRunnerConfig): Promise<RunnerStateOwner> =>
|
|
173
|
+
await RunnerStateOwner.acquire({
|
|
174
|
+
stateDirectory: config.stateDirectory,
|
|
175
|
+
...(config.oci.workspaceHelperPath
|
|
176
|
+
? { helperSourcePath: config.oci.workspaceHelperPath }
|
|
177
|
+
: {}),
|
|
178
|
+
});
|
|
179
|
+
|
|
165
180
|
const runDaemon = async (
|
|
166
181
|
options: Map<string, string | true>,
|
|
167
182
|
once: boolean,
|
|
168
183
|
): Promise<void> => {
|
|
169
184
|
const path = configPath(options);
|
|
170
185
|
let config = await loadRunnerConfig(path);
|
|
171
|
-
const
|
|
172
|
-
const executor = new OciExecutor(config);
|
|
173
|
-
await executor.verifyRuntime();
|
|
186
|
+
const stateOwner = await acquireStateOwner(config);
|
|
174
187
|
const shutdown = new AbortController();
|
|
175
188
|
const shutdownListener = (): void => shutdown.abort('runner_shutdown');
|
|
176
|
-
const
|
|
177
|
-
for (const signal of
|
|
178
|
-
try {
|
|
179
|
-
Deno.addSignalListener(signal, shutdownListener);
|
|
180
|
-
installedSignals.push(signal);
|
|
181
|
-
} catch {
|
|
182
|
-
// Signal listeners are unavailable on some supported hosts.
|
|
183
|
-
}
|
|
184
|
-
}
|
|
189
|
+
const signals = ['SIGINT', 'SIGTERM'] as const;
|
|
190
|
+
for (const signal of signals) process.on(signal, shutdownListener);
|
|
185
191
|
try {
|
|
192
|
+
const api = apiFor(config);
|
|
193
|
+
const executor = new OciExecutor(config, stateOwner);
|
|
186
194
|
const reportMessage = (message: string): void => console.error(message);
|
|
187
195
|
const runner = new ShipRunner(config, {
|
|
196
|
+
stateOwner,
|
|
188
197
|
api,
|
|
189
198
|
executor,
|
|
190
199
|
workspaceManager: new SourceWorkspaceManager(config, api),
|
|
@@ -200,7 +209,8 @@ const runDaemon = async (
|
|
|
200
209
|
const result = await runner.run({ once, signal: shutdown.signal });
|
|
201
210
|
if (once) console.log(result.claimed ? `Job ${result.status}` : 'No job available');
|
|
202
211
|
} finally {
|
|
203
|
-
for (const signal of
|
|
212
|
+
for (const signal of signals) process.off(signal, shutdownListener);
|
|
213
|
+
await stateOwner.release();
|
|
204
214
|
}
|
|
205
215
|
};
|
|
206
216
|
|
|
@@ -226,6 +236,7 @@ export const runCli = async (arguments_: string[]): Promise<void> => {
|
|
|
226
236
|
break;
|
|
227
237
|
}
|
|
228
238
|
case 'version':
|
|
239
|
+
case '--version':
|
|
229
240
|
console.log(runnerVersion);
|
|
230
241
|
break;
|
|
231
242
|
case 'help':
|
|
@@ -238,6 +249,6 @@ export const runCli = async (arguments_: string[]): Promise<void> => {
|
|
|
238
249
|
}
|
|
239
250
|
} catch (error) {
|
|
240
251
|
console.error(error instanceof Error ? error.message : 'Runner failed');
|
|
241
|
-
|
|
252
|
+
process.exitCode = 1;
|
|
242
253
|
}
|
|
243
254
|
};
|