hammerkit 2.1.0-next.9 → 2.1.0

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 (69) hide show
  1. package/build.schema.json +28 -126
  2. package/dist/cli.js +0 -5
  3. package/dist/dashboard/assets/graph-canvas-DtJSpova.js +8 -0
  4. package/dist/dashboard/assets/index-BndChMep.css +2 -0
  5. package/dist/dashboard/assets/{index-CE5PSB3y.js → index-DRSwIRXd.js} +9 -15
  6. package/dist/dashboard/index.html +2 -2
  7. package/dist/docker/item-network.js +5 -6
  8. package/dist/docker/remove-orphaned-containers.js +4 -5
  9. package/dist/environment/replace-env-variables.js +5 -8
  10. package/dist/environment/run-source-envs.js +1 -2
  11. package/dist/executer/check-readiness.js +4 -8
  12. package/dist/executer/deadline.js +63 -10
  13. package/dist/executer/docker-service.js +15 -21
  14. package/dist/executer/execute-work-task.js +15 -3
  15. package/dist/harness/sandbox-client.js +1 -0
  16. package/dist/harness/service-tools.js +25 -1
  17. package/dist/kubernetes/cluster-state.js +48 -14
  18. package/dist/kubernetes/ensure-kubernetes-deployment-exists.js +14 -62
  19. package/dist/kubernetes/ensure-persistent-data.js +14 -3
  20. package/dist/kubernetes/kept-claims.js +9 -12
  21. package/dist/kubernetes/resources.js +5 -1
  22. package/dist/optimizer/work-task-cache-description.js +3 -5
  23. package/dist/planner/image-build.js +0 -5
  24. package/dist/planner/service-definition.js +1 -2
  25. package/dist/planner/utils/append-work-service.js +4 -12
  26. package/dist/planner/utils/dependency-outputs.js +6 -7
  27. package/dist/planner/validate.js +0 -41
  28. package/dist/planner/work-healthcheck.js +2 -23
  29. package/dist/planner/work-runtime-docker.js +1 -24
  30. package/dist/planner/work-runtime-kubernetes.js +16 -37
  31. package/dist/planner/work-secret.js +11 -33
  32. package/dist/planner/work-service-id.js +6 -30
  33. package/dist/planner/work-service.js +2 -2
  34. package/dist/program.js +1 -19
  35. package/dist/remote/annotations.js +31 -11
  36. package/dist/remote/collect-bundle.js +3 -2
  37. package/dist/remote/remote-status.js +1 -1
  38. package/dist/remote/remote-work-commands.js +53 -12
  39. package/dist/schema/build-file-base-task-schema.js +1 -16
  40. package/dist/schema/build-file-image-build-schema.js +8 -5
  41. package/dist/schema/build-file-service-container-healthcheck.js +7 -25
  42. package/dist/schema/reference-parser.js +43 -108
  43. package/dist/schema/work-scope-parser.js +0 -8
  44. package/dist/secrets/prefetch-secrets.js +1 -20
  45. package/dist/server/capacity.js +6 -18
  46. package/dist/server/endpoints.js +52 -32
  47. package/dist/server/kubernetes-backend.js +28 -114
  48. package/dist/server/kubernetes-sandbox-storage.js +2 -3
  49. package/dist/server/overview.js +1 -7
  50. package/dist/server/plan.js +0 -8
  51. package/dist/server/public-paths.js +52 -0
  52. package/dist/server/run-request.js +52 -1
  53. package/dist/server/run-retry.js +6 -0
  54. package/dist/server/run-source-environment.js +1 -1
  55. package/dist/server/runs.js +6 -4
  56. package/dist/server/sandbox-files-api.js +12 -27
  57. package/dist/server/sandbox-files.js +2 -3
  58. package/dist/server/sandbox-pod.js +1 -1
  59. package/dist/server/sandboxes-api.js +14 -65
  60. package/dist/server/sandboxes.js +3 -19
  61. package/dist/server/server-config.js +2 -59
  62. package/dist/server/server.js +20 -8
  63. package/dist/server/service-runs.js +41 -8
  64. package/package.json +1 -1
  65. package/dist/dashboard/assets/graph-canvas-BFnEN5i0.js +0 -8
  66. package/dist/dashboard/assets/index-Dt3ITvRO.css +0 -2
  67. package/dist/executer/docker-healthcheck.js +0 -73
  68. package/dist/network/healthcheck-request.js +0 -38
  69. package/dist/server/borrowed-quota.js +0 -216
