hammerkit 2.1.0 → 2.2.0-next.2

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 (103) hide show
  1. package/build.schema.json +126 -28
  2. package/dist/cache/backends/registry/push-credentials.js +50 -0
  3. package/dist/cache/backends/registry/registry-client.js +41 -10
  4. package/dist/cache/backends/registry-cache-backend.js +6 -1
  5. package/dist/cache/cache-inventory.js +3 -0
  6. package/dist/cli.js +5 -0
  7. package/dist/dashboard/assets/graph-canvas-D6GMgkoe.js +8 -0
  8. package/dist/dashboard/assets/index-BNq9j5Jo.js +23 -0
  9. package/dist/dashboard/assets/index-DP3_hKOe.css +2 -0
  10. package/dist/dashboard/index.html +2 -2
  11. package/dist/docker/item-network.js +6 -5
  12. package/dist/docker/remove-orphaned-containers.js +5 -4
  13. package/dist/environment/replace-env-variables.js +8 -5
  14. package/dist/environment/run-source-envs.js +2 -1
  15. package/dist/executer/archive-task-entry.js +1 -1
  16. package/dist/executer/check-readiness.js +8 -4
  17. package/dist/executer/docker-healthcheck.js +73 -0
  18. package/dist/executer/docker-service.js +21 -15
  19. package/dist/executer/event-cache.js +7 -1
  20. package/dist/executer/execute-work-task.js +8 -0
  21. package/dist/executer/runner-commands.js +36 -0
  22. package/dist/file/get-file-context.js +4 -7
  23. package/dist/harness/connect.js +12 -8
  24. package/dist/harness/reconnect.js +141 -0
  25. package/dist/harness/sandbox-client.js +241 -33
  26. package/dist/harness/service-tools.js +11 -2
  27. package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +62 -14
  28. package/dist/kubernetes/ensure-persistent-data.js +1 -1
  29. package/dist/kubernetes/follow-pod-logs.js +8 -5
  30. package/dist/kubernetes/kept-claims.js +38 -14
  31. package/dist/kubernetes/sandbox-runner.js +526 -156
  32. package/dist/kubernetes/store-kubernetes-data.js +18 -3
  33. package/dist/kubernetes/sync-changes.js +463 -0
  34. package/dist/kubernetes/volumes.js +23 -1
  35. package/dist/network/healthcheck-request.js +38 -0
  36. package/dist/optimizer/get-work-cache-stats.js +7 -0
  37. package/dist/optimizer/work-task-cache-description.js +5 -3
  38. package/dist/planner/image-build.js +5 -0
  39. package/dist/planner/service-definition.js +2 -1
  40. package/dist/planner/utils/append-work-service.js +12 -4
  41. package/dist/planner/utils/dependency-outputs.js +7 -6
  42. package/dist/planner/validate.js +41 -0
  43. package/dist/planner/work-healthcheck.js +23 -2
  44. package/dist/planner/work-item-status.js +12 -2
  45. package/dist/planner/work-runtime-aggregate.js +1 -0
  46. package/dist/planner/work-runtime-docker.js +33 -6
  47. package/dist/planner/work-runtime-kubernetes.js +313 -70
  48. package/dist/planner/work-runtime-local.js +8 -4
  49. package/dist/planner/work-secret.js +33 -11
  50. package/dist/planner/work-service-id.js +30 -6
  51. package/dist/planner/work-service.js +2 -2
  52. package/dist/program.js +19 -1
  53. package/dist/remote/annotations.js +8 -2
  54. package/dist/remote/bundle.js +6 -8
  55. package/dist/remote/device-login.js +4 -1
  56. package/dist/remote/remote-commands.js +16 -7
  57. package/dist/remote/remote-status.js +1 -1
  58. package/dist/remote/remote-work-commands.js +220 -68
  59. package/dist/remote/server-client.js +38 -40
  60. package/dist/schema/build-file-base-task-schema.js +16 -1
  61. package/dist/schema/build-file-image-build-schema.js +5 -8
  62. package/dist/schema/build-file-service-container-healthcheck.js +25 -7
  63. package/dist/schema/reference-parser.js +108 -43
  64. package/dist/schema/work-scope-parser.js +8 -0
  65. package/dist/secrets/prefetch-secrets.js +20 -1
  66. package/dist/server/artifacts-api.js +56 -0
  67. package/dist/server/borrowed-quota.js +216 -0
  68. package/dist/server/cache-push.js +50 -0
  69. package/dist/server/capacity.js +18 -6
  70. package/dist/server/definitions-api.js +62 -8
  71. package/dist/server/executor.js +131 -31
  72. package/dist/server/http.js +4 -1
  73. package/dist/server/keep-artifacts.js +230 -0
  74. package/dist/server/kubernetes-backend.js +292 -79
  75. package/dist/server/kubernetes-sandbox-storage.js +86 -24
  76. package/dist/server/overview.js +73 -9
  77. package/dist/server/paging.js +167 -0
  78. package/dist/server/plan.js +54 -8
  79. package/dist/server/run-access.js +24 -0
  80. package/dist/server/run-artifacts.js +171 -0
  81. package/dist/server/run-logs.js +25 -1
  82. package/dist/server/run-request.js +11 -0
  83. package/dist/server/run-source-environment.js +1 -1
  84. package/dist/server/run-worker.js +305 -40
  85. package/dist/server/runs.js +531 -105
  86. package/dist/server/sandbox-files-api.js +27 -12
  87. package/dist/server/sandbox-files.js +12 -10
  88. package/dist/server/sandbox-follow.js +54 -0
  89. package/dist/server/sandbox-pod.js +1 -1
  90. package/dist/server/sandbox-storage.js +38 -1
  91. package/dist/server/sandbox-sync.js +392 -0
  92. package/dist/server/sandboxes-api.js +116 -19
  93. package/dist/server/sandboxes.js +38 -3
  94. package/dist/server/server-config.js +133 -2
  95. package/dist/server/server.js +189 -39
  96. package/dist/server/task-order.js +56 -0
  97. package/dist/utils/project-path.js +20 -0
  98. package/dist/utils/tar-files.js +52 -0
  99. package/dist/utils/tar.js +37 -1
  100. package/package.json +1 -1
  101. package/dist/dashboard/assets/graph-canvas-DtJSpova.js +0 -8
  102. package/dist/dashboard/assets/index-BndChMep.css +0 -2
  103. package/dist/dashboard/assets/index-DRSwIRXd.js +0 -17
