hammerkit 2.1.0-next.9 → 2.2.0-next.1

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.
Files changed (70) hide show
  1. package/dist/dashboard/assets/{graph-canvas-BFnEN5i0.js → graph-canvas-D6GMgkoe.js} +1 -1
  2. package/dist/dashboard/assets/index-BNq9j5Jo.js +23 -0
  3. package/dist/dashboard/assets/{index-Dt3ITvRO.css → index-DP3_hKOe.css} +1 -1
  4. package/dist/dashboard/index.html +2 -2
  5. package/dist/executer/archive-task-entry.js +1 -1
  6. package/dist/executer/deadline.js +63 -10
  7. package/dist/executer/event-cache.js +5 -1
  8. package/dist/executer/execute-work-task.js +15 -3
  9. package/dist/executer/runner-commands.js +36 -0
  10. package/dist/file/get-file-context.js +4 -7
  11. package/dist/harness/connect.js +12 -8
  12. package/dist/harness/reconnect.js +141 -0
  13. package/dist/harness/sandbox-client.js +242 -33
  14. package/dist/harness/service-tools.js +36 -3
  15. package/dist/kubernetes/cluster-state.js +48 -14
  16. package/dist/kubernetes/ensure-persistent-data.js +15 -4
  17. package/dist/kubernetes/follow-pod-logs.js +8 -5
  18. package/dist/kubernetes/kept-claims.js +26 -5
  19. package/dist/kubernetes/resources.js +5 -1
  20. package/dist/kubernetes/sandbox-runner.js +526 -156
  21. package/dist/kubernetes/store-kubernetes-data.js +18 -3
  22. package/dist/kubernetes/sync-changes.js +463 -0
  23. package/dist/kubernetes/volumes.js +23 -1
  24. package/dist/optimizer/get-work-cache-stats.js +7 -0
  25. package/dist/planner/work-item-status.js +12 -2
  26. package/dist/planner/work-runtime-aggregate.js +1 -0
  27. package/dist/planner/work-runtime-docker.js +9 -5
  28. package/dist/planner/work-runtime-kubernetes.js +277 -55
  29. package/dist/planner/work-runtime-local.js +8 -4
  30. package/dist/remote/annotations.js +29 -3
  31. package/dist/remote/bundle.js +6 -8
  32. package/dist/remote/collect-bundle.js +3 -2
  33. package/dist/remote/device-login.js +4 -1
  34. package/dist/remote/remote-commands.js +16 -7
  35. package/dist/remote/remote-work-commands.js +265 -72
  36. package/dist/remote/server-client.js +38 -40
  37. package/dist/server/artifacts-api.js +56 -0
  38. package/dist/server/definitions-api.js +62 -8
  39. package/dist/server/endpoints.js +52 -32
  40. package/dist/server/executor.js +117 -30
  41. package/dist/server/http.js +4 -1
  42. package/dist/server/keep-artifacts.js +230 -0
  43. package/dist/server/kubernetes-backend.js +186 -59
  44. package/dist/server/kubernetes-sandbox-storage.js +83 -22
  45. package/dist/server/overview.js +67 -9
  46. package/dist/server/paging.js +167 -0
  47. package/dist/server/plan.js +8 -1
  48. package/dist/server/public-paths.js +52 -0
  49. package/dist/server/run-access.js +24 -0
  50. package/dist/server/run-artifacts.js +171 -0
  51. package/dist/server/run-logs.js +25 -1
  52. package/dist/server/run-request.js +63 -1
  53. package/dist/server/run-retry.js +6 -0
  54. package/dist/server/run-worker.js +267 -33
  55. package/dist/server/runs.js +527 -99
  56. package/dist/server/sandbox-files.js +9 -8
  57. package/dist/server/sandbox-follow.js +54 -0
  58. package/dist/server/sandbox-storage.js +38 -1
  59. package/dist/server/sandbox-sync.js +392 -0
  60. package/dist/server/sandboxes-api.js +54 -8
  61. package/dist/server/sandboxes.js +19 -0
  62. package/dist/server/server-config.js +14 -0
  63. package/dist/server/server.js +189 -46
  64. package/dist/server/service-runs.js +41 -8
  65. package/dist/server/task-order.js +56 -0
  66. package/dist/utils/project-path.js +20 -0
  67. package/dist/utils/tar-files.js +52 -0
  68. package/dist/utils/tar.js +37 -1
  69. package/package.json +1 -1
  70. package/dist/dashboard/assets/index-CE5PSB3y.js +0 -23
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortTasks = exports.parseTaskOrder = exports.taskSource = exports.TASK_FIELDS = void 0;
4
+ const paging_1 = require("./paging");
5
+ // what GET /v1/tasks?values= answers the values of: where the tasks ran from
6
+ exports.TASK_FIELDS = ['source'];
7
+ // where the runs of a task are from, as the source filter of the runs names it
8
+ function taskSource(stats) {
9
+ return stats.repo === 'an upload' ? 'upload' : stats.repo;
10
+ }
11
+ exports.taskSource = taskSource;
12
+ // of its runs, how many came from the cache, and how many ended well (cached passed before)
13
+ const rate = (part, stats) => (stats.runs ? part / stats.runs : undefined);
14
+ // what `sort` of GET /v1/tasks orders by: the columns of the Tasks page
15
+ const SORT_BY = {
16
+ task: (stats) => stats.task,
17
+ last: (stats) => Date.parse(stats.last.at),
18
+ runs: (stats) => stats.runs,
19
+ cache: (stats) => rate(stats.cached, stats),
20
+ success: (stats) => rate(stats.runs - stats.failed, stats),
21
+ median: (stats) => stats.medianMs,
22
+ p90: (stats) => stats.p90Ms,
23
+ total: (stats) => stats.totalMs,
24
+ };
25
+ // `sort` and `order` (asc or desc, desc when left out): undefined when the caller names no sort.
26
+ function parseTaskOrder(params) {
27
+ const sort = params.get('sort');
28
+ if (sort === null) {
29
+ return undefined;
30
+ }
31
+ if (!(sort in SORT_BY)) {
32
+ throw new paging_1.ListParamError(`sort: one of ${Object.keys(SORT_BY).join(', ')}`);
33
+ }
34
+ const order = params.get('order') ?? 'desc';
35
+ if (order !== 'asc' && order !== 'desc') {
36
+ throw new paging_1.ListParamError('order: asc or desc');
37
+ }
38
+ return { sort, order };
39
+ }
40
+ exports.parseTaskOrder = parseTaskOrder;
41
+ // The tasks in that order, those without a value last, and by repository and name when equal.
42
+ function sortTasks(tasks, { sort, order }) {
43
+ const value = SORT_BY[sort];
44
+ return [...tasks].sort((a, b) => {
45
+ const x = value(a);
46
+ const y = value(b);
47
+ if (x === undefined || y === undefined) {
48
+ return x === y ? tie(a, b) : x === undefined ? 1 : -1;
49
+ }
50
+ const compared = typeof x === 'number' && typeof y === 'number' ? x - y : String(x).localeCompare(String(y));
51
+ return (order === 'asc' ? compared : -compared) || tie(a, b);
52
+ });
53
+ }
54
+ exports.sortTasks = sortTasks;
55
+ const tie = (a, b) => a.repo.localeCompare(b.repo) || a.task.localeCompare(b.task);
56
+ //# sourceMappingURL=task-order.js.map
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRelativePath = void 0;
4
+ /**
5
+ * A path relative to a root (of a project, a bundle, a sandbox), as the API and the CLI take
6
+ * it: at most `maxLength` characters, `/` between names, no `.` or `..` or empty name, no
7
+ * backslash, no NUL, nothing absolute (`/x`, `C:x`). The one rule every path an input names
8
+ * is checked by, so the places that check it can not drift apart.
9
+ */
10
+ function isRelativePath(path, maxLength) {
11
+ return (path.length > 0 &&
12
+ path.length <= maxLength &&
13
+ !path.startsWith('/') &&
14
+ !/^[A-Za-z]:/.test(path) &&
15
+ !path.includes('\\') &&
16
+ !path.includes('\0') &&
17
+ !path.split('/').some((part) => part === '' || part === '.' || part === '..'));
18
+ }
19
+ exports.isRelativePath = isRelativePath;
20
+ //# sourceMappingURL=project-path.js.map
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tarFiles = void 0;
4
+ const tar_1 = require("tar");
5
+ const path_1 = require("path");
6
+ const BLOCK = 512;
7
+ // the header of an entry, encoded in one block (node-tar cuts a long name to fit it)
8
+ function block(header) {
9
+ const buf = Buffer.alloc(BLOCK);
10
+ header.encode(buf, 0);
11
+ return buf;
12
+ }
13
+ // the bytes of `content` padded to whole blocks
14
+ function padded(content) {
15
+ const rest = content.length % BLOCK;
16
+ return rest === 0 ? content : Buffer.concat([content, Buffer.alloc(BLOCK - rest)]);
17
+ }
18
+ /**
19
+ * The archive of `files`: each at its path, with its mode, mtime and content. An empty list is
20
+ * an empty archive, the two blocks that end one.
21
+ */
22
+ function tarFiles(files) {
23
+ const blocks = [];
24
+ for (const file of files) {
25
+ const mtime = file.mtime ?? new Date();
26
+ const header = new tar_1.Header({
27
+ path: file.path,
28
+ mode: file.mode,
29
+ size: file.content.length,
30
+ type: 'File',
31
+ mtime,
32
+ });
33
+ // encoding sets `needPax` when the path does not fit a ustar header
34
+ const head = block(header);
35
+ if (header.needPax) {
36
+ const body = Buffer.from(new tar_1.Pax({ path: file.path }, false).encodeBody());
37
+ const extended = new tar_1.Header({
38
+ path: `PaxHeader/${path_1.posix.basename(file.path)}`.slice(0, 100),
39
+ mode: 0o644,
40
+ size: body.length,
41
+ type: 'ExtendedHeader',
42
+ mtime,
43
+ });
44
+ blocks.push(block(extended), padded(body));
45
+ }
46
+ blocks.push(head, padded(file.content));
47
+ }
48
+ blocks.push(Buffer.alloc(BLOCK * 2));
49
+ return Buffer.concat(blocks);
50
+ }
51
+ exports.tarFiles = tarFiles;
52
+ //# sourceMappingURL=tar-files.js.map
package/dist/utils/tar.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.onlyBelow = exports.extractOutput = exports.packArchive = void 0;
3
+ exports.onlyBelow = exports.extractOutput = exports.measureArchive = exports.packArchive = void 0;
4
+ const fs_1 = require("fs");
4
5
  const tar_1 = require("tar");
