hammerkit 2.0.0-next.2 → 2.0.0-next.20
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/cache/backends/registry/registry-client.js +8 -2
- package/dist/cache/explain.js +7 -5
- package/dist/cache/last-resolved.js +11 -0
- package/dist/cli.js +4 -1
- 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 +3 -3
- package/dist/dashboard/logo.png +0 -0
- package/dist/docker/item-network.js +51 -18
- package/dist/docker/package.js +85 -76
- package/dist/docker/server-tools.js +96 -0
- package/dist/docker/stream.js +15 -7
- package/dist/environment/replace-env-variables.js +1 -1
- package/dist/environment/run-source-envs.js +18 -0
- package/dist/executer/check-container-binds.js +158 -0
- package/dist/executer/docker-service.js +42 -3
- package/dist/executer/docker-task.js +21 -5
- package/dist/executer/execute-command.js +9 -15
- package/dist/executer/execute-work-task.js +14 -2
- package/dist/executer/execute-work-tree.js +2 -1
- package/dist/executer/execution-steps.js +3 -2
- package/dist/executer/local-task.js +3 -0
- package/dist/executer/print-container-options.js +10 -10
- package/dist/executer/process-manager.js +84 -5
- package/dist/executer/scheduler/enqueue-next.js +6 -1
- package/dist/executer/scheduler/state-key.js +71 -34
- package/dist/executer/task-priority.js +131 -0
- package/dist/executer/watch-loop.js +18 -5
- package/dist/file/get-file-context.js +5 -1
- package/dist/file/stat-beneath.js +66 -0
- package/dist/file/within-root.js +13 -4
- package/dist/harness/connect.js +1 -6
- package/dist/harness/mcp-command.js +1 -1
- package/dist/harness/sandbox-client.js +39 -4
- package/dist/harness/service-tools.js +2 -2
- package/dist/kubernetes/await-running-state.js +98 -18
- package/dist/kubernetes/claim-layout.js +10 -1
- package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +10 -1
- package/dist/kubernetes/ensure-persistent-data.js +129 -26
- package/dist/kubernetes/follow-pod-logs.js +128 -29
- package/dist/kubernetes/kept-claims.js +16 -1
- package/dist/kubernetes/network-gate.js +74 -11
- package/dist/kubernetes/network-policy.js +35 -13
- package/dist/kubernetes/quota-wait.js +97 -0
- package/dist/kubernetes/remove-stale-items.js +15 -2
- package/dist/kubernetes/restore-kubernetes-data.js +28 -4
- package/dist/kubernetes/sandbox-runner.js +3 -4
- package/dist/kubernetes/store-kubernetes-data.js +14 -2
- package/dist/kubernetes/transfer-tools.js +66 -0
- package/dist/kubernetes/volumes.js +78 -14
- package/dist/optimizer/calculate-checksum.js +46 -3
- package/dist/optimizer/check-key.js +7 -0
- package/dist/optimizer/check-keys.js +19 -5
- package/dist/optimizer/get-work-cache-stats.js +55 -31
- package/dist/optimizer/work-task-cache-description.js +36 -7
- package/dist/parser/read-build-file.js +8 -3
- package/dist/planner/utils/append-work-service.js +1 -1
- package/dist/planner/utils/append-work-task.js +1 -1
- package/dist/planner/utils/assert-item-paths.js +6 -7
- package/dist/planner/utils/template-value.js +20 -4
- package/dist/planner/work-item-executions.js +27 -0
- package/dist/planner/work-runtime-docker.js +31 -50
- package/dist/planner/work-runtime-kubernetes.js +70 -41
- package/dist/planner/work-runtime-local.js +3 -7
- package/dist/planner/work-secret.js +135 -13
- package/dist/planner/work-tree.js +10 -0
- package/dist/remote/collect-bundle.js +9 -1
- package/dist/remote/host-config.js +49 -3
- package/dist/remote/location.js +5 -5
- package/dist/remote/remote-commands.js +12 -14
- package/dist/remote/remote-work-commands.js +19 -10
- package/dist/schema/schema-parser.js +46 -2
- package/dist/schema/work-scope-parser.js +16 -1
- package/dist/secrets/secret-catalog.js +8 -1
- package/dist/server/capacity.js +71 -41
- package/dist/server/dashboard.js +27 -9
- package/dist/server/endpoints.js +10 -1
- package/dist/server/executor.js +68 -35
- package/dist/server/kubernetes-backend.js +29 -4
- package/dist/server/kubernetes-sandbox-storage.js +14 -4
- package/dist/server/oauth.js +16 -1
- package/dist/server/overview.js +80 -11
- package/dist/server/plan.js +41 -6
- package/dist/server/policy.js +22 -9
- package/dist/server/repo-access.js +4 -3
- package/dist/server/run-environment.js +5 -2
- package/dist/server/run-plan.js +18 -6
- package/dist/server/run-source-environment.js +39 -0
- package/dist/server/run-worker.js +71 -9
- package/dist/server/runs.js +133 -7
- package/dist/server/sandbox-files.js +339 -55
- package/dist/server/sandbox-patch.js +43 -17
- package/dist/server/sandboxes.js +57 -23
- package/dist/server/server-config.js +28 -5
- package/dist/server/server.js +94 -16
- package/dist/server/service-runs.js +50 -5
- package/dist/server/sources.js +68 -11
- package/dist/server/timings.js +23 -3
- package/dist/utils/buffer-context.js +30 -20
- package/dist/utils/limit.js +30 -0
- package/dist/utils/line-splitter.js +52 -0
- package/dist/utils/read-lines.js +65 -0
- package/dist/utils/tar.js +51 -1
- package/dist/utils/units.js +36 -1
- package/dist/utils/web-links.js +34 -0
- package/package.json +1 -1
- package/dist/dashboard/assets/index-CjnKm5-3.css +0 -2
- package/dist/dashboard/assets/index-zPXa4klZ.js +0 -13
- package/dist/dashboard/favicon.svg +0 -1
package/dist/server/plan.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.inspectBundle = exports.planBundle = exports.getCredentialReads = exports.PLAIN_SERVER_ENVS = exports.DefinitionError = void 0;
|
|
3
|
+
exports.inspectBundle = exports.planBundle = exports.getCredentialReads = exports.withSymbolicValues = exports.PLAIN_SERVER_ENVS = exports.DefinitionError = void 0;
|
|
4
4
|
const promises_1 = require("fs/promises");
|
|
5
5
|
const os_1 = require("os");
|
|
6
6
|
const path_1 = require("path");
|
|
@@ -18,12 +18,24 @@ const log_1 = require("../log");
|
|
|
18
18
|
const parse_error_1 = require("../schema/parse-error");
|
|
19
19
|
const task_arguments_1 = require("../planner/utils/task-arguments");
|
|
20
20
|
const work_network_1 = require("../planner/work-network");
|
|
21
|
+
const run_source_envs_1 = require("../environment/run-source-envs");
|
|
21
22
|
class DefinitionError extends Error {
|
|
22
23
|
}
|
|
23
24
|
exports.DefinitionError = DefinitionError;
|
|
24
25
|
// Variables of a server that hold no credential (FR-008): a task may read these and
|
|
25
|
-
// still take arguments, or reach any network.
|
|
26
|
-
exports.PLAIN_SERVER_ENVS = ['PATH', 'HOME', 'CI'];
|
|
26
|
+
// still take arguments, or reach any network. The ones of the run's source are set for each run.
|
|
27
|
+
exports.PLAIN_SERVER_ENVS = ['PATH', 'HOME', 'CI', ...run_source_envs_1.RUN_SOURCE_ENVS];
|
|
28
|
+
// The environment of runs as a build file is read before anybody runs it (a publish, a
|
|
29
|
+
// proposal, POST /v1/definitions/plan): each variable but the plain ones stands for its name,
|
|
30
|
+
// `${NAME}`. What the server answers about a build file, a description or an image that reads
|
|
31
|
+
// `$NAME` included, then never holds a value a run would see. The tasks of a run read the values.
|
|
32
|
+
function withSymbolicValues(processEnvs) {
|
|
33
|
+
return Object.fromEntries(Object.entries(processEnvs).map(([name, value]) => [
|
|
34
|
+
name,
|
|
35
|
+
value === undefined || exports.PLAIN_SERVER_ENVS.includes(name.toUpperCase()) ? value : `\${${name}}`,
|
|
36
|
+
]));
|
|
37
|
+
}
|
|
38
|
+
exports.withSymbolicValues = withSymbolicValues;
|
|
27
39
|
// What an item holds that its command must not hand out: its secrets, and the variables
|
|
28
40
|
// of the server its `envs` read, but the plain ones.
|
|
29
41
|
function getCredentialReads(item) {
|
|
@@ -255,6 +267,15 @@ function findItemPolicyProblems(item, policy, root) {
|
|
|
255
267
|
problems.push(`${item.name}: volume ${volume.name} is not a volume name, a path of the server can't be mounted`);
|
|
256
268
|
}
|
|
257
269
|
}
|
|
270
|
+
if (policy.readableEnvs) {
|
|
271
|
+
const allowed = policy.readableEnvs;
|
|
272
|
+
const refusedEnvs = ('envs' in data ? data.envs.processNames ?? [] : []).filter((name) => !exports.PLAIN_SERVER_ENVS.includes(name.toUpperCase()) && !allowed.includes(name));
|
|
273
|
+
if (refusedEnvs.length > 0) {
|
|
274
|
+
problems.push(`${item.name}: reads ${refusedEnvs
|
|
275
|
+
.map((name) => `$${name}`)
|
|
276
|
+
.join(', ')} of the server, which it does not list in ${policy.envsFrom ?? 'runs.env.allow'}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
258
279
|
for (const secret of secretsOf(item)) {
|
|
259
280
|
const source = secret.source;
|
|
260
281
|
if (policy.backend === 'kubernetes' && source.type === 'provider') {
|
|
@@ -294,6 +315,13 @@ function describeMountSource(mount) {
|
|
|
294
315
|
const home = (0, normalize_path_1.getHomeReference)(mount.mount.split(':')[0]);
|
|
295
316
|
return home ? `${mount.localPath} (${home} is the home directory)` : mount.localPath;
|
|
296
317
|
}
|
|
318
|
+
// where the build file of an item is: in the bundle, or in the repository of a git include
|
|
319
|
+
function declaredIn(root, scope) {
|
|
320
|
+
if (scope.remote) {
|
|
321
|
+
return `${scope.remote.git} ${(0, path_1.relative)(scope.remote.root, scope.fileName).split(path_1.sep).join('/')}`;
|
|
322
|
+
}
|
|
323
|
+
return (0, path_1.relative)(root, scope.fileName).split(path_1.sep).join('/');
|
|
324
|
+
}
|
|
297
325
|
function toPlan(root, item) {
|
|
298
326
|
const data = item.data;
|
|
299
327
|
const secrets = secretsOf(item).map(describeSecret);
|
|
@@ -322,6 +350,7 @@ function toPlan(root, item) {
|
|
|
322
350
|
const isTask = data.type === 'local-task' || data.type === 'container-task';
|
|
323
351
|
return {
|
|
324
352
|
kind: isTask ? 'task' : 'service',
|
|
353
|
+
file: declaredIn(root, data.scope),
|
|
325
354
|
...(data.description ? { description: data.description } : {}),
|
|
326
355
|
runtime: (0, work_task_1.isAggregateTask)(data) ? 'none' : data.type === 'local-task' ? 'local' : 'docker',
|
|
327
356
|
...((0, work_task_1.isContainerWorkTask)(data) || (0, work_service_1.isContainerWorkService)(data) ? { image: data.image } : {}),
|
|
@@ -330,13 +359,19 @@ function toPlan(root, item) {
|
|
|
330
359
|
network: (0, work_network_1.toNetworkSchema)('network' in data ? data.network : { type: 'open' }),
|
|
331
360
|
...('args' in data && data.args !== null ? { args: data.args } : {}),
|
|
332
361
|
deps: item.deps.map((dep) => dep.name).sort(),
|
|
333
|
-
|
|
362
|
+
// by their names in the plan, not the names the task reaches them at (`postgres` of an include)
|
|
363
|
+
needs: item.needs.map((need) => need.service.name).sort(),
|
|
364
|
+
...((0, work_service_1.isContainerWorkService)(data) && data.init ? { init: data.init.task.name } : {}),
|
|
334
365
|
accounts,
|
|
335
366
|
secrets,
|
|
336
367
|
serverEnvs: 'envs' in data ? data.envs.processNames ?? [] : [],
|
|
337
368
|
mounts,
|
|
338
369
|
ports,
|
|
339
|
-
|
|
370
|
+
// where in the bundle, as the build file names them: the directory the server read it in is
|
|
371
|
+
// its own
|
|
372
|
+
generates: 'generates' in data
|
|
373
|
+
? data.generates.map((generate) => insideBundle(root, data.cwd, generate.path)[0] ?? generate.path)
|
|
374
|
+
: [],
|
|
340
375
|
...(capAdd.length > 0 ? { capAdd: [...capAdd] } : {}),
|
|
341
376
|
flags,
|
|
342
377
|
};
|
|
@@ -400,7 +435,7 @@ async function planBundle(bundle, environment, options = {}) {
|
|
|
400
435
|
? item.data.mounts.flatMap((mount) => insideBundle(directory, item.data.cwd, mount.localPath))
|
|
401
436
|
: [],
|
|
402
437
|
deps: item.deps.map((dep) => dep.name).sort(),
|
|
403
|
-
needs: item.needs.map((need) => need.name).sort(),
|
|
438
|
+
needs: item.needs.map((need) => need.service.name).sort(),
|
|
404
439
|
};
|
|
405
440
|
}
|
|
406
441
|
const plan = {};
|
package/dist/server/policy.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decideRun = exports.sandboxRepos = exports.decideSandbox = exports.sandboxPushBranches = exports.sandboxBranchType = exports.endpointLevel = exports.getGrant = exports.usedAccounts = exports.mayYank = exports.canUse = exports.maySeeDefinitions = exports.mayPublish = exports.mayPropose = exports.mayReadChecks = exports.mayRun = exports.matches = void 0;
|
|
3
|
+
exports.decideRun = exports.sandboxRepos = exports.decideSandbox = exports.sandboxPushBranches = exports.sandboxBranchType = exports.endpointLevel = exports.getGrant = exports.usedAccounts = exports.mayYank = exports.accountLevel = exports.canUse = exports.maySeeDefinitions = exports.mayPublish = exports.mayPropose = exports.mayReadChecks = exports.mayRun = exports.matches = exports.subjectName = void 0;
|
|
4
4
|
const repo_1 = require("./repo");
|
|
5
5
|
const BUILDS_ORDER = ['run', 'propose', 'publish'];
|
|
6
|
+
// The name an entitlement gives a subject, for the pages to name its runs by when its tokens
|
|
7
|
+
// name nobody.
|
|
8
|
+
function subjectName(entitlements, who) {
|
|
9
|
+
return entitlements.find((entitlement) => entitlement.subject?.name && entitlement.subject.iss === who.iss && entitlement.subject.sub === who.sub)?.subject?.name;
|
|
10
|
+
}
|
|
11
|
+
exports.subjectName = subjectName;
|
|
6
12
|
function matches(entitlement, principal) {
|
|
7
13
|
if (entitlement.subject) {
|
|
8
14
|
return entitlement.subject.iss === principal.iss && entitlement.subject.sub === principal.sub;
|
|
@@ -34,16 +40,22 @@ const mayPublish = (grant) => atLeast(grant, 'publish');
|
|
|
34
40
|
exports.mayPublish = mayPublish;
|
|
35
41
|
// A caller who can neither run nor publish anything sees nothing of the server's
|
|
36
42
|
// build files either. Someone who uses an account sees them: they have to know what
|
|
37
|
-
// they approve.
|
|
43
|
+
// they approve. Who observes sees them too, as they see what every run ran.
|
|
38
44
|
function maySeeDefinitions(grant) {
|
|
39
|
-
return grant.builds !== null || Object.keys(grant.accounts).length > 0;
|
|
45
|
+
return grant.builds !== null || Object.keys(grant.accounts).length > 0 || grant.observe;
|
|
40
46
|
}
|
|
41
47
|
exports.maySeeDefinitions = maySeeDefinitions;
|
|
42
48
|
// `use` includes deciding about the runs others request on the account.
|
|
43
49
|
function canUse(grant, account) {
|
|
44
|
-
return grant
|
|
50
|
+
return accountLevel(grant, account) === 'use';
|
|
45
51
|
}
|
|
46
52
|
exports.canUse = canUse;
|
|
53
|
+
// The level the caller has for an account, only when an entitlement names it: an account
|
|
54
|
+
// called `constructor` or `toString` is not found on the prototype of the record.
|
|
55
|
+
function accountLevel(grant, account) {
|
|
56
|
+
return Object.prototype.hasOwnProperty.call(grant.accounts, account) ? grant.accounts[account] : undefined;
|
|
57
|
+
}
|
|
58
|
+
exports.accountLevel = accountLevel;
|
|
47
59
|
// Pulling a version back is a safe thing to do, so it is open to who publishes the build
|
|
48
60
|
// file, and to who uses an account the version works with: they are the ones who
|
|
49
61
|
// answer for what runs as it.
|
|
@@ -52,13 +64,14 @@ function mayYank(grant, version) {
|
|
|
52
64
|
}
|
|
53
65
|
exports.mayYank = mayYank;
|
|
54
66
|
function usedAccounts(grant) {
|
|
55
|
-
return Object.keys(grant.accounts).filter((account) => grant
|
|
67
|
+
return Object.keys(grant.accounts).filter((account) => canUse(grant, account));
|
|
56
68
|
}
|
|
57
69
|
exports.usedAccounts = usedAccounts;
|
|
58
70
|
// Default deny: a caller without a matching entitlement gets nothing.
|
|
59
71
|
function getGrant(entitlements, principal) {
|
|
60
72
|
const matched = [];
|
|
61
|
-
|
|
73
|
+
// no prototype: an account named like one of its properties (`__proto__`) is a key like any other
|
|
74
|
+
const accounts = Object.create(null);
|
|
62
75
|
const repos = [];
|
|
63
76
|
const sandboxes = [];
|
|
64
77
|
const endpoints = [];
|
|
@@ -73,7 +86,7 @@ function getGrant(entitlements, principal) {
|
|
|
73
86
|
checks = checks || entitlement.checks === 'read';
|
|
74
87
|
observe = observe || entitlement.observe === true;
|
|
75
88
|
for (const [account, level] of Object.entries(entitlement.accounts)) {
|
|
76
|
-
if (accounts
|
|
89
|
+
if (accountLevel({ accounts }, account) !== 'use') {
|
|
77
90
|
accounts[account] = level;
|
|
78
91
|
}
|
|
79
92
|
}
|
|
@@ -227,11 +240,11 @@ function decideRun(input) {
|
|
|
227
240
|
}
|
|
228
241
|
const request = [];
|
|
229
242
|
for (const account of accounts) {
|
|
230
|
-
const level = grant
|
|
243
|
+
const level = accountLevel(grant, account);
|
|
231
244
|
if (level === undefined) {
|
|
232
245
|
return { type: 'refuse', status: 403, error: `you may not use the account ${account}, it needs use or request` };
|
|
233
246
|
}
|
|
234
|
-
const rules = catalog[account];
|
|
247
|
+
const rules = Object.prototype.hasOwnProperty.call(catalog, account) ? catalog[account] : undefined;
|
|
235
248
|
// a sandbox holds changes nobody reviewed: an account takes its runs only when it says so
|
|
236
249
|
const sources = rules?.source ?? ['ref', 'upload'];
|
|
237
250
|
if (!sources.includes(source.type)) {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RepoAccess = void 0;
|
|
4
4
|
const redact_1 = require("../utils/redact");
|
|
5
5
|
const provider_values_1 = require("../secrets/provider-values");
|
|
6
|
+
const secret_catalog_1 = require("../secrets/secret-catalog");
|
|
6
7
|
const git_checkout_1 = require("./git-checkout");
|
|
7
8
|
const repo_1 = require("./repo");
|
|
8
9
|
// A token is read again after this long, so a short-lived one (a GitHub App
|
|
@@ -119,9 +120,9 @@ class RepoAccess {
|
|
|
119
120
|
const catalog = this.environment.hosted?.catalog;
|
|
120
121
|
const kind = secret.from.substring(0, secret.from.indexOf(':'));
|
|
121
122
|
const ref = secret.from.substring(secret.from.indexOf(':') + 1);
|
|
122
|
-
const provider = catalog.providers
|
|
123
|
-
const account = catalog.accounts
|
|
124
|
-
const credentials = account
|
|
123
|
+
const provider = (0, secret_catalog_1.declared)(catalog.providers, kind);
|
|
124
|
+
const account = (0, secret_catalog_1.declared)(catalog.accounts, secret.account);
|
|
125
|
+
const credentials = account ? (0, secret_catalog_1.declared)(account.providers, kind) : undefined;
|
|
125
126
|
if (!provider || !credentials) {
|
|
126
127
|
throw new Error(`the source credential ${secret.from} as ${secret.account} is not defined`);
|
|
127
128
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runEnvironment = void 0;
|
|
4
|
+
const run_source_envs_1 = require("../environment/run-source-envs");
|
|
4
5
|
// What a run sees of the server's environment: the variables the operator listed
|
|
5
6
|
// in `runs.env.allow`, and the fixed ones of `runs.env.set`. The credentials of a
|
|
6
|
-
// run are not among them, they exist only as the secrets of an account.
|
|
7
|
+
// run are not among them, they exist only as the secrets of an account. The variables of
|
|
8
|
+
// what a run is from are the run's own (the config refuses them, see run-source-envs.ts).
|
|
7
9
|
function runEnvironment(config, processEnvs) {
|
|
8
10
|
const passed = {};
|
|
9
11
|
for (const name of config.runs.env.allow) {
|
|
@@ -14,7 +16,8 @@ function runEnvironment(config, processEnvs) {
|
|
|
14
16
|
passed[name] = processEnvs[key];
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
|
-
|
|
19
|
+
const all = { ...passed, ...config.runs.env.set };
|
|
20
|
+
return Object.fromEntries(Object.entries(all).filter(([name]) => !(0, run_source_envs_1.isRunSourceEnv)(name)));
|
|
18
21
|
}
|
|
19
22
|
exports.runEnvironment = runEnvironment;
|
|
20
23
|
//# sourceMappingURL=run-environment.js.map
|
package/dist/server/run-plan.js
CHANGED
|
@@ -6,7 +6,8 @@ const plan_1 = require("./plan");
|
|
|
6
6
|
function labels(values) {
|
|
7
7
|
return values && values.length > 0 ? (0, parse_label_arguments_1.parseLabelArguments)(values) : undefined;
|
|
8
8
|
}
|
|
9
|
-
// The tasks
|
|
9
|
+
// The tasks named, as one scope: they are planned together and run side by side as far
|
|
10
|
+
// as their dependencies allow, in no particular order; by labels when none is named. A
|
|
10
11
|
// service run is one scope of its services.
|
|
11
12
|
// The arguments, if any, go to the one task named (the request allows no more). That
|
|
12
13
|
// task runs uncached unless the request names a `cache` method, as `run --cache` does.
|
|
@@ -17,11 +18,22 @@ function getRunScopes(tasks, options, services = []) {
|
|
|
17
18
|
const args = options.args && options.args.length > 0
|
|
18
19
|
? { values: options.args, services: false, cache: options.cache !== undefined }
|
|
19
20
|
: undefined;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const named = [...new Set(tasks)];
|
|
22
|
+
if (named.length === 1) {
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
name: named[0],
|
|
26
|
+
scope: { taskName: named[0], environmentName: options.env ?? null, ...(args ? { args } : {}) },
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
return named.length > 0
|
|
31
|
+
? [
|
|
32
|
+
{
|
|
33
|
+
name: named.join(', '),
|
|
34
|
+
scope: { taskNames: named, environmentName: options.env ?? null, ...(args ? { args } : {}) },
|
|
35
|
+
},
|
|
36
|
+
]
|
|
25
37
|
: [
|
|
26
38
|
{
|
|
27
39
|
name: 'labels',
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runPlanningEnvironment = exports.withRunSource = exports.runSourceEnvironment = exports.RUN_SOURCE_ENVS = void 0;
|
|
4
|
+
const run_source_envs_1 = require("../environment/run-source-envs");
|
|
5
|
+
Object.defineProperty(exports, "RUN_SOURCE_ENVS", { enumerable: true, get: function () { return run_source_envs_1.RUN_SOURCE_ENVS; } });
|
|
6
|
+
// a ref may name a commit, which is no branch or tag (see git-checkout.ts)
|
|
7
|
+
const COMMIT = /^[0-9a-f]{40}([0-9a-f]{24})?$/i;
|
|
8
|
+
// What a run is from, for the `envs` of its tasks and services (`$HAMMERKIT_RUN_REF`): the
|
|
9
|
+
// repository, and the branch or tag and the commit it was pinned to, or the repository and the
|
|
10
|
+
// sandbox. None of them is a credential, so a task that reads them still takes arguments and
|
|
11
|
+
// keeps its network (see PLAIN_SERVER_ENVS). A sandbox has no commit: its files may hold
|
|
12
|
+
// changes. A run from an upload has none of them.
|
|
13
|
+
function runSourceEnvironment(source) {
|
|
14
|
+
if (source.type === 'ref') {
|
|
15
|
+
return {
|
|
16
|
+
HAMMERKIT_RUN_REPO: source.repo,
|
|
17
|
+
...(COMMIT.test(source.ref) ? {} : { HAMMERKIT_RUN_REF: source.ref }),
|
|
18
|
+
...(source.commit ? { HAMMERKIT_RUN_COMMIT: source.commit } : {}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (source.type === 'sandbox') {
|
|
22
|
+
return { HAMMERKIT_RUN_REPO: source.repo, HAMMERKIT_RUN_SANDBOX: source.id };
|
|
23
|
+
}
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
exports.runSourceEnvironment = runSourceEnvironment;
|
|
27
|
+
// The variables of a process, and the run's own in place of any of the same name, in any case.
|
|
28
|
+
function withRunSource(envs, source) {
|
|
29
|
+
const kept = Object.fromEntries(Object.entries(envs).filter(([name]) => !(0, run_source_envs_1.isRunSourceEnv)(name)));
|
|
30
|
+
return { ...kept, ...runSourceEnvironment(source) };
|
|
31
|
+
}
|
|
32
|
+
exports.withRunSource = withRunSource;
|
|
33
|
+
// The environment a run's files are read with, on the server, before its process starts: so
|
|
34
|
+
// the plan an approver reads shows what the tasks will see.
|
|
35
|
+
function runPlanningEnvironment(environment, source) {
|
|
36
|
+
return { ...environment, processEnvs: withRunSource(environment.processEnvs, source) };
|
|
37
|
+
}
|
|
38
|
+
exports.runPlanningEnvironment = runPlanningEnvironment;
|
|
39
|
+
//# sourceMappingURL=run-source-environment.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.workerMain = exports.readInput = exports.taskCauses = exports.describeFailures = exports.runTasks = exports.getEndpointTargets = exports.publishEndpoints = exports.getRunNetwork = exports.workerInputSchema = void 0;
|
|
3
|
+
exports.workerMain = exports.readInput = exports.taskCommands = exports.taskCauses = exports.describeFailures = exports.failedTasks = exports.runTasks = exports.getEndpointTargets = exports.publishEndpoints = exports.getRunNetwork = exports.workerInputSchema = void 0;
|
|
4
4
|
const readline_1 = require("readline");
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const cli_1 = require("../cli");
|
|
@@ -10,6 +10,7 @@ const schema_parser_1 = require("../schema/schema-parser");
|
|
|
10
10
|
const reference_parser_1 = require("../schema/reference-parser");
|
|
11
11
|
const work_scope_parser_1 = require("../schema/work-scope-parser");
|
|
12
12
|
const work_item_status_1 = require("../planner/work-item-status");
|
|
13
|
+
const work_item_executions_1 = require("../planner/work-item-executions");
|
|
13
14
|
const plan_work_tasks_1 = require("../planner/utils/plan-work-tasks");
|
|
14
15
|
const assert_item_paths_1 = require("../planner/utils/assert-item-paths");
|
|
15
16
|
const hosted_volumes_1 = require("../planner/utils/hosted-volumes");
|
|
@@ -79,6 +80,8 @@ exports.workerInputSchema = zod_1.z
|
|
|
79
80
|
.optional(),
|
|
80
81
|
// the run's results count as checks: report each task's check key before it runs
|
|
81
82
|
check: zod_1.z.boolean().optional(),
|
|
83
|
+
// what its tasks took in past runs, in ms by name, so the longest chain starts first
|
|
84
|
+
durations: zod_1.z.record(zod_1.z.number().nonnegative()).optional(),
|
|
82
85
|
})
|
|
83
86
|
.strict();
|
|
84
87
|
// The ceiling of the run, combined here and not in the server: the lower of two allow lists
|
|
@@ -205,6 +208,7 @@ up) {
|
|
|
205
208
|
maxTimeout: options.maxTimeout ? (0, units_1.parseDuration)(options.maxTimeout) : null,
|
|
206
209
|
skipDeps: options.skipDeps !== false,
|
|
207
210
|
network: getRunNetwork(input),
|
|
211
|
+
...(input.durations ? { durations: input.durations } : {}),
|
|
208
212
|
// why a task was not taken from the cache goes into its result
|
|
209
213
|
explain: true,
|
|
210
214
|
};
|
|
@@ -213,16 +217,25 @@ up) {
|
|
|
213
217
|
// the files as they are before any task wrote to them, a second task's too: a first
|
|
214
218
|
// one that formats or generates into src would key it by files no commit holds
|
|
215
219
|
for (const { scope } of scopes) {
|
|
216
|
-
for (const [task, { key }] of Object.entries(await (0, check_keys_1.getCheckKeys)(input.entry, environment, scope))) {
|
|
220
|
+
for (const [task, { key }] of Object.entries(await (0, check_keys_1.getCheckKeys)(input.entry, environment, scope, input.directory))) {
|
|
217
221
|
emit({ type: 'key', task, key });
|
|
218
222
|
}
|
|
219
223
|
}
|
|
220
224
|
}
|
|
225
|
+
// every scope is planned before any task runs: what the run executes is read from the
|
|
226
|
+
// published files as they were when it started, whatever a task does to its files
|
|
227
|
+
const planned = [];
|
|
221
228
|
for (const { name, scope } of scopes) {
|
|
222
229
|
const { ctx, scope: parsed } = await (0, schema_parser_1.createParseContext)(input.entry, environment, {
|
|
223
230
|
directory: input.directory,
|
|
224
231
|
});
|
|
225
|
-
|
|
232
|
+
planned.push({
|
|
233
|
+
name,
|
|
234
|
+
workTree: (0, work_scope_parser_1.getWorkContext)(await (0, reference_parser_1.parseReferences)(ctx, parsed, environment), scope, environment),
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
let started = false;
|
|
238
|
+
for (const { name, workTree } of planned) {
|
|
226
239
|
await (0, assert_item_paths_1.assertWorkTreePathsWithinRoot)(workTree, work);
|
|
227
240
|
if (input.volumeScope && !input.kubernetes) {
|
|
228
241
|
(0, hosted_volumes_1.scopeServiceVolumes)(workTree, input.volumeScope);
|
|
@@ -234,6 +247,16 @@ up) {
|
|
|
234
247
|
if (cli.tasks().length === 0 && (!input.up || cli.services().length === 0)) {
|
|
235
248
|
throw new Error(`no tasks found for ${name}`);
|
|
236
249
|
}
|
|
250
|
+
if (!started) {
|
|
251
|
+
// from the start of this process, which the executor started for the run
|
|
252
|
+
started = true;
|
|
253
|
+
emit({
|
|
254
|
+
type: 'phase',
|
|
255
|
+
phase: 'plan',
|
|
256
|
+
startedAt: new Date(performance.timeOrigin).toISOString(),
|
|
257
|
+
finishedAt: new Date().toISOString(),
|
|
258
|
+
});
|
|
259
|
+
}
|
|
237
260
|
const execution = input.up
|
|
238
261
|
? cli.up({ ...execOptions, workers: cli.defaultWorkers(), daemon: false, wait: 'ready' })
|
|
239
262
|
: cli.exec({ ...execOptions, workers: cli.defaultWorkers() });
|
|
@@ -261,14 +284,19 @@ up) {
|
|
|
261
284
|
if (input.kubernetes.server?.serviceRun) {
|
|
262
285
|
// a run that moved here from another commit: what it made for items it has no more
|
|
263
286
|
const ids = [...Object.values(workTree.tasks), ...Object.values(workTree.services)].map((item) => item.id());
|
|
264
|
-
await (0, remove_stale_items_1.removeStaleItems)((0, kubernetes_instance_1.createKubernetesInstances)(input.kubernetes), input.kubernetes, ids
|
|
287
|
+
await (0, remove_stale_items_1.removeStaleItems)((0, kubernetes_instance_1.createKubernetesInstances)(input.kubernetes), input.kubernetes, ids, {
|
|
288
|
+
signal: abortCtrl.signal,
|
|
289
|
+
}).catch((e) => emit({
|
|
265
290
|
type: 'log',
|
|
266
291
|
task: 'hammerkit',
|
|
267
292
|
stream: 'stderr',
|
|
268
293
|
text: `what the run made at its previous commit could not be removed: ${(0, log_1.getErrorMessage)(e)}`,
|
|
269
294
|
}));
|
|
270
295
|
}
|
|
271
|
-
|
|
296
|
+
// stopped while the old pods ended, or up until it is stopped
|
|
297
|
+
if (!abortCtrl.signal.aborted) {
|
|
298
|
+
await new Promise((resolve) => abortCtrl.signal.addEventListener('abort', () => resolve(), { once: true }));
|
|
299
|
+
}
|
|
272
300
|
return;
|
|
273
301
|
}
|
|
274
302
|
if (input.up && ready) {
|
|
@@ -287,7 +315,7 @@ up) {
|
|
|
287
315
|
}
|
|
288
316
|
// a service run names what failed and why: its services have no results of their own
|
|
289
317
|
const failures = input.up ? describeFailures(execution.state.current, (text) => secrets.redact(text)) : [];
|
|
290
|
-
throw new Error(failures.length > 0 ? failures.join('; ').slice(0, runs_1.MAX_TASK_ERROR) : `${name} failed`);
|
|
318
|
+
throw new Error(failures.length > 0 ? failures.join('; ').slice(0, runs_1.MAX_TASK_ERROR) : `${failedTasks(workTree, name)} failed`);
|
|
291
319
|
}
|
|
292
320
|
}
|
|
293
321
|
finally {
|
|
@@ -351,6 +379,19 @@ function lastError(item) {
|
|
|
351
379
|
}
|
|
352
380
|
return last;
|
|
353
381
|
}
|
|
382
|
+
// Of several tasks named, the ones that failed: those named first, else the dependencies
|
|
383
|
+
// that failed under them. One task named is the run's name, as before.
|
|
384
|
+
function failedTasks(workTree, name) {
|
|
385
|
+
const requested = workTree.requested ?? [];
|
|
386
|
+
if (requested.length < 2) {
|
|
387
|
+
return name;
|
|
388
|
+
}
|
|
389
|
+
const failed = [...(0, plan_work_tasks_1.iterateWorkTasks)(workTree)].filter((task) => task.state.current.type === 'error' || task.state.current.type === 'crash');
|
|
390
|
+
const named = failed.filter((task) => requested.includes(task.name));
|
|
391
|
+
const names = (named.length > 0 ? named : failed).map((task) => task.name);
|
|
392
|
+
return names.length > 0 ? names.join(', ') : name;
|
|
393
|
+
}
|
|
394
|
+
exports.failedTasks = failedTasks;
|
|
354
395
|
/**
|
|
355
396
|
* What failed in a run, one line each, for its error: the services and tasks that failed,
|
|
356
397
|
* with their reason. Those that only stopped because another failed are left out.
|
|
@@ -392,6 +433,19 @@ function taskCauses(causes, redact) {
|
|
|
392
433
|
: {};
|
|
393
434
|
}
|
|
394
435
|
exports.taskCauses = taskCauses;
|
|
436
|
+
// When the commands of a task that is over ran, as its runtime saw them.
|
|
437
|
+
function taskCommands(task) {
|
|
438
|
+
const executions = (0, work_item_executions_1.readExecutions)(task);
|
|
439
|
+
return executions.length
|
|
440
|
+
? {
|
|
441
|
+
commands: executions.slice(0, runs_1.MAX_COMMANDS).map((e) => ({
|
|
442
|
+
startedAt: e.startedAt.toISOString(),
|
|
443
|
+
finishedAt: e.finishedAt.toISOString(),
|
|
444
|
+
})),
|
|
445
|
+
}
|
|
446
|
+
: {};
|
|
447
|
+
}
|
|
448
|
+
exports.taskCommands = taskCommands;
|
|
395
449
|
// A task event when a task has moved on since the last look, with what its result needs
|
|
396
450
|
// once it is over.
|
|
397
451
|
function reportTasks(emit, workTree, seen,
|
|
@@ -414,17 +468,25 @@ redact) {
|
|
|
414
468
|
state: status,
|
|
415
469
|
...(status === 'skipped' ? {} : { durationMs: state.duration }),
|
|
416
470
|
...taskCauses(state.missCauses, redact),
|
|
471
|
+
...(status === 'succeeded' ? taskCommands(task.data) : {}),
|
|
417
472
|
};
|
|
418
473
|
}
|
|
419
474
|
else if (state.type === 'crash') {
|
|
420
|
-
event = {
|
|
475
|
+
event = {
|
|
476
|
+
type: 'task',
|
|
477
|
+
task: task.name,
|
|
478
|
+
state: 'failed',
|
|
479
|
+
exitCode: state.exitCode,
|
|
480
|
+
...since(),
|
|
481
|
+
...taskCommands(task.data),
|
|
482
|
+
};
|
|
421
483
|
}
|
|
422
484
|
else if (state.type === 'error') {
|
|
423
485
|
const error = redact(state.errorMessage).slice(0, runs_1.MAX_TASK_ERROR);
|
|
424
|
-
event = { type: 'task', task: task.name, state: 'failed', error, ...since() };
|
|
486
|
+
event = { type: 'task', task: task.name, state: 'failed', error, ...since(), ...taskCommands(task.data) };
|
|
425
487
|
}
|
|
426
488
|
else if (state.type === 'canceled') {
|
|
427
|
-
event = { type: 'task', task: task.name, state: 'cancelled' };
|
|
489
|
+
event = { type: 'task', task: task.name, state: 'cancelled', ...taskCommands(task.data) };
|
|
428
490
|
}
|
|
429
491
|
if (event && before?.status !== event.state) {
|
|
430
492
|
seen.set(task.name, { status: event.state, started });
|