@@ -6,8 +6,10 @@ const promises_1 = require("fs/promises");
6
6
  const path_1 = require("path");
7
7
  const units_1 = require("../utils/units");
8
8
  const git_checkout_1 = require("./git-checkout");
9
+ const oauth_1 = require("./oauth");
9
10
  const runs_1 = require("./runs");
10
11
  const repo_1 = require("./repo");
12
+ const sandbox_files_1 = require("./sandbox-files");
11
13
  const sandbox_storage_1 = require("./sandbox-storage");
12
14
  // How long creating a sandbox or moving it to another commit may take
13
15
  const FETCH_TIMEOUT_MS = 10 * 60 * 1000;
@@ -22,7 +24,8 @@ class SandboxError extends Error {
22
24
  exports.SandboxError = SandboxError;
23
25
  /**
24
26
  * The sandboxes of a server: who owns which, the limits, and one change at a time per
25
- * sandbox. Everything is scoped to the owner: somebody else's sandbox is "not found".
27
+ * sandbox. Everything is scoped to the owner: somebody else's sandbox is "not found". Only
28
+ * `all` and `peek` show the sandboxes of everybody, for who may read them (`observe`).
26
29
  */
27
30
  class SandboxRegistry {
28
31
  constructor(options) {
@@ -38,6 +41,8 @@ class SandboxRegistry {
38
41
  // the measures of runs that are over, which a run's result does not wait for
39
42
  this.measuring = new Map();
40
43
  this.locks = new Map();
44
+ // what hears of the files of a sandbox changing: an edit, or a run that wrote to them
45
+ this.listeners = new Set();
41
46
  this.runs = { holder: () => undefined, stop: async () => undefined };
42
47
  this.now = options.now ?? Date.now;
43
48
  }
@@ -45,6 +50,16 @@ class SandboxRegistry {
45
50
  useRuns(runs) {
46
51
  this.runs = runs;
47
52
  }
53
+ // Calls `listener` with the id of a sandbox whose files may have changed: after each edit,
54
+ // and after each run that wrote to them (measure). It may come when nothing changed.
55
+ onChange(listener) {
56
+ this.listeners.add(listener);
57
+ }
58
+ changed(id) {
59
+ for (const listener of this.listeners) {
60
+ listener(id);
61
+ }
62
+ }
48
63
  get limits() {
49
64
  return this.options.limits;
50
65
  }
@@ -111,6 +126,18 @@ class SandboxRegistry {
111
126
  const sandbox = this.sandboxes.get(id);
112
127
  return sandbox && owns(owner, sandbox) && !this.deleting.has(id) ? copy(sandbox) : undefined;
113
128
  }
129
+ // The sandboxes of everybody, oldest first: what who observes sees.
130
+ all() {
131
+ return [...this.sandboxes.values()]
132
+ .filter((sandbox) => !this.deleting.has(sandbox.id))
133
+ .sort((a, b) => a.createdAt.localeCompare(b.createdAt))
134
+ .map(copy);
135
+ }
136
+ // A sandbox of anybody, for who observes: to read, never to change.
137
+ peek(id) {
138
+ const sandbox = this.sandboxes.get(id);
139
+ return sandbox && !this.deleting.has(id) ? copy(sandbox) : undefined;
140
+ }
114
141
  holder(id) {
115
142
  return this.runs.holder(id);
116
143
  }
@@ -188,9 +215,10 @@ class SandboxRegistry {
188
215
  }
189
216
  this.creating.set(id, { owner: { iss: owner.iss, sub: owner.sub }, bytes });
190
217
  const at = this.timestamp();
218
+ const name = (0, oauth_1.displayName)(owner);
191
219
  const sandbox = {
192
220
  id,
193
- owner: { iss: owner.iss, sub: owner.sub },
221
+ owner: { iss: owner.iss, sub: owner.sub, ...(name ? { name } : {}) },
194
222
  repo,
195
223
  ref,
196
224
  commit,
@@ -246,6 +274,10 @@ class SandboxRegistry {
246
274
  });
247
275
  }
248
276
  catch (e) {
277
+ // a file of the sandbox in the way of the ref, which a checkout would overwrite
278
+ if (e instanceof sandbox_files_1.SandboxFileError && e.status === 409) {
279
+ throw new SandboxError(409, repos.scrub(e, credentials.values).message);
280
+ }
249
281
  throw new SandboxError(502, repos.scrub(e, credentials.values).message);
250
282
  }
251
283
  sandbox.ref = ref;
@@ -440,6 +472,7 @@ class SandboxRegistry {
440
472
  sandbox.bytes = Math.max(0, sandbox.bytes + plan.bytes);
441
473
  sandbox.lastUsedAt = this.timestamp();
442
474
  await this.save(sandbox);
475
+ this.changed(id);
443
476
  return plan.files;
444
477
  });
445
478
  }
@@ -473,6 +506,7 @@ class SandboxRegistry {
473
506
  }
474
507
  sandbox.bytes = await this.options.storage.usage(keyOf(sandbox));
475
508
  await this.save(sandbox);
509
+ this.changed(id);
476
510
  });
