hammerkit 2.0.0-next.2 → 2.0.0-next.21
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-DtJSpova.js +8 -0
- package/dist/dashboard/assets/index-BndChMep.css +2 -0
- package/dist/dashboard/assets/index-DRSwIRXd.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 +31 -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 +35 -14
- 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 +100 -13
- 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-retry.js +57 -0
- 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 +150 -20
- 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
|
@@ -1,59 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stateKeyDigest = exports.getStateKey = exports.getWorkItemCheckoutStats = exports.getWorkItemCacheStats = exports.getWorkCacheStats = void 0;
|
|
3
|
+
exports.stateKeyDigest = exports.encodeStateEntries = exports.getStateKey = exports.getWorkItemCheckoutStats = exports.getWorkItemCacheStats = exports.getWorkCacheStats = void 0;
|
|
4
4
|
const calculate_checksum_1 = require("./calculate-checksum");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const crypto_1 = require("crypto");
|
|
7
7
|
const promises_1 = require("fs/promises");
|
|
8
|
+
const limit_1 = require("../utils/limit");
|
|
8
9
|
function isExcluded(path, excluded) {
|
|
9
10
|
return excluded.some((excludedPath) => path === excludedPath || path.startsWith(excludedPath + path_1.sep));
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
+
// What the walk does at once: a stat, a listing or a checksum of a file each. Awaited one
|
|
13
|
+
// after the other, a walk of a thousand files spent most of its time waiting for the disk.
|
|
14
|
+
const WALK_CONCURRENCY = 32;
|
|
15
|
+
async function addWorkCacheStats(result, cwd, path, matcher, context, root, excluded, limit = (0, limit_1.createLimit)(WALK_CONCURRENCY)) {
|
|
12
16
|
if (isExcluded(path, excluded)) {
|
|
13
17
|
return 0;
|
|
14
18
|
}
|
|
19
|
+
// the slot is held for what this path needs of the disk, not while its children are walked
|
|
20
|
+
const visited = await limit(() => visitPath(cwd, path, matcher, context, root));
|
|
21
|
+
if (visited.type === 'file') {
|
|
22
|
+
// '/'-separated on every OS, so a Windows host keys a container task like Linux
|
|
23
|
+
result.files[visited.key] = { lastModified: visited.lastModified, checksum: visited.checksum };
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
if (visited.type === 'directory') {
|
|
27
|
+
const counts = await Promise.all(visited.files.map((file) => addWorkCacheStats(result, cwd, (0, path_1.join)(path, file), matcher, context, false, excluded, limit)));
|
|
28
|
+
return counts.reduce((sum, count) => sum + count, 0);
|
|
29
|
+
}
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
async function visitPath(cwd, path, matcher, context, root) {
|
|
33
|
+
const key = (0, path_1.relative)(cwd, path).split(path_1.sep).join(path_1.posix.sep);
|
|
15
34
|
// On a server the files were written by a commit or a task: a link is a source as it is,
|
|
16
35
|
// its target, and never followed. A `**` would walk `x -> /` through the server's disk.
|
|
17
36
|
if (context.hosted) {
|
|
18
37
|
const link = await (0, promises_1.lstat)(path).catch(() => undefined);
|
|
19
38
|
if (link?.isSymbolicLink()) {
|
|
20
39
|
if (!matcher(path)) {
|
|
21
|
-
return
|
|
40
|
+
return { type: 'none' };
|
|
22
41
|
}
|
|
23
|
-
|
|
42
|
+
// `l` and the digest of its target, a kind of entry of its own: no checksum of a file
|
|
43
|
+
// starts with a letter past `f`
|
|
44
|
+
const checksum = `l${(0, crypto_1.createHash)('sha256')
|
|
24
45
|
.update(`link:${await (0, promises_1.readlink)(path)}`)
|
|
25
|
-
.digest('hex')
|
|
26
|
-
|
|
27
|
-
return 1;
|
|
46
|
+
.digest('hex')}`;
|
|
47
|
+
return { type: 'file', key, lastModified: link.mtimeMs, checksum };
|
|
28
48
|
}
|
|
29
49
|
}
|
|
30
50
|
const exists = await context.file.exists(path);
|
|
31
51
|
if (!exists) {
|
|
32
|
-
return
|
|
52
|
+
return { type: 'none' };
|
|
33
53
|
}
|
|
34
54
|
const stats = await context.file.stats(path);
|
|
35
55
|
if (stats.type === 'file') {
|
|
36
56
|
if (!matcher(path)) {
|
|
37
|
-
return
|
|
57
|
+
return { type: 'none' };
|
|
38
58
|
}
|
|
39
|
-
const checksum = await (0, calculate_checksum_1.calculateChecksum)(context, path);
|
|
40
|
-
|
|
41
|
-
result.files[(0, path_1.relative)(cwd, path).split(path_1.sep).join(path_1.posix.sep)] = { lastModified: stats.lastModified, checksum };
|
|
42
|
-
return 1;
|
|
59
|
+
const checksum = await (0, calculate_checksum_1.calculateChecksum)(context, path, stats);
|
|
60
|
+
return { type: 'file', key, lastModified: stats.lastModified, checksum };
|
|
43
61
|
}
|
|
44
62
|
else if (stats.type === 'directory') {
|
|
45
63
|
// A glob such as src/**/*.ts never matches a directory itself, so a
|
|
46
64
|
// directory is walked when files inside it could match.
|
|
47
65
|
if (!root && !matcher(path, true)) {
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
let matched = 0;
|
|
51
|
-
for (const file of await context.file.listFiles(path)) {
|
|
52
|
-
matched += await addWorkCacheStats(result, cwd, (0, path_1.join)(path, file), matcher, context, false, excluded);
|
|
66
|
+
return { type: 'none' };
|
|
53
67
|
}
|
|
54
|
-
return
|
|
68
|
+
return { type: 'directory', files: await context.file.listFiles(path) };
|
|
55
69
|
}
|
|
56
|
-
return
|
|
70
|
+
return { type: 'none' };
|
|
57
71
|
}
|
|
58
72
|
async function getWorkCacheStats(work, environment) {
|
|
59
73
|
return (await collectSourceStats(work, environment, [])).stats;
|
|
@@ -66,14 +80,14 @@ async function collectSourceStats(work, environment, excluded) {
|
|
|
66
80
|
created: new Date(),
|
|
67
81
|
files: {},
|
|
68
82
|
};
|
|
69
|
-
|
|
70
|
-
|
|
83
|
+
// one limit for all its srcs, which are walked at once: an inherited src is often a large
|
|
84
|
+
// part of what a task hashes
|
|
85
|
+
const limit = (0, limit_1.createLimit)(WALK_CONCURRENCY);
|
|
86
|
+
const matches = await Promise.all(work.src.map((src) => {
|
|
71
87
|
const matcher = (file, partial) => src.matcher(file, work.cwd, partial);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
}
|
|
88
|
+
return addWorkCacheStats(result, work.cwd, src.absolutePath, matcher, environment, true, excluded, limit);
|
|
89
|
+
}));
|
|
90
|
+
const unmatched = work.src.filter((src, index) => matches[index] === 0 && !src.inherited && !isExcluded(src.absolutePath, excluded));
|
|
77
91
|
return { stats: result, unmatched };
|
|
78
92
|
}
|
|
79
93
|
// The source stats of a task or service, leaving out everything its (transitive)
|
|
@@ -109,20 +123,30 @@ function dependencyOutputs(item) {
|
|
|
109
123
|
return [...outputs];
|
|
110
124
|
}
|
|
111
125
|
function getStateKey(stats, cacheMethod) {
|
|
112
|
-
const
|
|
126
|
+
const entries = [];
|
|
113
127
|
// Sorted: the walk follows the filesystem's listing order, which differs
|
|
114
128
|
// between machines (ext4 and overlayfs list in hash order).
|
|
115
129
|
for (const key of Object.keys(stats.files).sort()) {
|
|
116
130
|
if (cacheMethod === 'checksum') {
|
|
117
|
-
|
|
131
|
+
entries.push([key, stats.files[key].checksum]);
|
|
118
132
|
}
|
|
119
133
|
else if (cacheMethod === 'modify-date') {
|
|
120
|
-
|
|
134
|
+
entries.push([key, `${stats.files[key].lastModified}`]);
|
|
121
135
|
}
|
|
122
136
|
}
|
|
123
|
-
return stateKeyDigest(
|
|
137
|
+
return stateKeyDigest(encodeStateEntries(entries));
|
|
124
138
|
}
|
|
125
139
|
exports.getStateKey = getStateKey;
|
|
140
|
+
// The paths and values of a tree as one text that names no other tree. `path:value,...` as
|
|
141
|
+
// before while no path holds `:` or `,` (a value is hex digits or a date), so those keys stay
|
|
142
|
+
// what they were; else JSON after a NUL, which no path holds.
|
|
143
|
+
function encodeStateEntries(entries) {
|
|
144
|
+
if (entries.some(([path]) => /[:,]/.test(path))) {
|
|
145
|
+
return `\0${JSON.stringify(entries)}`;
|
|
146
|
+
}
|
|
147
|
+
return entries.map(([path, value]) => `${path}:${value}`).join(',');
|
|
148
|
+
}
|
|
149
|
+
exports.encodeStateEntries = encodeStateEntries;
|
|
126
150
|
// A state key is also the value of the `hammerkit.dev/state` label on Kubernetes, which
|
|
127
151
|
// takes at most 63 characters: the sha256 in base 36 has 50.
|
|
128
152
|
function stateKeyDigest(content) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.storedCacheDescription = exports.getWorkServiceCacheIdentity = exports.getWorkTaskCacheDescription = void 0;
|
|
3
|
+
exports.storedCacheDescription = exports.getWorkServiceCacheIdentity = exports.getSecretSources = exports.getWorkTaskCacheDescription = void 0;
|
|
4
4
|
const os_1 = require("os");
|
|
5
5
|
const crypto_1 = require("crypto");
|
|
6
6
|
const replace_env_variables_1 = require("../environment/replace-env-variables");
|
|
@@ -24,6 +24,7 @@ function getWorkTaskCacheDescription(item) {
|
|
|
24
24
|
.filter((secret) => secret.cache)
|
|
25
25
|
.map((secret) => `${(0, work_secret_1.getPortableSecretName)(task.projectRoot, secret)}=${secret.digest()}`)
|
|
26
26
|
.sort();
|
|
27
|
+
const secretSources = getSecretSources(task.projectRoot, task.secrets);
|
|
27
28
|
return {
|
|
28
29
|
shell: task.shell ?? undefined,
|
|
29
30
|
platform: task.type === 'container-task' ? task.image : (0, os_1.platform)(),
|
|
@@ -44,11 +45,26 @@ function getWorkTaskCacheDescription(item) {
|
|
|
44
45
|
cwd: portable(task.cwd),
|
|
45
46
|
deps: item.deps.length > 0 ? item.deps.map((dep) => dep.id()).sort() : undefined,
|
|
46
47
|
secrets: cachedSecrets.length > 0 ? cachedSecrets : undefined,
|
|
48
|
+
secretSources: secretSources.length > 0 ? secretSources : undefined,
|
|
47
49
|
claimLayout: (0, claim_layout_1.hasPathsEndingAlike)(item) || (0, claim_layout_1.hasOutputsFlatteningAlike)(item) ? 2 : undefined,
|
|
48
50
|
needs: item.needs.length > 0 ? getNeedsIdentities(item) : undefined,
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
exports.getWorkTaskCacheDescription = getWorkTaskCacheDescription;
|
|
54
|
+
// The secrets without `cache: true`, by name and source: `NAME<env:VAR`, `NAME<gcp:ref as
|
|
55
|
+
// account`, `NAME<file` (a path of the machine, which differs between machines). Their values
|
|
56
|
+
// stay out of the key, as before: what a provider returns may change on every read.
|
|
57
|
+
function getSecretSources(projectRoot, secrets) {
|
|
58
|
+
return secrets
|
|
59
|
+
.filter((secret) => !secret.cache)
|
|
60
|
+
.map((secret) => {
|
|
61
|
+
const source = secret.source;
|
|
62
|
+
const from = source.type === 'file' ? 'file' : (0, work_secret_1.describeSecretSource)(secret);
|
|
63
|
+
return `${(0, work_secret_1.getPortableSecretName)(projectRoot, secret)}<${from}`;
|
|
64
|
+
})
|
|
65
|
+
.sort();
|
|
66
|
+
}
|
|
67
|
+
exports.getSecretSources = getSecretSources;
|
|
52
68
|
// `visiting` holds the services on the way here: services that need each other in a loop
|
|
53
69
|
// fail to plan (checkForLoop), the identity only has to come back to say so
|
|
54
70
|
function getNeedsIdentities(item, visiting = new Set()) {
|
|
@@ -78,6 +94,10 @@ function getWorkServiceCacheIdentity(item, visiting = new Set()) {
|
|
|
78
94
|
.filter((secret) => secret.cache)
|
|
79
95
|
.map((secret) => `${(0, work_secret_1.getPortableSecretName)(service.projectRoot, secret)}=${secret.digest()}`)
|
|
80
96
|
.sort(),
|
|
97
|
+
// left out when it reads none, so the identity of such a service stays what it was
|
|
98
|
+
...(service.secrets.some((secret) => !secret.cache)
|
|
99
|
+
? { secretSources: getSecretSources(service.projectRoot, service.secrets) }
|
|
100
|
+
: {}),
|
|
81
101
|
// as declared: arguments after -- of a run of the init leave the service as it is
|
|
82
102
|
init: service.init ? (0, work_cache_id_1.getDeclaredWorkTaskId)(service.init.task) : null,
|
|
83
103
|
}
|
|
@@ -96,16 +116,25 @@ exports.getWorkServiceCacheIdentity = getWorkServiceCacheIdentity;
|
|
|
96
116
|
// The form written to disk: description.json in a cache entry (pushed to remote
|
|
97
117
|
// backends, readable by everyone who can pull) and the local explain record.
|
|
98
118
|
// Env is where tokens get passed, so each value is stored as a digest; the task
|
|
99
|
-
// id is still hashed from the values themselves.
|
|
119
|
+
// id is still hashed from the values themselves. So are where its secrets come from: who may
|
|
120
|
+
// pull an entry need not know which secrets of which provider a task reads.
|
|
100
121
|
function storedCacheDescription(description) {
|
|
101
|
-
if (!description.envs) {
|
|
122
|
+
if (!description.envs && !description.secretSources) {
|
|
102
123
|
return description;
|
|
103
124
|
}
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
125
|
+
const digest = (value) => `sha256:${(0, crypto_1.createHash)('sha256').update(value).digest('hex')}`;
|
|
126
|
+
const stored = { ...description };
|
|
127
|
+
if (description.envs) {
|
|
128
|
+
const envs = {};
|
|
129
|
+
for (const [key, value] of Object.entries(description.envs)) {
|
|
130
|
+
envs[key] = digest(value);
|
|
131
|
+
}
|
|
132
|
+
stored.envs = envs;
|
|
133
|
+
}
|
|
134
|
+
if (description.secretSources) {
|
|
135
|
+
stored.secretSources = description.secretSources.map(digest);
|
|
107
136
|
}
|
|
108
|
-
return
|
|
137
|
+
return stored;
|
|
109
138
|
}
|
|
110
139
|
exports.storedCacheDescription = storedCacheDescription;
|
|
111
140
|
//# sourceMappingURL=work-task-cache-description.js.map
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.read = exports.write = void 0;
|
|
3
|
+
exports.readSized = exports.read = exports.write = void 0;
|
|
4
4
|
const yaml_1 = require("yaml");
|
|
5
5
|
async function write(filename, content, context) {
|
|
6
6
|
await context.file.writeFile(filename, (0, yaml_1.stringify)(content));
|
|
7
7
|
}
|
|
8
8
|
exports.write = write;
|
|
9
9
|
async function read(fileName, context) {
|
|
10
|
+
return (await readSized(fileName, context)).value;
|
|
11
|
+
}
|
|
12
|
+
exports.read = read;
|
|
13
|
+
// The parsed file and the bytes it took.
|
|
14
|
+
async function readSized(fileName, context) {
|
|
10
15
|
context.status.context({ type: 'cli', name: 'hammerkit' }).write('debug', `read ${fileName} build file`);
|
|
11
16
|
let content;
|
|
12
17
|
try {
|
|
@@ -16,7 +21,7 @@ async function read(fileName, context) {
|
|
|
16
21
|
throw new Error(`unable to read ${fileName}`);
|
|
17
22
|
}
|
|
18
23
|
try {
|
|
19
|
-
return (0, yaml_1.parse)(content);
|
|
24
|
+
return { value: (0, yaml_1.parse)(content), bytes: Buffer.byteLength(content, 'utf8') };
|
|
20
25
|
}
|
|
21
26
|
catch (e) {
|
|
22
27
|
if (e instanceof Error) {
|
|
@@ -27,5 +32,5 @@ async function read(fileName, context) {
|
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
|
-
exports.
|
|
35
|
+
exports.readSized = readSized;
|
|
31
36
|
//# sourceMappingURL=read-build-file.js.map
|
|
@@ -115,7 +115,7 @@ function parseService(workTree, service, environment, context) {
|
|
|
115
115
|
caching,
|
|
116
116
|
// set once the service is planned, see appendServiceInit
|
|
117
117
|
init: null,
|
|
118
|
-
secrets: (0, work_secret_1.parseWorkSecrets)(service.cwd, context.projectRoot, service.schema.secrets, envs, environment, context.secrets, service.schema.account),
|
|
118
|
+
secrets: (0, work_secret_1.parseWorkSecrets)(service.cwd, context.projectRoot, service.schema.secrets, envs, environment, context.secrets, `service ${service.relativeName}`, service.schema.account),
|
|
119
119
|
resources: (0, work_resources_1.parseWorkResources)(service.schema.resources),
|
|
120
120
|
volumeSize: service.schema.volumeSize ?? null,
|
|
121
121
|
restarts: service.schema.restarts ?? null,
|
|
@@ -80,7 +80,7 @@ function parseTask(cwd, task, environment, context) {
|
|
|
80
80
|
caching: (0, resolve_cache_1.resolveCache)(task.schema.cache ?? null, context.caches, task.relativeName),
|
|
81
81
|
shell: task.schema.shell ? (0, template_value_1.templateValue)(task.schema.shell, envs) : '/bin/sh',
|
|
82
82
|
timeout: task.schema.timeout ? (0, units_1.parseDuration)(task.schema.timeout) : null,
|
|
83
|
-
secrets: (0, work_secret_1.parseWorkSecrets)(cwd, context.projectRoot, task.schema.secrets, envs, environment, context.secrets, task.schema.account),
|
|
83
|
+
secrets: (0, work_secret_1.parseWorkSecrets)(cwd, context.projectRoot, task.schema.secrets, envs, environment, context.secrets, `task ${task.relativeName}`, task.schema.account),
|
|
84
84
|
resources: (0, work_resources_1.parseWorkResources)(task.schema.resources),
|
|
85
85
|
network: (0, work_network_1.parseWorkNetwork)(task.schema.network),
|
|
86
86
|
networkCeiling: null,
|
|
@@ -11,14 +11,14 @@ const hosted_volumes_1 = require("./hosted-volumes");
|
|
|
11
11
|
* checkout it did not write either: a `src: ../..` or a link in the checkout would
|
|
12
12
|
* have the server mount or upload its own files (its credentials, other callers'
|
|
13
13
|
* caches) into a task. Checked when the run is planned and again before each item
|
|
14
|
-
* runs, since an earlier task may have left a link behind
|
|
14
|
+
* runs, since an earlier task may have left a link behind: the sources and outputs it
|
|
15
|
+
* inherits from its dependencies too, which a task after them may have swapped for a link.
|
|
15
16
|
*/
|
|
16
17
|
async function assertItemPathsWithinRoot(item, root) {
|
|
17
18
|
const data = item.data;
|
|
18
19
|
for (const source of 'src' in data ? data.src : []) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
20
|
+
const of = source.inherited ? ` of ${source.inherited.name}` : '';
|
|
21
|
+
await (0, within_root_1.assertWithinRoot)(root, source.absolutePath, `${item.name}: src ${source.source}${of}`);
|
|
22
22
|
}
|
|
23
23
|
if ((0, work_task_1.isContainerWorkTask)(data) || (0, work_service_1.isContainerWorkService)(data)) {
|
|
24
24
|
for (const mount of data.mounts) {
|
|
@@ -34,9 +34,8 @@ async function assertItemPathsWithinRoot(item, root) {
|
|
|
34
34
|
}
|
|
35
35
|
if ((0, work_task_1.isWorkTask)(data)) {
|
|
36
36
|
for (const generate of data.generates) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
37
|
+
const of = generate.inherited ? ` of ${generate.inherited.name}` : '';
|
|
38
|
+
await (0, within_root_1.assertWithinRoot)(root, generate.path, `${item.name}: generates ${generate.path}${of}`);
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
}
|
|
@@ -5,11 +5,27 @@ function templateValue(value, envs) {
|
|
|
5
5
|
if (!value || !envs) {
|
|
6
6
|
return value;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
// A name is matched as the text it is, in any case; when two names match the same `$`, the
|
|
9
|
+
// one listed first wins. One pass over the value: a value put in is not read again.
|
|
10
|
+
const names = Object.keys(envs.variables).filter((name) => name.length > 0);
|
|
11
|
+
if (names.length === 0) {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
const values = new Map();
|
|
15
|
+
for (const name of names) {
|
|
16
|
+
const key = name.toLowerCase();
|
|
17
|
+
if (!values.has(key)) {
|
|
18
|
+
values.set(key, envs.variables[name]);
|
|
19
|
+
}
|
|
11
20
|
}
|
|
12
|
-
|
|
21
|
+
const alternatives = names.map(escapeRegExp).join('|');
|
|
22
|
+
const pattern = new RegExp(`\\$\\{(${alternatives})\\}|\\$(${alternatives})`, 'gi');
|
|
23
|
+
return value.replace(pattern, (match, braced, bare) => {
|
|
24
|
+
return values.get((braced ?? bare ?? '').toLowerCase()) ?? match;
|
|
25
|
+
});
|
|
13
26
|
}
|
|
14
27
|
exports.templateValue = templateValue;
|
|
28
|
+
function escapeRegExp(text) {
|
|
29
|
+
return text.replace(/[\\^$.*+?()[\]{}|/-]/g, '\\$&');
|
|
30
|
+
}
|
|
15
31
|
//# sourceMappingURL=template-value.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readExecutions = exports.clearExecutions = exports.recordExecution = void 0;
|
|
4
|
+
// kept by the task, not its item: the runtime and the scheduler hold copies of the item
|
|
5
|
+
const executions = new WeakMap();
|
|
6
|
+
function recordExecution(task, startedAt, finishedAt) {
|
|
7
|
+
if (Number.isNaN(startedAt.getTime()) || Number.isNaN(finishedAt.getTime()) || finishedAt < startedAt) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
let list = executions.get(task);
|
|
11
|
+
if (!list) {
|
|
12
|
+
list = [];
|
|
13
|
+
executions.set(task, list);
|
|
14
|
+
}
|
|
15
|
+
list.push({ startedAt, finishedAt });
|
|
16
|
+
}
|
|
17
|
+
exports.recordExecution = recordExecution;
|
|
18
|
+
// a task that runs again (watch) starts with none
|
|
19
|
+
function clearExecutions(task) {
|
|
20
|
+
executions.delete(task);
|
|
21
|
+
}
|
|
22
|
+
exports.clearExecutions = clearExecutions;
|
|
23
|
+
function readExecutions(task) {
|
|
24
|
+
return executions.get(task) ?? [];
|
|
25
|
+
}
|
|
26
|
+
exports.readExecutions = readExecutions;
|
|
27
|
+
//# sourceMappingURL=work-item-executions.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dockerServiceRuntime = exports.dockerTaskRuntime = void 0;
|
|
3
|
+
exports.dockerServiceRuntime = exports.getCacheHelperOptions = exports.dockerTaskRuntime = void 0;
|
|
4
4
|
const run_labels_1 = require("../docker/run-labels");
|
|
5
5
|
const execute_docker_1 = require("../executer/execute-docker");
|
|
6
6
|
const remove_container_1 = require("../docker/remove-container");
|
|
@@ -11,8 +11,7 @@ const using_container_1 = require("../docker/using-container");
|
|
|
11
11
|
const event_cache_1 = require("../executer/event-cache");
|
|
12
12
|
const get_docker_executor_1 = require("../executer/get-docker-executor");
|
|
13
13
|
const path_1 = require("path");
|
|
14
|
-
const tar_1 = require("tar");
|
|
15
|
-
const tar_2 = require("../utils/tar");
|
|
14
|
+
const tar_1 = require("../utils/tar");
|
|
16
15
|
const plan_work_volume_1 = require("./utils/plan-work-volume");
|
|
17
16
|
const work_instance_id_1 = require("./work-instance-id");
|
|
18
17
|
const stream_1 = require("stream");
|
|
@@ -117,20 +116,11 @@ exports.dockerTaskRuntime = dockerTaskRuntime;
|
|
|
117
116
|
function isOnHost(generate) {
|
|
118
117
|
return generate.isFile || generate.export;
|
|
119
118
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (root) {
|
|
126
|
-
const names = item.data.type === 'container-service'
|
|
127
|
-
? item.data.volumes.filter((v) => !v.inherited).map((v) => v.name)
|
|
128
|
-
: item.data.generates.filter((v) => !v.inherited && !v.isFile).map((v) => v.volumeName);
|
|
129
|
-
for (const name of names) {
|
|
130
|
-
await (0, get_docker_executor_1.ensureVolumeExists)(docker, item.status, name, (0, get_docker_executor_1.volumeLabels)(root));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
await (0, using_container_1.usingContainer)(docker, item, {
|
|
119
|
+
// The container that copies an item's outputs into and out of its volumes for the cache:
|
|
120
|
+
// the item's image with those volumes mounted, kept running while archives go in or out.
|
|
121
|
+
// The image is the item's, so whatever its network, this step has none.
|
|
122
|
+
function getCacheHelperOptions(item, environment) {
|
|
123
|
+
return {
|
|
134
124
|
abortSignal: environment.abortCtrl.signal,
|
|
135
125
|
Image: item.data.image,
|
|
136
126
|
Tty: true,
|
|
@@ -145,18 +135,32 @@ async function restoreContainer(docker, environment, item, path) {
|
|
|
145
135
|
},
|
|
146
136
|
HostConfig: {
|
|
147
137
|
AutoRemove: true,
|
|
148
|
-
|
|
149
|
-
//
|
|
150
|
-
// throwaway container's filesystem
|
|
138
|
+
NetworkMode: 'none',
|
|
139
|
+
// the item's own output volumes, so restored archives land there rather than in
|
|
140
|
+
// this throwaway container's filesystem
|
|
151
141
|
Binds: item.data.type === 'container-service'
|
|
152
|
-
? item.data.volumes
|
|
153
|
-
.filter((v) => !v.inherited)
|
|
154
|
-
.map((v) => `${v.name}:${(0, execute_docker_1.convertToPosixPath)(v.containerPath)}`)
|
|
142
|
+
? item.data.volumes.filter((v) => !v.inherited).map((v) => `${v.name}:${(0, execute_docker_1.convertToPosixPath)(v.containerPath)}`)
|
|
155
143
|
: item.data.generates
|
|
156
144
|
.filter((v) => !v.inherited && !v.isFile)
|
|
157
145
|
.map((v) => `${v.volumeName}:${(0, execute_docker_1.convertToPosixPath)(v.path)}`),
|
|
158
146
|
},
|
|
159
|
-
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
exports.getCacheHelperOptions = getCacheHelperOptions;
|
|
150
|
+
async function restoreContainer(docker, environment, item, path) {
|
|
151
|
+
await (0, execution_steps_1.refuseHostLinks)(item, environment);
|
|
152
|
+
// on a server the volumes the outputs are restored into carry the run's files, so they
|
|
153
|
+
// are removed with a sandbox
|
|
154
|
+
const root = (0, execution_steps_1.hostedRoot)(environment);
|
|
155
|
+
if (root) {
|
|
156
|
+
const names = item.data.type === 'container-service'
|
|
157
|
+
? item.data.volumes.filter((v) => !v.inherited).map((v) => v.name)
|
|
158
|
+
: item.data.generates.filter((v) => !v.inherited && !v.isFile).map((v) => v.volumeName);
|
|
159
|
+
for (const name of names) {
|
|
160
|
+
await (0, get_docker_executor_1.ensureVolumeExists)(docker, item.status, name, (0, get_docker_executor_1.volumeLabels)(root));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
await (0, using_container_1.usingContainer)(docker, item, getCacheHelperOptions(item, environment), async (container) => {
|
|
160
164
|
for (const generate of (0, event_cache_1.getArchivePaths)(item.data, path)) {
|
|
161
165
|
if (await environment.file.exists(generate.filename)) {
|
|
162
166
|
// a cache hit means exactly the stored outputs: whatever a failed or
|
|
@@ -174,7 +178,7 @@ async function restoreContainer(docker, environment, item, path) {
|
|
|
174
178
|
for (const generate of (0, event_cache_1.getArchivePaths)(item.data, path)) {
|
|
175
179
|
if (onHost.has(generate.path) && (await environment.file.exists(generate.filename))) {
|
|
176
180
|
await environment.file.remove(generate.path);
|
|
177
|
-
await (0, tar_1.
|
|
181
|
+
await (0, tar_1.extractOutput)(generate.filename, (0, path_1.dirname)(generate.path), (0, path_1.basename)(generate.path), !!environment.hosted);
|
|
178
182
|
}
|
|
179
183
|
}
|
|
180
184
|
}
|
|
@@ -273,37 +277,14 @@ function dockerServiceRuntime(service, workEnvironment) {
|
|
|
273
277
|
exports.dockerServiceRuntime = dockerServiceRuntime;
|
|
274
278
|
async function archiveContainer(docker, environment, item, path) {
|
|
275
279
|
await (0, execution_steps_1.refuseHostLinks)(item, environment);
|
|
276
|
-
await (0, using_container_1.usingContainer)(docker, item, {
|
|
277
|
-
abortSignal: environment.abortCtrl.signal,
|
|
278
|
-
Image: item.data.image,
|
|
279
|
-
Tty: true,
|
|
280
|
-
Entrypoint: ['sh'],
|
|
281
|
-
Cmd: ['-c', 'sleep 3600'],
|
|
282
|
-
WorkingDir: (0, execute_docker_1.convertToPosixPath)(item.data.cwd),
|
|
283
|
-
Labels: {
|
|
284
|
-
app: 'hammerkit',
|
|
285
|
-
'hammerkit-id': (0, work_instance_id_1.getWorkInstanceId)(item),
|
|
286
|
-
...(0, run_labels_1.getRunLabels)(),
|
|
287
|
-
'hammerkit-type': 'task',
|
|
288
|
-
},
|
|
289
|
-
HostConfig: {
|
|
290
|
-
AutoRemove: true,
|
|
291
|
-
Binds: item.data.type === 'container-service'
|
|
292
|
-
? item.data.volumes
|
|
293
|
-
.filter((v) => !v.inherited)
|
|
294
|
-
.map((v) => `${v.name}:${(0, execute_docker_1.convertToPosixPath)(v.containerPath)}`)
|
|
295
|
-
: item.data.generates
|
|
296
|
-
.filter((v) => !v.inherited && !v.isFile)
|
|
297
|
-
.map((v) => `${v.volumeName}:${(0, execute_docker_1.convertToPosixPath)(v.path)}`),
|
|
298
|
-
},
|
|
299
|
-
}, async (container) => {
|
|
280
|
+
await (0, using_container_1.usingContainer)(docker, item, getCacheHelperOptions(item, environment), async (container) => {
|
|
300
281
|
const hostFiles = new Set(item.data.type === 'container-task'
|
|
301
282
|
? item.data.generates.filter((g) => !g.inherited && g.isFile).map((g) => g.path)
|
|
302
283
|
: []);
|
|
303
284
|
for (const generatedArchive of (0, event_cache_1.getArchivePaths)(item.data, path)) {
|
|
304
285
|
// a file output is a bind mount of a host file, so archive it from the host
|
|
305
286
|
const readable = hostFiles.has(generatedArchive.path)
|
|
306
|
-
? stream_1.Readable.from((0,
|
|
287
|
+
? stream_1.Readable.from((0, tar_1.packArchive)({ cwd: (0, path_1.dirname)(generatedArchive.path) }, [(0, path_1.basename)(generatedArchive.path)]))
|
|
307
288
|
: await container.getArchive({
|
|
308
289
|
path: generatedArchive.path,
|
|
309
290
|
});
|