5
6
  const path_1 = require("path");
6
7
  function packArchive(options, files) {
@@ -34,6 +35,41 @@ const NOT_PACKED = '\0';
34
35
  function isExact(key) {
35
36
  return key.split(':').every((part) => Number.isSafeInteger(Number(part)));
36
37
  }
38
+ // The entries of an archive and the bytes of their content, unpacked, measured before anything
39
+ // is extracted from it. Reading stops at the first entry that takes it past `limit`, so what
40
+ // is returned is then more than the limit, and the rest of the archive is not read.
41
+ function measureArchive(file, limit) {
42
+ return new Promise((resolve, reject) => {
43
+ const measured = { entries: 0, bytes: 0 };
44
+ let done = false;
45
+ const source = (0, fs_1.createReadStream)(file);
46
+ const parser = new tar_1.Parser({
47
+ onReadEntry: (entry) => {
48
+ if (done) {
49
+ entry.resume();
50
+ return;
51
+ }
52
+ measured.entries++;
53
+ measured.bytes += entry.size ?? 0;
54
+ entry.resume();
55
+ if (measured.entries > limit.entries || measured.bytes > limit.bytes) {
56
+ done = true;
57
+ source.unpipe(parser);
58
+ source.destroy();
59
+ resolve({ ...measured });
60
+ }
61
+ },
62
+ });
63
+ parser.on('end', () => {
64
+ done = true;
65
+ resolve({ ...measured });
66
+ });
67
+ parser.on('error', reject);
68
+ source.on('error', reject);
69
+ source.pipe(parser);
70
+ });
71
+ }
72
+ exports.measureArchive = measureArchive;
37
73
  // Extracts the archive of one output (a path relative to `cwd`) into `cwd`. An archive
38
74
  // comes from a cache another run, or whoever writes to the cache backend, filled, so only
39
75
  // entries of that output are taken: one beside it (another output, a source of the task, a
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hammerkit",
3
3
  "description": "Containerized build tool with incremental caching that runs the same build file locally, in Docker and on Kubernetes.",
4
- "version": "2.1.0-next.9",
4
+ "version": "2.2.0-next.1",
5
5
  "keywords": [
6
6
  "build",
7
7
  "build-tool",