477
511
  const settled = measure.catch(() => undefined);
478
512
  this.measuring.set(id, settled);
@@ -548,8 +582,9 @@ function owns(owner, sandbox) {
548
582
  const of = 'owner' in sandbox ? sandbox.owner : sandbox;
549
583
  return of.iss === owner.iss && of.sub === owner.sub;
550
584
  }
585
+ // what the storage keeps a sandbox by: its owner's identity, not the name they had
551
586
  function keyOf(sandbox) {
552
- return { id: sandbox.id, owner: sandbox.owner };
587
+ return { id: sandbox.id, owner: { iss: sandbox.owner.iss, sub: sandbox.owner.sub } };
553
588
  }
554
589
  function copy(sandbox) {
555
590
  return {
@@ -1,18 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.detectPlatform = exports.getSecretCatalog = exports.readServerConfig = exports.getServerAccounts = exports.getSandboxRuntimes = exports.serverConfigSchema = exports.sourceSchema = exports.entitlementSchema = exports.endpointGrantSchema = exports.endpointLevelSchema = exports.sandboxGrantSchema = exports.sandboxBranchTypeSchema = exports.buildsLevelSchema = exports.accountLevelSchema = exports.getMaxVolumeSize = exports.DEFAULT_MAX_VOLUME_SIZE = exports.DEFAULT_DENIED_EGRESS = exports.kubernetesPoolSchema = exports.accountSchema = exports.issuerSchema = exports.serverPlatformSchema = void 0;
3
+ exports.getMaxQuotaIssues = exports.detectPlatform = exports.getSecretCatalog = exports.readServerConfig = exports.getServerAccounts = exports.getSandboxRuntimes = exports.serverConfigSchema = exports.sourceSchema = exports.entitlementSchema = exports.endpointGrantSchema = exports.endpointLevelSchema = exports.sandboxGrantSchema = exports.sandboxBranchTypeSchema = exports.buildsLevelSchema = exports.accountLevelSchema = exports.getMaxVolumeSize = exports.DEFAULT_MAX_VOLUME_SIZE = exports.DEFAULT_DENIED_EGRESS = exports.kubernetesPoolSchema = exports.accountSchema = exports.issuerSchema = exports.serverPlatformSchema = void 0;
4
4
  const run_source_envs_1 = require("../environment/run-source-envs");
5
5
  const net_1 = require("net");
6
6
  const zod_1 = require("zod");
7
7
  const yaml_1 = require("yaml");
8
8
  const log_1 = require("../log");
9
9
  const units_1 = require("../utils/units");
10
+ const borrowed_quota_1 = require("./borrowed-quota");
10
11
  const version_1 = require("../version");
11
12
  const network_schema_1 = require("../schema/network-schema");
12
13
  const capabilities_schema_1 = require("../schema/capabilities-schema");
13
14
  const build_file_secret_provider_schema_1 = require("../schema/build-file-secret-provider-schema");
14
15
  const repo_1 = require("./repo");
15
16
  const work_network_1 = require("../planner/work-network");
17
+ const registry_reference_1 = require("../cache/backends/registry/registry-reference");
16
18
  const LOOPBACK_HOSTS = ['127.0.0.1', 'localhost', '::1'];
17
19
  exports.serverPlatformSchema = zod_1.z
18
20
  .object({
@@ -275,8 +277,12 @@ const kubernetesBackendSchema = zod_1.z
275
277
  })
276
278
  .strict())
277
279
  .default({}),
278
- // the ResourceQuota of every caller's namespace, such as `requests.cpu: '8'`
280
+ // the ResourceQuota of every caller's namespace, such as `requests.cpu: '8'`: what each
281
+ // caller is promised
279
282
  quota: zod_1.z.record(zod_1.z.union([zod_1.z.string().min(1), zod_1.z.number()]).transform(String)).optional(),
283
+ // how far the CPU and memory of a caller's quota rise above `quota` while the nodes of the
284
+ // pools have room no other caller is promised (see BorrowedQuotas); never when left out
285
+ maxQuota: zod_1.z.record(zod_1.z.union([zod_1.z.string().min(1), zod_1.z.number()]).transform(String)).optional(),
280
286
  // what a container without `resources` requests (a LimitRange), so it is
281
287
  // admitted under a quota that limits compute
282
288
  defaultResources: zod_1.z
@@ -422,6 +428,41 @@ exports.sourceSchema = zod_1.z
422
428
  .optional(),
423
429
  })
