hammerkit 1.27.0-next.9 → 2.0.0-next.10
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/build.schema.json +176 -6
- package/dist/cache/backends/local-cache-backend.js +6 -0
- package/dist/cache/backends/registry/registry-client.js +1 -0
- package/dist/cache/cache-sync.js +1 -1
- package/dist/cache/explain.js +23 -4
- package/dist/cli.js +2 -0
- package/dist/dashboard/assets/graph-canvas-DLioOiRN.css +1 -0
- package/dist/dashboard/assets/graph-canvas-HmkW_-XJ.js +8 -0
- package/dist/dashboard/assets/index-gIBDC_m8.css +2 -0
- package/dist/dashboard/assets/index-vE22S5E_.js +17 -0
- package/dist/dashboard/index.html +15 -0
- package/dist/dashboard/logo.png +0 -0
- package/dist/docker/item-network.js +13 -5
- package/dist/executer/archive-task-entry.js +4 -2
- package/dist/executer/deadline.js +17 -3
- package/dist/executer/deferred-restore.js +36 -0
- package/dist/executer/docker-service.js +30 -8
- package/dist/executer/docker-task.js +24 -1
- package/dist/executer/execute-work-service.js +2 -0
- package/dist/executer/execute-work-task.js +14 -5
- package/dist/executer/execution-steps.js +25 -4
- package/dist/executer/local-task.js +3 -0
- package/dist/executer/reset-work-tree.js +4 -0
- package/dist/executer/scheduler/enqueue-next.js +63 -7
- package/dist/executer/scheduler/state-key.js +89 -15
- package/dist/executer/watch-loop.js +22 -6
- package/dist/file/get-file-context.js +5 -1
- package/dist/harness/connect.js +20 -6
- package/dist/harness/mcp-command.js +22 -6
- package/dist/harness/mcp.js +63 -114
- package/dist/harness/opencode.js +158 -50
- package/dist/harness/pi.js +29 -0
- package/dist/harness/sandbox-client.js +194 -23
- package/dist/harness/service-tools.js +141 -0
- package/dist/harness/task-tools.js +221 -0
- package/dist/kubernetes/apply.js +49 -1
- package/dist/kubernetes/await-running-state.js +241 -18
- package/dist/kubernetes/claim-layout.js +10 -1
- package/dist/kubernetes/cluster-state.js +245 -0
- package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +142 -9
- package/dist/kubernetes/ensure-kubernetes-service-exists.js +2 -0
- package/dist/kubernetes/ensure-persistent-data.js +305 -12
- package/dist/kubernetes/follow-pod-logs.js +281 -0
- package/dist/kubernetes/job-placement.js +36 -12
- package/dist/kubernetes/kept-claims.js +16 -1
- package/dist/kubernetes/kubernetes-instance.js +1 -0
- package/dist/kubernetes/network-policy.js +6 -5
- package/dist/kubernetes/quota-wait.js +97 -0
- package/dist/kubernetes/remove-stale-items.js +46 -0
- package/dist/kubernetes/restore-kubernetes-data.js +35 -8
- package/dist/kubernetes/sandbox-runner.js +628 -0
- package/dist/kubernetes/service-rollouts.js +74 -0
- package/dist/kubernetes/store-kubernetes-data.js +18 -4
- package/dist/kubernetes/volumes.js +124 -12
- package/dist/main.js +2 -0
- package/dist/optimizer/calculate-checksum.js +49 -5
- package/dist/optimizer/check-key.js +94 -0
- package/dist/optimizer/check-keys.js +66 -0
- package/dist/optimizer/get-work-cache-stats.js +53 -27
- package/dist/optimizer/work-task-cache-description.js +49 -1
- package/dist/parser/read-build-file.js +8 -3
- package/dist/planner/service-definition.js +9 -4
- package/dist/planner/utils/append-work-dependencies.js +5 -3
- package/dist/planner/utils/append-work-service.js +18 -1
- package/dist/planner/utils/append-work-task.js +13 -3
- package/dist/planner/utils/get-work-runtime.js +6 -1
- package/dist/planner/utils/normalize-path.js +19 -1
- package/dist/planner/utils/parse-work-mount.js +7 -1
- package/dist/planner/utils/parse-work-port.js +4 -1
- package/dist/planner/utils/template-value.js +20 -4
- package/dist/planner/validate.js +22 -0
- package/dist/planner/work-item-executions.js +27 -0
- package/dist/planner/work-network.js +3 -1
- package/dist/planner/work-runtime-aggregate.js +32 -0
- package/dist/planner/work-runtime-kubernetes.js +204 -53
- package/dist/planner/work-task.js +6 -1
- package/dist/program.js +27 -9
- package/dist/remote/device-login.js +7 -2
- package/dist/remote/host-config.js +69 -3
- package/dist/remote/remote-commands.js +33 -7
- package/dist/remote/remote-status.js +112 -0
- package/dist/remote/remote-work-commands.js +571 -45
- package/dist/remote/server-client.js +15 -2
- package/dist/remote/token-source.js +64 -26
- package/dist/run-program.js +9 -0
- package/dist/schema/build-file-base-task-schema.js +3 -3
- package/dist/schema/build-file-container-service-schema.js +10 -0
- package/dist/schema/build-file-container-task-schema.js +16 -1
- package/dist/schema/build-file-include-schema.js +18 -4
- package/dist/schema/build-file-kubernetes-service-schema.js +2 -0
- package/dist/schema/build-file-task-schema.js +5 -1
- package/dist/schema/capabilities-schema.js +56 -0
- package/dist/schema/reference-parser.js +119 -11
- package/dist/schema/removed-properties.js +20 -0
- package/dist/schema/schema-parser.js +140 -43
- package/dist/schema/work-scope-parser.js +33 -10
- package/dist/secrets/command-secret-provider.js +3 -1
- package/dist/secrets/github-app-token-command.js +3 -1
- package/dist/secrets/secret-catalog.js +43 -19
- package/dist/server/accounts-api.js +4 -1
- package/dist/server/approvals-api.js +1 -1
- package/dist/server/capacity-format.js +36 -0
- package/dist/server/capacity.js +330 -0
- package/dist/server/checks-api.js +83 -0
- package/dist/server/checks.js +116 -0
- package/dist/server/dashboard.js +214 -0
- package/dist/server/definitions-api.js +66 -3
- package/dist/server/endpoints.js +803 -0
- package/dist/server/executor.js +216 -30
- package/dist/server/kubernetes-backend.js +415 -48
- package/dist/server/kubernetes-sandbox-storage.js +60 -6
- package/dist/server/oauth.js +16 -1
- package/dist/server/overview.js +340 -0
- package/dist/server/plan.js +186 -124
- package/dist/server/policy.js +42 -4
- package/dist/server/proposals-api.js +17 -8
- package/dist/server/repo-access.js +5 -0
- package/dist/server/run-logs.js +4 -0
- package/dist/server/run-plan.js +38 -4
- package/dist/server/run-request.js +58 -3
- package/dist/server/run-worker.js +307 -17
- package/dist/server/runs.js +1036 -42
- package/dist/server/sandbox-files.js +107 -16
- package/dist/server/sandbox-patch.js +43 -17
- package/dist/server/sandbox-pod.js +28 -0
- package/dist/server/sandbox-storage.js +23 -0
- package/dist/server/sandboxes.js +65 -23
- package/dist/server/server-config.js +250 -11
- package/dist/server/server.js +465 -33
- package/dist/server/service-runs.js +89 -0
- package/dist/server/sources.js +68 -11
- package/dist/server/timings.js +152 -0
- package/dist/server/wait-reason.js +21 -0
- package/dist/utils/buffer-context.js +30 -20
- package/dist/utils/limit.js +30 -0
- package/dist/utils/read-lines.js +65 -0
- package/dist/utils/tar.js +28 -1
- package/dist/utils/terminal-prompt.js +53 -0
- package/dist/utils/units.js +36 -1
- package/dist/utils/web-links.js +34 -0
- package/package.json +8 -2
package/dist/server/executor.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HostExecutor = exports.volumeScope = exports.cacheNamespace = exports.defaultWorker = void 0;
|
|
3
|
+
exports.HostExecutor = exports.removeServiceRunVolumes = exports.serviceRunScopes = exports.volumeScope = exports.cacheNamespace = exports.defaultWorker = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const crypto_1 = require("crypto");
|
|
6
|
+
const checks_1 = require("./checks");
|
|
6
7
|
const fs_1 = require("fs");
|
|
7
8
|
const promises_1 = require("fs/promises");
|
|
8
9
|
const path_1 = require("path");
|
|
@@ -11,6 +12,7 @@ const resolve_git_source_1 = require("../includes/resolve-git-source");
|
|
|
11
12
|
const git_checkout_1 = require("./git-checkout");
|
|
12
13
|
const run_plan_1 = require("./run-plan");
|
|
13
14
|
const work_network_1 = require("../planner/work-network");
|
|
15
|
+
const execute_docker_1 = require("../executer/execute-docker");
|
|
14
16
|
// `.git` as a file system may read it: any case, and a name Windows reads without its
|
|
15
17
|
// trailing dots and spaces, or by its short name
|
|
16
18
|
function isGitDirectory(segment) {
|
|
@@ -35,19 +37,74 @@ exports.defaultWorker = defaultWorker;
|
|
|
35
37
|
// share one, those of an upload or a sandbox only their owner's. Somebody who can only
|
|
36
38
|
// upload, or an agent on a sandbox, can not leave an entry for a run from a reviewed
|
|
37
39
|
// repository to find.
|
|
40
|
+
//
|
|
41
|
+
// A check on a sandbox runs on a copy of the files a commit of them would hold, so it is a
|
|
42
|
+
// run of the repository like a ref run of that commit, and shares its cache: what its
|
|
43
|
+
// owner may write in the sandbox is not part of it. It leaves entries a run from main can
|
|
44
|
+
// find, keyed by the files it ran on, as a ref run of a branch does: so only a caller who
|
|
45
|
+
// may push a branch of the repository and run from it may check (server.ts).
|
|
46
|
+
//
|
|
47
|
+
// An approved run on a sandbox runs on a copy of the approved files too, but its owner
|
|
48
|
+
// may not use its accounts without the approval: it has a cache of its own, so what the
|
|
49
|
+
// owner's other runs built from files nobody approved (ignored ones) is not restored in it.
|
|
38
50
|
function cacheNamespace(run) {
|
|
39
|
-
const
|
|
40
|
-
|
|
51
|
+
const repository = run.source.type === 'ref' || (run.source.type === 'sandbox' && run.source.check);
|
|
52
|
+
const kind = repository
|
|
53
|
+
? 'ref'
|
|
54
|
+
: run.source.type === 'sandbox' && (run.approvals?.length ?? 0) > 0
|
|
55
|
+
? 'approved'
|
|
56
|
+
: run.source.type;
|
|
57
|
+
const key = repository
|
|
58
|
+
? `ref\0${run.source.repo}`
|
|
59
|
+
: `${kind}\0${run.owner.iss}\0${run.owner.sub}`;
|
|
60
|
+
return `${kind}-${(0, crypto_1.createHash)('sha256').update(key).digest('hex').slice(0, 24)}`;
|
|
41
61
|
}
|
|
42
62
|
exports.cacheNamespace = cacheNamespace;
|
|
43
63
|
// The docker volumes of a run's services are its caller's, within the cache's source trust:
|
|
44
64
|
// two callers of one repository share a cache, a task is keyed by what it reads, but not the
|
|
45
|
-
// data their services keep.
|
|
46
|
-
|
|
65
|
+
// data their services keep. A service run's are its own: they stay while it sleeps and go
|
|
66
|
+
// when it ends (removeServiceRunVolumes). They carry the server's key (see serviceRunScopes),
|
|
67
|
+
// so a server sweeps its own only, next to another one on the same docker.
|
|
68
|
+
function volumeScope(run, server = '') {
|
|
69
|
+
if (run.up) {
|
|
70
|
+
return `${serviceRunScopes(server)}${(0, crypto_1.createHash)('sha256').update(run.id).digest('hex').slice(0, 24)}`;
|
|
71
|
+
}
|
|
47
72
|
const key = `${cacheNamespace(run)}\0${run.owner.iss}\0${run.owner.sub}`;
|
|
48
73
|
return `${run.source.type}-${(0, crypto_1.createHash)('sha256').update(key).digest('hex').slice(0, 24)}`;
|
|
49
74
|
}
|
|
50
75
|
exports.volumeScope = volumeScope;
|
|
76
|
+
// the start of the volume scopes of the service runs of a server, by the directory its runs
|
|
77
|
+
// work in
|
|
78
|
+
function serviceRunScopes(server) {
|
|
79
|
+
return `up-${(0, crypto_1.createHash)('sha256').update(server).digest('hex').slice(0, 8)}-`;
|
|
80
|
+
}
|
|
81
|
+
exports.serviceRunScopes = serviceRunScopes;
|
|
82
|
+
// the volume of a service of a service run, with the scope of its run (see scopeServiceVolumes)
|
|
83
|
+
const SERVICE_RUN_VOLUME = /^hammerkit-(up-[0-9a-f]{8}-[0-9a-f]{24})-/;
|
|
84
|
+
/**
|
|
85
|
+
* Removes the docker volumes of the services of service runs whose scope `remove` names: of
|
|
86
|
+
* one run that ended, or at a start, of every run but those that sleep with their volumes.
|
|
87
|
+
* One a container still uses stays, and is said.
|
|
88
|
+
*/
|
|
89
|
+
async function removeServiceRunVolumes(docker, remove, log) {
|
|
90
|
+
const listed = await docker.listVolumes({ filters: { name: ['hammerkit-up-'] } });
|
|
91
|
+
const removed = [];
|
|
92
|
+
for (const volume of listed.Volumes ?? []) {
|
|
93
|
+
const scope = SERVICE_RUN_VOLUME.exec(volume.Name)?.[1];
|
|
94
|
+
if (!scope || !remove(scope)) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
await docker.getVolume(volume.Name).remove();
|
|
99
|
+
removed.push(volume.Name);
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
log(`the volume ${volume.Name} could not be removed: ${e instanceof Error ? e.message : String(e)}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return removed;
|
|
106
|
+
}
|
|
107
|
+
exports.removeServiceRunVolumes = removeServiceRunVolumes;
|
|
51
108
|
/**
|
|
52
109
|
* Runs the tasks of a run on this machine with the engine of `hammerkit run`, in a
|
|
53
110
|
* process of its own.
|
|
@@ -65,6 +122,56 @@ exports.volumeScope = volumeScope;
|
|
|
65
122
|
class HostExecutor {
|
|
66
123
|
constructor(options) {
|
|
67
124
|
this.options = options;
|
|
125
|
+
// the directories of the executions that run now
|
|
126
|
+
this.directories = new Set();
|
|
127
|
+
}
|
|
128
|
+
// the docker daemon the runs' services are on, as their processes reach it
|
|
129
|
+
docker() {
|
|
130
|
+
return (0, execute_docker_1.createDockerClient)(this.options.planning.environment.processEnvs.DOCKER_HOST);
|
|
131
|
+
}
|
|
132
|
+
// the volumes of a service run's services, which its end removes
|
|
133
|
+
async removeVolumes(run, context) {
|
|
134
|
+
const scope = volumeScope(run, this.options.directory);
|
|
135
|
+
const say = (text) => {
|
|
136
|
+
this.options.log?.(`run=${run.id} ${text}`);
|
|
137
|
+
context?.emit({ type: 'log', task: 'hammerkit', stream: 'stderr', text });
|
|
138
|
+
};
|
|
139
|
+
try {
|
|
140
|
+
await removeServiceRunVolumes(this.docker(), (candidate) => candidate === scope, say);
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
say(`the volumes of the services could not be removed: ${e instanceof Error ? e.message : String(e)}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/** A service run that slept with its volumes ended without waking: they go. */
|
|
147
|
+
async forget(run) {
|
|
148
|
+
if (run.up && !this.options.placement) {
|
|
149
|
+
await this.removeVolumes(run);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* At the start of the server: the volumes of service runs go, but of those that sleep with
|
|
154
|
+
* them. A server without docker has none.
|
|
155
|
+
*/
|
|
156
|
+
restored(runs) {
|
|
157
|
+
if (this.options.placement) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const own = serviceRunScopes(this.options.directory);
|
|
161
|
+
const kept = new Set(runs.filter((run) => run.up).map((run) => volumeScope(run, this.options.directory)));
|
|
162
|
+
const log = (line) => this.options.log?.(line);
|
|
163
|
+
removeServiceRunVolumes(this.docker(), (scope) => scope.startsWith(own) && !kept.has(scope), log)
|
|
164
|
+
.then((removed) => {
|
|
165
|
+
if (removed.length > 0) {
|
|
166
|
+
log(`removed ${removed.length} volumes of service runs from before the server started`);
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
.catch((e) => {
|
|
170
|
+
const code = e.code;
|
|
171
|
+
if (code !== 'ENOENT' && code !== 'ECONNREFUSED') {
|
|
172
|
+
log(`the volumes of earlier service runs could not be removed: ${e instanceof Error ? e.message : e}`);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
68
175
|
}
|
|
69
176
|
async execute(run, context) {
|
|
70
177
|
const { definitions, planning, repos } = this.options;
|
|
@@ -110,50 +217,97 @@ class HostExecutor {
|
|
|
110
217
|
abort();
|
|
111
218
|
}
|
|
112
219
|
context.signal.addEventListener('abort', abort, { once: true });
|
|
113
|
-
|
|
220
|
+
// a service run that moves executes beside itself, each in a directory of its own
|
|
221
|
+
const root = this.directoryOf(run);
|
|
114
222
|
let attachment;
|
|
115
223
|
try {
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
|
|
224
|
+
// The process of the run starts in the published files, which it reads its build files
|
|
225
|
+
// from, and its tasks work on other files (`work`): a checkout, a sandbox or a copy of
|
|
226
|
+
// one. The published files are a directory of the run no task mounts, so what the
|
|
227
|
+
// process parses for each task it runs, and what the secret providers it starts read
|
|
228
|
+
// of their directory, is what was published and never what a task wrote.
|
|
229
|
+
const published = (0, path_1.join)(root, 'bundle');
|
|
230
|
+
await (0, promises_1.mkdir)(published, { recursive: true });
|
|
231
|
+
await this.writeBundle(published, bundle.files);
|
|
120
232
|
let input;
|
|
121
233
|
let claim;
|
|
122
|
-
// the files
|
|
234
|
+
// the files the tasks work on
|
|
123
235
|
let work;
|
|
124
|
-
|
|
125
|
-
|
|
236
|
+
const sourceStarted = new Date();
|
|
237
|
+
// A check works on the files a push of the sandbox commits, copied out of it, and so
|
|
238
|
+
// does a run that was approved: what was approved is those files, and the sandbox has
|
|
239
|
+
// more (its ignored files, node_modules, outputs), which its owner and their runs write
|
|
240
|
+
// while the run waits and runs.
|
|
241
|
+
const copied = source.type === 'sandbox' && (source.check || (run.approvals?.length ?? 0) > 0);
|
|
242
|
+
// (`source.type` again: TypeScript narrows `source` by it, not by `copied`)
|
|
243
|
+
if (source.type === 'sandbox' && copied) {
|
|
244
|
+
const { registry, network } = sandboxes;
|
|
245
|
+
const what = source.check ? 'the check' : 'the approved run';
|
|
246
|
+
if (!source.check) {
|
|
247
|
+
// what was approved is what runs: the files may have changed since, by a run
|
|
248
|
+
// before this one on the sandbox (the copy checks it again, under the sandbox's lock)
|
|
249
|
+
const state = await registry.state(source.id, abortCtrl.signal);
|
|
250
|
+
if (state.tree !== source.tree) {
|
|
251
|
+
throw new Error(`the files of the sandbox ${source.id} changed since the run was approved, they are ${state.tree} now and were ${source.tree}, submit the run again`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
work = (0, path_1.join)(root, 'source');
|
|
255
|
+
try {
|
|
256
|
+
await registry.exportTree(source.id, source.tree, work, abortCtrl.signal);
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
throw new Error(`the files of the sandbox ${source.id} could not be copied for ${what}, submit it again: ${e instanceof Error ? e.message : String(e)}`);
|
|
260
|
+
}
|
|
261
|
+
// a repository of its own, as a checkout of the commit is: the root of the project,
|
|
262
|
+
// which the paths of the tasks' keys are relative to, is the one of git
|
|
263
|
+
await (0, git_checkout_1.git)(['init', '--quiet', work], {}, abortCtrl.signal, `${what} of sandbox ${source.id}`, 'init');
|
|
264
|
+
context.emit({
|
|
265
|
+
type: 'log',
|
|
266
|
+
task: 'hammerkit',
|
|
267
|
+
stream: 'stdout',
|
|
268
|
+
text: `${source.check ? 'check' : 'approved run'} of sandbox ${source.id} of ${source.repo}: files ${source.tree}, fetched at ${source.commit}`,
|
|
269
|
+
});
|
|
270
|
+
// the tasks see the published build files in place of the sandbox's own
|
|
271
|
+
await this.writeBundle(work, bundle.files);
|
|
272
|
+
input = {
|
|
273
|
+
entry: (0, path_1.join)(published, version.entry),
|
|
274
|
+
directory: { read: published, work },
|
|
275
|
+
...(planning.policy.network ? { network: (0, work_network_1.toNetworkSchema)(planning.policy.network) } : {}),
|
|
276
|
+
sandboxNetwork: network,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
else if (source.type === 'ref') {
|
|
280
|
+
work = (0, path_1.join)(root, 'source');
|
|
126
281
|
const { repo, ref, commit: pinned } = source;
|
|
127
282
|
const credentials = await repos.credentials(repo);
|
|
128
283
|
let commit;
|
|
129
284
|
try {
|
|
130
|
-
commit
|
|
285
|
+
// a woken service run starts the commit it started first, where the ref is now or not
|
|
286
|
+
const fetched = run.wakes ? pinned : ref;
|
|
287
|
+
commit = await (0, git_checkout_1.checkoutRef)(repos.url(repo), fetched, work, credentials.env, abortCtrl.signal, pinned);
|
|
131
288
|
}
|
|
132
289
|
catch (e) {
|
|
133
290
|
throw repos.scrub(e, credentials.values);
|
|
134
291
|
}
|
|
135
292
|
context.emit({ type: 'log', task: 'hammerkit', stream: 'stdout', text: `checked out ${repo} at ${commit}` });
|
|
136
|
-
|
|
293
|
+
// the tasks see the published build files in place of the checkout's own
|
|
294
|
+
await this.writeBundle(work, bundle.files);
|
|
137
295
|
// what the version was checked against at publish holds while it runs too
|
|
138
296
|
input = {
|
|
139
|
-
entry: (0, path_1.join)(
|
|
297
|
+
entry: (0, path_1.join)(published, version.entry),
|
|
298
|
+
directory: { read: published, work },
|
|
140
299
|
...(planning.policy.network ? { network: (0, work_network_1.toNetworkSchema)(planning.policy.network) } : {}),
|
|
141
300
|
};
|
|
142
301
|
}
|
|
143
302
|
else {
|
|
144
|
-
//
|
|
145
|
-
//
|
|
303
|
+
// a run its caller may run without an approval works on the sandbox itself, whose
|
|
304
|
+
// own build files are just files
|
|
146
305
|
const { registry, network } = sandboxes;
|
|
147
306
|
// read before the run attaches: until then the walk of the last run's measure holds
|
|
148
307
|
const state = await registry.state(source.id, abortCtrl.signal);
|
|
149
308
|
attachment = await registry.attach(source.id, (0, path_1.join)(root, 'sandbox'));
|
|
150
309
|
work = attachment.directory;
|
|
151
310
|
claim = attachment.claim;
|
|
152
|
-
// what was approved is what runs: the files may have changed since, by a run
|
|
153
|
-
// before this one on the sandbox
|
|
154
|
-
if (run.approvals?.length && state.tree !== source.tree) {
|
|
155
|
-
throw new Error(`the files of the sandbox ${source.id} changed since the run was approved, they are ${state.tree} now and were ${source.tree}, submit the run again`);
|
|
156
|
-
}
|
|
157
311
|
if (claim && !this.options.placement) {
|
|
158
312
|
throw new Error(`the sandbox ${source.id} is a claim on a cluster, this server runs tasks on its own docker`);
|
|
159
313
|
}
|
|
@@ -163,10 +317,6 @@ class HostExecutor {
|
|
|
163
317
|
stream: 'stdout',
|
|
164
318
|
text: `sandbox ${source.id} of ${source.repo} at ${state.commit}, files ${state.tree}${state.clean ? '' : ' with changes'}`,
|
|
165
319
|
});
|
|
166
|
-
const published = (0, path_1.join)(root, 'bundle');
|
|
167
|
-
await (0, promises_1.mkdir)(published, { recursive: true });
|
|
168
|
-
await this.writeBundle(published, bundle.files);
|
|
169
|
-
cwd = published;
|
|
170
320
|
input = {
|
|
171
321
|
entry: (0, path_1.join)(published, version.entry),
|
|
172
322
|
directory: { read: published, work },
|
|
@@ -175,39 +325,68 @@ class HostExecutor {
|
|
|
175
325
|
sandboxNetwork: network,
|
|
176
326
|
};
|
|
177
327
|
}
|
|
328
|
+
emitPhase(context, 'source', sourceStarted);
|
|
178
329
|
const home = (0, path_1.join)(root, 'home');
|
|
179
330
|
await (0, promises_1.mkdir)(home, { recursive: true });
|
|
180
331
|
const cache = (0, path_1.join)(this.options.cache, cacheNamespace(run));
|
|
181
332
|
await (0, promises_1.mkdir)(cache, { recursive: true });
|
|
182
333
|
const placement = this.options.placement;
|
|
183
|
-
const
|
|
334
|
+
const namespaceStarted = new Date();
|
|
335
|
+
const placed = placement ? await placement.prepare(run, context, { root: work, claim }) : undefined;
|
|
336
|
+
if (placed) {
|
|
337
|
+
emitPhase(context, 'namespace', namespaceStarted);
|
|
338
|
+
}
|
|
184
339
|
try {
|
|
185
340
|
await this.runInProcess(worker, {
|
|
186
341
|
...input,
|
|
187
342
|
tasks: run.tasks,
|
|
188
343
|
options: run.options,
|
|
189
344
|
accounts: run.accounts,
|
|
190
|
-
volumeScope: volumeScope(run),
|
|
345
|
+
volumeScope: volumeScope(run, this.options.directory),
|
|
346
|
+
...((0, checks_1.isCheckRun)(run) ? { check: true } : {}),
|
|
191
347
|
catalog: planning.environment.hosted?.catalog,
|
|
348
|
+
...(run.up
|
|
349
|
+
? {
|
|
350
|
+
up: {
|
|
351
|
+
services: run.up.services,
|
|
352
|
+
endpoints: run.up.endpoints.map(({ service, port }) => ({ service, port })),
|
|
353
|
+
},
|
|
354
|
+
}
|
|
355
|
+
: {}),
|
|
192
356
|
...(placed ? { kubernetes: placed.kubernetes } : {}),
|
|
193
|
-
|
|
357
|
+
...(!placed && this.options.capabilityRuntime ? { capabilityRuntime: this.options.capabilityRuntime } : {}),
|
|
358
|
+
}, published, { ...this.processEnvironment(home, cache), ...placed?.env }, context, abortCtrl.signal);
|
|
194
359
|
}
|
|
195
360
|
finally {
|
|
196
361
|
if (placement && placed) {
|
|
197
362
|
await placement.release(run, context);
|
|
198
363
|
}
|
|
364
|
+
else if (run.up && !context.keep?.()) {
|
|
365
|
+
// the services are gone with the process, their volumes stay only while the run sleeps
|
|
366
|
+
await this.removeVolumes(run, context);
|
|
367
|
+
}
|
|
199
368
|
}
|
|
200
369
|
}
|
|
201
370
|
finally {
|
|
202
371
|
context.signal.removeEventListener('abort', abort);
|
|
203
372
|
attachment?.release?.();
|
|
204
373
|
await this.removeRunDirectory(run, root, context);
|
|
374
|
+
this.directories.delete(root);
|
|
205
375
|
if (source.type === 'sandbox') {
|
|
206
376
|
// what the run wrote counts against the owner's limits, from their next run or create
|
|
207
377
|
sandboxes?.registry.measure(source.id).catch(() => undefined);
|
|
208
378
|
}
|
|
209
379
|
}
|
|
210
380
|
}
|
|
381
|
+
directoryOf(run) {
|
|
382
|
+
for (let execution = 1;; execution++) {
|
|
383
|
+
const root = (0, path_1.join)(this.options.directory, execution === 1 ? run.id : `${run.id}-${execution}`);
|
|
384
|
+
if (!this.directories.has(root)) {
|
|
385
|
+
this.directories.add(root);
|
|
386
|
+
return root;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
211
390
|
// A task of the run may still hold a file of its directory for a moment after the run
|
|
212
391
|
// ended, which Windows refuses to remove. A directory that stays is reported, to the run
|
|
213
392
|
// by its error code and to the operator with its path; it does not change how the run ended.
|
|
@@ -282,6 +461,9 @@ class HostExecutor {
|
|
|
282
461
|
if (message.kind === 'event') {
|
|
283
462
|
context.emit(message.event);
|
|
284
463
|
}
|
|
464
|
+
else if (message.kind === 'up') {
|
|
465
|
+
context.up?.(message.targets);
|
|
466
|
+
}
|
|
285
467
|
else if (message.kind === 'result') {
|
|
286
468
|
result = message;
|
|
287
469
|
// nothing left to tell the process
|
|
@@ -349,4 +531,8 @@ class HostExecutor {
|
|
|
349
531
|
}
|
|
350
532
|
}
|
|
351
533
|
exports.HostExecutor = HostExecutor;
|
|
534
|
+
// A step of a run before its tasks, for its timeline (RunPhase)
|
|
535
|
+
function emitPhase(context, phase, startedAt) {
|
|
536
|
+
context.emit({ type: 'phase', phase, startedAt: startedAt.toISOString(), finishedAt: new Date().toISOString() });
|
|
537
|
+
}
|
|
352
538
|
//# sourceMappingURL=executor.js.map
|