@faable/faable 4.24.0 → 4.25.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.
package/dist/api/FaableApi.js
CHANGED
|
@@ -341,6 +341,17 @@ class FaableApi {
|
|
|
341
341
|
// Rebuild a failed deployment from its recorded source (CAS manifest or
|
|
342
342
|
// git ref). The API enforces the guards: failed phase only, never older
|
|
343
343
|
// than what production serves.
|
|
344
|
+
// Tasks (one-off commands in a copy of the app's pod; api `task/`).
|
|
345
|
+
async createTask(team, body) {
|
|
346
|
+
return data(this.client.post(`/task`, body, {
|
|
347
|
+
headers: projectHeader(team)
|
|
348
|
+
}));
|
|
349
|
+
}
|
|
350
|
+
async getTask(task_id, team) {
|
|
351
|
+
return data(this.client.get(`/task/${task_id}`, {
|
|
352
|
+
headers: projectHeader(team)
|
|
353
|
+
}));
|
|
354
|
+
}
|
|
344
355
|
async redeployDeployment(deployment_id, team) {
|
|
345
356
|
return data(this.client.post(`/deployment/${deployment_id}/redeploy`, undefined, { headers: projectHeader(team) }));
|
|
346
357
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { github } from './github/index.js';
|
|
2
1
|
import { link } from '../link/index.js';
|
|
3
2
|
import { apps, apps_list_legacy } from './apps/index.js';
|
|
4
3
|
import { domains } from './domains/index.js';
|
|
4
|
+
import { github } from './github/index.js';
|
|
5
5
|
import { capture_deploy_help } from './help.js';
|
|
6
6
|
import { cancel } from './inspect/cancel.js';
|
|
7
7
|
import { deployments } from './inspect/deployments.js';
|
|
@@ -9,6 +9,7 @@ import { inspect } from './inspect/inspect.js';
|
|
|
9
9
|
import { logs } from './inspect/logs.js';
|
|
10
10
|
import { open_app } from './inspect/open.js';
|
|
11
11
|
import { redeploy } from './inspect/redeploy.js';
|
|
12
|
+
import { run } from './inspect/run.js';
|
|
12
13
|
import { status } from './inspect/status.js';
|
|
13
14
|
import { traffic } from './inspect/traffic.js';
|
|
14
15
|
import { trigger } from './inspect/trigger.js';
|
|
@@ -43,6 +44,7 @@ const deploy = {
|
|
|
43
44
|
.command(waf)
|
|
44
45
|
.command(logs)
|
|
45
46
|
.command(status)
|
|
47
|
+
.command(run)
|
|
46
48
|
.command(traffic)
|
|
47
49
|
.command(usage)
|
|
48
50
|
.command(quota)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { requireApi } from '../../../api/context.js';
|
|
2
|
+
import { CliError } from '../../../lib/errors.js';
|
|
3
|
+
import { print_json, json_option } from '../../../lib/listing.js';
|
|
4
|
+
import { log } from '../../../log.js';
|
|
5
|
+
import { resolve_app_id } from '../resolve_app_id.js';
|
|
6
|
+
import { waitForTask } from './task_wait.js';
|
|
7
|
+
|
|
8
|
+
const run = {
|
|
9
|
+
command: 'run',
|
|
10
|
+
// Hidden until the WordPress blueprint is published (api `/task` is
|
|
11
|
+
// internal: blueprint apps and staff only). Then: the describe below.
|
|
12
|
+
// 'Run a one-off command with the image, variables and volumes of the live deployment'
|
|
13
|
+
describe: false,
|
|
14
|
+
builder: yargs => json_option(yargs)
|
|
15
|
+
.parserConfiguration({ 'populate--': true })
|
|
16
|
+
.option('app', {
|
|
17
|
+
alias: 'a',
|
|
18
|
+
type: 'string',
|
|
19
|
+
description: 'App id, name or slug (defaults to the linked app)'
|
|
20
|
+
})
|
|
21
|
+
.option('wait', {
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
default: true,
|
|
24
|
+
description: 'Wait for the result and print its output (--no-wait to only queue it)'
|
|
25
|
+
})
|
|
26
|
+
.option('timeout', {
|
|
27
|
+
type: 'number',
|
|
28
|
+
description: 'Seconds before the task is stopped (default 900, max 3600)'
|
|
29
|
+
})
|
|
30
|
+
.example('$0 deploy run -a my-blog -- wp plugin list', 'wp-cli on a WordPress app')
|
|
31
|
+
.example('$0 deploy run -- node scripts/migrate.js', 'A script of your own app')
|
|
32
|
+
.showHelpOnFail(false),
|
|
33
|
+
handler: async (args) => {
|
|
34
|
+
const argv = (args['--'] ?? []).map(String);
|
|
35
|
+
if (argv.length === 0) {
|
|
36
|
+
throw new CliError('usage', 'Say what to run after --, e.g. faable deploy run -- wp plugin list');
|
|
37
|
+
}
|
|
38
|
+
const ctx = await requireApi();
|
|
39
|
+
const app_id = await resolve_app_id(args.app, ctx.appId, ctx.api);
|
|
40
|
+
const app = await ctx.api.getApp(app_id);
|
|
41
|
+
const queued = await ctx.api.createTask(app.team, {
|
|
42
|
+
app_id,
|
|
43
|
+
argv,
|
|
44
|
+
...(args.timeout ? { timeout_s: args.timeout } : {})
|
|
45
|
+
});
|
|
46
|
+
if (!args.wait) {
|
|
47
|
+
if (args.json)
|
|
48
|
+
return print_json(queued);
|
|
49
|
+
log.info(`🧰 Queued ${queued.id} on ${app.name}.`);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!args.json)
|
|
53
|
+
log.info(`🧰 ${argv.join(' ')} on ${app.name} (${queued.id})`);
|
|
54
|
+
const done = await waitForTask(() => ctx.api.getTask(queued.id, app.team), {
|
|
55
|
+
onStatus: s => {
|
|
56
|
+
if (!args.json && s === 'running')
|
|
57
|
+
log.info('… running');
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (args.json) {
|
|
61
|
+
print_json(done);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
if (done.output_tail)
|
|
65
|
+
process.stdout.write(done.output_tail.replace(/\n?$/, '\n'));
|
|
66
|
+
const how = done.status === 'succeeded'
|
|
67
|
+
? '✅ Done'
|
|
68
|
+
: done.status === 'timed_out'
|
|
69
|
+
? '⏱️ Timed out'
|
|
70
|
+
: `❌ ${done.reason ?? 'Failed'}`;
|
|
71
|
+
log.info(`${how}${done.exit_code != null ? ` (exit ${done.exit_code})` : ''}`);
|
|
72
|
+
}
|
|
73
|
+
// The command's own exit code, so scripts can branch on it.
|
|
74
|
+
if (done.status !== 'succeeded')
|
|
75
|
+
process.exitCode = done.exit_code || 1;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export { run };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const DONE = new Set(['succeeded', 'failed', 'timed_out', 'canceled']);
|
|
2
|
+
const POLL_MS = 3000;
|
|
3
|
+
/** Polls a task until it is done (or the caller's patience runs out). */
|
|
4
|
+
const waitForTask = async (get, opts = {}) => {
|
|
5
|
+
const sleep = opts.sleep ?? (ms => new Promise(r => setTimeout(r, ms)));
|
|
6
|
+
let last = '';
|
|
7
|
+
for (;;) {
|
|
8
|
+
const t = await get();
|
|
9
|
+
if (t.status !== last)
|
|
10
|
+
opts.onStatus?.(t.status);
|
|
11
|
+
last = t.status;
|
|
12
|
+
if (DONE.has(t.status))
|
|
13
|
+
return t;
|
|
14
|
+
await sleep(POLL_MS);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { waitForTask };
|