@@ -24,9 +24,9 @@ function getServiceCommand(service, options = {}) {
24
24
  return { entrypoint: null, cmd: [service.cmd.parsed.command, ...args] };
25
25
  }
26
26
  exports.getServiceCommand = getServiceCommand;
27
- // The `cmd` of the healthcheck as an exec command, through the service's `shell` if it has one.
27
+ // The healthcheck as an exec command, through the service's `shell` if it has one.
28
28
  function getHealthcheckCommand(service) {
29
- if (!service.healthcheck || !('cmd' in service.healthcheck)) {
29
+ if (!service.healthcheck) {
30
30
  return null;
31
31
  }
32
32
  const cmd = service.healthcheck.cmd;
package/dist/program.js CHANGED
@@ -31,7 +31,6 @@ const run_worker_command_1 = require("./server/run-worker-command");
31
31
  const github_app_token_command_1 = require("./secrets/github-app-token-command");
32
32
  const work_network_1 = require("./planner/work-network");
33
33
  const task_arguments_1 = require("./planner/utils/task-arguments");
34
- const work_secret_1 = require("./planner/work-secret");
35
34
  async function createCli(fileName, environment, workScope) {
36
35
  const { ctx, scope } = await (0, schema_parser_1.createParseContext)(fileName, environment);
37
36
  const referencedScope = await (0, reference_parser_1.parseReferences)(ctx, scope, environment);
@@ -84,22 +83,9 @@ function printTaskDefinition(environment, definition) {
84
83
  (0, log_1.printProperty)(environment, `env ${reference.name}`, `from $${reference.from} ${colors_1.default.grey(reference.available ? '(set)' : '(not set)')}`);
85
84
  }
86
85
  }
87
- // A task or service that reads a secret this machine can't read is listed, saying so: only
88
- // running it fails
89
- function printUnreadableSecrets(environment, item) {
90
- for (const reason of (0, work_secret_1.getUnreadableSecrets)('secrets' in item ? item.secrets : [])) {
91
- (0, log_1.printProperty)(environment, "can't run here", reason);
92
- }
93
- }
94
- // only when there are, so the list of a build file without them stays as it was
95
- function unreadableJson(item) {
96
- const unreadable = (0, work_secret_1.getUnreadableSecrets)('secrets' in item ? item.secrets : []);
97
- return unreadable.length > 0 ? { unreadableSecrets: unreadable } : {};
98
- }
99
86
  // `ls --json`: what a caller (an agent picking a task) needs to know, with the
100
87
  // command that arguments after `--` are appended to (null: it takes none) and
101
- // `args` as the build file says it (false: it refuses them), and the secrets this
102
- // machine can't read, which make running it fail (`unreadableSecrets`, when there are).
88
+ // `args` as the build file says it (false: it refuses them).
103
89
  function getListJson(tasks, services) {
104
90
  return {
105
91
  tasks: tasks.map(({ item }) => ({
@@ -112,7 +98,6 @@ function getListJson(tasks, services) {
112
98
  labels: item.data.labels,
113
99
  command: (0, task_arguments_1.getArgumentsTarget)(item.data)?.cmd ?? null,
114
100
  args: item.data.args,
115
- ...unreadableJson(item.data),
116
101
  })),
117
102
  services: services.map(({ item }) => ({
118
103
  name: item.name,
@@ -123,7 +108,6 @@ function getListJson(tasks, services) {
123
108
  labels: item.data.labels,
124
109
  command: (0, task_arguments_1.getArgumentsTarget)(item.data)?.cmd ?? null,
125
110
  args: item.data.type === 'container-service' ? item.data.args : null,
126
- ...unreadableJson(item.data),
127
111
  })),
128
112
  };
129
113
  }
@@ -220,7 +204,6 @@ async function getProgram(environment, argv) {
220
204
  (0, log_1.printTitle)(environment, 'Services');
221
205
  for (const service of services) {
222
206
  (0, log_1.printItem)(environment, service.item.data);
223
- printUnreadableSecrets(environment, service.item.data);
224
207
  (0, log_1.printProperty)(environment, 'ports', service.item.data.ports.map((p) => `127.0.0.1:${p.hostPort} -> ${p.containerPort}`).join(', '));
225
208
  if (service.item.data.type === 'kubernetes-service') {
226
209
  (0, log_1.printProperty)(environment, 'context', service.item.data.context);
@@ -238,7 +221,6 @@ async function getProgram(environment, argv) {
238
221
  (0, log_1.printTitle)(environment, 'Tasks');
239
222
  for (const task of tasks) {
240
223
  (0, log_1.printItem)(environment, task.item.data);
241
- printUnreadableSecrets(environment, task.item.data);
242
224
  if (task.item.needs.length > 0) {
243
225
  (0, log_1.printProperty)(environment, 'needs', task.item.needs.map((d) => d.name).join(', '));
244
226
  }
@@ -36,26 +36,50 @@ function remoteRepo(url) {
36
36
  }
37
37
  }
38
38
  exports.remoteRepo = remoteRepo;
39
+ // what the server takes for a commit, not for the name of a branch or tag
40
+ const COMMIT_NAME = /^[0-9a-f]{40}([0-9a-f]{24})?$/i;
41
+ const ORIGIN_BRANCHES = 'refs/remotes/origin/';
42
+ const TAGS = 'refs/tags/';
39
43
  // The checkout a directory is in: the repository of its `origin`, the branch it is on and
40
- // its commit, what can be found of them.
44
+ // its commit, what can be found of them. A detached HEAD is on no branch: `heads` are then the
45
+ // branches of origin (as the last fetch or push left them) and the tags whose head is its
46
+ // commit, branches first, as git sorts them.
41
47
  async function readCheckout(cwd) {
42
48
  if ((await git(cwd, 'rev-parse', '--is-inside-work-tree')) !== 'true') {
43
49
  return {};
44
50
  }
45
51
  const remote = await git(cwd, 'remote', 'get-url', 'origin');
46
- // a detached HEAD is on no branch
52
+ const repo = remote ? remoteRepo(remote) : undefined;
47
53
  const branch = await git(cwd, 'symbolic-ref', '--quiet', '--short', 'HEAD');
48
- return { repo: remote ? remoteRepo(remote) : undefined, branch, commit: await git(cwd, 'rev-parse', 'HEAD') };
54
+ const commit = await git(cwd, 'rev-parse', 'HEAD');
55
+ if (branch || !commit) {
56
+ return { repo, branch, commit };
57
+ }
58
+ const refs = await git(cwd, 'for-each-ref', `--points-at=${commit}`, '--format=%(refname)%09%(symref)', ORIGIN_BRANCHES, TAGS);
59
+ const heads = [];
60
+ for (const line of refs?.split('\n') ?? []) {
61
+ const [ref, symref] = line.split('\t');
62
+ // origin/HEAD names the default branch of origin, it is no branch of its own
63
+ if (symref || ref === `${ORIGIN_BRANCHES}HEAD`) {
64
+ continue;
65
+ }
66
+ const head = ref.startsWith(ORIGIN_BRANCHES)
67
+ ? { name: ref.slice(ORIGIN_BRANCHES.length), kind: 'branch' }
68
+ : { name: ref.slice(TAGS.length), kind: 'tag' };
69
+ // a name that looks like a commit would be run as that commit
70
+ if (head.name && !COMMIT_NAME.test(head.name)) {
71
+ heads.push(head);
72
+ }
73
+ }
74
+ return { repo, commit, heads };
49
75
  }
50
76
  exports.readCheckout = readCheckout;
51
77
  // Where a build file is published from: its path in its repository (or on this
52
- // machine, outside of one), the repository, branch and commit, this machine and its user.
53
- // The branch is the one checked out; on a detached HEAD, a pull request's job of GitHub
54
- // Actions names it in `GITHUB_HEAD_REF`.
78
+ // machine, outside of one), the repository and commit, this machine and its user.
55
79
  // `files` are the paths of the bundle, relative to the build file's directory: when
56
80
  // one of them differs from the commit, `dirty=true` says the version is not that
57
81
  // commit's. What can not be found is left out.
58
- async function collectAnnotations(fileName, files = [(0, path_1.basename)(fileName)], env = process.env) {
82
+ async function collectAnnotations(fileName, files = [(0, path_1.basename)(fileName)]) {
59
83
  const path = (0, path_1.resolve)(fileName);
60
84
  const cwd = (0, path_1.dirname)(path);
61
85
  const annotations = {};
@@ -71,10 +95,6 @@ async function collectAnnotations(fileName, files = [(0, path_1.basename)(fileNa
71
95
  if (repo) {
72
96
  annotations.repo = repo;
73
97
  }
74
- const branch = (await git(cwd, 'symbolic-ref', '--quiet', '--short', 'HEAD')) ?? env.GITHUB_HEAD_REF;
75
- if (branch) {
76
- annotations.branch = branch.slice(0, 500);
77
- }
78
98
  if (commit) {
79
99
  annotations.commit = commit;
80
100
  const changed = await git(cwd, '--literal-pathspecs', 'status', '--porcelain', '--untracked-files=all', '--', ...files);
@@ -15,9 +15,10 @@ const bundle_1 = require("./bundle");
15
15
  // where a file really is too: a link to a file outside of the directory is refused
16
16
  // rather than followed, so publishing a checkout never sends a file of this machine
17
17
  // that the checkout only points to.
18
- async function collectBundle(fileName, environment) {
18
+ // `missing` is what to do when there is no build file, said after that.
19
+ async function collectBundle(fileName, environment, options = {}) {
19
20
  if (!(await environment.file.exists(fileName))) {
20
- throw new Error(`there is no build file at ${fileName}`);
21
+ throw new Error(`there is no build file at ${fileName}${options.missing ? `. ${options.missing}` : ''}`);
21
22
  }
22
23
  const entryPath = (0, path_1.resolve)(fileName);
23
24
  const root = (0, path_1.dirname)(entryPath);
@@ -95,7 +95,7 @@ function describeCapacity(capacity, short = false) {
95
95
  return lines;
96
96
  }
97
97
  for (const group of capacity.groups) {
98
- lines.push(` ${(0, server_client_1.printable)(group.name)} ${group.kind === 'service-run' ? 'service run' : 'caller'}${group.owner ? ` of ${(0, server_client_1.printable)(group.owner.sub)}` : ''}${group.run ? ` ${(0, server_client_1.printable)(group.run)}` : ''} ${(0, capacity_format_1.plural)(group.pods ?? 0, 'pod')} requested ${resources(group.requested)}${group.quota ? ` of ${resources(group.quota)}` : ''}${group.share ? ` (borrowed, share ${resources(group.share)})` : ''}${group.used ? ` in use ${resources(group.used)}` : ''}`);
98
+ lines.push(` ${(0, server_client_1.printable)(group.name)} ${group.kind === 'service-run' ? 'service run' : 'caller'}${group.owner ? ` of ${(0, server_client_1.printable)(group.owner.sub)}` : ''}${group.run ? ` ${(0, server_client_1.printable)(group.run)}` : ''} ${(0, capacity_format_1.plural)(group.pods ?? 0, 'pod')} requested ${resources(group.requested)}${group.quota ? ` of ${resources(group.quota)}` : ''}${group.used ? ` in use ${resources(group.used)}` : ''}`);
99
99
  }
100
100
  for (const problem of capacity.problems) {
101
101
  lines.push(colors_1.default.yellow(` not shown: ${(0, server_client_1.printable)(problem)}`));
@@ -10,6 +10,7 @@ const token_source_1 = require("./token-source");
10
10
  const collect_bundle_1 = require("./collect-bundle");
11
11
  const bundle_1 = require("./bundle");
12
12
  const annotations_1 = require("./annotations");
13
+ const repo_1 = require("../server/repo");
13
14
  const server_client_1 = require("./server-client");
14
15
  const bundle_text_1 = require("./bundle-text");
15
16
  const sandbox_client_1 = require("../harness/sandbox-client");
@@ -169,21 +170,53 @@ function describePlan(plan) {
169
170
  ]);
170
171
  }
171
172
  exports.describePlan = describePlan;
173
+ // The ref of a detached checkout: the one branch or tag of origin at its commit. The server
174
+ // would also fetch the commit itself, but an account limited to some branches (`refs`) never
175
+ // runs for a commit, and the run would not say where its code comes from. A branch and a tag
176
+ // of the same name are two heads, which the server can not tell apart by the name.
177
+ function onlyHead(heads) {
178
+ return heads?.length === 1 ? heads[0].name : undefined;
179
+ }
180
+ // why the ref of a run is not known, and what to do
181
+ function describeMissingRef(repo, ours, checkout) {
182
+ if (!checkout.commit) {
183
+ return `name the branch or tag of ${(0, server_client_1.printable)(repo)} with --ref, there is no commit checked out here`;
184
+ }
185
+ if (!ours) {
186
+ return `name the branch or tag of ${(0, server_client_1.printable)(repo)} with --ref, the checkout here is on no branch and ${checkout.repo ? `of ${(0, server_client_1.printable)(checkout.repo)}` : 'has no origin it can be told by'}`;
187
+ }
188
+ const heads = checkout.heads ?? [];
189
+ if (heads.length === 0) {
190
+ return (`the checkout here is on no branch, and no branch or tag of origin is at its commit ${checkout.commit}: ` +
191
+ 'name the branch or tag with --ref');
192
+ }
193
+ const names = heads.map((head) => `${head.kind} ${(0, server_client_1.printable)(head.name)}`);
194
+ const twice = heads.find((head, i) => heads.findIndex((other) => other.name === head.name) !== i);
195
+ return (`the checkout here is on no branch, and its commit ${checkout.commit} is the head of ` +
196
+ `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]} of origin: ` +
197
+ (twice
198
+ ? `${(0, server_client_1.printable)(twice.name)} is a branch and a tag, which --ref can not tell apart: ` +
199
+ `name another, or the commit with --ref ${checkout.commit}`
200
+ : 'name one with --ref'));
201
+ }
172
202
  function registerWorkCommands(remote, context) {
173
203
  const { environment, buildFile, getServer, guarded, passthrough, fail } = context;
174
204
  // the ref a run starts from: what the options name, else the checkout here
175
205
  const refSource = async (options) => {
176
206
  const checkout = options.repo && options.ref ? {} : await (0, annotations_1.readCheckout)((0, path_1.dirname)(buildFile));
177
207
  const repo = options.repo ?? checkout.repo;
178
- const ref = options.ref ?? checkout.branch;
179
- // the commit checked out here is the code meant, when the ref is the branch it is on
180
- const commit = options.commit ?? (options.ref ? undefined : checkout.commit);
181
208
  if (!repo) {
182
209
  throw new Error('name the repository with --repo, the checkout here has no origin it can be told by');
183
210
  }
211
+ // the heads of origin name refs of the repository of the run only when origin is that one
212
+ const ours = !!checkout.repo && (0, repo_1.normalizeRepo)(repo) === checkout.repo;
213
+ const ref = options.ref ?? checkout.branch ?? (ours ? onlyHead(checkout.heads) : undefined);
184
214
  if (!ref) {
185
- throw new Error('name the branch or tag with --ref, the checkout here is on no branch');
215
+ throw new Error(describeMissingRef(repo, ours, checkout));
186
216
  }
217
+ // the commit checked out here is the code meant, when the ref is the branch it is on, or
218
+ // the one branch or tag of a detached checkout: when it moved since, the server refuses the run
219
+ const commit = options.commit ?? (options.ref ? undefined : checkout.commit);
187
220
  return { type: 'ref', repo, ref, ...(commit ? { commit } : {}) };
188
221
  };
189
222
  const connect = async (name, how) => {
@@ -246,7 +279,11 @@ function registerWorkCommands(remote, context) {
246
279
  }
247
280
  return { definition: named };
248
281
  }
249
- const local = await (0, collect_bundle_1.collectBundle)(buildFile, environment);
282
+ const local = await (0, collect_bundle_1.collectBundle)(buildFile, environment, {
283
+ // most often run in another folder than the checkout meant
284
+ missing: 'Run this in the checkout whose build file the server has, ' +
285
+ 'or name a published version with --build <hash>, listed by: hammerkit remote versions',
286
+ });
250
287
  return { definition: (0, bundle_1.hashBundle)(local), local };
251
288
  };
252
289
  // Submits a run of a published version. When the server does not have the build file
@@ -343,7 +380,8 @@ function registerWorkCommands(remote, context) {
343
380
  .addOption(new commander_1.Option('--server <name>', 'the server to run on; when left out, the default of remote use or the only registered server'))
344
381
  .addOption(new commander_1.Option('--build <hash>', 'the published version to run (sha256:...), or HAMMERKIT_BUILD; the hash of the build file here when left out'))
345
382
  .addOption(new commander_1.Option('--repo <host/path>', 'the repository, such as github.com/corp/payments; origin of the checkout here when left out'))
346
- .addOption(new commander_1.Option('--ref <ref>', 'the branch or tag to run; the branch checked out here when left out'))
383
+ .addOption(new commander_1.Option('--ref <ref>', 'the branch or tag to run; the branch checked out here when left out, ' +
384
+ 'or the one branch or tag of origin at the commit of a detached checkout'))
347
385
  .addOption(new commander_1.Option('--commit <sha>', 'the commit the ref has to be at, else the run is refused; the commit checked out here when --ref is left out'))
348
386
  .addOption(new commander_1.Option('--env <name>', 'the environment of the build file, as --env of run'))
349
387
  .addOption(new commander_1.Option('--cache <method>', 'as --cache of run').choices(['checksum', 'modify-date', 'none']))
@@ -409,6 +447,8 @@ function registerWorkCommands(remote, context) {
409
447
  'with their endpoints at addresses of their own behind the sign-in of the server')
410
448
  .addOption(new commander_1.Option('--server <name>', 'the server to run on; when left out, the default of remote use or the only registered server'))
411
449
  .addOption(new commander_1.Option('--endpoint <service:port>', 'publish this port of a service, such as web:8080; may be given more than once').argParser(collectOption))
450
+ .addOption(new commander_1.Option('--public-path <run:service:port=paths>', 'paths of an endpoint that need no sign-in of the server, for an app that signs in on its own, such as ' +
451
+ 'preview:web:8080=/mcp,/.well-known; the run is the --name of this run; may be given more than once').argParser(collectOption))
412
452
  .addOption(new commander_1.Option('--ttl <duration>', 'how long they stay once ready, such as 2h, then they are removed; the server default when left out'))
413
453
  .addOption(new commander_1.Option('--sleep-ttl <duration>', 'how long they stay up without a request, such as 30m, then they sleep until the next request wakes them; ' +
414
454
  'the server default when left out'))
@@ -416,13 +456,15 @@ function registerWorkCommands(remote, context) {
416
456
  'starts other services or another build file; the addresses stay; the branch when left out'))
417
457
  .addOption(new commander_1.Option('--build <hash>', 'the published version to run (sha256:...), or HAMMERKIT_BUILD; the hash of the build file here when left out'))
418
458
  .addOption(new commander_1.Option('--repo <host/path>', 'the repository; origin of the checkout here when left out'))
419
- .addOption(new commander_1.Option('--ref <ref>', 'the branch or tag to start; the branch checked out here when left out'))
459
+ .addOption(new commander_1.Option('--ref <ref>', 'the branch or tag to start; the branch checked out here when left out, ' +
460
+ 'or the one branch or tag of origin at the commit of a detached checkout'))
420
461
  .addOption(new commander_1.Option('--commit <sha>', 'the commit the ref has to be at; the commit checked out here when --ref is left out'))
421
462
  .addOption(new commander_1.Option('--env <name>', 'the environment of the build file, as --env of run'))
422
463
  .addOption(new commander_1.Option('--publish', 'publish the build file here first when the server does not have it, without asking; for CI and scripts'))
423
464
  .action(guarded('Remote up was not successful', async (services, options) => {
424
465
  const { definition, local } = await runDefinition(options);
425
466
  const endpoints = (options.endpoint ?? []).map(service_tools_1.parseEndpoint);
467
+ const publicPaths = (options.publicPath ?? []).map(service_tools_1.parsePublicPath);
426
468
  const source = await refSource(options);
427
469
  const { name: serverName, server } = await getServer(options.server, 'with --server <name>');
428
470
  const connection = { url: server.url, ...(0, token_source_1.getTokenSource)(environment, serverName, server) };
@@ -430,6 +472,7 @@ function registerWorkCommands(remote, context) {
430
472
  definition,
431
473
  services,
432
474
  endpoints,
475
+ ...(publicPaths.length > 0 ? { publicPaths } : {}),
433
476
  ...(options.ttl ? { ttl: options.ttl } : {}),
434
477
  ...(options.sleepTtl ? { sleepTtl: options.sleepTtl } : {}),
435
478
  ...(options.name ? { name: options.name } : {}),
@@ -469,12 +512,10 @@ function registerWorkCommands(remote, context) {
469
512
  fail(`${(0, server_client_1.printable)(run.id)} did not move to ${(0, server_client_1.printable)(lastMove.commit)}: ${(0, server_client_1.printable)(lastMove.error)}; it stays at ${(0, server_client_1.printable)(run.source.type === 'ref' ? run.source.commit : '-')}`, 1);
470
513
  }
471
514
  if (run.state === 'asleep') {
472
- // its addresses stay while it sleeps, and a request to one of them wakes it
473
- environment.stdout.write(`${(0, server_client_1.printable)(run.id)} sleeps, at ${(0, server_client_1.printable)(run.source.type === 'ref' ? run.source.commit : '-')} when it wakes, until ${(0, server_client_1.printable)(run.expiresAt ?? '-')}${run.up?.endpoints.length ? ', a request to an endpoint wakes it' : ''}\n`);
474
- }
475
- else {
476
- environment.stdout.write(`${(0, server_client_1.printable)(run.id)} is up until ${(0, server_client_1.printable)(run.expiresAt ?? '-')}${run.up?.sleepTtl ? `, asleep after ${(0, units_1.formatDuration)(run.up.sleepTtl)} without a request` : ''}\n`);
515
+ environment.stdout.write(`${(0, server_client_1.printable)(run.id)} sleeps, at ${(0, server_client_1.printable)(run.source.type === 'ref' ? run.source.commit : '-')} when it wakes, until ${(0, server_client_1.printable)(run.expiresAt ?? '-')}\n`);
516
+ return;
477
517
  }
518
+ environment.stdout.write(`${(0, server_client_1.printable)(run.id)} is up until ${(0, server_client_1.printable)(run.expiresAt ?? '-')}${run.up?.sleepTtl ? `, asleep after ${(0, units_1.formatDuration)(run.up.sleepTtl)} without a request` : ''}\n`);
478
519
  for (const endpoint of run.up?.endpoints ?? []) {
479
520
  environment.stdout.write(` ${(0, server_client_1.printable)(endpoint.service)}:${endpoint.port} ${(0, server_client_1.printable)(endpoint.url)}\n`);
480
521
  }
@@ -14,27 +14,12 @@ const resources_schema_1 = require("./resources-schema");
14
14
  const runner_schema_1 = require("./runner-schema");
15
15
  const network_schema_1 = require("./network-schema");
16
16
  // what `extend` adds to (the rest, e.g. `image` or `shell`, the task just overrides)
17
- exports.RESET_PROPERTIES = [
18
- 'deps',
19
- 'needs',
20
- 'src',
21
- 'generates',
22
- 'cmds',
23
- 'mounts',
24
- 'envs',
25
- 'labels',
26
- 'build',
27
- 'secrets',
28
- 'capAdd',
29
- ];
17
+ exports.RESET_PROPERTIES = ['deps', 'needs', 'src', 'generates', 'cmds', 'mounts', 'envs', 'labels'];
30
18
  exports.buildFileBaseTaskSchema = (0, zod_1.object)({
31
19
  deps: (0, zod_1.array)((0, zod_1.string)()).optional(),
32
20
  needs: (0, zod_1.array)(build_file_need_schema_1.buildFileNeedSchema).optional(),
33
21
  description: (0, zod_1.string)().optional(),
34
22
  extend: (0, zod_1.string)().optional(),
35
- // true: a base other tasks extend, which doesn't run itself: not listed, no dependency, not
36
- // published by a server. Unlike a task, it passes on its secrets, resources and claim too.
37
- abstract: (0, zod_1.boolean)().optional(),
38
23
  // properties of the `extend` base this task does not inherit
39
24
  reset: (0, zod_1.array)((0, zod_1.enum)(exports.RESET_PROPERTIES)).optional(),
40
25
  envs: envs_schema_1.envsSchema.optional(),
@@ -57,14 +57,17 @@ exports.buildFileImageBuildSchema = (0, zod_1.object)({
57
57
  .describe('the platforms to build for, such as linux/amd64 and linux/arm64, as docker build --platform'),
58
58
  })
59
59
  .strict()
60
- // that push and digest need tags is checked once `extend` has merged in the base's
61
- // (parseWorkImageBuild): a base may set push for tasks that set their tags
60
+ .refine((build) => !build.push || build.tags !== undefined, {
61
+ message: 'push needs tags, the names of the image to push',
62
+ })
63
+ .refine((build) => build.digest === undefined || build.tags !== undefined, {
64
+ message: 'digest needs tags, the name the digest is written with',
65
+ })
62
66
  .describe('builds a Dockerfile with BuildKit, as docker build does');
63
67
  // A task that builds an image: hammerkit runs BuildKit for it, so it names no image, commands or
64
- // shell of its own and takes no arguments. It may extend another task, which merges `build` key
65
- // by key (applySchemaExtension).
68
+ // shell of its own, and doesn't extend another task or take arguments.
66
69
  exports.buildFileImageBuildTaskSchema = build_file_base_task_schema_1.buildFileBaseTaskSchema
67
- .omit({ cmds: true, shell: true, args: true })
70
+ .omit({ extend: true, reset: true, cmds: true, shell: true, args: true })
68
71
  .extend({
69
72
  build: exports.buildFileImageBuildSchema,
70
73
  volumeSize: size_schema_1.sizeSchema.describe('size of its claim on Kubernetes, e.g. 10Gi').optional(),
@@ -1,30 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildFileServiceContainerHealthcheck = exports.buildFileServiceTcpHealthcheck = exports.buildFileServiceHttpHealthcheck = void 0;
3
+ exports.buildFileServiceContainerHealthcheck = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const duration_schema_1 = require("./duration-schema");
6
- // How long the service may take to pass its check once its container runs
7
- // (default 20s, HAMMERKIT_HEALTHCHECK_TIMEOUT changes the default).
8
- const timeout = duration_schema_1.durationSchema.optional();
9
- const port = (0, zod_1.number)().int().min(1).max(65535);
10
- // A request to a port of the service, from its own network: no tool of the image runs it.
11
- exports.buildFileServiceHttpHealthcheck = (0, zod_1.object)({
12
- port,
13
- path: (0, zod_1.string)().startsWith('/', 'path must start with /').optional(),
14
- scheme: (0, zod_1.enum)(['http', 'https']).optional(),
15
- // the status codes that count as healthy, any 2xx or 3xx without
16
- status: (0, zod_1.array)((0, zod_1.number)().int().min(100).max(599)).min(1).optional(),
17
- })
18
- .strict()
19
- .describe('GET <scheme>://<service>:<port><path>, healthy on one of status (default any 2xx or 3xx)');
20
- // a connection to a port of the service
21
- exports.buildFileServiceTcpHealthcheck = (0, zod_1.object)({ port })
22
- .strict()
23
- .describe('healthy once <port> takes a connection');
24
- // Exactly one of `cmd`, `http` or `tcp`.
25
- exports.buildFileServiceContainerHealthcheck = (0, zod_1.union)([
26
- (0, zod_1.object)({ cmd: (0, zod_1.string)(), timeout }).strict(),
27
- (0, zod_1.object)({ http: exports.buildFileServiceHttpHealthcheck, timeout }).strict(),
28
- (0, zod_1.object)({ tcp: exports.buildFileServiceTcpHealthcheck, timeout }).strict(),
29
- ]).describe('exactly one of cmd, http or tcp, and how long it may take to pass');
6
+ exports.buildFileServiceContainerHealthcheck = (0, zod_1.object)({
7
+ cmd: (0, zod_1.string)(),
8
+ // How long the service may take to pass `cmd` once its container runs
9
+ // (default 20s, HAMMERKIT_HEALTHCHECK_TIMEOUT changes the default).
10
+ timeout: duration_schema_1.durationSchema.optional(),
11
+ });
30
12
  //# sourceMappingURL=build-file-service-container-healthcheck.js.map