@myapihq/cli 2.31.0 → 2.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// A failed deploy has to say which half failed.
|
|
2
|
+
//
|
|
3
|
+
// One fixed sentence covered every failure: "Build/deploy failed — check
|
|
4
|
+
// `myapi container logs <id>`". ImmoPilot read thirty lines of healthy nginx
|
|
5
|
+
// after a ROLLOUT failure — the image had built, served two 200s to our own
|
|
6
|
+
// startup probes, then taken a SIGTERM — and a second deploy of the same code
|
|
7
|
+
// succeeded unchanged. The sentence sent them looking for a defect in code that
|
|
8
|
+
// was fine.
|
|
9
|
+
//
|
|
10
|
+
// I hit the same message the day before, on a container the probe had already
|
|
11
|
+
// deleted, so the logs it named did not exist either.
|
|
12
|
+
//
|
|
13
|
+
// The platform now returns error, error_stage and error_retryable, so the CLI
|
|
14
|
+
// can stop guessing.
|
|
15
|
+
import { describe, it, expect } from 'vitest';
|
|
16
|
+
import { describeDeployFailure } from './container.js';
|
|
17
|
+
const ID = 'c1';
|
|
18
|
+
const base = { id: ID };
|
|
19
|
+
describe('describeDeployFailure', () => {
|
|
20
|
+
it('leads with what the platform said, not our paraphrase', () => {
|
|
21
|
+
const out = describeDeployFailure({ ...base, error: 'Deployment failed after the image built.', error_stage: 'deploy' }, ID);
|
|
22
|
+
expect(out.split('\n')[0]).toBe('Deployment failed after the image built.');
|
|
23
|
+
});
|
|
24
|
+
it('on a rollout failure, says their application logs are the wrong place', () => {
|
|
25
|
+
// The whole point. "Check the logs" is what cost a customer a deploy.
|
|
26
|
+
const out = describeDeployFailure({ ...base, error_stage: 'deploy' }, ID);
|
|
27
|
+
expect(out).toMatch(/not the place to look/i);
|
|
28
|
+
expect(out).not.toContain(`myapi container logs ${ID}`);
|
|
29
|
+
});
|
|
30
|
+
it('on a build failure, sends them to the build logs', () => {
|
|
31
|
+
const out = describeDeployFailure({ ...base, error_stage: 'build' }, ID);
|
|
32
|
+
expect(out).toContain(`myapi container build-logs ${ID}`);
|
|
33
|
+
});
|
|
34
|
+
it('says so when the failure is ours and retrying is reasonable', () => {
|
|
35
|
+
const out = describeDeployFailure({ ...base, error_stage: 'deploy', error_retryable: true }, ID);
|
|
36
|
+
expect(out).toMatch(/retrying is reasonable/i);
|
|
37
|
+
});
|
|
38
|
+
it('does not invite a retry when the failure is theirs', () => {
|
|
39
|
+
// Telling someone to retry a broken build wastes four minutes per attempt.
|
|
40
|
+
const out = describeDeployFailure({ ...base, error_stage: 'build', error_retryable: false }, ID);
|
|
41
|
+
expect(out).not.toMatch(/retrying is reasonable/i);
|
|
42
|
+
});
|
|
43
|
+
it('offers both logs when the platform did not say which stage', () => {
|
|
44
|
+
// Older backends, and any future status that predates the field.
|
|
45
|
+
const out = describeDeployFailure(base, ID);
|
|
46
|
+
expect(out).toContain(`build-logs ${ID}`);
|
|
47
|
+
expect(out).toContain(`logs ${ID}`);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -13,6 +13,7 @@ export declare function create(nameArg: string | undefined, flags: Flags): Promi
|
|
|
13
13
|
export declare function list(flags: Flags): Promise<void>;
|
|
14
14
|
export declare function get(id: string, flags: Flags): Promise<void>;
|
|
15
15
|
export declare function healthCheck(id: string, flags: Flags): Promise<void>;
|
|
16
|
+
export declare function describeDeployFailure(c: sdkContainer.Container, id: string): string;
|
|
16
17
|
export declare function del(id: string, flags: Flags): Promise<void>;
|
|
17
18
|
export declare function _checkProbePath(hc: string): string;
|
|
18
19
|
export declare function _isTarball(p: string): boolean;
|
|
@@ -277,6 +277,39 @@ export async function healthCheck(id, flags) {
|
|
|
277
277
|
? ` The runtime now waits for ${value} to answer before sending traffic to a new revision.`
|
|
278
278
|
: ' No startup probe: a new revision takes traffic as soon as the runtime reports it started.');
|
|
279
279
|
}
|
|
280
|
+
// What to say when a deploy fails, and where to send them.
|
|
281
|
+
//
|
|
282
|
+
// One fixed sentence used to cover every failure: "Build/deploy failed — check
|
|
283
|
+
// `myapi container logs <id>`". A customer read thirty lines of healthy nginx
|
|
284
|
+
// after a ROLLOUT failure — the image had built, served two 200s to our own
|
|
285
|
+
// startup probes, then taken a SIGTERM — and a second deploy of the same code
|
|
286
|
+
// succeeded unchanged. The message sent them to look for a defect in code that
|
|
287
|
+
// was fine.
|
|
288
|
+
//
|
|
289
|
+
// The platform now says which stage failed and whether it is worth retrying,
|
|
290
|
+
// so the CLI can stop guessing. `build` is their image; `deploy` is our rollout
|
|
291
|
+
// of an image that built, which is the case where their application logs are
|
|
292
|
+
// the wrong place to look.
|
|
293
|
+
export function describeDeployFailure(c, id) {
|
|
294
|
+
const lines = [c.error?.trim() || 'The deploy failed.'];
|
|
295
|
+
if (c.error_stage === 'build') {
|
|
296
|
+
lines.push(` Your image did not build: myapi container build-logs ${id}`);
|
|
297
|
+
}
|
|
298
|
+
else if (c.error_stage === 'deploy') {
|
|
299
|
+
// Said explicitly, because "check the logs" is what cost the customer a
|
|
300
|
+
// deploy: the image built and ran, so the application logs look healthy.
|
|
301
|
+
lines.push(' The image built — this failed while we rolled it out, so your');
|
|
302
|
+
lines.push(' application logs will look healthy and are not the place to look.');
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
lines.push(` Build logs: myapi container build-logs ${id}`);
|
|
306
|
+
lines.push(` Runtime logs: myapi container logs ${id}`);
|
|
307
|
+
}
|
|
308
|
+
if (c.error_retryable) {
|
|
309
|
+
lines.push(' This one is ours and retrying is reasonable: myapi container deploy ' + id + ' --source <dir>');
|
|
310
|
+
}
|
|
311
|
+
return lines.join('\n');
|
|
312
|
+
}
|
|
280
313
|
export async function del(id, flags) {
|
|
281
314
|
const config = requireConfig();
|
|
282
315
|
const orgId = requireOrg(flags, config, 'myapi container delete <id> [--yes] [--org <id>]');
|
|
@@ -421,7 +454,7 @@ export async function deploy(id, image, flags) {
|
|
|
421
454
|
check: () => sdkContainer.getContainer(config.api_key, orgId, id),
|
|
422
455
|
isDone: (c) => c.status === 'active',
|
|
423
456
|
isFailed: (c) => c.status === 'build_error' || c.status === 'deploy_error',
|
|
424
|
-
failedMessage:
|
|
457
|
+
failedMessage: (c) => describeDeployFailure(c, id),
|
|
425
458
|
timeoutMs: 600_000,
|
|
426
459
|
intervalMs: 5_000,
|
|
427
460
|
});
|
package/dist/utils.d.ts
CHANGED
|
@@ -20,8 +20,15 @@ export interface PollOptions<T> {
|
|
|
20
20
|
intervalMs?: number;
|
|
21
21
|
/** Message shown via error() on timeout. Defaults to a generic phrase. */
|
|
22
22
|
timeoutMessage?: string;
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Message shown via error() when isFailed returns true.
|
|
25
|
+
*
|
|
26
|
+
* A function when the useful message depends on WHY it failed. `container
|
|
27
|
+
* deploy` printed one fixed sentence for every failure, so a rollout problem
|
|
28
|
+
* and a broken build read identically — a customer spent a deploy reading
|
|
29
|
+
* healthy nginx logs because the sentence sent them there.
|
|
30
|
+
*/
|
|
31
|
+
failedMessage?: string | ((state: T) => string);
|
|
25
32
|
}
|
|
26
33
|
/**
|
|
27
34
|
* Generic spinner+poll helper. Used wherever the CLI kicks off a long-running
|
package/dist/utils.js
CHANGED
|
@@ -46,7 +46,10 @@ export async function pollJob(opts) {
|
|
|
46
46
|
}
|
|
47
47
|
if (opts.isFailed && opts.isFailed(state)) {
|
|
48
48
|
clearLine();
|
|
49
|
-
|
|
49
|
+
const msg = typeof opts.failedMessage === 'function'
|
|
50
|
+
? opts.failedMessage(state)
|
|
51
|
+
: opts.failedMessage;
|
|
52
|
+
error(msg ?? `${opts.label} failed`);
|
|
50
53
|
}
|
|
51
54
|
spinnerWrite(`\r${opts.label} ${spinnerFrame(i++)}`);
|
|
52
55
|
await sleep(intervalMs);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myapihq/cli",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "2.31.
|
|
4
|
+
"version": "2.31.1",
|
|
5
5
|
"description": "MyAPI command-line interface",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"lint:skills:strict": "node scripts/copy-skills.js && node scripts/lint-skills.js --strict"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@myapihq/sdk": "^2.31.
|
|
50
|
+
"@myapihq/sdk": "^2.31.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/node": "^25.6.0",
|