@cnc-tools/storm 0.15.0 → 0.17.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/dist/application.d.ts +22 -13
- package/dist/application.js +21 -10
- package/dist/bin/run.d.ts +18 -0
- package/dist/bin/run.js +31 -0
- package/dist/bin/storm.js +42 -26
- package/dist/build-info.js +1 -1
- package/dist/chunks/{chunk-5CCP36QQ.js → chunk-2RNDPDTJ.js} +2 -2
- package/dist/chunks/chunk-2VP4GRJM.js +1219 -0
- package/dist/chunks/{chunk-SZEURWRS.js → chunk-4O5C2XGJ.js} +18 -15
- package/dist/chunks/{chunk-VL7WFTVQ.js → chunk-4WAMTUWZ.js} +419 -340
- package/dist/chunks/{chunk-QVS7HRU7.js → chunk-6UHIJXZG.js} +3 -3
- package/dist/chunks/{chunk-CN4EFA5J.js → chunk-72ZFEMAW.js} +1 -1
- package/dist/chunks/{chunk-4U4DZ7VG.js → chunk-7DZE67QM.js} +2 -2
- package/dist/chunks/{chunk-VUPZH7J2.js → chunk-BCBKYOHW.js} +1 -1
- package/dist/chunks/{chunk-QUHY6FGN.js → chunk-CKGZA25H.js} +1 -18
- package/dist/chunks/{chunk-ZG3WQ4UF.js → chunk-D27KILIA.js} +1 -1
- package/dist/chunks/{chunk-KC4KDJ5K.js → chunk-DADEYJDW.js} +174 -153
- package/dist/chunks/{chunk-R7XVBZOY.js → chunk-EEENLQHE.js} +59 -11
- package/dist/chunks/chunk-F4MOYHRY.js +198 -0
- package/dist/chunks/{chunk-CXAT7ZKP.js → chunk-FNBB6V4R.js} +1 -1
- package/dist/chunks/{chunk-OX7X4B2L.js → chunk-GRT3UIBV.js} +18 -1
- package/dist/chunks/chunk-HP3CURSZ.js +88 -0
- package/dist/chunks/{chunk-PN5ULTTH.js → chunk-HWIQ2S7K.js} +5 -5
- package/dist/chunks/chunk-JN3YY6ZH.js +2166 -0
- package/dist/chunks/{chunk-TJNFVNKR.js → chunk-LKTZ5OXS.js} +1 -1
- package/dist/chunks/{chunk-XEVHP5ZW.js → chunk-M7EKRGVD.js} +8 -8
- package/dist/chunks/chunk-MR77L2GK.js +340 -0
- package/dist/chunks/{chunk-L36GBUBB.js → chunk-RNAS7JHE.js} +1755 -522
- package/dist/chunks/{chunk-5GBMR4HM.js → chunk-RWIXDDCK.js} +4 -192
- package/dist/chunks/{chunk-5VXBKPW6.js → chunk-WV3DP6NR.js} +1 -1
- package/dist/chunks/{chunk-AWBSONHB.js → chunk-XBDRVFEV.js} +55 -16
- package/dist/chunks/{chunk-YV7GE6EV.js → chunk-YEPFSLQR.js} +480 -375
- package/dist/chunks/{live-app-PI3BAN6Y.js → live-app-R76JQXZL.js} +15 -13
- package/dist/commands/exec/across-sandboxes-outcomes.d.ts +1 -1
- package/dist/commands/exec/across-sandboxes-outcomes.js +4 -3
- package/dist/commands/exec/before-run.d.ts +123 -0
- package/dist/commands/exec/before-run.js +105 -0
- package/dist/commands/exec/command.d.ts +39 -4
- package/dist/commands/exec/command.js +31 -95
- package/dist/commands/exec/driver-plan.d.ts +9 -4
- package/dist/commands/exec/driver-plan.js +8 -8
- package/dist/commands/exec/exec-words.js +1 -1
- package/dist/commands/exec/execute-run.d.ts +39 -0
- package/dist/commands/exec/execute-run.js +325 -0
- package/dist/commands/exec/live-view.d.ts +3 -3
- package/dist/commands/exec/live-view.js +16 -15
- package/dist/commands/exec/metadata.js +1 -1
- package/dist/commands/exec/mint-failed.d.ts +38 -0
- package/dist/commands/exec/mint-failed.js +27 -4
- package/dist/commands/exec/outcomes.d.ts +38 -9
- package/dist/commands/exec/outcomes.js +32 -25
- package/dist/commands/exec/plan-run.d.ts +58 -150
- package/dist/commands/exec/plan-run.js +232 -88
- package/dist/commands/exec/planned-outcome.js +8 -1
- package/dist/commands/exec/progress.d.ts +10 -6
- package/dist/commands/exec/progress.js +38 -25
- package/dist/commands/exec/run-bin.d.ts +11 -11
- package/dist/commands/exec/run-bin.js +9 -9
- package/dist/commands/exec/run-flags.d.ts +69 -0
- package/dist/commands/exec/run-flags.js +58 -0
- package/dist/commands/exec/run-metadata.js +5 -5
- package/dist/commands/exec/run-summary.d.ts +58 -0
- package/dist/commands/exec/run-summary.js +205 -0
- package/dist/commands/exec/runner-refusals.d.ts +82 -0
- package/dist/commands/exec/runner-refusals.js +71 -0
- package/dist/commands/exec/sandbox-progress.js +3 -0
- package/dist/commands/exec/stopped-outcome.d.ts +12 -0
- package/dist/commands/exec/stopped-outcome.js +77 -0
- package/dist/commands/exec/view.d.ts +20 -11
- package/dist/commands/exec/view.js +103 -47
- package/dist/commands/runs/facts.d.ts +9 -4
- package/dist/commands/runs/facts.js +28 -11
- package/dist/commands/runs/list/command.d.ts +16 -6
- package/dist/commands/runs/list/command.js +10 -10
- package/dist/commands/runs/list/outcomes.d.ts +8 -3
- package/dist/commands/runs/logs/command.d.ts +6 -2
- package/dist/commands/runs/logs/command.js +10 -10
- package/dist/commands/runs/logs/outcomes.d.ts +3 -1
- package/dist/commands/runs/past-run.d.ts +14 -5
- package/dist/commands/runs/past-run.js +16 -5
- package/dist/commands/runs/show/command.d.ts +20 -8
- package/dist/commands/runs/show/command.js +30 -28
- package/dist/commands/runs/show/outcomes.d.ts +10 -4
- package/dist/commands/runs/show/outcomes.js +7 -5
- package/dist/commands/snapshots/access.d.ts +111 -0
- package/dist/commands/snapshots/access.js +96 -0
- package/dist/commands/snapshots/build/command.d.ts +360 -93
- package/dist/commands/snapshots/build/command.js +446 -150
- package/dist/commands/snapshots/build/metadata.d.ts +10 -0
- package/dist/commands/snapshots/build/metadata.js +31 -11
- package/dist/commands/snapshots/build/outcomes.d.ts +234 -43
- package/dist/commands/snapshots/build/outcomes.js +200 -36
- package/dist/commands/snapshots/list/command.d.ts +368 -27
- package/dist/commands/snapshots/list/command.js +296 -66
- package/dist/commands/snapshots/list/metadata.d.ts +16 -0
- package/dist/commands/snapshots/list/metadata.js +29 -6
- package/dist/commands/snapshots/list/outcomes.d.ts +245 -13
- package/dist/commands/snapshots/list/outcomes.js +221 -50
- package/dist/commands/snapshots/metadata.js +1 -1
- package/dist/commands/snapshots/prune/command.d.ts +430 -0
- package/dist/commands/snapshots/prune/command.js +161 -0
- package/dist/commands/snapshots/prune/metadata.d.ts +28 -0
- package/dist/commands/snapshots/prune/metadata.js +39 -0
- package/dist/commands/snapshots/prune/outcomes.d.ts +208 -0
- package/dist/commands/snapshots/prune/outcomes.js +78 -0
- package/dist/commands/suites/list/command.js +19 -18
- package/dist/commands/suites/list/outcomes.js +4 -4
- package/dist/commands/test/command.d.ts +39 -4
- package/dist/commands/test/command.js +50 -255
- package/dist/commands/test/metadata.js +1 -1
- package/dist/commands/test/outcomes.d.ts +19 -2
- package/dist/commands/test/outcomes.js +2 -2
- package/dist/config/check-runner.d.ts +5 -3
- package/dist/config/check-runner.js +33 -7
- package/dist/config/check-suites.js +1 -0
- package/dist/config/credential-resolver.d.ts +50 -5
- package/dist/config/credential-resolver.js +51 -19
- package/dist/config/credential-settle.d.ts +6 -2
- package/dist/config/credential-settle.js +11 -5
- package/dist/config/gateways.d.ts +7 -3
- package/dist/config/index.d.ts +4 -5
- package/dist/config/index.js +3 -4
- package/dist/config/live/config-gateway.js +5 -2
- package/dist/config/load.d.ts +21 -4
- package/dist/config/load.js +129 -15
- package/dist/config/runner.d.ts +7 -8
- package/dist/config/runner.js +1 -1
- package/dist/config/schema.d.ts +17 -5
- package/dist/config/schema.js +11 -3
- package/dist/config/typed-options.d.ts +1 -6
- package/dist/config/typed-options.js +2 -10
- package/dist/config-file/define.d.ts +1 -11
- package/dist/config-file/define.js +3 -3
- package/dist/config-file/runner.d.ts +5 -6
- package/dist/config-file/toolchain.d.ts +13 -7
- package/dist/config-file/toolchain.js +53 -37
- package/dist/context.d.ts +8 -6
- package/dist/context.js +7 -6
- package/dist/core/across-sandboxes.d.ts +7 -6
- package/dist/core/across-sandboxes.js +123 -152
- package/dist/core/coordinator.d.ts +166 -0
- package/dist/core/coordinator.js +233 -0
- package/dist/core/events.d.ts +2 -2
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +1 -1
- package/dist/core/outcomes.d.ts +148 -0
- package/dist/core/{sandbox-end.js → outcomes.js} +28 -4
- package/dist/core/resources.d.ts +31 -53
- package/dist/core/resources.js +32 -70
- package/dist/core/run-state.d.ts +7 -1
- package/dist/core/run-state.js +2 -0
- package/dist/core/run.d.ts +32 -236
- package/dist/core/run.js +106 -266
- package/dist/core/state-directory.d.ts +1 -1
- package/dist/core/state-directory.js +2 -2
- package/dist/credential/gateways.d.ts +15 -1
- package/dist/credential/index.d.ts +4 -3
- package/dist/credential/index.js +3 -2
- package/dist/credential/live/vercel-cli-gateway.d.ts +1 -1
- package/dist/credential/live/vercel-cli-gateway.js +1 -1
- package/dist/credential/live/vercel-oidc-token-gateway.d.ts +11 -0
- package/dist/credential/live/vercel-oidc-token-gateway.js +16 -0
- package/dist/credential/source.d.ts +73 -6
- package/dist/credential/source.js +55 -2
- package/dist/extension-commands.d.ts +6 -1
- package/dist/extension-commands.js +15 -1
- package/dist/extensions/github/resource.d.ts +1 -1
- package/dist/extensions/github/resource.js +1 -1
- package/dist/extensions/testserver/commands/pool/create/command.d.ts +35 -2
- package/dist/extensions/testserver/commands/pool/create/command.js +7 -7
- package/dist/extensions/testserver/commands/pool/create/metadata.js +5 -5
- package/dist/extensions/testserver/commands/pool/create/outcomes.d.ts +17 -1
- package/dist/extensions/testserver/commands/pool/list/command.js +4 -4
- package/dist/extensions/testserver/credential-facts.d.ts +6 -2
- package/dist/extensions/testserver/credential-facts.js +29 -11
- package/dist/extensions/testserver/lifecycle.js +7 -1
- package/dist/extensions/testserver/limit.d.ts +3 -0
- package/dist/extensions/testserver/limit.js +3 -0
- package/dist/extensions/testserver/provision.d.ts +8 -1
- package/dist/extensions/testserver/provision.js +8 -3
- package/dist/extensions/testserver/refusals.d.ts +6 -1
- package/dist/extensions/testserver/refusals.js +16 -1
- package/dist/extensions/testserver/resource.d.ts +2 -2
- package/dist/extensions/testserver/resource.js +2 -2
- package/dist/extensions/testserver/result.d.ts +1 -1
- package/dist/extensions/testserver/result.js +9 -4
- package/dist/planning/driver-file-lists.d.ts +0 -15
- package/dist/planning/driver-file-lists.js +2 -21
- package/dist/planning/plan-only.d.ts +7 -15
- package/dist/planning/plan-only.js +16 -22
- package/dist/planning/run-kind-flags.js +2 -2
- package/dist/planning/run-plan.d.ts +45 -13
- package/dist/planning/run-plan.js +4 -3
- package/dist/planning/suites.d.ts +1 -1
- package/dist/planning/suites.js +2 -2
- package/dist/planning/test-plan.d.ts +9 -0
- package/dist/planning/test-plan.js +10 -2
- package/dist/run-directory/recording.js +2 -2
- package/dist/run-directory/run-record.d.ts +21 -6
- package/dist/run-directory/run-record.js +12 -9
- package/dist/runner/base.d.ts +0 -6
- package/dist/runner/base.js +1 -16
- package/dist/runner/build-snapshots.d.ts +55 -29
- package/dist/runner/build-snapshots.js +135 -35
- package/dist/runner/context.d.ts +15 -7
- package/dist/runner/context.js +19 -6
- package/dist/runner/events.d.ts +16 -10
- package/dist/runner/gateways.d.ts +92 -21
- package/dist/runner/gateways.js +1 -1
- package/dist/runner/index.d.ts +11 -7
- package/dist/runner/index.js +9 -4
- package/dist/runner/live/sandbox-errors.d.ts +2 -0
- package/dist/runner/live/sandbox-errors.js +4 -0
- package/dist/runner/live/sandbox-gateway.js +141 -3
- package/dist/runner/live/snapshot-index-gateway.d.ts +12 -0
- package/dist/runner/live/{snapshot-cache-gateway.js → snapshot-index-gateway.js} +11 -11
- package/dist/runner/live/snapshot-records.js +6 -7
- package/dist/runner/local-snapshot-index.d.ts +199 -0
- package/dist/runner/local-snapshot-index.js +211 -0
- package/dist/runner/network-policy.d.ts +6 -6
- package/dist/runner/network-policy.js +7 -7
- package/dist/runner/policy-writes.d.ts +1 -1
- package/dist/runner/policy-writes.js +1 -1
- package/dist/runner/prepare.d.ts +25 -24
- package/dist/runner/prepare.js +28 -20
- package/dist/runner/ready.d.ts +18 -10
- package/dist/runner/ready.js +104 -33
- package/dist/runner/sandboxed-command.d.ts +3 -3
- package/dist/runner/sandboxed-command.js +3 -3
- package/dist/runner/scope.d.ts +10 -6
- package/dist/runner/scope.js +10 -3
- package/dist/runner/secrets.d.ts +13 -13
- package/dist/runner/secrets.js +18 -15
- package/dist/runner/session.d.ts +8 -8
- package/dist/runner/session.js +3 -3
- package/dist/runner/shared-snapshot-entry.d.ts +92 -0
- package/dist/runner/shared-snapshot-entry.js +168 -0
- package/dist/runner/shared-snapshot-list.d.ts +81 -0
- package/dist/runner/shared-snapshot-list.js +155 -0
- package/dist/runner/shared-snapshot-lookup.d.ts +51 -0
- package/dist/runner/shared-snapshot-lookup.js +118 -0
- package/dist/runner/shared-snapshot-prune.d.ts +58 -0
- package/dist/runner/shared-snapshot-prune.js +133 -0
- package/dist/runner/snapshot-build.d.ts +42 -14
- package/dist/runner/snapshot-build.js +38 -28
- package/dist/runner/snapshot-choice.js +1 -1
- package/dist/runner/snapshot-inspect.d.ts +39 -40
- package/dist/runner/snapshot-inspect.js +58 -38
- package/dist/runner/snapshot-key.d.ts +30 -21
- package/dist/runner/snapshot-key.js +49 -29
- package/dist/runner/steps.d.ts +1 -1
- package/dist/runner/steps.js +1 -1
- package/dist/runner/{recipe-check.d.ts → vercel-sandbox-check.d.ts} +2 -2
- package/dist/runner/{recipe-check.js → vercel-sandbox-check.js} +3 -2
- package/dist/runner/{recipe.d.ts → vercel-sandbox-options.d.ts} +82 -82
- package/dist/runner/vercel-sandbox-options.js +510 -0
- package/dist/runner/{recipe-secrets.d.ts → vercel-sandbox-secrets.d.ts} +6 -6
- package/dist/runner/{recipe-secrets.js → vercel-sandbox-secrets.js} +20 -20
- package/dist/sdk/extension/commands.d.ts +8 -3
- package/dist/sdk/extension/commands.js +3 -1
- package/dist/sdk/extension/credential-diagnosis.d.ts +3 -1
- package/dist/sdk/extension/credential-diagnosis.js +25 -5
- package/dist/sdk/extension/credential-source.d.ts +20 -3
- package/dist/sdk/extension/credential-source.js +4 -4
- package/dist/sdk/extension/index.d.ts +3 -2
- package/dist/sdk/extension/index.js +2 -1
- package/dist/sdk/extension/resource-definition.d.ts +4 -3
- package/dist/sdk/extension/resource-definition.js +3 -2
- package/dist/sdk/extension/resource-factory.js +3 -4
- package/dist/sdk/extension/secret-source.d.ts +1 -1
- package/dist/sdk/extension/secret-source.js +1 -1
- package/dist/sdk/extension/vercel-oidc-facts.d.ts +20 -0
- package/dist/sdk/extension/vercel-oidc-facts.js +20 -0
- package/dist/sdk/run/present.d.ts +3 -3
- package/dist/sdk/run/present.js +1 -3
- package/dist/shared/cleanup.d.ts +3 -3
- package/dist/shared/cleanup.js +15 -5
- package/dist/shared/snapshot-text.d.ts +4 -4
- package/dist/shared/snapshot-text.js +11 -11
- package/dist/time/duration.js +1 -1
- package/package.json +3 -2
- package/skills/overview.md +6 -4
- package/skills/plan-runs.md +2 -2
- package/skills/read-run-output.md +6 -6
- package/dist/chunks/chunk-E4PJNZVG.js +0 -783
- package/dist/chunks/chunk-RAQEXKL6.js +0 -2591
- package/dist/commands/exec/across-sandboxes-run.d.ts +0 -180
- package/dist/commands/exec/across-sandboxes-run.js +0 -339
- package/dist/commands/exec/plan-only.d.ts +0 -10
- package/dist/commands/exec/plan-only.js +0 -46
- package/dist/commands/exec/run-command.d.ts +0 -476
- package/dist/commands/exec/run-command.js +0 -604
- package/dist/commands/exec/run-planned.d.ts +0 -20
- package/dist/commands/exec/run-planned.js +0 -22
- package/dist/commands/exec/sandbox-view.d.ts +0 -19
- package/dist/commands/exec/sandbox-view.js +0 -72
- package/dist/commands/test/plan.d.ts +0 -92
- package/dist/commands/test/plan.js +0 -128
- package/dist/config/recipe-run.d.ts +0 -33
- package/dist/config/recipe-run.js +0 -28
- package/dist/core/sandbox-end.d.ts +0 -64
- package/dist/runner/live/snapshot-cache-gateway.d.ts +0 -12
- package/dist/runner/recipe.js +0 -425
- package/dist/runner/snapshot-cache.d.ts +0 -148
- package/dist/runner/snapshot-cache.js +0 -126
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Clock } from "../time/index.ts";
|
|
2
|
+
import type { CheckoutGateway, RunnerSandboxGateway, RunnerSnapshotEntry, SandboxAccess } from "./gateways.ts";
|
|
3
|
+
import type { CheckedVercelSandboxOptions } from "./vercel-sandbox-options.ts";
|
|
4
|
+
/** Gateways and seams used to look up, list, or prune shared snapshots. */
|
|
5
|
+
export interface SharedSnapshotLookupContext {
|
|
6
|
+
readonly runnerSandboxes: RunnerSandboxGateway;
|
|
7
|
+
readonly checkout: CheckoutGateway;
|
|
8
|
+
readonly clock: Clock;
|
|
9
|
+
}
|
|
10
|
+
/** What `lookupSharedSnapshot` searches for in the shared snapshot index. */
|
|
11
|
+
export interface SharedSnapshotLookupRequest {
|
|
12
|
+
readonly access: SandboxAccess;
|
|
13
|
+
readonly repoRoot: string;
|
|
14
|
+
readonly runner: Pick<CheckedVercelSandboxOptions, "name" | "region" | "runtime">;
|
|
15
|
+
readonly snapshotKey: string;
|
|
16
|
+
readonly mergeBase: string;
|
|
17
|
+
/**
|
|
18
|
+
* When set, the commit distance behind `mergeBase` of the local snapshot index's candidate: only shared snapshots that
|
|
19
|
+
* beat it (`sharedBeatsLocal`) qualify. When no ancestor can beat it, the bucket listing is skipped after the exact
|
|
20
|
+
* check misses.
|
|
21
|
+
*/
|
|
22
|
+
readonly maxCommitsBehindMergeBase?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* What `lookupSharedSnapshot` found:
|
|
26
|
+
*
|
|
27
|
+
* - `hit`: a verified, unexpired snapshot with time left at the merge-base (`commitsBehindMergeBase === 0`) or its
|
|
28
|
+
* closest qualifying ancestor.
|
|
29
|
+
* - `miss`: no usable shared snapshot was found in the bucket.
|
|
30
|
+
* - `unavailable`: a Sandbox API call failed, so the caller can degrade gracefully.
|
|
31
|
+
* - `aborted`: the caller's signal aborted the lookup.
|
|
32
|
+
*/
|
|
33
|
+
export type SharedSnapshotLookupResult = {
|
|
34
|
+
readonly kind: "hit";
|
|
35
|
+
readonly entry: RunnerSnapshotEntry;
|
|
36
|
+
readonly commitsBehindMergeBase: number;
|
|
37
|
+
readonly sandboxName: string;
|
|
38
|
+
} | {
|
|
39
|
+
readonly kind: "miss";
|
|
40
|
+
} | {
|
|
41
|
+
readonly kind: "unavailable";
|
|
42
|
+
readonly message: string;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: "aborted";
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Looks up a usable shared snapshot for `request`: first checks the exact named sandbox for `request.mergeBase`
|
|
48
|
+
* without listing, and falls back to listing the bucket and selecting the closest verified ancestor of
|
|
49
|
+
* `request.mergeBase` (tie-breaking by newest `createdAt`, then ascending `name`).
|
|
50
|
+
*/
|
|
51
|
+
export declare function lookupSharedSnapshot(context: SharedSnapshotLookupContext, request: SharedSnapshotLookupRequest, signal?: AbortSignal): Promise<SharedSnapshotLookupResult>;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Live run lookup against the shared snapshot index: checks the exact merge-base named sandbox first without
|
|
2
|
+
// listing, then falls back to scanning the bucket for the closest verified ancestor of the merge-base.
|
|
3
|
+
import { compareSnapshotCandidates, sharedBeatsLocal } from "./local-snapshot-index.js";
|
|
4
|
+
import { classifyUnverifiedSharedSandbox, INDEX_CONCURRENCY, parseSharedSnapshotSandboxName, runLimited, sharedSnapshotBucket, sharedSnapshotSandboxName, sharedSnapshotSandboxPrefix, usableSharedEntry, } from "./shared-snapshot-entry.js";
|
|
5
|
+
/**
|
|
6
|
+
* Looks up a usable shared snapshot for `request`: first checks the exact named sandbox for `request.mergeBase`
|
|
7
|
+
* without listing, and falls back to listing the bucket and selecting the closest verified ancestor of
|
|
8
|
+
* `request.mergeBase` (tie-breaking by newest `createdAt`, then ascending `name`).
|
|
9
|
+
*/
|
|
10
|
+
export async function lookupSharedSnapshot(context, request, signal) {
|
|
11
|
+
const { runnerSandboxes, checkout, clock } = context;
|
|
12
|
+
const { access, repoRoot, runner, snapshotKey, mergeBase, maxCommitsBehindMergeBase } = request;
|
|
13
|
+
// Even an entry at the merge-base can't beat the caller's candidate.
|
|
14
|
+
if (!sharedBeatsLocal(0, maxCommitsBehindMergeBase))
|
|
15
|
+
return { kind: "miss" };
|
|
16
|
+
const bucket = sharedSnapshotBucket({
|
|
17
|
+
teamId: access.teamId,
|
|
18
|
+
projectId: access.projectId,
|
|
19
|
+
region: runner.region,
|
|
20
|
+
runtime: runner.runtime,
|
|
21
|
+
runnerName: runner.name,
|
|
22
|
+
snapshotKey,
|
|
23
|
+
});
|
|
24
|
+
// Step 1: fast exact check for `mergeBase` without calling `listNamedSandboxes`.
|
|
25
|
+
const exactName = sharedSnapshotSandboxName(bucket, mergeBase);
|
|
26
|
+
const exact = await runnerSandboxes.getNamedSandbox(access, { name: exactName }, signal);
|
|
27
|
+
if (!exact.ok) {
|
|
28
|
+
return unavailable(exact.failure);
|
|
29
|
+
}
|
|
30
|
+
if (exact.value.kind === "found") {
|
|
31
|
+
const { sandbox } = exact.value;
|
|
32
|
+
const unverified = classifyUnverifiedSharedSandbox(sandbox);
|
|
33
|
+
if (unverified.kind === "needs-snapshot") {
|
|
34
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
35
|
+
if (!verified.ok) {
|
|
36
|
+
return unavailable(verified.failure);
|
|
37
|
+
}
|
|
38
|
+
if (verified.value.kind === "found") {
|
|
39
|
+
const entry = usableSharedEntry(access, runner, snapshotKey, mergeBase, sandbox, verified.value.snapshot, clock.now());
|
|
40
|
+
if (entry !== null) {
|
|
41
|
+
return { kind: "hit", entry, commitsBehindMergeBase: 0, sandboxName: sandbox.name };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Only the exact match above can beat the caller's candidate when no ancestor, 1 commit behind or more, can.
|
|
47
|
+
if (!sharedBeatsLocal(1, maxCommitsBehindMergeBase))
|
|
48
|
+
return { kind: "miss" };
|
|
49
|
+
// Step 2: ancestor scan across the bucket.
|
|
50
|
+
const listed = await runnerSandboxes.listNamedSandboxes(access, { namePrefix: sharedSnapshotSandboxPrefix(bucket) }, signal);
|
|
51
|
+
if (!listed.ok) {
|
|
52
|
+
return unavailable(listed.failure);
|
|
53
|
+
}
|
|
54
|
+
const stoppedRows = [];
|
|
55
|
+
for (const row of listed.value) {
|
|
56
|
+
const unverified = classifyUnverifiedSharedSandbox(row);
|
|
57
|
+
if (unverified.kind !== "needs-snapshot")
|
|
58
|
+
continue;
|
|
59
|
+
const parsed = parseSharedSnapshotSandboxName(row.name);
|
|
60
|
+
if (parsed === null || parsed.bucket !== bucket || parsed.base === mergeBase)
|
|
61
|
+
continue;
|
|
62
|
+
stoppedRows.push({ row, base: parsed.base, snapshotId: unverified.snapshotId });
|
|
63
|
+
}
|
|
64
|
+
const checked = await runLimited(stoppedRows.length, INDEX_CONCURRENCY, () => signal?.aborted !== true, async (index) => {
|
|
65
|
+
const item = stoppedRows[index];
|
|
66
|
+
const ancestor = await checkout.contains({ repoRoot, ancestor: item.base, descendant: mergeBase });
|
|
67
|
+
if (!ancestor.ok || !ancestor.value)
|
|
68
|
+
return null;
|
|
69
|
+
if (signal?.aborted === true)
|
|
70
|
+
return null;
|
|
71
|
+
const counted = await checkout.commitCount({ repoRoot, from: item.base, to: mergeBase });
|
|
72
|
+
if (!counted.ok)
|
|
73
|
+
return null;
|
|
74
|
+
if (!sharedBeatsLocal(counted.value, maxCommitsBehindMergeBase))
|
|
75
|
+
return null;
|
|
76
|
+
return {
|
|
77
|
+
row: item.row,
|
|
78
|
+
base: item.base,
|
|
79
|
+
snapshotId: item.snapshotId,
|
|
80
|
+
commitsBehindMergeBase: counted.value,
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
if (signal?.aborted === true)
|
|
84
|
+
return { kind: "aborted" };
|
|
85
|
+
const candidates = checked.filter((candidate) => candidate != null);
|
|
86
|
+
candidates.sort((a, b) => compareSnapshotCandidates({
|
|
87
|
+
commitsBehindMergeBase: a.commitsBehindMergeBase,
|
|
88
|
+
createdAt: a.row.createdAt,
|
|
89
|
+
tieBreaker: a.row.name,
|
|
90
|
+
}, {
|
|
91
|
+
commitsBehindMergeBase: b.commitsBehindMergeBase,
|
|
92
|
+
createdAt: b.row.createdAt,
|
|
93
|
+
tieBreaker: b.row.name,
|
|
94
|
+
}));
|
|
95
|
+
// Verify candidates sequentially in closest-first order so we stop on the first usable snapshot.
|
|
96
|
+
for (const candidate of candidates) {
|
|
97
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: candidate.snapshotId }, signal);
|
|
98
|
+
if (!verified.ok) {
|
|
99
|
+
return unavailable(verified.failure);
|
|
100
|
+
}
|
|
101
|
+
if (verified.value.kind !== "found")
|
|
102
|
+
continue;
|
|
103
|
+
const entry = usableSharedEntry(access, runner, snapshotKey, candidate.base, candidate.row, verified.value.snapshot, clock.now());
|
|
104
|
+
if (entry !== null) {
|
|
105
|
+
return {
|
|
106
|
+
kind: "hit",
|
|
107
|
+
entry,
|
|
108
|
+
commitsBehindMergeBase: candidate.commitsBehindMergeBase,
|
|
109
|
+
sandboxName: candidate.row.name,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return { kind: "miss" };
|
|
114
|
+
}
|
|
115
|
+
/** How the lookup ends on a failed Sandbox call: aborted for the signal, and `unavailable` otherwise. */
|
|
116
|
+
function unavailable(failure) {
|
|
117
|
+
return failure.kind === "aborted" ? { kind: "aborted" } : { kind: "unavailable", message: failure.message };
|
|
118
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { SandboxAccess } from "./gateways.ts";
|
|
2
|
+
import type { SharedSnapshotLookupContext } from "./shared-snapshot-lookup.ts";
|
|
3
|
+
/** What `pruneSharedSnapshots` deletes or previews across the project's shared snapshot index. */
|
|
4
|
+
export interface SharedSnapshotPruneRequest {
|
|
5
|
+
readonly access: SandboxAccess;
|
|
6
|
+
readonly dryRun: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Why a shared snapshot index sandbox is eligible for pruning. */
|
|
9
|
+
export type SharedSnapshotPruneReason = "no-snapshot" | "expired" | "missing" | "failed";
|
|
10
|
+
/** One shared snapshot index sandbox deleted (or marked for deletion under `dryRun`). */
|
|
11
|
+
export type PrunedSharedSnapshot = {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly reason: "no-snapshot";
|
|
14
|
+
} | {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly reason: "failed";
|
|
17
|
+
} | {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly reason: "expired";
|
|
20
|
+
readonly snapshotId: string;
|
|
21
|
+
} | {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly reason: "missing";
|
|
24
|
+
readonly snapshotId: string;
|
|
25
|
+
};
|
|
26
|
+
/** One shared snapshot index sandbox whose verification or deletion failed during pruning. */
|
|
27
|
+
export interface SharedSnapshotPruneFailure {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly message: string;
|
|
30
|
+
}
|
|
31
|
+
/** What `pruneSharedSnapshots` scanned, deleted, skipped, and failed on. */
|
|
32
|
+
export interface SharedSnapshotPruneSummary {
|
|
33
|
+
readonly scanned: number;
|
|
34
|
+
readonly deleted: readonly PrunedSharedSnapshot[];
|
|
35
|
+
readonly skipped: number;
|
|
36
|
+
readonly failed: readonly SharedSnapshotPruneFailure[];
|
|
37
|
+
readonly dryRun: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** How `pruneSharedSnapshots` ended. */
|
|
40
|
+
export type SharedSnapshotPruneResult = {
|
|
41
|
+
readonly kind: "ok";
|
|
42
|
+
readonly summary: SharedSnapshotPruneSummary;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: "failed";
|
|
45
|
+
readonly message: string;
|
|
46
|
+
} | {
|
|
47
|
+
readonly kind: "aborted";
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Scans every valid `storm-snap-<bucket>-<base>` named sandbox in the project and deletes entries that ended failed or
|
|
51
|
+
* aborted (`failed`), stopped entries without a `currentSnapshotId` (`no-snapshot`), or stopped entries whose snapshot
|
|
52
|
+
* is verified missing or not `created` (`missing`) or expired (`expired`). Active builds (`pending`, `running`,
|
|
53
|
+
* `snapshotting`, or `stopping`) and stopped entries whose `expires-at` tag is still in the future are skipped without
|
|
54
|
+
* calling `getSnapshot` (including entries that expire within the hour and are not yet expired). Non-index sandboxes
|
|
55
|
+
* whose names do not match `storm-snap-<16-hex>-<40-hex>` are ignored. Verification and deletion run with bounded
|
|
56
|
+
* concurrency.
|
|
57
|
+
*/
|
|
58
|
+
export declare function pruneSharedSnapshots(context: Pick<SharedSnapshotLookupContext, "runnerSandboxes" | "clock">, request: SharedSnapshotPruneRequest, signal?: AbortSignal): Promise<SharedSnapshotPruneResult>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Pruning dead entries from the shared snapshot index (`storm snapshots prune`): scans valid
|
|
2
|
+
// `storm-snap-<bucket>-<base>` named sandboxes, skips active builds and stopped entries whose `expires-at` tag is
|
|
3
|
+
// still in the future, classifies the remaining entries through the canonical shared-snapshot classifier, and deletes
|
|
4
|
+
// `failed`, `no-snapshot`, `missing`, and `expired` entries.
|
|
5
|
+
import { classifyUnverifiedSharedSandbox, classifyVerifiedSharedSnapshot, INDEX_CONCURRENCY, parseSharedSnapshotSandboxName, runLimited, SHARED_SNAPSHOT_SANDBOX_PREFIX, } from "./shared-snapshot-entry.js";
|
|
6
|
+
/**
|
|
7
|
+
* Scans every valid `storm-snap-<bucket>-<base>` named sandbox in the project and deletes entries that ended failed or
|
|
8
|
+
* aborted (`failed`), stopped entries without a `currentSnapshotId` (`no-snapshot`), or stopped entries whose snapshot
|
|
9
|
+
* is verified missing or not `created` (`missing`) or expired (`expired`). Active builds (`pending`, `running`,
|
|
10
|
+
* `snapshotting`, or `stopping`) and stopped entries whose `expires-at` tag is still in the future are skipped without
|
|
11
|
+
* calling `getSnapshot` (including entries that expire within the hour and are not yet expired). Non-index sandboxes
|
|
12
|
+
* whose names do not match `storm-snap-<16-hex>-<40-hex>` are ignored. Verification and deletion run with bounded
|
|
13
|
+
* concurrency.
|
|
14
|
+
*/
|
|
15
|
+
export async function pruneSharedSnapshots(context, request, signal) {
|
|
16
|
+
const { runnerSandboxes, clock } = context;
|
|
17
|
+
const { access, dryRun } = request;
|
|
18
|
+
const listed = await runnerSandboxes.listNamedSandboxes(access, { namePrefix: SHARED_SNAPSHOT_SANDBOX_PREFIX }, signal);
|
|
19
|
+
if (!listed.ok) {
|
|
20
|
+
return listed.failure.kind === "aborted"
|
|
21
|
+
? { kind: "aborted" }
|
|
22
|
+
: { kind: "failed", message: listed.failure.message };
|
|
23
|
+
}
|
|
24
|
+
const validRows = listed.value.filter((row) => parseSharedSnapshotSandboxName(row.name) !== null);
|
|
25
|
+
const now = clock.now();
|
|
26
|
+
const nowMs = now.getTime();
|
|
27
|
+
let aborted = false;
|
|
28
|
+
const checked = await runLimited(validRows.length, INDEX_CONCURRENCY, () => !aborted && !isAborted(signal), async (index) => {
|
|
29
|
+
const row = validRows[index];
|
|
30
|
+
const unverified = classifyUnverifiedSharedSandbox(row);
|
|
31
|
+
if (unverified.kind === "settled") {
|
|
32
|
+
switch (unverified.status) {
|
|
33
|
+
case "building":
|
|
34
|
+
return { kind: "skip" };
|
|
35
|
+
case "failed":
|
|
36
|
+
return { kind: "mark", entry: { name: row.name, reason: "failed" } };
|
|
37
|
+
case "no-snapshot":
|
|
38
|
+
return { kind: "mark", entry: { name: row.name, reason: "no-snapshot" } };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Fast-path: skip stopped entries whose `expires-at` tag is still in the future without calling `getSnapshot`.
|
|
42
|
+
const tagExpiresAt = row.tags["expires-at"];
|
|
43
|
+
if (tagExpiresAt !== undefined) {
|
|
44
|
+
const tagMs = Date.parse(tagExpiresAt);
|
|
45
|
+
if (!Number.isNaN(tagMs) && tagMs > nowMs)
|
|
46
|
+
return { kind: "skip" };
|
|
47
|
+
}
|
|
48
|
+
const verified = await runnerSandboxes.getSnapshot(access, { snapshotId: unverified.snapshotId }, signal);
|
|
49
|
+
if (!verified.ok) {
|
|
50
|
+
if (verified.failure.kind === "aborted") {
|
|
51
|
+
aborted = true;
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return { kind: "failed", failure: { name: row.name, message: verified.failure.message } };
|
|
55
|
+
}
|
|
56
|
+
const classified = classifyVerifiedSharedSnapshot({ ...row, currentSnapshotId: unverified.snapshotId }, verified.value, now);
|
|
57
|
+
switch (classified.status) {
|
|
58
|
+
case "missing":
|
|
59
|
+
return { kind: "mark", entry: { name: row.name, reason: "missing", snapshotId: unverified.snapshotId } };
|
|
60
|
+
case "expired":
|
|
61
|
+
return { kind: "mark", entry: { name: row.name, reason: "expired", snapshotId: unverified.snapshotId } };
|
|
62
|
+
case "ready":
|
|
63
|
+
case "expires-soon":
|
|
64
|
+
case "unknown-expiry":
|
|
65
|
+
return { kind: "skip" };
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
if (aborted || isAborted(signal))
|
|
69
|
+
return { kind: "aborted" };
|
|
70
|
+
const marked = [];
|
|
71
|
+
const failed = [];
|
|
72
|
+
let skipped = 0;
|
|
73
|
+
for (const outcome of checked) {
|
|
74
|
+
if (outcome === undefined)
|
|
75
|
+
continue;
|
|
76
|
+
switch (outcome.kind) {
|
|
77
|
+
case "skip":
|
|
78
|
+
skipped += 1;
|
|
79
|
+
break;
|
|
80
|
+
case "mark":
|
|
81
|
+
marked.push(outcome.entry);
|
|
82
|
+
break;
|
|
83
|
+
case "failed":
|
|
84
|
+
failed.push(outcome.failure);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const deleted = [];
|
|
89
|
+
if (dryRun) {
|
|
90
|
+
deleted.push(...marked);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const deleteResults = await runLimited(marked.length, INDEX_CONCURRENCY, () => !aborted && !isAborted(signal), async (index) => {
|
|
94
|
+
const entry = marked[index];
|
|
95
|
+
const removed = await runnerSandboxes.deleteNamedSandbox(access, { name: entry.name }, signal);
|
|
96
|
+
if (removed.ok)
|
|
97
|
+
return { kind: "deleted", entry };
|
|
98
|
+
if (removed.failure.kind === "aborted") {
|
|
99
|
+
aborted = true;
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
return { kind: "failed", failure: { name: entry.name, message: removed.failure.message } };
|
|
103
|
+
});
|
|
104
|
+
if (aborted || isAborted(signal))
|
|
105
|
+
return { kind: "aborted" };
|
|
106
|
+
for (const outcome of deleteResults) {
|
|
107
|
+
if (outcome === undefined)
|
|
108
|
+
continue;
|
|
109
|
+
switch (outcome.kind) {
|
|
110
|
+
case "deleted":
|
|
111
|
+
deleted.push(outcome.entry);
|
|
112
|
+
break;
|
|
113
|
+
case "failed":
|
|
114
|
+
failed.push(outcome.failure);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
kind: "ok",
|
|
121
|
+
summary: {
|
|
122
|
+
scanned: validRows.length,
|
|
123
|
+
deleted,
|
|
124
|
+
skipped,
|
|
125
|
+
failed,
|
|
126
|
+
dryRun,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** Whether `signal` has aborted now. */
|
|
131
|
+
function isAborted(signal) {
|
|
132
|
+
return signal?.aborted === true;
|
|
133
|
+
}
|
|
@@ -1,51 +1,79 @@
|
|
|
1
1
|
import type { SandboxCredential } from "../sdk/extension/index.ts";
|
|
2
2
|
import { type RunnerContext } from "./context.ts";
|
|
3
3
|
import type { RunnerProgress, RunnerStage, SnapshotBuildReason } from "./events.ts";
|
|
4
|
-
import type {
|
|
4
|
+
import type { RunnerSnapshotEntry, RunnerSnapshotIndexFailure, SandboxAccess } from "./gateways.ts";
|
|
5
5
|
import type { PreparedRunner } from "./prepare.ts";
|
|
6
6
|
import type { RunnerSandboxScope } from "./scope.ts";
|
|
7
7
|
/** How long a build sandbox may live: 30 minutes. */
|
|
8
8
|
export declare const BUILD_SANDBOX_TIMEOUT_MS: number;
|
|
9
9
|
/** The label of the step between the toolchain and prebuild steps that commits the base's files. */
|
|
10
10
|
export declare const BASE_INDEX_LABEL = "Committing the base's files";
|
|
11
|
-
/** A runner snapshot a run built and the
|
|
11
|
+
/** A runner snapshot a run built and the local snapshot index entry recorded for it, or why it couldn't record it. */
|
|
12
12
|
export interface BuiltSnapshot {
|
|
13
13
|
readonly entry: RunnerSnapshotEntry;
|
|
14
|
-
/** How long the build took, from its start to the
|
|
14
|
+
/** How long the build took, from its start to the local snapshot index entry. */
|
|
15
15
|
readonly ms: number;
|
|
16
16
|
readonly sizeBytes: number;
|
|
17
|
-
/** Why the
|
|
18
|
-
readonly
|
|
17
|
+
/** Why the local snapshot index couldn't write `entry`; null when it wrote it. */
|
|
18
|
+
readonly localIndexFailure: RunnerSnapshotIndexFailure | null;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* What a
|
|
21
|
+
* What a runner snapshot build reads of a prepared run, or of a `storm snapshots build` plan: the runner options, the
|
|
22
22
|
* checkout, the base, its snapshot steps and key, and how many commits HEAD has after the base.
|
|
23
23
|
*/
|
|
24
|
-
export interface
|
|
24
|
+
export interface RunnerSnapshotPlan extends Pick<PreparedRunner, "options" | "repoRoot" | "base" | "baseFiles" | "snapshotKey"> {
|
|
25
25
|
/** How many commits HEAD has after the base; null for a `--base` commit that isn't HEAD's merge-base. */
|
|
26
26
|
readonly commitsAfterBase: number | null;
|
|
27
27
|
}
|
|
28
28
|
/** What a snapshot build needs to know: what it builds, who it runs as, the credentials, and why it builds. */
|
|
29
29
|
export interface BuildSnapshotRequest {
|
|
30
|
-
readonly prepared:
|
|
30
|
+
readonly prepared: RunnerSnapshotPlan;
|
|
31
31
|
readonly access: SandboxAccess;
|
|
32
32
|
/** The local user, for the sandbox's `user` tag. */
|
|
33
33
|
readonly user: string;
|
|
34
34
|
/**
|
|
35
|
-
* The
|
|
35
|
+
* The runner's credentials, with their values; the firewall adds each one from before the first toolchain step until
|
|
36
36
|
* the scope revokes them before the snapshot save, or in its fence if the build ends early.
|
|
37
37
|
*/
|
|
38
38
|
readonly credentials: readonly Required<SandboxCredential>[];
|
|
39
39
|
/** Why it builds, for the line that says so. */
|
|
40
40
|
readonly why: SnapshotBuildReason;
|
|
41
|
+
/**
|
|
42
|
+
* Publish the build to the shared snapshot index: the build sandbox takes `name` and `tags`
|
|
43
|
+
* (`snapshotIndexTags`), and stays in the project, stopped, once saved. Undefined builds an unnamed build sandbox
|
|
44
|
+
* with the runner's tags, which is deleted once saved.
|
|
45
|
+
*/
|
|
46
|
+
readonly publish?: SnapshotPublish;
|
|
47
|
+
}
|
|
48
|
+
/** The name and tags of a build sandbox kept stopped as a shared snapshot index entry. */
|
|
49
|
+
export interface SnapshotPublish {
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly tags: Readonly<Record<string, string>>;
|
|
41
52
|
}
|
|
42
53
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* same identity, a base snapshot of the same owner, recipe, snapshot key and base. A cache entry that can't be written
|
|
46
|
-
* is reported, and the build still succeeds, saying why (`BuiltSnapshot.cacheFailure`).
|
|
54
|
+
* How a published snapshot build ended: a build's stage, or `name-taken` when a sandbox named `name` already exists in
|
|
55
|
+
* the project, such as one another build started first, so this build started nothing.
|
|
47
56
|
*/
|
|
48
|
-
export
|
|
57
|
+
export type PublishedSnapshotStage = RunnerStage<BuiltSnapshot> | {
|
|
58
|
+
readonly kind: "name-taken";
|
|
59
|
+
readonly name: string;
|
|
60
|
+
readonly message: string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Builds a runner snapshot of `prepared.base`. The build sandbox starts while the base's files are packed, and is
|
|
64
|
+
* deleted once saved; a build that fails leaves it to the scope to stop and delete. Its local snapshot index entry
|
|
65
|
+
* replaces one of the same identity, a runner snapshot of the same owner, runner, snapshot key, and base. A local
|
|
66
|
+
* snapshot index entry that can't be written is reported, and the build still succeeds, saying why
|
|
67
|
+
* (`BuiltSnapshot.localIndexFailure`). With `publish`, the build sandbox takes its name and tags and stays in the
|
|
68
|
+
* project, stopped, once saved, and a name already taken ends the build `name-taken` before anything else starts.
|
|
69
|
+
*/
|
|
70
|
+
export declare function buildSnapshot(context: Pick<RunnerContext, "checkout" | "runnerSnapshots" | "runnerSandboxes" | "clock">, request: BuildSnapshotRequest & {
|
|
71
|
+
readonly publish?: undefined;
|
|
72
|
+
}, control: {
|
|
49
73
|
readonly scope: RunnerSandboxScope;
|
|
50
74
|
readonly signal: AbortSignal;
|
|
51
75
|
}, progress: RunnerProgress): Promise<RunnerStage<BuiltSnapshot>>;
|
|
76
|
+
export declare function buildSnapshot(context: Pick<RunnerContext, "checkout" | "runnerSnapshots" | "runnerSandboxes" | "clock">, request: BuildSnapshotRequest, control: {
|
|
77
|
+
readonly scope: RunnerSandboxScope;
|
|
78
|
+
readonly signal: AbortSignal;
|
|
79
|
+
}, progress: RunnerProgress): Promise<PublishedSnapshotStage>;
|
|
@@ -1,52 +1,53 @@
|
|
|
1
1
|
// Building a runner snapshot of a run's base: a build sandbox runs the toolchain steps, commits exactly the base's
|
|
2
|
-
// tracked files, runs the prebuild steps, and is saved as a snapshot, which the
|
|
3
|
-
// grants the
|
|
4
|
-
// scope's fence if the build fails or is canceled).
|
|
2
|
+
// tracked files, runs the prebuild steps, and is saved as a snapshot, which the local snapshot index then records. The
|
|
3
|
+
// sandbox scope grants the runner's credentials before the first toolchain step, and revokes them before the snapshot
|
|
4
|
+
// save (or in the scope's fence if the build fails or is canceled). A published build names its build sandbox and keeps
|
|
5
|
+
// it stopped once saved, as an entry of the shared snapshot index.
|
|
5
6
|
import { runnerTags } from "./context.js";
|
|
6
|
-
import { SNAPSHOT_EXPIRATION_MS } from "./snapshot-
|
|
7
|
+
import { SNAPSHOT_EXPIRATION_MS } from "./local-snapshot-index.js";
|
|
7
8
|
import { baseIndexScript, STAGED_FILES } from "./snapshot-key.js";
|
|
8
9
|
import { networkPolicyStop, runStep, sandboxStop } from "./steps.js";
|
|
9
10
|
/** How long a build sandbox may live: 30 minutes. */
|
|
10
11
|
export const BUILD_SANDBOX_TIMEOUT_MS = 30 * 60_000;
|
|
11
12
|
/** The label of the step between the toolchain and prebuild steps that commits the base's files. */
|
|
12
13
|
export const BASE_INDEX_LABEL = "Committing the base's files";
|
|
13
|
-
/**
|
|
14
|
-
* Builds a base snapshot of `prepared.base`. The build sandbox starts while the base's files are packed, and is
|
|
15
|
-
* deleted once saved; a build that fails leaves it to the scope to stop and delete. Its cache entry replaces one of the
|
|
16
|
-
* same identity, a base snapshot of the same owner, recipe, snapshot key and base. A cache entry that can't be written
|
|
17
|
-
* is reported, and the build still succeeds, saying why (`BuiltSnapshot.cacheFailure`).
|
|
18
|
-
*/
|
|
19
14
|
export async function buildSnapshot(context, request, control, progress) {
|
|
20
15
|
const { prepared, access } = request;
|
|
21
|
-
const {
|
|
16
|
+
const { options, repoRoot, base } = prepared;
|
|
22
17
|
const { scope, signal } = control;
|
|
18
|
+
const { publish } = request;
|
|
23
19
|
const now = () => context.clock.now().getTime();
|
|
24
20
|
const startedAt = now();
|
|
25
21
|
await progress.emit({
|
|
26
22
|
kind: "snapshot-build-started",
|
|
27
23
|
base,
|
|
28
24
|
why: request.why,
|
|
29
|
-
summary:
|
|
25
|
+
summary: options.snapshot.summary ??
|
|
26
|
+
[...options.snapshot.toolchains, ...options.snapshot.prebuild].map(({ label }) => label).join(", "),
|
|
30
27
|
});
|
|
31
28
|
const [started, archive] = await Promise.all([
|
|
32
29
|
scope.startBuildSandbox(access, {
|
|
33
|
-
region:
|
|
34
|
-
runtime:
|
|
35
|
-
vcpus:
|
|
30
|
+
region: options.region,
|
|
31
|
+
runtime: options.runtime,
|
|
32
|
+
vcpus: options.snapshot.vcpus,
|
|
36
33
|
timeoutMs: BUILD_SANDBOX_TIMEOUT_MS,
|
|
37
|
-
|
|
34
|
+
...(publish === undefined
|
|
35
|
+
? { tags: runnerTags(options.name, "snapshot-build", request.user) }
|
|
36
|
+
: { name: publish.name, tags: publish.tags }),
|
|
38
37
|
}),
|
|
39
38
|
context.checkout.baseArchive({ repoRoot, base }),
|
|
40
39
|
]);
|
|
41
40
|
if (!started.ok)
|
|
42
|
-
return
|
|
41
|
+
return started.failure.kind === "name-taken"
|
|
42
|
+
? { kind: "name-taken", name: started.failure.name, message: started.failure.message }
|
|
43
|
+
: sandboxStop("start-build-sandbox", started.failure);
|
|
43
44
|
const sandbox = started.value;
|
|
44
45
|
await progress.emit({
|
|
45
46
|
kind: "sandbox-started",
|
|
46
47
|
role: "snapshot-build",
|
|
47
48
|
name: sandbox.name,
|
|
48
|
-
region:
|
|
49
|
-
vcpus:
|
|
49
|
+
region: options.region,
|
|
50
|
+
vcpus: options.snapshot.vcpus,
|
|
50
51
|
ms: now() - startedAt,
|
|
51
52
|
});
|
|
52
53
|
if (!archive.ok)
|
|
@@ -57,16 +58,22 @@ export async function buildSnapshot(context, request, control, progress) {
|
|
|
57
58
|
], signal);
|
|
58
59
|
if (!staged.ok)
|
|
59
60
|
return sandboxStop("upload", staged.failure);
|
|
60
|
-
|
|
61
|
+
if (prepared.baseFiles.length > 0) {
|
|
62
|
+
const encoder = new TextEncoder();
|
|
63
|
+
const placed = await context.runnerSandboxes.placeBaseFiles(sandbox, prepared.baseFiles.map(({ path, text }) => ({ name: path, content: encoder.encode(text) })), signal);
|
|
64
|
+
if (!placed.ok)
|
|
65
|
+
return sandboxStop("upload", placed.failure);
|
|
66
|
+
}
|
|
67
|
+
// Every credential the runner declares goes on the steps' requests, from before the first toolchain step until
|
|
61
68
|
// `saveSnapshot` revokes them before saving (or the scope's fence revokes them if a step fails or the build is
|
|
62
69
|
// canceled). storm's own base-index step falls inside: it runs only tar and git on the uploaded files, so it makes no
|
|
63
70
|
// request, and revoking and granting again around it would add two writes and their failures for nothing.
|
|
64
71
|
const steps = [
|
|
65
|
-
...
|
|
72
|
+
...options.snapshot.toolchains,
|
|
66
73
|
{ label: BASE_INDEX_LABEL, script: baseIndexScript(base, staged.value.directory) },
|
|
67
|
-
...
|
|
74
|
+
...options.snapshot.prebuild,
|
|
68
75
|
];
|
|
69
|
-
await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region:
|
|
76
|
+
await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region: options.region });
|
|
70
77
|
let stop;
|
|
71
78
|
if (request.credentials.length > 0) {
|
|
72
79
|
const granted = await scope.grantCredentials(sandbox, request.credentials, signal);
|
|
@@ -107,7 +114,10 @@ export async function buildSnapshot(context, request, control, progress) {
|
|
|
107
114
|
if (signal.aborted)
|
|
108
115
|
return { kind: "aborted" };
|
|
109
116
|
await progress.emit({ kind: "snapshot-saving" });
|
|
110
|
-
const saved = await scope.saveSnapshot(sandbox, {
|
|
117
|
+
const saved = await scope.saveSnapshot(sandbox, {
|
|
118
|
+
expirationMs: SNAPSHOT_EXPIRATION_MS,
|
|
119
|
+
...(publish === undefined ? {} : { keepStopped: true }),
|
|
120
|
+
});
|
|
111
121
|
if (!saved.ok)
|
|
112
122
|
return saved.failure.kind === "credential-not-revoked"
|
|
113
123
|
? networkPolicyStop("remove", "snapshot-save", saved.failure.failure)
|
|
@@ -116,9 +126,9 @@ export async function buildSnapshot(context, request, control, progress) {
|
|
|
116
126
|
const entry = {
|
|
117
127
|
teamId: access.teamId,
|
|
118
128
|
projectId: access.projectId,
|
|
119
|
-
region:
|
|
120
|
-
runtime:
|
|
121
|
-
|
|
129
|
+
region: options.region,
|
|
130
|
+
runtime: options.runtime,
|
|
131
|
+
runnerName: options.name,
|
|
122
132
|
snapshotKey: prepared.snapshotKey,
|
|
123
133
|
base,
|
|
124
134
|
snapshotId: saved.value.snapshotId,
|
|
@@ -139,6 +149,6 @@ export async function buildSnapshot(context, request, control, progress) {
|
|
|
139
149
|
});
|
|
140
150
|
return {
|
|
141
151
|
kind: "ok",
|
|
142
|
-
value: { entry, ms, sizeBytes: saved.value.sizeBytes,
|
|
152
|
+
value: { entry, ms, sizeBytes: saved.value.sizeBytes, localIndexFailure: written.ok ? null : written.failure },
|
|
143
153
|
};
|
|
144
154
|
}
|
|
@@ -19,7 +19,7 @@ export async function chooseSnapshotForRun(context, request, control, progress)
|
|
|
19
19
|
// reporting cancellation or stopping sandboxes outside the running step.
|
|
20
20
|
const scope = runnerSandboxScope(context, progress, {
|
|
21
21
|
keepMs: 0,
|
|
22
|
-
basePolicy: runnerNetworkPolicy(request.prepared.
|
|
22
|
+
basePolicy: runnerNetworkPolicy(request.prepared.options),
|
|
23
23
|
signal,
|
|
24
24
|
});
|
|
25
25
|
try {
|