@ship.zone/runner 2.1.0 → 4.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 +118 -3
- package/changelog.md +101 -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 +47 -0
- package/dist_ts/api-client.js +600 -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 +18 -0
- package/dist_ts/cli.d.ts +14 -0
- package/dist_ts/cli.js +243 -0
- package/dist_ts/config.d.ts +8 -0
- package/dist_ts/config.js +495 -0
- package/dist_ts/egress-proxy.d.ts +99 -0
- package/dist_ts/egress-proxy.js +607 -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 +20 -0
- package/dist_ts/index.js +21 -0
- package/dist_ts/interfaces.d.ts +685 -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/microvm-executor.d.ts +90 -0
- package/dist_ts/microvm-executor.js +1045 -0
- package/dist_ts/node-version.d.ts +11 -0
- package/dist_ts/node-version.js +43 -0
- package/dist_ts/npm-grants.d.ts +9 -0
- package/dist_ts/npm-grants.js +44 -0
- package/dist_ts/oci-registry.d.ts +73 -0
- package/dist_ts/oci-registry.js +508 -0
- package/dist_ts/plugins.d.ts +23 -0
- package/dist_ts/plugins.js +27 -0
- package/dist_ts/protocol-validator.d.ts +39 -0
- package/dist_ts/protocol-validator.js +488 -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 +65 -0
- package/dist_ts/runner.js +912 -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 +291 -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/vsock-protocol.d.ts +130 -0
- package/dist_ts/vsock-protocol.js +336 -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 +31 -26
- package/readme.md +157 -95
- package/rust/.cargo/config.toml +1 -1
- package/rust/Cargo.lock +1 -0
- package/rust/Cargo.toml +3 -2
- package/rust/src/cpio.rs +147 -0
- package/rust/src/extfs.rs +747 -0
- package/rust/src/guest.rs +2411 -0
- package/rust/src/lib.rs +197 -1
- package/rust/src/main.rs +7 -2
- package/rust/src/oci_tar.rs +842 -0
- package/rust-toolchain.toml +4 -0
- package/ts/00_commitinfo_data.ts +2 -2
- package/ts/api-client.ts +29 -8
- 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 +17 -0
- package/ts/cli.ts +86 -53
- package/ts/config.ts +146 -62
- package/ts/egress-proxy.ts +649 -0
- package/ts/errors.ts +19 -0
- package/ts/filesystem.ts +316 -0
- package/ts/index.ts +20 -15
- package/ts/interfaces.ts +105 -23
- package/ts/log-sender.ts +4 -4
- package/ts/microvm-executor.ts +1265 -0
- package/ts/node-version.ts +49 -0
- package/ts/npm-grants.ts +49 -0
- package/ts/oci-registry.ts +649 -0
- package/ts/plugins.ts +25 -3
- package/ts/protocol-validator.ts +34 -30
- package/ts/redactor.ts +2 -2
- package/ts/registration-state.ts +82 -90
- package/ts/runner.ts +81 -34
- 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 +353 -0
- package/ts/transfer-archive.ts +214 -243
- package/ts/validation.ts +1 -1
- package/ts/vsock-protocol.ts +437 -0
- 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/oci-executor.ts +0 -3137
package/ts/00_commitinfo_data.ts
CHANGED
package/ts/api-client.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
LeaseLostError,
|
|
5
5
|
ProtocolError,
|
|
6
6
|
ResourceCleanupError,
|
|
7
|
-
} from './errors.
|
|
7
|
+
} from './errors.js';
|
|
8
8
|
import type {
|
|
9
9
|
IAbandonJobRequest,
|
|
10
10
|
IAcceptJobRequest,
|
|
@@ -15,12 +15,14 @@ import type {
|
|
|
15
15
|
ICompleteJobResponse,
|
|
16
16
|
IDiscoveryResponse,
|
|
17
17
|
IErrorResponse,
|
|
18
|
+
IImageRecord,
|
|
18
19
|
IJobHeartbeatRequest,
|
|
19
20
|
IJobHeartbeatResponse,
|
|
20
21
|
IJobIdentity,
|
|
21
22
|
IJobSource,
|
|
22
23
|
ILogAcknowledgement,
|
|
23
24
|
ILogChunk,
|
|
25
|
+
IRecordImageRequest,
|
|
24
26
|
IRecoverAttemptRequest,
|
|
25
27
|
IRegisterRunnerRequest,
|
|
26
28
|
IRegisterRunnerResponse,
|
|
@@ -33,14 +35,14 @@ import type {
|
|
|
33
35
|
ITransferRecord,
|
|
34
36
|
TCacheDownload,
|
|
35
37
|
TOpenTransferBody,
|
|
36
|
-
} from './interfaces.
|
|
37
|
-
import { runnerProtocolBasePath } from './plugins.
|
|
38
|
-
import { runnerSpecVersion, specMajorVersionsMatch } from './spec-version.
|
|
39
|
-
import { isProtocolTimestamp, isRecord, validateHttpUrl } from './validation.
|
|
40
|
-
import { isValidWireMessage, type TWireSchemaName, validateWireMessage } from './wire-schema.
|
|
38
|
+
} from './interfaces.js';
|
|
39
|
+
import { runnerProtocolBasePath } from './plugins.js';
|
|
40
|
+
import { runnerSpecVersion, specMajorVersionsMatch } from './spec-version.js';
|
|
41
|
+
import { isProtocolTimestamp, isRecord, validateHttpUrl } from './validation.js';
|
|
42
|
+
import { isValidWireMessage, type TWireSchemaName, validateWireMessage } from './wire-schema.js';
|
|
41
43
|
|
|
42
44
|
export type TRunnerFetch = (
|
|
43
|
-
input:
|
|
45
|
+
input: string | URL | Request,
|
|
44
46
|
init?: RequestInit,
|
|
45
47
|
) => Promise<Response>;
|
|
46
48
|
|
|
@@ -59,6 +61,7 @@ export interface IRunnerApiClientOptions {
|
|
|
59
61
|
|
|
60
62
|
interface IJsonRequestOptions {
|
|
61
63
|
requestSchema: TWireSchemaName;
|
|
64
|
+
method?: 'POST' | 'PUT';
|
|
62
65
|
token?: string;
|
|
63
66
|
signal?: AbortSignal;
|
|
64
67
|
fenced?: boolean;
|
|
@@ -437,6 +440,21 @@ export class RunnerApiClient {
|
|
|
437
440
|
);
|
|
438
441
|
}
|
|
439
442
|
|
|
443
|
+
public async recordImage(
|
|
444
|
+
request: IRecordImageRequest,
|
|
445
|
+
signal?: AbortSignal,
|
|
446
|
+
): Promise<IImageRecord> {
|
|
447
|
+
return validateWireMessage<IImageRecord>(
|
|
448
|
+
'ImageRecord',
|
|
449
|
+
await this.requestJson(this.jobPath(request.identity, 'image'), request, {
|
|
450
|
+
method: 'PUT',
|
|
451
|
+
requestSchema: 'RecordImageRequest',
|
|
452
|
+
signal,
|
|
453
|
+
fenced: true,
|
|
454
|
+
}),
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
|
|
440
458
|
public async completeJob(
|
|
441
459
|
request: ICompleteJobRequest,
|
|
442
460
|
signal?: AbortSignal,
|
|
@@ -632,7 +650,7 @@ export class RunnerApiClient {
|
|
|
632
650
|
let response: Response;
|
|
633
651
|
try {
|
|
634
652
|
response = await this.fetchImplementation(new URL(path, this.baseUrl), {
|
|
635
|
-
method: 'POST',
|
|
653
|
+
method: options.method ?? 'POST',
|
|
636
654
|
headers: {
|
|
637
655
|
authorization: `Bearer ${token}`,
|
|
638
656
|
'content-type': 'application/json',
|
|
@@ -741,6 +759,9 @@ export class RunnerApiClient {
|
|
|
741
759
|
method: 'PUT',
|
|
742
760
|
headers,
|
|
743
761
|
body,
|
|
762
|
+
// A streamed request body must be sent half-duplex: the request body is written before
|
|
763
|
+
// the response is read.
|
|
764
|
+
duplex: 'half',
|
|
744
765
|
redirect: 'error',
|
|
745
766
|
signal: requestSignal,
|
|
746
767
|
});
|
package/ts/artifact-manager.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
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.
|
|
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.
|
|
18
|
+
} from './interfaces.js';
|
|
19
19
|
import {
|
|
20
20
|
createTarGzipArchive,
|
|
21
21
|
ensureStagingCapacity,
|
|
22
22
|
validateRelativeSelections,
|
|
23
23
|
validateTransferRecord,
|
|
24
|
-
} from './transfer-archive.
|
|
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
|
|
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
|
|
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,
|
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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { assertSupportedNodeVersion } from './node-version.js';
|
|
3
|
+
|
|
4
|
+
// The CLI's modules load only after the Node.js version check, so an unsupported release gets a
|
|
5
|
+
// clear refusal instead of a failure deep inside.
|
|
6
|
+
let supported = false;
|
|
7
|
+
try {
|
|
8
|
+
assertSupportedNodeVersion(process.versions.node);
|
|
9
|
+
supported = true;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error(error instanceof Error ? error.message : 'Runner failed');
|
|
12
|
+
process.exitCode = 1;
|
|
13
|
+
}
|
|
14
|
+
if (supported) {
|
|
15
|
+
const { runCli } = await import('./cli.js');
|
|
16
|
+
await runCli(process.argv.slice(2));
|
|
17
|
+
}
|