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,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mayOpenEndpoints = exports.getRunRepo = exports.toRunEndpoints = exports.refuseEndpoints = exports.getEndpointHosts = exports.getServiceRunName = void 0;
|
|
3
|
+
exports.mayPublishEndpoints = exports.mayOpenEndpoints = exports.getRunRepo = exports.toRunEndpoints = exports.refuseEndpoints = exports.getEndpointHosts = exports.getServiceRunName = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const plan_1 = require("./plan");
|
|
6
6
|
const policy_1 = require("./policy");
|
|
@@ -38,7 +38,9 @@ function containerPorts(plan) {
|
|
|
38
38
|
* Why the endpoints of a service run can't be published, or null. Each is a port its
|
|
39
39
|
* service declares, of a service the run starts. Under a `runs.secretNetwork` below `open`
|
|
40
40
|
* a service behind an endpoint may not read a secret or a credential of the server: a page
|
|
41
|
-
* is a way out that no mask of the log covers.
|
|
41
|
+
* is a way out that no mask of the log covers. Nor may what it is made from or talks to: a
|
|
42
|
+
* task it depends on (its init task too) can leave a value in a file the service serves,
|
|
43
|
+
* and a service it needs can hand one over the connection it answers on.
|
|
42
44
|
*/
|
|
43
45
|
function refuseEndpoints(request, plan, secretNetworkOpen) {
|
|
44
46
|
for (const endpoint of request.endpoints) {
|
|
@@ -50,14 +52,50 @@ function refuseEndpoints(request, plan, secretNetworkOpen) {
|
|
|
50
52
|
const ports = containerPorts(item);
|
|
51
53
|
return `${endpoint.service} has no port ${endpoint.port}${ports.length > 0 ? `, its ports are ${ports.join(', ')}` : ', it declares none'}`;
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
if (secretNetworkOpen) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
for (const { name, path } of reachedFrom(endpoint.service, plan)) {
|
|
59
|
+
const reads = (0, plan_1.getCredentialReads)(plan[name]);
|
|
60
|
+
if (reads.length === 0) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const what = reads.join(', ');
|
|
64
|
+
if (path.length === 0) {
|
|
65
|
+
return `${name} reads ${what}, it can not be behind an endpoint on this server (runs.secretNetwork): a page could show it`;
|
|
66
|
+
}
|
|
67
|
+
// the way from the service to what reads it: `web needs api, which needs vault`
|
|
68
|
+
const way = path.map((step, index) => `${index === 0 ? '' : ', which '}${step.relation} ${step.name}`).join('');
|
|
69
|
+
return (`${endpoint.service} ${way}, which reads ${what}: ` +
|
|
70
|
+
'it can not be behind an endpoint on this server (runs.secretNetwork), a page could show it');
|
|
56
71
|
}
|
|
57
72
|
}
|
|
58
73
|
return null;
|
|
59
74
|
}
|
|
60
75
|
exports.refuseEndpoints = refuseEndpoints;
|
|
76
|
+
function reachedFrom(service, plan) {
|
|
77
|
+
if (!plan[service]) {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
const reached = [{ name: service, path: [] }];
|
|
81
|
+
const seen = new Set([service]);
|
|
82
|
+
for (let index = 0; index < reached.length; index++) {
|
|
83
|
+
const { name, path } = reached[index];
|
|
84
|
+
const item = plan[name];
|
|
85
|
+
const next = [
|
|
86
|
+
...(item.init ? [{ relation: 'is initialized by', name: item.init }] : []),
|
|
87
|
+
...(item.deps ?? []).map((dep) => ({ relation: 'depends on', name: dep })),
|
|
88
|
+
...(item.needs ?? []).map((need) => ({ relation: 'needs', name: need })),
|
|
89
|
+
];
|
|
90
|
+
for (const step of next) {
|
|
91
|
+
if (plan[step.name] && !seen.has(step.name)) {
|
|
92
|
+
seen.add(step.name);
|
|
93
|
+
reached.push({ name: step.name, path: [...path, step] });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return reached;
|
|
98
|
+
}
|
|
61
99
|
function toRunEndpoints(endpoints, hosts, url) {
|
|
62
100
|
return endpoints.map((endpoint, index) => ({
|
|
63
101
|
service: endpoint.service,
|
|
@@ -79,4 +117,11 @@ function mayOpenEndpoints(grant, run) {
|
|
|
79
117
|
return repo !== null && (0, policy_1.endpointLevel)(grant, repo) !== null;
|
|
80
118
|
}
|
|
81
119
|
exports.mayOpenEndpoints = mayOpenEndpoints;
|
|
120
|
+
// Who may publish endpoints of the run's repository: they could bring up a run of their own
|
|
121
|
+
// there, so they may stop somebody else's (a preview left running), besides its owner.
|
|
122
|
+
function mayPublishEndpoints(grant, run) {
|
|
123
|
+
const repo = getRunRepo(run);
|
|
124
|
+
return repo !== null && (0, policy_1.endpointLevel)(grant, repo) === 'publish';
|
|
125
|
+
}
|
|
126
|
+
exports.mayPublishEndpoints = mayPublishEndpoints;
|
|
82
127
|
//# sourceMappingURL=service-runs.js.map
|
package/dist/server/sources.js
CHANGED
|
@@ -15,7 +15,11 @@ class SourceError extends Error {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.SourceError = SourceError;
|
|
18
|
-
exports.DEFAULT_SOURCE_LIMITS = {
|
|
18
|
+
exports.DEFAULT_SOURCE_LIMITS = {
|
|
19
|
+
subjectBytes: 4 * 1024 * 1024 * 1024,
|
|
20
|
+
subjectManifests: 1000,
|
|
21
|
+
subjectManifestBytes: 64 * 1024 * 1024,
|
|
22
|
+
};
|
|
19
23
|
// The directory name of a caller: the issuer and subject, hashed.
|
|
20
24
|
function subjectKey(principal) {
|
|
21
25
|
return (0, crypto_1.createHash)('sha256')
|
|
@@ -35,11 +39,11 @@ exports.subjectKey = subjectKey;
|
|
|
35
39
|
* what other people work on.
|
|
36
40
|
*/
|
|
37
41
|
class SourceStore {
|
|
38
|
-
constructor(directory, limits =
|
|
42
|
+
constructor(directory, limits = {}, now = Date.now) {
|
|
39
43
|
this.directory = directory;
|
|
40
|
-
this.limits = limits;
|
|
41
44
|
this.now = now;
|
|
42
45
|
this.subjects = new Map();
|
|
46
|
+
this.limits = { ...exports.DEFAULT_SOURCE_LIMITS, ...limits };
|
|
43
47
|
}
|
|
44
48
|
// Announces a tree. Answers what has to be sent to complete it.
|
|
45
49
|
async announce(principal, manifest) {
|
|
@@ -70,9 +74,27 @@ class SourceStore {
|
|
|
70
74
|
sizes.set(file.sha256, file.size);
|
|
71
75
|
}
|
|
72
76
|
const stored = { manifest, createdAt: new Date(this.now()).toISOString() };
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
const content = JSON.stringify(stored);
|
|
78
|
+
const bytes = Buffer.byteLength(content, 'utf8');
|
|
79
|
+
if (subject.manifests.size >= this.limits.subjectManifests) {
|
|
80
|
+
throw new SourceError(413, `the server keeps at most ${this.limits.subjectManifests} trees for you, delete one with DELETE /v1/sources/<snapshot>`);
|
|
81
|
+
}
|
|
82
|
+
const manifestBytes = [...subject.manifestBytes.values()].reduce((sum, size) => sum + size, 0);
|
|
83
|
+
if (manifestBytes + bytes > this.limits.subjectManifestBytes) {
|
|
84
|
+
throw new SourceError(413, `the server keeps at most ${this.limits.subjectManifestBytes} bytes of trees for you, delete one with DELETE /v1/sources/<snapshot>`);
|
|
85
|
+
}
|
|
86
|
+
// taken before the write, so announcements at once can not pass the limits together
|
|
75
87
|
subject.manifests.set(snapshot, stored);
|
|
88
|
+
subject.manifestBytes.set(snapshot, bytes);
|
|
89
|
+
try {
|
|
90
|
+
await (0, promises_1.mkdir)((0, path_1.join)(this.directory, key, 'manifests'), { recursive: true });
|
|
91
|
+
await this.write((0, path_1.join)(this.directory, key, 'manifests', `${snapshot.slice('sha256:'.length)}.json`), content);
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
subject.manifests.delete(snapshot);
|
|
95
|
+
subject.manifestBytes.delete(snapshot);
|
|
96
|
+
throw e;
|
|
97
|
+
}
|
|
76
98
|
for (const [digest, size] of sizes) {
|
|
77
99
|
subject.wanted.set(digest, size);
|
|
78
100
|
}
|
|
@@ -91,14 +113,38 @@ class SourceStore {
|
|
|
91
113
|
throw new SourceError(400, 'this file is not part of a tree you announced');
|
|
92
114
|
}
|
|
93
115
|
const target = this.blob(key, digest);
|
|
116
|
+
// the same file sent twice at once is received once: the second waits for the first
|
|
117
|
+
for (let pending = subject.sending.get(digest); pending; pending = subject.sending.get(digest)) {
|
|
118
|
+
await pending;
|
|
119
|
+
}
|
|
94
120
|
if (await exists(target)) {
|
|
95
121
|
body.resume();
|
|
96
122
|
return 'exists';
|
|
97
123
|
}
|
|
98
|
-
|
|
124
|
+
// a send that came in while this one looked waits for this one
|
|
125
|
+
if (subject.sending.has(digest)) {
|
|
126
|
+
return this.put(principal, digest, body);
|
|
127
|
+
}
|
|
128
|
+
// files being received count too: uploads at once can not pass the limit together
|
|
129
|
+
if (subject.stored + subject.receiving + size > this.limits.subjectBytes) {
|
|
99
130
|
body.resume();
|
|
100
131
|
throw new SourceError(413, `the server keeps at most ${this.limits.subjectBytes} bytes of files for you`);
|
|
101
132
|
}
|
|
133
|
+
subject.receiving += size;
|
|
134
|
+
const received = this.receive(subject, key, digest, size, target, body);
|
|
135
|
+
const settled = received.then(() => undefined, () => undefined);
|
|
136
|
+
subject.sending.set(digest, settled);
|
|
137
|
+
try {
|
|
138
|
+
return await received;
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
subject.receiving -= size;
|
|
142
|
+
if (subject.sending.get(digest) === settled) {
|
|
143
|
+
subject.sending.delete(digest);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async receive(subject, key, digest, size, target, body) {
|
|
102
148
|
await (0, promises_1.mkdir)((0, path_1.join)(this.directory, key, 'blobs'), { recursive: true });
|
|
103
149
|
const temporary = `${target}.${(0, crypto_2.randomBytes)(8).toString('hex')}.tmp`;
|
|
104
150
|
const hash = (0, crypto_1.createHash)('sha256');
|
|
@@ -166,6 +212,7 @@ class SourceStore {
|
|
|
166
212
|
if (!subject.manifests.delete(snapshot)) {
|
|
167
213
|
return false;
|
|
168
214
|
}
|
|
215
|
+
subject.manifestBytes.delete(snapshot);
|
|
169
216
|
await (0, promises_1.rm)((0, path_1.join)(this.directory, key, 'manifests', `${snapshot.slice('sha256:'.length)}.json`), { force: true });
|
|
170
217
|
const kept = new Map();
|
|
171
218
|
for (const stored of subject.manifests.values()) {
|
|
@@ -202,9 +249,9 @@ class SourceStore {
|
|
|
202
249
|
blob(key, digest) {
|
|
203
250
|
return (0, path_1.join)(this.directory, key, 'blobs', digest);
|
|
204
251
|
}
|
|
205
|
-
async write(file,
|
|
252
|
+
async write(file, content) {
|
|
206
253
|
const temporary = `${file}.${(0, crypto_2.randomBytes)(8).toString('hex')}.tmp`;
|
|
207
|
-
await (0, promises_1.writeFile)(temporary,
|
|
254
|
+
await (0, promises_1.writeFile)(temporary, content, { flag: 'wx' });
|
|
208
255
|
await (0, promises_1.rename)(temporary, file);
|
|
209
256
|
}
|
|
210
257
|
// Reads what is kept for one caller the first time they are seen.
|
|
@@ -217,7 +264,14 @@ class SourceStore {
|
|
|
217
264
|
return loaded;
|
|
218
265
|
}
|
|
219
266
|
async load(key) {
|
|
220
|
-
const subject = {
|
|
267
|
+
const subject = {
|
|
268
|
+
wanted: new Map(),
|
|
269
|
+
stored: 0,
|
|
270
|
+
receiving: 0,
|
|
271
|
+
sending: new Map(),
|
|
272
|
+
manifests: new Map(),
|
|
273
|
+
manifestBytes: new Map(),
|
|
274
|
+
};
|
|
221
275
|
const manifests = (0, path_1.join)(this.directory, key, 'manifests');
|
|
222
276
|
let names = [];
|
|
223
277
|
try {
|
|
@@ -227,8 +281,11 @@ class SourceStore {
|
|
|
227
281
|
return subject;
|
|
228
282
|
}
|
|
229
283
|
for (const name of names.filter((n) => n.endsWith('.json'))) {
|
|
230
|
-
const
|
|
231
|
-
|
|
284
|
+
const content = await (0, promises_1.readFile)((0, path_1.join)(manifests, name), 'utf8');
|
|
285
|
+
const stored = JSON.parse(content);
|
|
286
|
+
const snapshot = (0, source_manifest_1.hashSource)(stored.manifest);
|
|
287
|
+
subject.manifests.set(snapshot, stored);
|
|
288
|
+
subject.manifestBytes.set(snapshot, Buffer.byteLength(content, 'utf8'));
|
|
232
289
|
for (const file of stored.manifest.files) {
|
|
233
290
|
subject.wanted.set(file.sha256, file.size);
|
|
234
291
|
}
|
package/dist/server/timings.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTaskStats = exports.roughly = exports.ranMs = exports.waitedMs = void 0;
|
|
3
|
+
exports.getTaskStats = exports.getOldestCounted = exports.roughly = exports.ranMs = exports.waitedMs = void 0;
|
|
4
4
|
const at = (iso) => (iso ? Date.parse(iso) : NaN);
|
|
5
5
|
// How long a run waited in the queue for a place: from when it was queued (after its
|
|
6
6
|
// approval, or when it woke) until it started, or until now while it waits.
|
|
@@ -64,9 +64,27 @@ function quantile(sorted, q) {
|
|
|
64
64
|
}
|
|
65
65
|
return sorted[Math.min(sorted.length - 1, Math.max(0, Math.ceil(q * sorted.length) - 1))];
|
|
66
66
|
}
|
|
67
|
+
// a task that ran to its end or came from the cache; one that runs, was skipped or stopped says
|
|
68
|
+
// nothing about what it takes
|
|
69
|
+
const counts = (timing) => timing.status !== 'running' && timing.status !== 'skipped' && timing.status !== 'cancelled';
|
|
70
|
+
/**
|
|
71
|
+
* When the oldest run that getTaskStats counts was created: the start of what its numbers
|
|
72
|
+
* cover. Undefined when it counts none.
|
|
73
|
+
*/
|
|
74
|
+
function getOldestCounted(runs) {
|
|
75
|
+
let oldest;
|
|
76
|
+
for (const run of runs) {
|
|
77
|
+
if (Object.values(run.timings ?? {}).some(counts) && (!oldest || Date.parse(run.createdAt) < Date.parse(oldest))) {
|
|
78
|
+
oldest = run.createdAt;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return oldest;
|
|
82
|
+
}
|
|
83
|
+
exports.getOldestCounted = getOldestCounted;
|
|
67
84
|
/**
|
|
68
85
|
* Per task and repository, newest first: how often it ran and how, what it took the last
|
|
69
|
-
* time,
|
|
86
|
+
* time, the median and 90th percentile of the times it executed, and those times added up.
|
|
87
|
+
* `runs` is newest first.
|
|
70
88
|
*/
|
|
71
89
|
function getTaskStats(runs, now) {
|
|
72
90
|
const groups = new Map();
|
|
@@ -74,7 +92,7 @@ function getTaskStats(runs, now) {
|
|
|
74
92
|
const repo = run.source.repo ?? 'an upload';
|
|
75
93
|
const waited = waitedMs(run, now);
|
|
76
94
|
for (const [task, timing] of Object.entries(run.timings ?? {})) {
|
|
77
|
-
if (timing
|
|
95
|
+
if (!counts(timing)) {
|
|
78
96
|
continue;
|
|
79
97
|
}
|
|
80
98
|
const key = `${repo}\0${task}`;
|
|
@@ -92,6 +110,7 @@ function getTaskStats(runs, now) {
|
|
|
92
110
|
status: timing.status,
|
|
93
111
|
at: timing.finishedAt ?? run.finishedAt ?? run.createdAt,
|
|
94
112
|
...(timing.durationMs !== undefined ? { durationMs: timing.durationMs } : {}),
|
|
113
|
+
...(run.definition ? { definition: run.definition } : {}),
|
|
95
114
|
},
|
|
96
115
|
},
|
|
97
116
|
durations: [],
|
|
@@ -124,6 +143,7 @@ function getTaskStats(runs, now) {
|
|
|
124
143
|
...stats,
|
|
125
144
|
...(median !== undefined ? { medianMs: median } : {}),
|
|
126
145
|
...(p90 !== undefined ? { p90Ms: p90 } : {}),
|
|
146
|
+
...(durations.length > 0 ? { totalMs: durations.reduce((sum, ms) => sum + ms, 0) } : {}),
|
|
127
147
|
...(wait !== undefined ? { medianWaitMs: wait } : {}),
|
|
128
148
|
};
|
|
129
149
|
});
|
|
@@ -1,42 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BufferContext = void 0;
|
|
4
|
+
// The last `limit` entries of each id, and all of those in the order they came. An entry an id
|
|
5
|
+
// no longer keeps leaves both; the list of all of them drops what left now and then, so an
|
|
6
|
+
// entry costs the same however many ids there are.
|
|
4
7
|
class BufferContext {
|
|
5
8
|
constructor(limit) {
|
|
6
9
|
this.limit = limit;
|
|
7
|
-
this.scopedBuffer =
|
|
10
|
+
this.scopedBuffer = new Map();
|
|
8
11
|
this.buffer = [];
|
|
12
|
+
this.dropped = 0;
|
|
9
13
|
}
|
|
10
14
|
add(id, data) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const bufferIndex = this.buffer.indexOf(removedBuffer);
|
|
18
|
-
if (bufferIndex >= 0) {
|
|
19
|
-
this.buffer.splice(bufferIndex, 1);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
15
|
+
const entry = { data, kept: true };
|
|
16
|
+
this.buffer.push(entry);
|
|
17
|
+
let scopedBuffer = this.scopedBuffer.get(id);
|
|
18
|
+
if (!scopedBuffer) {
|
|
19
|
+
scopedBuffer = [];
|
|
20
|
+
this.scopedBuffer.set(id, scopedBuffer);
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
scopedBuffer.push(entry);
|
|
23
|
+
if (scopedBuffer.length > this.limit) {
|
|
24
|
+
const removed = scopedBuffer.shift();
|
|
25
|
+
removed.kept = false;
|
|
26
|
+
this.dropped++;
|
|
27
|
+
if (this.dropped * 2 > this.buffer.length) {
|
|
28
|
+
this.compact();
|
|
29
|
+
}
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
current(id) {
|
|
28
|
-
|
|
33
|
+
const value = this.scopedBuffer.get(id);
|
|
34
|
+
if (!value || value.length === 0) {
|
|
29
35
|
return null;
|
|
30
36
|
}
|
|
31
|
-
|
|
32
|
-
return value[value.length - 1];
|
|
37
|
+
return value[value.length - 1].data;
|
|
33
38
|
}
|
|
34
39
|
get(id) {
|
|
35
40
|
if (id) {
|
|
36
|
-
return this.scopedBuffer
|
|
41
|
+
return (this.scopedBuffer.get(id) ?? []).map((entry) => entry.data);
|
|
37
42
|
}
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
this.compact();
|
|
44
|
+
return this.buffer.map((entry) => entry.data);
|
|
45
|
+
}
|
|
46
|
+
compact() {
|
|
47
|
+
if (this.dropped > 0) {
|
|
48
|
+
this.buffer = this.buffer.filter((entry) => entry.kept);
|
|
49
|
+
this.dropped = 0;
|
|
40
50
|
}
|
|
41
51
|
}
|
|
42
52
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLimit = void 0;
|
|
4
|
+
function createLimit(concurrency) {
|
|
5
|
+
let running = 0;
|
|
6
|
+
const waiting = [];
|
|
7
|
+
return async (fn) => {
|
|
8
|
+
if (running >= concurrency) {
|
|
9
|
+
await new Promise((resolve) => waiting.push(resolve));
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
running++;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
return await fn();
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
const next = waiting.shift();
|
|
19
|
+
if (next) {
|
|
20
|
+
// the slot goes to the next one as it is
|
|
21
|
+
next();
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
running--;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.createLimit = createLimit;
|
|
30
|
+
//# sourceMappingURL=limit.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lineSplitter = exports.MAX_LINE_CHARS = void 0;
|
|
4
|
+
const string_decoder_1 = require("string_decoder");
|
|
5
|
+
// The most of a line that is held back for its end: a longer one is passed on in parts.
|
|
6
|
+
exports.MAX_LINE_CHARS = 64 * 1024;
|
|
7
|
+
/**
|
|
8
|
+
* The lines of output that arrives in chunks, split where getLogs splits a chunk: at a line
|
|
9
|
+
* feed, with a CR before it. A line that two chunks (or two frames of docker) split is passed
|
|
10
|
+
* on whole once it ends, so the mask of the secrets of a run (SecretRegistry.redact, which
|
|
11
|
+
* works per line) covers a value that was split between them. Empty lines are left out, as
|
|
12
|
+
* getLogs does. A line of more than `maxChars` is passed on in parts of that length.
|
|
13
|
+
*/
|
|
14
|
+
function lineSplitter(onLine, maxChars = exports.MAX_LINE_CHARS) {
|
|
15
|
+
// a character split between two chunks stays whole
|
|
16
|
+
const decoder = new string_decoder_1.StringDecoder('utf8');
|
|
17
|
+
let pending = '';
|
|
18
|
+
const take = (text) => {
|
|
19
|
+
const lines = (pending + text).split(/\r?\n/);
|
|
20
|
+
pending = lines.pop() ?? '';
|
|
21
|
+
for (const line of lines) {
|
|
22
|
+
if (line) {
|
|
23
|
+
onLine(line);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
while (pending.length > maxChars) {
|
|
27
|
+
onLine(pending.slice(0, maxChars));
|
|
28
|
+
pending = pending.slice(maxChars);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
let ended = false;
|
|
32
|
+
return {
|
|
33
|
+
write(chunk) {
|
|
34
|
+
if (!ended) {
|
|
35
|
+
take(typeof chunk === 'string' ? chunk : decoder.write(chunk));
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
end() {
|
|
39
|
+
if (ended) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
ended = true;
|
|
43
|
+
take(decoder.end());
|
|
44
|
+
if (pending) {
|
|
45
|
+
onLine(pending);
|
|
46
|
+
pending = '';
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.lineSplitter = lineSplitter;
|
|
52
|
+
//# sourceMappingURL=line-splitter.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readLines = void 0;
|
|
4
|
+
const string_decoder_1 = require("string_decoder");
|
|
5
|
+
/**
|
|
6
|
+
* Calls `onLine` with each line of `input` as readline does: a line ends at a line feed, a CR
|
|
7
|
+
* or both. It holds at most `maxChars` of a line: a longer line is cut there and says so, the
|
|
8
|
+
* rest of it up to the end of the line is passed over.
|
|
9
|
+
*/
|
|
10
|
+
function readLines(input, maxChars, onLine) {
|
|
11
|
+
const decoder = new string_decoder_1.StringDecoder('utf8');
|
|
12
|
+
let pending = '';
|
|
13
|
+
let cut = false;
|
|
14
|
+
// the last line ended with a CR, so a line feed right after it ends no other line
|
|
15
|
+
let afterCr = false;
|
|
16
|
+
const emit = () => {
|
|
17
|
+
onLine(cut ? `${pending} … [cut at ${maxChars} characters]` : pending);
|
|
18
|
+
pending = '';
|
|
19
|
+
cut = false;
|
|
20
|
+
};
|
|
21
|
+
const take = (text) => {
|
|
22
|
+
let start = 0;
|
|
23
|
+
if (afterCr && text.length > 0) {
|
|
24
|
+
afterCr = false;
|
|
25
|
+
if (text[0] === '\n') {
|
|
26
|
+
start = 1;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const ends = /[\r\n]/g;
|
|
30
|
+
for (;;) {
|
|
31
|
+
ends.lastIndex = start;
|
|
32
|
+
const end = ends.exec(text);
|
|
33
|
+
if (!cut) {
|
|
34
|
+
pending += text.slice(start, end ? end.index : undefined);
|
|
35
|
+
if (pending.length > maxChars) {
|
|
36
|
+
pending = pending.slice(0, maxChars);
|
|
37
|
+
cut = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!end) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
emit();
|
|
44
|
+
start = end.index + 1;
|
|
45
|
+
if (end[0] === '\r') {
|
|
46
|
+
if (start === text.length) {
|
|
47
|
+
afterCr = true;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (text[start] === '\n') {
|
|
51
|
+
start++;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
input.on('data', (chunk) => take(typeof chunk === 'string' ? chunk : decoder.write(chunk)));
|
|
57
|
+
input.on('end', () => {
|
|
58
|
+
take(decoder.end());
|
|
59
|
+
if (pending.length > 0 || cut) {
|
|
60
|
+
emit();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
exports.readLines = readLines;
|
|
65
|
+
//# sourceMappingURL=read-lines.js.map
|
package/dist/utils/tar.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.packArchive = void 0;
|
|
3
|
+
exports.onlyBelow = exports.extractOutput = exports.packArchive = void 0;
|
|
4
4
|
const tar_1 = require("tar");
|
|
5
|
+
const path_1 = require("path");
|
|
5
6
|
function packArchive(options, files) {
|
|
6
7
|
return (0, tar_1.create)({ ...options, jobs: 1, linkCache: new ExactLinkCache() }, files);
|
|
7
8
|
}
|
|
@@ -33,4 +34,53 @@ const NOT_PACKED = '\0';
|
|
|
33
34
|
function isExact(key) {
|
|
34
35
|
return key.split(':').every((part) => Number.isSafeInteger(Number(part)));
|
|
35
36
|
}
|
|
37
|
+
// Extracts the archive of one output (a path relative to `cwd`) into `cwd`. An archive
|
|
38
|
+
// comes from a cache another run, or whoever writes to the cache backend, filled, so only
|
|
39
|
+
// entries of that output are taken: one beside it (another output, a source of the task, a
|
|
40
|
+
// build file) would otherwise be written over the project. A hard link is taken only to a
|
|
41
|
+
// file of the output (packArchive stores one to a file outside as its content). A symbolic
|
|
42
|
+
// link may point out of the output on a machine (a node_modules links its workspace
|
|
43
|
+
// packages); on a server, which did not write the archive, it is left out.
|
|
44
|
+
async function extractOutput(file, cwd, output, hosted) {
|
|
45
|
+
const below = onlyBelow(output);
|
|
46
|
+
await (0, tar_1.extract)({
|
|
47
|
+
file,
|
|
48
|
+
cwd,
|
|
49
|
+
filter: (path, entry) => {
|
|
50
|
+
if (!below(path)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const read = entry;
|
|
54
|
+
if (read.type === 'Link') {
|
|
55
|
+
return below(read.linkpath ?? '');
|
|
56
|
+
}
|
|
57
|
+
if (read.type === 'SymbolicLink' && hosted) {
|
|
58
|
+
const target = read.linkpath ?? '';
|
|
59
|
+
return !path_1.posix.isAbsolute(target) && below(path_1.posix.join(path_1.posix.dirname(normalizeEntry(path)), target));
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
exports.extractOutput = extractOutput;
|
|
66
|
+
// Whether an entry of an archive is the output (a path relative to where the archive is
|
|
67
|
+
// extracted) or below it.
|
|
68
|
+
function onlyBelow(output) {
|
|
69
|
+
const own = normalizeEntry(output);
|
|
70
|
+
return (path) => {
|
|
71
|
+
const entry = normalizeEntry(path);
|
|
72
|
+
if (own === '.') {
|
|
73
|
+
// the output is the folder the archive is extracted in
|
|
74
|
+
return entry !== '..' && !entry.startsWith('../') && !path_1.posix.isAbsolute(entry);
|
|
75
|
+
}
|
|
76
|
+
return entry === own || entry.startsWith(`${own}/`);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
exports.onlyBelow = onlyBelow;
|
|
80
|
+
function normalizeEntry(path) {
|
|
81
|
+
return path_1.posix
|
|
82
|
+
.normalize(path.replace(/\\/g, '/'))
|
|
83
|
+
.replace(/^(\.\/)+/, '')
|
|
84
|
+
.replace(/\/+$/, '');
|
|
85
|
+
}
|
|
36
86
|
//# sourceMappingURL=tar.js.map
|
package/dist/utils/units.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseCpus = exports.formatSize = exports.parseSize = exports.formatDuration = exports.parseDuration = void 0;
|
|
3
|
+
exports.parseQuantity = exports.parseCpus = exports.formatSize = exports.parseSize = exports.formatDuration = exports.parseDuration = void 0;
|
|
4
4
|
const DURATION_UNITS = {
|
|
5
5
|
ms: 1,
|
|
6
6
|
s: 1000,
|
|
@@ -97,4 +97,39 @@ function parseCpus(value) {
|
|
|
97
97
|
return millicores / 1000;
|
|
98
98
|
}
|
|
99
99
|
exports.parseCpus = parseCpus;
|
|
100
|
+
const QUANTITY_UNITS = {
|
|
101
|
+
n: 1e-9,
|
|
102
|
+
u: 1e-6,
|
|
103
|
+
m: 1e-3,
|
|
104
|
+
'': 1,
|
|
105
|
+
k: 1e3,
|
|
106
|
+
K: 1e3,
|
|
107
|
+
M: 1e6,
|
|
108
|
+
G: 1e9,
|
|
109
|
+
T: 1e12,
|
|
110
|
+
P: 1e15,
|
|
111
|
+
E: 1e18,
|
|
112
|
+
Ki: 1024,
|
|
113
|
+
Mi: 1024 ** 2,
|
|
114
|
+
Gi: 1024 ** 3,
|
|
115
|
+
Ti: 1024 ** 4,
|
|
116
|
+
Pi: 1024 ** 5,
|
|
117
|
+
Ei: 1024 ** 6,
|
|
118
|
+
};
|
|
119
|
+
// A quantity of Kubernetes (`250m`, `1.5`, `512Mi`, `12345678n`, `1e3`), as a number.
|
|
120
|
+
function parseQuantity(value) {
|
|
121
|
+
if (value === undefined) {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
if (typeof value === 'number') {
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
const match = /^([+-]?[0-9.]+(?:[eE][+-]?\d+)?)([a-zA-Z]*)$/.exec(value.trim());
|
|
128
|
+
if (!match || !(match[2] in QUANTITY_UNITS)) {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
const number = Number(match[1]);
|
|
132
|
+
return Number.isFinite(number) ? number * QUANTITY_UNITS[match[2]] : undefined;
|
|
133
|
+
}
|
|
134
|
+
exports.parseQuantity = parseQuantity;
|
|
100
135
|
//# sourceMappingURL=units.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webLinks = void 0;
|
|
4
|
+
const REPO = /^[A-Za-z0-9.-]+(:[0-9]{1,5})?(\/[A-Za-z0-9._~-]+)+$/;
|
|
5
|
+
const COMMIT = /^[0-9a-f]{7,64}$/;
|
|
6
|
+
// a branch keeps its slashes, as the forges read them; the rest of each part is encoded
|
|
7
|
+
const refPath = (ref) => ref.split('/').map(encodeURIComponent).join('/');
|
|
8
|
+
function webLinks(repo) {
|
|
9
|
+
if (!REPO.test(repo)) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const base = `https://${repo}`;
|
|
13
|
+
const host = repo
|
|
14
|
+
.split('/')[0]
|
|
15
|
+
.replace(/:[0-9]+$/, '')
|
|
16
|
+
.toLowerCase();
|
|
17
|
+
const forge = (tree, commits) => ({
|
|
18
|
+
repo: base,
|
|
19
|
+
ref: (ref) => `${base}/${tree}/${refPath(ref)}`,
|
|
20
|
+
commit: (commit) => (COMMIT.test(commit) ? `${base}/${commits}/${commit}` : base),
|
|
21
|
+
});
|
|
22
|
+
if (host === 'github.com' || host.startsWith('github.')) {
|
|
23
|
+
return forge('tree', 'commit');
|
|
24
|
+
}
|
|
25
|
+
if (host.split('.').some((label) => label.includes('gitlab'))) {
|
|
26
|
+
return forge('-/tree', '-/commit');
|
|
27
|
+
}
|
|
28
|
+
if (host === 'bitbucket.org') {
|
|
29
|
+
return forge('src', 'commits');
|
|
30
|
+
}
|
|
31
|
+
return { repo: base };
|
|
32
|
+
}
|
|
33
|
+
exports.webLinks = webLinks;
|
|
34
|
+
//# sourceMappingURL=web-links.js.map
|
package/package.json
CHANGED