424
430
  .strict();
431
+ // A trusted run of these repositories and branches writes a registry cache, with the credential
432
+ // of its registry. A build file can name the registry it reads from, never the credential; a run
433
+ // writes only the registry of the first rule that covers it, and only with that credential.
434
+ const cachePushSchema = zod_1.z
435
+ .object({
436
+ // the repositories, as a pattern of `host/path`, such as github.com/corp/*
437
+ repo: repoPatternSchema,
438
+ // the branches a trusted run is from: the default branch, such as `main` or `release/*`. A
439
+ // commit is never one, nor a tag, so a sandbox and an upload never are.
440
+ refs: zod_1.z.array(branchPatternSchema).min(1),
441
+ registry: zod_1.z
442
+ .object({
443
+ // the repository of the build file's `backend.repository`, written the same way; a password
444
+ // goes over https only, so a registry on localhost is refused here
445
+ repository: zod_1.z
446
+ .string()
447
+ .min(1)
448
+ .superRefine((value, ctx) => {
449
+ try {
450
+ if ((0, registry_reference_1.parseRegistryReference)(value).insecure) {
451
+ ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, message: 'a push credential goes over https only' });
452
+ }
453
+ }
454
+ catch (e) {
455
+ ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, message: (0, log_1.getErrorMessage)(e) });
456
+ }
457
+ }),
458
+ username: zod_1.z.string().min(1),
459
+ // the variable of the server's environment that holds its password or token; it is read
460
+ // by the server and passed to the one run that pushes, never to a task
461
+ passwordEnv: zod_1.z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/),
462
+ })
463
+ .strict(),
464
+ })
465
+ .strict();
425
466
  // The server config is written by an operator and reviewed like code, so a typo
