hammerkit 2.1.0-next.2 → 2.1.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/build.schema.json +39 -18
- package/dist/cli.js +5 -0
- package/dist/dashboard/assets/graph-canvas-D6GMgkoe.js +8 -0
- package/dist/dashboard/assets/index-BNq9j5Jo.js +23 -0
- package/dist/dashboard/assets/index-DP3_hKOe.css +2 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/environment/replace-env-variables.js +8 -5
- package/dist/environment/run-source-envs.js +2 -1
- package/dist/executer/archive-task-entry.js +1 -1
- package/dist/executer/deadline.js +63 -10
- package/dist/executer/event-cache.js +5 -1
- package/dist/executer/execute-work-task.js +15 -3
- package/dist/executer/runner-commands.js +36 -0
- package/dist/file/get-file-context.js +4 -7
- package/dist/harness/connect.js +12 -8
- package/dist/harness/reconnect.js +141 -0
- package/dist/harness/sandbox-client.js +241 -33
- package/dist/harness/service-tools.js +11 -2
- package/dist/kubernetes/cluster-state.js +48 -14
- package/dist/kubernetes/ensure-persistent-data.js +15 -4
- package/dist/kubernetes/follow-pod-logs.js +8 -5
- package/dist/kubernetes/kept-claims.js +26 -5
- package/dist/kubernetes/resources.js +5 -1
- package/dist/kubernetes/sandbox-runner.js +526 -156
- package/dist/kubernetes/store-kubernetes-data.js +18 -3
- package/dist/kubernetes/sync-changes.js +463 -0
- package/dist/kubernetes/volumes.js +23 -1
- package/dist/optimizer/get-work-cache-stats.js +7 -0
- package/dist/optimizer/work-task-cache-description.js +3 -2
- package/dist/planner/image-build.js +5 -0
- package/dist/planner/utils/dependency-outputs.js +7 -6
- package/dist/planner/validate.js +41 -0
- package/dist/planner/work-item-status.js +12 -2
- package/dist/planner/work-runtime-aggregate.js +1 -0
- package/dist/planner/work-runtime-docker.js +33 -6
- package/dist/planner/work-runtime-kubernetes.js +313 -70
- package/dist/planner/work-runtime-local.js +8 -4
- package/dist/planner/work-secret.js +33 -11
- package/dist/planner/work-service-id.js +30 -6
- package/dist/program.js +19 -1
- package/dist/remote/annotations.js +37 -5
- package/dist/remote/bundle.js +6 -8
- package/dist/remote/collect-bundle.js +3 -2
- package/dist/remote/device-login.js +4 -1
- package/dist/remote/remote-commands.js +16 -7
- package/dist/remote/remote-work-commands.js +266 -75
- package/dist/remote/server-client.js +38 -40
- package/dist/schema/build-file-base-task-schema.js +16 -1
- package/dist/schema/build-file-image-build-schema.js +5 -8
- package/dist/schema/reference-parser.js +108 -43
- package/dist/schema/work-scope-parser.js +8 -0
- package/dist/secrets/prefetch-secrets.js +20 -1
- package/dist/server/artifacts-api.js +56 -0
- package/dist/server/definitions-api.js +62 -8
- package/dist/server/executor.js +117 -30
- package/dist/server/http.js +4 -1
- package/dist/server/keep-artifacts.js +230 -0
- package/dist/server/kubernetes-backend.js +186 -59
- package/dist/server/kubernetes-sandbox-storage.js +3 -2
- package/dist/server/overview.js +73 -9
- package/dist/server/paging.js +167 -0
- package/dist/server/plan.js +16 -1
- package/dist/server/run-access.js +24 -0
- package/dist/server/run-artifacts.js +171 -0
- package/dist/server/run-logs.js +25 -1
- package/dist/server/run-request.js +11 -0
- package/dist/server/run-source-environment.js +1 -1
- package/dist/server/run-worker.js +267 -33
- package/dist/server/runs.js +527 -99
- package/dist/server/sandbox-files-api.js +27 -12
- package/dist/server/sandbox-files.js +12 -10
- package/dist/server/sandbox-follow.js +54 -0
- package/dist/server/sandbox-pod.js +1 -1
- package/dist/server/sandbox-storage.js +38 -1
- package/dist/server/sandbox-sync.js +392 -0
- package/dist/server/sandboxes-api.js +116 -19
- package/dist/server/sandboxes.js +38 -3
- package/dist/server/server-config.js +14 -0
- package/dist/server/server.js +169 -38
- package/dist/server/task-order.js +56 -0
- package/dist/utils/project-path.js +20 -0
- package/dist/utils/tar-files.js +52 -0
- package/dist/utils/tar.js +37 -1
- package/package.json +1 -1
- package/dist/dashboard/assets/graph-canvas-DtJSpova.js +0 -8
- package/dist/dashboard/assets/index-BndChMep.css +0 -2
- package/dist/dashboard/assets/index-DRSwIRXd.js +0 -17
|
@@ -3,23 +3,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.registerWorkCommands = exports.describePlan = exports.describeApproval = exports.keepRuns = exports.describeListedRun = exports.describeRunEnd = void 0;
|
|
6
|
+
exports.registerWorkCommands = exports.describeArtifacts = exports.selectArtifacts = exports.keptProjectOutputs = exports.isProjectPath = exports.describePlan = exports.describeApproval = exports.keepRuns = exports.describeListedRun = exports.describeRunEnd = void 0;
|
|
7
7
|
const commander_1 = require("commander");
|
|
8
8
|
const colors_1 = __importDefault(require("colors"));
|
|
9
|
-
const token_source_1 = require("./token-source");
|
|
10
9
|
const collect_bundle_1 = require("./collect-bundle");
|
|
11
10
|
const bundle_1 = require("./bundle");
|
|
12
11
|
const annotations_1 = require("./annotations");
|
|
12
|
+
const repo_1 = require("../server/repo");
|
|
13
13
|
const server_client_1 = require("./server-client");
|
|
14
14
|
const bundle_text_1 = require("./bundle-text");
|
|
15
15
|
const sandbox_client_1 = require("../harness/sandbox-client");
|
|
16
16
|
const units_1 = require("../utils/units");
|
|
17
17
|
const service_tools_1 = require("../harness/service-tools");
|
|
18
|
+
const reconnect_1 = require("../harness/reconnect");
|
|
18
19
|
const path_1 = require("path");
|
|
20
|
+
const promises_1 = require("fs/promises");
|
|
21
|
+
const os_1 = require("os");
|
|
22
|
+
const tar_1 = require("../utils/tar");
|
|
19
23
|
const check_keys_1 = require("../optimizer/check-keys");
|
|
20
24
|
const remote_status_1 = require("./remote-status");
|
|
21
25
|
const timings_1 = require("../server/timings");
|
|
22
26
|
const terminal_prompt_1 = require("../utils/terminal-prompt");
|
|
27
|
+
const project_path_1 = require("../utils/project-path");
|
|
23
28
|
function describeOutcome(planned) {
|
|
24
29
|
switch (planned.outcome) {
|
|
25
30
|
case 'published':
|
|
@@ -169,35 +174,151 @@ function describePlan(plan) {
|
|
|
169
174
|
]);
|
|
170
175
|
}
|
|
171
176
|
exports.describePlan = describePlan;
|
|
177
|
+
// A path in the project, as the server names an output: relative, `/` separated, no `.` or
|
|
178
|
+
// `..` in it. A file is written at it.
|
|
179
|
+
function isProjectPath(path) {
|
|
180
|
+
return (0, project_path_1.isRelativePath)(path, 4096);
|
|
181
|
+
}
|
|
182
|
+
exports.isProjectPath = isProjectPath;
|
|
183
|
+
// `--path` as written: `./app/screenshots/` is `app/screenshots`
|
|
184
|
+
function projectPath(value) {
|
|
185
|
+
const path = path_1.posix
|
|
186
|
+
.normalize(value.replace(/\\/g, '/'))
|
|
187
|
+
.replace(/^(\.\/)+/, '')
|
|
188
|
+
.replace(/\/+$/, '');
|
|
189
|
+
if (!isProjectPath(path)) {
|
|
190
|
+
throw new Error('--path is a path in the project, such as app/cypress/screenshots');
|
|
191
|
+
}
|
|
192
|
+
return path;
|
|
193
|
+
}
|
|
194
|
+
// The outputs a server names that are paths in the project: one that is not is written nowhere,
|
|
195
|
+
// whatever the server says of it.
|
|
196
|
+
function keptProjectOutputs(outputs) {
|
|
197
|
+
return outputs.filter((output) => isProjectPath(output.path));
|
|
198
|
+
}
|
|
199
|
+
exports.keptProjectOutputs = keptProjectOutputs;
|
|
200
|
+
/**
|
|
201
|
+
* The outputs `remote artifacts` takes, each with what of it: of one task, and the output at a
|
|
202
|
+
* path, the outputs below it, or the files below it of the output it is in.
|
|
203
|
+
*/
|
|
204
|
+
function selectArtifacts(outputs, options) {
|
|
205
|
+
return outputs
|
|
206
|
+
.filter((output) => options.task === undefined || output.task === options.task)
|
|
207
|
+
.flatMap((output) => {
|
|
208
|
+
const path = options.path;
|
|
209
|
+
if (path === undefined || output.path.startsWith(`${path}/`)) {
|
|
210
|
+
return [{ output, below: output.path }];
|
|
211
|
+
}
|
|
212
|
+
return path === output.path || path.startsWith(`${output.path}/`) ? [{ output, below: path }] : [];
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
exports.selectArtifacts = selectArtifacts;
|
|
216
|
+
// Writes the chosen outputs into `out`, each at its paths in the project. Only entries of the
|
|
217
|
+
// output, or of the path asked for, are written, and no link out of them: the archives come
|
|
218
|
+
// from a server.
|
|
219
|
+
async function downloadArtifacts(connection, id, chosen, out, write) {
|
|
220
|
+
const staging = await (0, promises_1.mkdtemp)((0, path_1.join)((0, os_1.tmpdir)(), 'hammerkit-artifacts-'));
|
|
221
|
+
try {
|
|
222
|
+
await (0, promises_1.mkdir)(out, { recursive: true });
|
|
223
|
+
for (const { output, below } of chosen) {
|
|
224
|
+
const file = (0, path_1.join)(staging, `${output.id}.tgz`);
|
|
225
|
+
await (0, sandbox_client_1.downloadRunArtifact)(connection, id, output.id, file);
|
|
226
|
+
await (0, tar_1.extractOutput)(file, out, below, true);
|
|
227
|
+
write(`${(0, server_client_1.printable)(below)} of ${(0, server_client_1.printable)(output.task)} -> ${(0, path_1.join)(out, below)}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
finally {
|
|
231
|
+
await (0, promises_1.rm)(staging, { recursive: true, force: true });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function describeArtifacts(id, serverName, kept, outputs) {
|
|
235
|
+
const left = kept.left.map((output) => `did not keep ${(0, server_client_1.printable)(output.path)} of ${(0, server_client_1.printable)(output.task)}: ${(0, server_client_1.printable)(output.reason)}`);
|
|
236
|
+
if (outputs.length === 0) {
|
|
237
|
+
return [
|
|
238
|
+
`${(0, server_client_1.printable)(id)} on ${serverName} kept no outputs${kept.reason ? `: ${(0, server_client_1.printable)(kept.reason)}` : ''}`,
|
|
239
|
+
...left,
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
const tasks = Math.max(...outputs.map((output) => (0, server_client_1.printable)(output.task).length));
|
|
243
|
+
const paths = Math.max(...outputs.map((output) => (0, server_client_1.printable)(output.path).length));
|
|
244
|
+
return [
|
|
245
|
+
`${(0, server_client_1.printable)(id)} on ${serverName} kept ${outputs.length} ${outputs.length === 1 ? 'output' : 'outputs'}, until ${(0, server_client_1.printable)(kept.expiresAt ?? '-')}:`,
|
|
246
|
+
...outputs.map((output) => ` ${(0, server_client_1.printable)(output.task).padEnd(tasks)} ${(0, server_client_1.printable)(output.path).padEnd(paths)} ${(0, units_1.formatSize)(output.bytes)}`),
|
|
247
|
+
...left,
|
|
248
|
+
`download them with: hammerkit remote artifacts ${(0, server_client_1.printable)(id)} --out <dir>`,
|
|
249
|
+
];
|
|
250
|
+
}
|
|
251
|
+
exports.describeArtifacts = describeArtifacts;
|
|
252
|
+
// The ref of a detached checkout: the one branch or tag of origin at its commit. The server
|
|
253
|
+
// would also fetch the commit itself, but an account limited to some branches (`refs`) never
|
|
254
|
+
// runs for a commit, and the run would not say where its code comes from. A branch and a tag
|
|
255
|
+
// of the same name are two heads, which the server can not tell apart by the name.
|
|
256
|
+
function onlyHead(heads) {
|
|
257
|
+
return heads?.length === 1 ? heads[0].name : undefined;
|
|
258
|
+
}
|
|
259
|
+
// why the ref of a run is not known, and what to do
|
|
260
|
+
function describeMissingRef(repo, ours, checkout) {
|
|
261
|
+
if (!checkout.commit) {
|
|
262
|
+
return `name the branch or tag of ${(0, server_client_1.printable)(repo)} with --ref, there is no commit checked out here`;
|
|
263
|
+
}
|
|
264
|
+
if (!ours) {
|
|
265
|
+
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'}`;
|
|
266
|
+
}
|
|
267
|
+
const heads = checkout.heads ?? [];
|
|
268
|
+
if (heads.length === 0) {
|
|
269
|
+
return (`the checkout here is on no branch, and no branch or tag of origin is at its commit ${checkout.commit}: ` +
|
|
270
|
+
'name the branch or tag with --ref');
|
|
271
|
+
}
|
|
272
|
+
const names = heads.map((head) => `${head.kind} ${(0, server_client_1.printable)(head.name)}`);
|
|
273
|
+
const twice = heads.find((head, i) => heads.findIndex((other) => other.name === head.name) !== i);
|
|
274
|
+
return (`the checkout here is on no branch, and its commit ${checkout.commit} is the head of ` +
|
|
275
|
+
`${names.slice(0, -1).join(', ')} and ${names[names.length - 1]} of origin: ` +
|
|
276
|
+
(twice
|
|
277
|
+
? `${(0, server_client_1.printable)(twice.name)} is a branch and a tag, which --ref can not tell apart: ` +
|
|
278
|
+
`name another, or the commit with --ref ${checkout.commit}`
|
|
279
|
+
: 'name one with --ref'));
|
|
280
|
+
}
|
|
281
|
+
// A call the server refused, said as `callServer` says it: by the server and what it answered
|
|
282
|
+
function describeRefusal(url, e) {
|
|
283
|
+
if (!(e instanceof sandbox_client_1.SandboxClientError) || e.status === undefined || e.status === 401) {
|
|
284
|
+
return e;
|
|
285
|
+
}
|
|
286
|
+
const said = e.message.startsWith(`${(0, reconnect_1.showUrl)(url)} answered`) ? '' : `: ${(0, server_client_1.printable)(e.message)}`;
|
|
287
|
+
return new server_client_1.ServerError(`${(0, reconnect_1.showUrl)(url)} answered ${e.status}${said}`, e.status);
|
|
288
|
+
}
|
|
172
289
|
function registerWorkCommands(remote, context) {
|
|
173
290
|
const { environment, buildFile, getServer, guarded, passthrough, fail } = context;
|
|
174
291
|
// the ref a run starts from: what the options name, else the checkout here
|
|
175
292
|
const refSource = async (options) => {
|
|
176
293
|
const checkout = options.repo && options.ref ? {} : await (0, annotations_1.readCheckout)((0, path_1.dirname)(buildFile));
|
|
177
294
|
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
295
|
if (!repo) {
|
|
182
296
|
throw new Error('name the repository with --repo, the checkout here has no origin it can be told by');
|
|
183
297
|
}
|
|
298
|
+
// the heads of origin name refs of the repository of the run only when origin is that one
|
|
299
|
+
const ours = !!checkout.repo && (0, repo_1.normalizeRepo)(repo) === checkout.repo;
|
|
300
|
+
const ref = options.ref ?? checkout.branch ?? (ours ? onlyHead(checkout.heads) : undefined);
|
|
184
301
|
if (!ref) {
|
|
185
|
-
throw new Error(
|
|
302
|
+
throw new Error(describeMissingRef(repo, ours, checkout));
|
|
186
303
|
}
|
|
304
|
+
// the commit checked out here is the code meant, when the ref is the branch it is on, or
|
|
305
|
+
// the one branch or tag of a detached checkout: when it moved since, the server refuses the run
|
|
306
|
+
const commit = options.commit ?? (options.ref ? undefined : checkout.commit);
|
|
187
307
|
return { type: 'ref', repo, ref, ...(commit ? { commit } : {}) };
|
|
188
308
|
};
|
|
309
|
+
// the server to call: its token is read for each call, a CI job or an agent brings its own, a
|
|
310
|
+
// person signs in
|
|
189
311
|
const connect = async (name, how) => {
|
|
190
312
|
const chosen = await getServer(name, how);
|
|
191
|
-
|
|
192
|
-
const token = await (0, token_source_1.getTokenSource)(environment, chosen.name, chosen.server).token();
|
|
193
|
-
return { ...chosen, token };
|
|
313
|
+
return { ...chosen, connection: (0, sandbox_client_1.getServerConnection)(environment, chosen.name, chosen.server) };
|
|
194
314
|
};
|
|
195
315
|
// publishes the bundle with where it comes from and says what it is now: published,
|
|
196
316
|
// already published, or only proposed
|
|
197
|
-
const publishBundle = async (serverName,
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
annotations,
|
|
317
|
+
const publishBundle = async (serverName, connection, bundle, annotations) => {
|
|
318
|
+
// what is published already changes nothing and is said so: sent again, it is the same
|
|
319
|
+
const answer = await (0, server_client_1.callServer)(connection, 'POST', '/v1/definitions', {
|
|
320
|
+
body: { ...bundle, annotations },
|
|
321
|
+
repeat: 'always',
|
|
201
322
|
});
|
|
202
323
|
const version = answer.body;
|
|
203
324
|
const files = Object.keys(bundle.files).length;
|
|
@@ -222,9 +343,13 @@ function registerWorkCommands(remote, context) {
|
|
|
222
343
|
return { version, proposed };
|
|
223
344
|
};
|
|
224
345
|
// what publishing the bundle would do, undefined from a server that can't say (before 2.0)
|
|
225
|
-
const planBundle = async (
|
|
346
|
+
const planBundle = async (connection, bundle) => {
|
|
226
347
|
try {
|
|
227
|
-
|
|
348
|
+
// a plan stores nothing, so it is sent again as often as the server does not answer
|
|
349
|
+
return (await (0, server_client_1.callServer)(connection, 'POST', '/v1/definitions/plan', {
|
|
350
|
+
body: bundle,
|
|
351
|
+
repeat: 'always',
|
|
352
|
+
})).body;
|
|
228
353
|
}
|
|
229
354
|
catch (e) {
|
|
230
355
|
if (e instanceof server_client_1.ServerError && e.status === 404) {
|
|
@@ -246,7 +371,11 @@ function registerWorkCommands(remote, context) {
|
|
|
246
371
|
}
|
|
247
372
|
return { definition: named };
|
|
248
373
|
}
|
|
249
|
-
const local = await (0, collect_bundle_1.collectBundle)(buildFile, environment
|
|
374
|
+
const local = await (0, collect_bundle_1.collectBundle)(buildFile, environment, {
|
|
375
|
+
// most often run in another folder than the checkout meant
|
|
376
|
+
missing: 'Run this in the checkout whose build file the server has, ' +
|
|
377
|
+
'or name a published version with --build <hash>, listed by: hammerkit remote versions',
|
|
378
|
+
});
|
|
250
379
|
return { definition: (0, bundle_1.hashBundle)(local), local };
|
|
251
380
|
};
|
|
252
381
|
// Submits a run of a published version. When the server does not have the build file
|
|
@@ -254,7 +383,7 @@ function registerWorkCommands(remote, context) {
|
|
|
254
383
|
// terminal says so. Without a terminal and without --publish the run fails and says how
|
|
255
384
|
// to publish it, so CI never waits on a question.
|
|
256
385
|
const submitPublishing = async (target, request, local, publish) => {
|
|
257
|
-
const { serverName,
|
|
386
|
+
const { serverName, connection } = target;
|
|
258
387
|
try {
|
|
259
388
|
return await (0, sandbox_client_1.submitRun)(connection, request);
|
|
260
389
|
}
|
|
@@ -266,14 +395,13 @@ function registerWorkCommands(remote, context) {
|
|
|
266
395
|
}
|
|
267
396
|
const definition = request.definition;
|
|
268
397
|
const notPublished = `the build file here is not published on ${serverName} (${definition})`;
|
|
269
|
-
const token = await connection.token();
|
|
270
398
|
if (!publish) {
|
|
271
399
|
if (!environment.prompt) {
|
|
272
400
|
throw new Error(`${notPublished}, publish it first with: hammerkit remote publish ${serverName}, or pass --publish`);
|
|
273
401
|
}
|
|
274
402
|
// a server before 2.0 can't say what publishing would do: it is asked all the same,
|
|
275
403
|
// and refuses then what the caller may not do
|
|
276
|
-
const planned = await planBundle(
|
|
404
|
+
const planned = await planBundle(connection, local);
|
|
277
405
|
if (planned && planned.outcome === null) {
|
|
278
406
|
throw new Error(`${notPublished}, and you may only run published build files (builds: run): ` +
|
|
279
407
|
`somebody who may publish publishes it with: hammerkit remote publish ${serverName}`);
|
|
@@ -299,7 +427,7 @@ function registerWorkCommands(remote, context) {
|
|
|
299
427
|
}
|
|
300
428
|
}
|
|
301
429
|
const annotations = await (0, annotations_1.collectAnnotations)(buildFile, Object.keys(local.files));
|
|
302
|
-
const { version, proposed } = await publishBundle(serverName,
|
|
430
|
+
const { version, proposed } = await publishBundle(serverName, connection, local, annotations).catch((e) => {
|
|
303
431
|
throw e instanceof server_client_1.ServerError && e.status === 403 ? new Error(`${notPublished}, ${e.message}`) : e;
|
|
304
432
|
});
|
|
305
433
|
if (version.hash !== definition) {
|
|
@@ -319,8 +447,11 @@ function registerWorkCommands(remote, context) {
|
|
|
319
447
|
.action(guarded('Remote publish was not successful', async (name, options) => {
|
|
320
448
|
const bundle = await (0, collect_bundle_1.collectBundle)(buildFile, environment);
|
|
321
449
|
if (options.dryRun) {
|
|
322
|
-
const { name: serverName,
|
|
323
|
-
const answer = await (0, server_client_1.callServer)(
|
|
450
|
+
const { name: serverName, connection } = await connect(name);
|
|
451
|
+
const answer = await (0, server_client_1.callServer)(connection, 'POST', '/v1/definitions/plan', {
|
|
452
|
+
body: bundle,
|
|
453
|
+
repeat: 'always',
|
|
454
|
+
}).catch((e) => {
|
|
324
455
|
throw e instanceof server_client_1.ServerError && e.status === 404
|
|
325
456
|
? new Error(`${serverName} can't check a build file without publishing it, it needs hammerkit 2.0`)
|
|
326
457
|
: e;
|
|
@@ -334,8 +465,8 @@ function registerWorkCommands(remote, context) {
|
|
|
334
465
|
return;
|
|
335
466
|
}
|
|
336
467
|
const annotations = (0, annotations_1.applyAnnotations)(await (0, annotations_1.collectAnnotations)(buildFile, Object.keys(bundle.files)), options.annotation ?? []);
|
|
337
|
-
const { name: serverName,
|
|
338
|
-
await publishBundle(serverName,
|
|
468
|
+
const { name: serverName, connection } = await connect(name);
|
|
469
|
+
await publishBundle(serverName, connection, bundle, annotations);
|
|
339
470
|
}));
|
|
340
471
|
remote
|
|
341
472
|
.command('run <tasks...>')
|
|
@@ -343,7 +474,8 @@ function registerWorkCommands(remote, context) {
|
|
|
343
474
|
.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
475
|
.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
476
|
.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'
|
|
477
|
+
.addOption(new commander_1.Option('--ref <ref>', 'the branch or tag to run; the branch checked out here when left out, ' +
|
|
478
|
+
'or the one branch or tag of origin at the commit of a detached checkout'))
|
|
347
479
|
.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
480
|
.addOption(new commander_1.Option('--env <name>', 'the environment of the build file, as --env of run'))
|
|
349
481
|
.addOption(new commander_1.Option('--cache <method>', 'as --cache of run').choices(['checksum', 'modify-date', 'none']))
|
|
@@ -356,7 +488,7 @@ function registerWorkCommands(remote, context) {
|
|
|
356
488
|
const source = await refSource(options);
|
|
357
489
|
const ref = source.ref;
|
|
358
490
|
const { name: serverName, server } = await getServer(options.server, 'with --server <name>');
|
|
359
|
-
const connection =
|
|
491
|
+
const connection = (0, sandbox_client_1.getServerConnection)(environment, serverName, server);
|
|
360
492
|
const runOptions = {};
|
|
361
493
|
for (const key of ['env', 'cache', 'timeout', 'maxTimeout']) {
|
|
362
494
|
if (options[key] !== undefined) {
|
|
@@ -366,7 +498,7 @@ function registerWorkCommands(remote, context) {
|
|
|
366
498
|
if (passthrough.length > 0) {
|
|
367
499
|
runOptions.args = passthrough;
|
|
368
500
|
}
|
|
369
|
-
const submitted = await submitPublishing({ serverName,
|
|
501
|
+
const submitted = await submitPublishing({ serverName, connection }, { definition, tasks, source, options: runOptions }, local, !!options.publish);
|
|
370
502
|
const at = submitted.source.type === 'ref' ? ` at ${(0, server_client_1.printable)(submitted.source.commit)}` : '';
|
|
371
503
|
environment.stdout.write(`${(0, server_client_1.printable)(submitted.id)} on ${serverName}: ${tasks.map(server_client_1.printable).join(', ')} from ${(0, server_client_1.printable)(ref)}${at}\n`);
|
|
372
504
|
if (options.detach) {
|
|
@@ -416,7 +548,8 @@ function registerWorkCommands(remote, context) {
|
|
|
416
548
|
'starts other services or another build file; the addresses stay; the branch when left out'))
|
|
417
549
|
.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
550
|
.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'
|
|
551
|
+
.addOption(new commander_1.Option('--ref <ref>', 'the branch or tag to start; the branch checked out here when left out, ' +
|
|
552
|
+
'or the one branch or tag of origin at the commit of a detached checkout'))
|
|
420
553
|
.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
554
|
.addOption(new commander_1.Option('--env <name>', 'the environment of the build file, as --env of run'))
|
|
422
555
|
.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'))
|
|
@@ -425,8 +558,8 @@ function registerWorkCommands(remote, context) {
|
|
|
425
558
|
const endpoints = (options.endpoint ?? []).map(service_tools_1.parseEndpoint);
|
|
426
559
|
const source = await refSource(options);
|
|
427
560
|
const { name: serverName, server } = await getServer(options.server, 'with --server <name>');
|
|
428
|
-
const connection =
|
|
429
|
-
const submitted = await submitPublishing({ serverName,
|
|
561
|
+
const connection = (0, sandbox_client_1.getServerConnection)(environment, serverName, server);
|
|
562
|
+
const submitted = await submitPublishing({ serverName, connection }, {
|
|
430
563
|
definition,
|
|
431
564
|
services,
|
|
432
565
|
endpoints,
|
|
@@ -469,10 +602,12 @@ function registerWorkCommands(remote, context) {
|
|
|
469
602
|
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
603
|
}
|
|
471
604
|
if (run.state === 'asleep') {
|
|
472
|
-
|
|
473
|
-
|
|
605
|
+
// its addresses stay while it sleeps, and a request to one of them wakes it
|
|
606
|
+
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`);
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
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`);
|
|
474
610
|
}
|
|
475
|
-
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`);
|
|
476
611
|
for (const endpoint of run.up?.endpoints ?? []) {
|
|
477
612
|
environment.stdout.write(` ${(0, server_client_1.printable)(endpoint.service)}:${endpoint.port} ${(0, server_client_1.printable)(endpoint.url)}\n`);
|
|
478
613
|
}
|
|
@@ -483,8 +618,8 @@ function registerWorkCommands(remote, context) {
|
|
|
483
618
|
.description('show how a server stands for you: the places that run, the queue and why each run in it waits, your limits and the runs that count against them, your service runs')
|
|
484
619
|
.addOption(new commander_1.Option('--json', 'print the overview as the server answers it, for scripts and agents'))
|
|
485
620
|
.action(guarded('Remote status was not successful', async (name, options) => {
|
|
486
|
-
const { name: serverName,
|
|
487
|
-
const overview = (await (0, server_client_1.callServer)(
|
|
621
|
+
const { name: serverName, connection } = await connect(name);
|
|
622
|
+
const overview = (await (0, server_client_1.callServer)(connection, 'GET', '/v1/overview')).body;
|
|
488
623
|
if (options.json) {
|
|
489
624
|
environment.stdout.write(`${JSON.stringify(overview, null, 2)}\n`);
|
|
490
625
|
return;
|
|
@@ -493,7 +628,8 @@ function registerWorkCommands(remote, context) {
|
|
|
493
628
|
environment.stdout.write(`${line}\n`);
|
|
494
629
|
}
|
|
495
630
|
// a server from before /v1/capacity, or one that can not read it, prints without
|
|
496
|
-
|
|
631
|
+
// best effort, printed after the overview: it is not waited for, the overview is already out
|
|
632
|
+
const capacity = await (0, server_client_1.callServer)(connection, 'GET', '/v1/capacity', { reconnectMs: 0 }).catch(() => undefined);
|
|
497
633
|
if (capacity) {
|
|
498
634
|
for (const line of (0, remote_status_1.describeCapacity)(capacity.body, true)) {
|
|
499
635
|
environment.stdout.write(`${line}\n`);
|
|
@@ -505,8 +641,8 @@ function registerWorkCommands(remote, context) {
|
|
|
505
641
|
.description('show what the machines of a server have and what its runs take: CPU and memory requested and in use, per namespace on Kubernetes')
|
|
506
642
|
.addOption(new commander_1.Option('--json', 'print it as the server answers it'))
|
|
507
643
|
.action(guarded('Remote capacity was not successful', async (name, options) => {
|
|
508
|
-
const {
|
|
509
|
-
const capacity = (await (0, server_client_1.callServer)(
|
|
644
|
+
const { connection } = await connect(name);
|
|
645
|
+
const capacity = (await (0, server_client_1.callServer)(connection, 'GET', '/v1/capacity')).body;
|
|
510
646
|
if (options.json) {
|
|
511
647
|
environment.stdout.write(`${JSON.stringify(capacity, null, 2)}\n`);
|
|
512
648
|
return;
|
|
@@ -523,7 +659,7 @@ function registerWorkCommands(remote, context) {
|
|
|
523
659
|
.addOption(new commander_1.Option('--until <when>', 'only the runs created until then: back from now, or a time'))
|
|
524
660
|
.addOption(new commander_1.Option('--json', 'print it as the server answers it'))
|
|
525
661
|
.action(guarded('Remote tasks was not successful', async (name, options) => {
|
|
526
|
-
const { name: serverName,
|
|
662
|
+
const { name: serverName, connection } = await connect(name);
|
|
527
663
|
const query = new URLSearchParams({ scope: options.mine ? 'mine' : 'visible' });
|
|
528
664
|
if (options.since) {
|
|
529
665
|
query.set('since', options.since);
|
|
@@ -531,7 +667,7 @@ function registerWorkCommands(remote, context) {
|
|
|
531
667
|
if (options.until) {
|
|
532
668
|
query.set('until', options.until);
|
|
533
669
|
}
|
|
534
|
-
const { tasks } = (await (0, server_client_1.callServer)(
|
|
670
|
+
const { tasks } = (await (0, server_client_1.callServer)(connection, 'GET', `/v1/tasks?${query}`)).body;
|
|
535
671
|
if (options.json) {
|
|
536
672
|
environment.stdout.write(`${JSON.stringify(tasks, null, 2)}\n`);
|
|
537
673
|
return;
|
|
@@ -549,7 +685,10 @@ function registerWorkCommands(remote, context) {
|
|
|
549
685
|
.description('print the address of the dashboard of a server, the pages of remote status, services, runs and logs')
|
|
550
686
|
.action(guarded('Remote dashboard was not successful', async (name) => {
|
|
551
687
|
const { name: serverName, server } = await getServer(name);
|
|
552
|
-
const discovery = await (0, server_client_1.getDiscovery)(server
|
|
688
|
+
const discovery = await (0, server_client_1.getDiscovery)(server, {
|
|
689
|
+
say: (line) => environment.stderr.write(`${line}\n`),
|
|
690
|
+
signal: environment.abortCtrl.signal,
|
|
691
|
+
});
|
|
553
692
|
if (!discovery.dashboard) {
|
|
554
693
|
throw new Error(`${serverName} has no dashboard: it needs endpoints with a login in its config, see https://hammerkit.dev/docs/remote-compute/status#dashboard`);
|
|
555
694
|
}
|
|
@@ -560,10 +699,11 @@ function registerWorkCommands(remote, context) {
|
|
|
560
699
|
.description('list the service runs that are starting, up or asleep: yours, and those whose endpoints you may open, with their addresses and when they end or sleep')
|
|
561
700
|
.addOption(new commander_1.Option('--ended', 'also the ones that ended, as long as the server keeps them'))
|
|
562
701
|
.action(guarded('Remote services was not successful', async (name, options) => {
|
|
563
|
-
const { name: serverName,
|
|
702
|
+
const { name: serverName, connection } = await connect(name);
|
|
564
703
|
const open = ['awaiting-approval', 'queued', 'running', 'up', 'asleep'];
|
|
565
704
|
const states = options.ended ? '' : `&state=${open.join(',')}`;
|
|
566
|
-
const runs = keepRuns((await (0, server_client_1.callServer)(
|
|
705
|
+
const runs = keepRuns((await (0, server_client_1.callServer)(connection, 'GET', `/v1/runs?scope=visible&kind=services${states}`))
|
|
706
|
+
.body.runs, options.ended ? undefined : open, 'services');
|
|
567
707
|
if (runs.length === 0) {
|
|
568
708
|
environment.stdout.write(`${serverName}: no service runs${options.ended ? '' : ' are starting, up or asleep'}\n`);
|
|
569
709
|
return;
|
|
@@ -597,9 +737,9 @@ function registerWorkCommands(remote, context) {
|
|
|
597
737
|
if (options.services || options.tasks) {
|
|
598
738
|
query.set('kind', options.services ? 'services' : 'tasks');
|
|
599
739
|
}
|
|
600
|
-
const { name: serverName,
|
|
740
|
+
const { name: serverName, connection } = await connect(name);
|
|
601
741
|
const path = `/v1/runs${query.toString() ? `?${query}` : ''}`;
|
|
602
|
-
const runs = keepRuns((await (0, server_client_1.callServer)(
|
|
742
|
+
const runs = keepRuns((await (0, server_client_1.callServer)(connection, 'GET', path)).body.runs, options.state ? String(options.state).split(',') : undefined, options.services ? 'services' : options.tasks ? 'tasks' : undefined);
|
|
603
743
|
if (runs.length === 0) {
|
|
604
744
|
environment.stdout.write(`${serverName}: ${query.toString() ? 'no runs it keeps are like that' : 'you have no runs it still keeps'}\n`);
|
|
605
745
|
return;
|
|
@@ -630,7 +770,7 @@ function registerWorkCommands(remote, context) {
|
|
|
630
770
|
throw new Error('--follow prints the whole log, leave --tail out');
|
|
631
771
|
}
|
|
632
772
|
const { name: serverName, server } = await getServer(name);
|
|
633
|
-
const connection =
|
|
773
|
+
const connection = (0, sandbox_client_1.getServerConnection)(environment, serverName, server);
|
|
634
774
|
const found = await (0, sandbox_client_1.getRun)(connection, id);
|
|
635
775
|
if (!found) {
|
|
636
776
|
throw new Error(`${serverName} keeps no run ${(0, server_client_1.printable)(id)} you may see, list them with: hammerkit remote runs`);
|
|
@@ -661,6 +801,41 @@ function registerWorkCommands(remote, context) {
|
|
|
661
801
|
environment.stdout.write(`${(0, server_client_1.printable)(run.id)} is ${(0, server_client_1.printable)(run.state)}, follow it with --follow\n`);
|
|
662
802
|
}
|
|
663
803
|
}));
|
|
804
|
+
remote
|
|
805
|
+
.command('artifacts <run> [server]')
|
|
806
|
+
.description('list or download the outputs the tasks of a run that ended export (generates with export: true, ' +
|
|
807
|
+
'or export: always also of a task that failed); none of a run in which anything reads a secret')
|
|
808
|
+
.addOption(new commander_1.Option('--task <name>', 'only the outputs of this task'))
|
|
809
|
+
.addOption(new commander_1.Option('--path <path>', 'only the output at this path in the project, or the files of one below it'))
|
|
810
|
+
.addOption(new commander_1.Option('--out <dir>', 'download them into this directory, at their paths in the project; else they are listed'))
|
|
811
|
+
.action(guarded('Remote artifacts was not successful', async (id, name, options) => {
|
|
812
|
+
if (!RUN_ID.test(id)) {
|
|
813
|
+
throw new Error(`${(0, server_client_1.printable)(id)} is not a run id (run_...), list them with: hammerkit remote runs`);
|
|
814
|
+
}
|
|
815
|
+
const path = options.path === undefined ? undefined : projectPath(options.path);
|
|
816
|
+
const { name: serverName, server } = await getServer(name);
|
|
817
|
+
const connection = (0, sandbox_client_1.getServerConnection)(environment, serverName, server);
|
|
818
|
+
const kept = await (0, sandbox_client_1.getRunArtifacts)(connection, id);
|
|
819
|
+
if (!kept) {
|
|
820
|
+
throw new Error(`${serverName} keeps no run ${(0, server_client_1.printable)(id)} you may see, list them with: hammerkit remote runs`);
|
|
821
|
+
}
|
|
822
|
+
const outputs = keptProjectOutputs(kept.outputs);
|
|
823
|
+
const chosen = selectArtifacts(outputs, { task: options.task, path });
|
|
824
|
+
const selecting = options.task !== undefined || path !== undefined;
|
|
825
|
+
if (chosen.length === 0 && selecting) {
|
|
826
|
+
const all = outputs.map((output) => (0, server_client_1.printable)(output.path)).join(' and ') || 'nothing';
|
|
827
|
+
throw new Error(`the run kept nothing ${path !== undefined ? `at or below ${(0, server_client_1.printable)(path)}` : `of ${(0, server_client_1.printable)(options.task)}`}, it kept ${all}`);
|
|
828
|
+
}
|
|
829
|
+
// nothing to download (or no --out): the listing, before anything is made
|
|
830
|
+
if (options.out === undefined || chosen.length === 0) {
|
|
831
|
+
const shown = selecting ? chosen.map(({ output }) => output) : outputs;
|
|
832
|
+
for (const line of describeArtifacts(id, serverName, kept, shown)) {
|
|
833
|
+
environment.stdout.write(`${line}\n`);
|
|
834
|
+
}
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
await downloadArtifacts(connection, id, chosen, (0, path_1.resolve)(environment.cwd, options.out), (line) => environment.stdout.write(`${line}\n`));
|
|
838
|
+
}));
|
|
664
839
|
remote
|
|
665
840
|
.command('extend <run> <ttl> [server]')
|
|
666
841
|
.description('keep a service run that is up for this long from now, such as 8h, at most the maxTtl of the server')
|
|
@@ -668,8 +843,10 @@ function registerWorkCommands(remote, context) {
|
|
|
668
843
|
if (!RUN_ID.test(id)) {
|
|
669
844
|
throw new Error(`${(0, server_client_1.printable)(id)} is not a run id (run_...)`);
|
|
670
845
|
}
|
|
671
|
-
const { name: serverName,
|
|
672
|
-
|
|
846
|
+
const { name: serverName, connection } = await connect(name);
|
|
847
|
+
// the end becomes this long from now, and never sooner than it was: a repeat sent late ends the
|
|
848
|
+
// run at most a retry window later than the first one did
|
|
849
|
+
const run = (await (0, server_client_1.callServer)(connection, 'POST', `/v1/runs/${id}/extend`, { body: { ttl }, repeat: 'always' })).body;
|
|
673
850
|
environment.stdout.write(`${(0, server_client_1.printable)(run.id)} on ${serverName} stays up until ${(0, server_client_1.printable)(run.expiresAt ?? '-')}\n`);
|
|
674
851
|
}));
|
|
675
852
|
remote
|
|
@@ -679,8 +856,9 @@ function registerWorkCommands(remote, context) {
|
|
|
679
856
|
if (!RUN_ID.test(id)) {
|
|
680
857
|
throw new Error(`${(0, server_client_1.printable)(id)} is not a run id (run_...)`);
|
|
681
858
|
}
|
|
682
|
-
const { name: serverName,
|
|
683
|
-
|
|
859
|
+
const { name: serverName, connection } = await connect(name);
|
|
860
|
+
// a run that is over stays so: sent again, the stop answers the same
|
|
861
|
+
const run = (await (0, server_client_1.callServer)(connection, 'POST', `/v1/runs/${id}/cancel`, { repeat: 'always' })).body;
|
|
684
862
|
environment.stdout.write(`${(0, server_client_1.printable)(run.id)} on ${serverName}: ${run.state === 'up' || run.state === 'running' ? 'stopping' : (0, server_client_1.printable)(run.state)}\n`);
|
|
685
863
|
}));
|
|
686
864
|
remote
|
|
@@ -690,8 +868,9 @@ function registerWorkCommands(remote, context) {
|
|
|
690
868
|
if (!RUN_ID.test(id)) {
|
|
691
869
|
throw new Error(`${(0, server_client_1.printable)(id)} is not a run id (run_...)`);
|
|
692
870
|
}
|
|
693
|
-
const { name: serverName,
|
|
694
|
-
|
|
871
|
+
const { name: serverName, connection } = await connect(name);
|
|
872
|
+
// each retry starts a run of its own: sent again only when the server did not take it
|
|
873
|
+
const run = (await (0, server_client_1.callServer)(connection, 'POST', `/v1/runs/${id}/retry`, { repeat: 'unsent' })).body;
|
|
695
874
|
environment.stdout.write(`${(0, server_client_1.printable)(run.id)} on ${serverName} retries ${(0, server_client_1.printable)(id)}: ${(0, server_client_1.printable)(run.state)}, ` +
|
|
696
875
|
`follow it with hammerkit remote logs ${(0, server_client_1.printable)(run.id)} --follow\n`);
|
|
697
876
|
}));
|
|
@@ -721,15 +900,17 @@ function registerWorkCommands(remote, context) {
|
|
|
721
900
|
keys.push({ task, key: found.key });
|
|
722
901
|
}
|
|
723
902
|
}
|
|
724
|
-
const { name: serverName, server
|
|
903
|
+
const { name: serverName, server } = await getServer(options.server, 'with --server <name>');
|
|
725
904
|
const answer = keys.length > 0
|
|
726
|
-
? await (0,
|
|
727
|
-
|
|
905
|
+
? await (0, sandbox_client_1.lookupChecks)((0, sandbox_client_1.getServerConnection)(environment, serverName, server), repo, keys).catch((e) => {
|
|
906
|
+
throw describeRefusal(server.url, e);
|
|
907
|
+
})
|
|
908
|
+
: { checks: [] };
|
|
728
909
|
const missing = [];
|
|
729
910
|
// by what was asked, never by what was answered: a task the answer leaves out, or
|
|
730
911
|
// answers for another key, is not verified
|
|
731
912
|
for (const { task, key } of keys) {
|
|
732
|
-
const check = answer.
|
|
913
|
+
const check = answer.checks.find((answered) => answered.task === task && answered.key === key);
|
|
733
914
|
if (check?.passed) {
|
|
734
915
|
environment.stdout.write(`${(0, server_client_1.printable)(task)}: ${(0, server_client_1.printable)(describePassed(check.passed))}\n`);
|
|
735
916
|
}
|
|
@@ -764,9 +945,9 @@ function registerWorkCommands(remote, context) {
|
|
|
764
945
|
}
|
|
765
946
|
query.append(filter.slice(0, index), filter.slice(index + 1));
|
|
766
947
|
}
|
|
767
|
-
const { name: serverName,
|
|
948
|
+
const { name: serverName, connection } = await connect(name);
|
|
768
949
|
const path = `/v1/definitions${query.toString() !== '' ? `?${query}` : ''}`;
|
|
769
|
-
const { body } = await (0, server_client_1.callServer)(
|
|
950
|
+
const { body } = await (0, server_client_1.callServer)(connection, 'GET', path);
|
|
770
951
|
if (body.definitions.length === 0) {
|
|
771
952
|
environment.stdout.write(`${serverName}: no published versions${query.toString() !== '' ? ' match' : ''}\n`);
|
|
772
953
|
return;
|
|
@@ -791,8 +972,8 @@ function registerWorkCommands(remote, context) {
|
|
|
791
972
|
.command('approvals [server]')
|
|
792
973
|
.description('list the runs on a server that wait for your approval')
|
|
793
974
|
.action(guarded('Remote approvals was not successful', async (name) => {
|
|
794
|
-
const { name: serverName,
|
|
795
|
-
const { body } = await (0, server_client_1.callServer)(
|
|
975
|
+
const { name: serverName, connection } = await connect(name);
|
|
976
|
+
const { body } = await (0, server_client_1.callServer)(connection, 'GET', '/v1/approvals');
|
|
796
977
|
if (body.approvals.length === 0) {
|
|
797
978
|
environment.stdout.write(`${serverName}: no runs wait for your approval\n`);
|
|
798
979
|
return;
|
|
@@ -805,11 +986,11 @@ function registerWorkCommands(remote, context) {
|
|
|
805
986
|
}
|
|
806
987
|
}));
|
|
807
988
|
// A version that is published: who published it, what its tasks do and every file.
|
|
808
|
-
const showPublished = async (hash, serverName,
|
|
989
|
+
const showPublished = async (hash, serverName, connection) => {
|
|
809
990
|
const path = `/v1/definitions/${hash}`;
|
|
810
991
|
let version;
|
|
811
992
|
try {
|
|
812
|
-
version = (await (0, server_client_1.callServer)(
|
|
993
|
+
version = (await (0, server_client_1.callServer)(connection, 'GET', path)).body;
|
|
813
994
|
}
|
|
814
995
|
catch (e) {
|
|
815
996
|
if (e instanceof server_client_1.ServerError && e.status === 404) {
|
|
@@ -817,7 +998,7 @@ function registerWorkCommands(remote, context) {
|
|
|
817
998
|
}
|
|
818
999
|
throw e;
|
|
819
1000
|
}
|
|
820
|
-
const files = (await (0, server_client_1.callServer)(
|
|
1001
|
+
const files = (await (0, server_client_1.callServer)(connection, 'GET', `${path}/files`)).body;
|
|
821
1002
|
environment.stdout.write(`${colors_1.default.bold((0, server_client_1.printable)(version.hash))} on ${serverName}, published by ${(0, server_client_1.printable)(version.publishedBy.sub)} (${(0, server_client_1.printable)(version.publishedBy.iss)}) at ${(0, server_client_1.printable)(version.publishedAt)}${version.approvedBy ? `, approved by ${(0, server_client_1.printable)(version.approvedBy.sub)}` : ''}\n`);
|
|
822
1003
|
for (const line of [
|
|
823
1004
|
...yankLines(version),
|
|
@@ -836,22 +1017,22 @@ function registerWorkCommands(remote, context) {
|
|
|
836
1017
|
if (!RUN_ID.test(target) && !bundle_1.HASH_PATTERN.test(target)) {
|
|
837
1018
|
throw new Error(`${(0, server_client_1.printable)(target)} is not a run id or a version, list them with: hammerkit remote approvals, remote proposals or remote versions`);
|
|
838
1019
|
}
|
|
839
|
-
const { name: serverName,
|
|
1020
|
+
const { name: serverName, connection } = await connect(name);
|
|
840
1021
|
if (bundle_1.HASH_PATTERN.test(target)) {
|
|
841
1022
|
const path = `/v1/proposals/${target}`;
|
|
842
1023
|
let proposal;
|
|
843
1024
|
try {
|
|
844
|
-
proposal = (await (0, server_client_1.callServer)(
|
|
1025
|
+
proposal = (await (0, server_client_1.callServer)(connection, 'GET', path)).body;
|
|
845
1026
|
}
|
|
846
1027
|
catch (e) {
|
|
847
1028
|
if (e instanceof server_client_1.ServerError && e.status === 404) {
|
|
848
|
-
await showPublished(target, serverName,
|
|
1029
|
+
await showPublished(target, serverName, connection);
|
|
849
1030
|
return;
|
|
850
1031
|
}
|
|
851
1032
|
throw e;
|
|
852
1033
|
}
|
|
853
1034
|
if (proposal.state === 'approved') {
|
|
854
|
-
await showPublished(target, serverName,
|
|
1035
|
+
await showPublished(target, serverName, connection);
|
|
855
1036
|
return;
|
|
856
1037
|
}
|
|
857
1038
|
if (proposal.state !== 'waiting') {
|
|
@@ -863,7 +1044,7 @@ function registerWorkCommands(remote, context) {
|
|
|
863
1044
|
environment.stdout.write(' its files are not kept once it is decided\n');
|
|
864
1045
|
return;
|
|
865
1046
|
}
|
|
866
|
-
const files = (await (0, server_client_1.callServer)(
|
|
1047
|
+
const files = (await (0, server_client_1.callServer)(connection, 'GET', `${path}/files`)).body;
|
|
867
1048
|
environment.stdout.write(`${colors_1.default.bold((0, server_client_1.printable)(proposal.hash))} on ${serverName}, proposed by ${(0, server_client_1.printable)(proposal.proposedBy.sub)} (${(0, server_client_1.printable)(proposal.proposedBy.iss)}), ${(0, server_client_1.printable)(proposal.state)}\n`);
|
|
868
1049
|
for (const line of [
|
|
869
1050
|
...annotationLines(proposal.annotations),
|
|
@@ -875,7 +1056,7 @@ function registerWorkCommands(remote, context) {
|
|
|
875
1056
|
}
|
|
876
1057
|
return;
|
|
877
1058
|
}
|
|
878
|
-
const view = (await (0, server_client_1.callServer)(
|
|
1059
|
+
const view = (await (0, server_client_1.callServer)(connection, 'GET', `/v1/approvals/${target}`)).body;
|
|
879
1060
|
for (const line of describeApproval(view)) {
|
|
880
1061
|
environment.stdout.write(`${line}\n`);
|
|
881
1062
|
}
|
|
@@ -885,8 +1066,8 @@ function registerWorkCommands(remote, context) {
|
|
|
885
1066
|
.command('proposals [server]')
|
|
886
1067
|
.description('list the proposed versions of build files you made or may approve')
|
|
887
1068
|
.action(guarded('Remote proposals was not successful', async (name) => {
|
|
888
|
-
const { name: serverName,
|
|
889
|
-
const { body } = await (0, server_client_1.callServer)(
|
|
1069
|
+
const { name: serverName, connection } = await connect(name);
|
|
1070
|
+
const { body } = await (0, server_client_1.callServer)(connection, 'GET', '/v1/proposals');
|
|
890
1071
|
if (body.proposals.length === 0) {
|
|
891
1072
|
environment.stdout.write(`${serverName}: no proposed versions\n`);
|
|
892
1073
|
return;
|
|
@@ -928,8 +1109,13 @@ function registerWorkCommands(remote, context) {
|
|
|
928
1109
|
if (!bundle_1.HASH_PATTERN.test(target)) {
|
|
929
1110
|
throw new Error(`${(0, server_client_1.printable)(target)} is not a version, name it by its hash: sha256:...`);
|
|
930
1111
|
}
|
|
931
|
-
const { name: serverName,
|
|
932
|
-
|
|
1112
|
+
const { name: serverName, connection } = await connect(name);
|
|
1113
|
+
// a yank sent again after a lost answer ends the same, unless somebody let the version go on
|
|
1114
|
+
// in between. An unyank is not repeated then: it would let a version go on that somebody yanked
|
|
1115
|
+
await (0, server_client_1.callServer)(connection, 'POST', `/v1/definitions/${target}/${action}`, {
|
|
1116
|
+
body: options.reason ? { reason: options.reason } : undefined,
|
|
1117
|
+
repeat: action === 'yank' ? 'always' : 'unsent',
|
|
1118
|
+
});
|
|
933
1119
|
environment.stdout.write(`${action === 'yank' ? 'yanked' : 'let go on'} ${(0, server_client_1.printable)(target)} on ${serverName}\n`);
|
|
934
1120
|
}));
|
|
935
1121
|
}
|
|
@@ -945,9 +1131,14 @@ function registerWorkCommands(remote, context) {
|
|
|
945
1131
|
if (!proposal && !RUN_ID.test(target)) {
|
|
946
1132
|
throw new Error(`${(0, server_client_1.printable)(target)} is not a run id or a proposed version, list them with: hammerkit remote approvals or remote proposals`);
|
|
947
1133
|
}
|
|
948
|
-
const { name: serverName,
|
|
1134
|
+
const { name: serverName, connection } = await connect(name);
|
|
949
1135
|
const path = proposal ? `/v1/proposals/${target}/${action}` : `/v1/approvals/${target}/${action}`;
|
|
950
|
-
|
|
1136
|
+
// a decision taken twice is refused the second time (409): sent again only when the
|
|
1137
|
+
// server did not take it
|
|
1138
|
+
const { body } = await (0, server_client_1.callServer)(connection, 'POST', path, {
|
|
1139
|
+
body: options.reason ? { reason: options.reason } : undefined,
|
|
1140
|
+
repeat: 'unsent',
|
|
1141
|
+
});
|
|
951
1142
|
const rejected = body.state === 'rejected';
|
|
952
1143
|
environment.stdout.write(proposal
|
|
953
1144
|
? rejected
|