426
467
  // is an error and not a silently ignored key.
427
468
  exports.serverConfigSchema = zod_1.z
@@ -474,6 +515,19 @@ exports.serverConfigSchema = zod_1.z
474
515
  .array(zod_1.z.enum(['docker', 'local']))
475
516
  .min(1)
476
517
  .default(['docker']),
518
+ // the registry caches of the build files a server runs: the hosts a run may read from
519
+ // (`registries`, besides those of the `push` rules, which are allowed already), and the rules
520
+ // by which a trusted run writes one (see cachePushSchema). A registry is read anonymously
521
+ // unless a rule of `push` writes it; nothing is read from a host not listed here.
522
+ cache: zod_1.z
523
+ .object({
524
+ registries: zod_1.z
525
+ .array(zod_1.z.string().regex(/^[A-Za-z0-9.-]+(:[0-9]{1,5})?$/, 'a registry host, such as ghcr.io'))
526
+ .default([]),
527
+ push: zod_1.z.array(cachePushSchema).default([]),
528
+ })
529
+ .strict()
530
+ .default({}),
477
531
  // where the server keeps what must survive a restart: the published build files
478
532
  storage: zod_1.z
479
533
  .object({ directory: zod_1.z.string().min(1).optional() })
@@ -576,6 +630,20 @@ exports.serverConfigSchema = zod_1.z
576
630
  .default({}),
577
631
  // how long a passed check stays for `remote verify` to find (see checks.ts)
578
632
  checksKeep: duration.default('30d'),
633
+ // the outputs the tasks of a run export (`export: true`, and `export: always` of a task
634
+ // that failed), kept for `remote artifacts`; none of a run in which anything reads a
635
+ // secret or a variable of the server (run-artifacts.ts)
636
+ artifacts: zod_1.z
637
+ .object({
638
+ // how long they stay after their run ended
639
+ keep: duration.default('1d'),
640
+ // what one run keeps, packed; an output that would take it over is left out
641
+ maxBytes: size.default('256Mi'),
642
+ // what all runs keep together; the oldest runs' go first
643
+ total: size.default('10Gi'),
644
+ })
645
+ .strict()
646
+ .default({}),
579
647
  })
580
648
  .strict()
581
649
  .default({}),
@@ -674,6 +742,17 @@ exports.serverConfigSchema = zod_1.z
674
742
  })
675
743
  .strict()
676
744
  .superRefine((config, ctx) => {
745
+ // the password of a cache push is the server's alone: a variable a run sees would reach its tasks
746
+ config.cache.push.forEach((rule, index) => {
747
+ const name = rule.registry.passwordEnv;
748
+ if (config.runs.env.allow.includes(name) || Object.prototype.hasOwnProperty.call(config.runs.env.set, name)) {
749
+ ctx.addIssue({
750
+ code: zod_1.z.ZodIssueCode.custom,
751
+ path: ['cache', 'push', index, 'registry', 'passwordEnv'],
752
+ message: `${name} is seen by the runs (runs.env), the password of a cache push may not be`,
753
+ });
754
+ }
755
+ });
677
756
  const issuers = config.issuers.map((i) => i.issuer);
678
757
  config.entitlements.forEach((entitlement, index) => {
679
758
  const iss = (entitlement.subject ?? entitlement.group ?? entitlement.claims)?.iss;
@@ -854,6 +933,13 @@ exports.serverConfigSchema = zod_1.z
854
933
  }
855
934
  }
856
935
  }
936
+ for (const issue of getMaxQuotaIssues(backend.quota, backend.maxQuota)) {
937
+ ctx.addIssue({
938
+ code: zod_1.z.ZodIssueCode.custom,
939
+ path: ['backend', 'maxQuota', ...issue.path],
940
+ message: issue.message,
941
+ });
942
+ }
857
943
  if (backend.maxVolumeSize && (0, units_1.parseSize)(backend.volumeSize) > (0, units_1.parseSize)(backend.maxVolumeSize)) {
858
944
  ctx.addIssue({
859
945
  code: zod_1.z.ZodIssueCode.custom,
@@ -1071,4 +1157,49 @@ function detectPlatform() {
1071
1157
  return { os, arch };
1072
1158
  }
1073
1159
  exports.detectPlatform = detectPlatform;
1160
+ // What is wrong with `backend.maxQuota`: a key a caller may borrow (CPU and memory, see
1161
+ // BORROWED_RESOURCES) that `quota` has too, no less than there, and a limit only with the
1162
+ // requests of its resource, which say how much room the caller takes of the nodes.
1163
+ function getMaxQuotaIssues(quota, maxQuota) {
1164
+ if (!maxQuota) {
1165
+ return [];
1166
+ }
1167
+ if (!quota) {
1168
+ return [{ path: [], message: 'a caller borrows above backend.quota, which is not set' }];
1169
+ }
1170
+ const issues = [];
1171
+ for (const [key, value] of Object.entries(maxQuota)) {
1172
+ const resource = (0, borrowed_quota_1.getBorrowedResource)(key);
1173
+ if (!resource) {
1174
+ issues.push({
1175
+ path: [key],
1176
+ message: `${key} can't be borrowed, only ${Object.values(borrowed_quota_1.BORROWED_RESOURCES)
1177
+ .flatMap((keys) => [...keys.requests, ...keys.limits])
1178
+ .join(', ')}`,
1179
+ });
1180
+ continue;
1181
+ }
1182
+ if (quota[key] === undefined) {
1183
+ issues.push({ path: [key], message: `${key} is not in backend.quota, the share it rises from` });
1184
+ continue;
1185
+ }
1186
+ const max = (0, units_1.parseQuantity)(value);
1187
+ const share = (0, units_1.parseQuantity)(quota[key]);
1188
+ if (max === undefined) {
1189
+ issues.push({ path: [key], message: `expected a quantity such as 8, 500m or 16Gi` });
1190
+ }
1191
+ else if (share !== undefined && max < share) {
1192
+ issues.push({ path: [key], message: `${value} is less than ${quota[key]} of backend.quota` });
1193
+ }
1194
+ const requests = borrowed_quota_1.BORROWED_RESOURCES[resource].requests;
1195
+ if (!requests.includes(key) && !requests.some((other) => maxQuota[other] !== undefined)) {
1196
+ issues.push({
1197
+ path: [key],
1198
+ message: `${key} rises with the requests of ${resource}, add ${requests[0]} to backend.maxQuota`,
1199
+ });
1200
+ }
1201
+ }
1202
+ return issues;
1203
+ }
1204
+ exports.getMaxQuotaIssues = getMaxQuotaIssues;
1074
1205
  //# sourceMappingURL=server-config.js.map