@nocobase/cli 2.1.0-beta.9 → 2.2.0-beta.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.
- package/assets/env-proxy/nginx/app.conf.tpl +23 -0
- package/assets/env-proxy/nginx/nocobase.conf.tpl +5 -0
- package/assets/env-proxy/nginx/snippets/dist-location.conf +5 -0
- package/assets/env-proxy/nginx/snippets/gzip.conf +17 -0
- package/assets/env-proxy/nginx/snippets/log-format-http.conf +13 -0
- package/assets/env-proxy/nginx/snippets/maps-http.conf +14 -0
- package/assets/env-proxy/nginx/snippets/mime-types.conf +98 -0
- package/assets/env-proxy/nginx/snippets/proxy-location.conf +17 -0
- package/assets/env-proxy/nginx/snippets/spa-location.conf +6 -0
- package/assets/env-proxy/nginx/snippets/uploads-location.conf +21 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +145 -0
- package/bin/session-env.js +39 -0
- package/dist/commands/api/resource/create.js +15 -0
- package/dist/commands/api/resource/destroy.js +15 -0
- package/dist/commands/api/resource/get.js +15 -0
- package/dist/commands/api/resource/index.js +20 -0
- package/dist/commands/api/resource/list.js +16 -0
- package/dist/commands/api/resource/query.js +15 -0
- package/dist/commands/api/resource/update.js +15 -0
- package/dist/commands/app/autostart/disable.js +55 -0
- package/dist/commands/app/autostart/enable.js +55 -0
- package/dist/commands/app/autostart/list.js +37 -0
- package/dist/commands/app/autostart/run.js +84 -0
- package/dist/commands/app/autostart/shared.js +49 -0
- package/dist/commands/app/destroy.js +234 -0
- package/dist/commands/app/down.js +71 -0
- package/dist/commands/app/logs.js +115 -0
- package/dist/commands/app/restart.js +229 -0
- package/dist/commands/app/shared.js +123 -0
- package/dist/commands/app/start.js +416 -0
- package/dist/commands/app/stop.js +183 -0
- package/dist/commands/app/upgrade.js +523 -0
- package/dist/commands/backup/create.js +147 -0
- package/dist/commands/backup/index.js +20 -0
- package/dist/commands/backup/restore.js +105 -0
- package/{src/cli.js → dist/commands/build.js} +4 -11
- package/dist/commands/config/delete.js +42 -0
- package/dist/commands/config/get.js +39 -0
- package/dist/commands/config/index.js +20 -0
- package/dist/commands/config/list.js +29 -0
- package/dist/commands/config/set.js +49 -0
- package/dist/commands/db/check.js +240 -0
- package/dist/commands/db/logs.js +85 -0
- package/dist/commands/db/ps.js +47 -0
- package/dist/commands/db/shared.js +96 -0
- package/dist/commands/db/start.js +86 -0
- package/dist/commands/db/stop.js +71 -0
- package/{templates/plugin/src/client/models/index.ts → dist/commands/dev.js} +4 -4
- package/{src/commands/locale/react-js-cron/index.js → dist/commands/down.js} +3 -8
- package/dist/commands/download.js +13 -0
- package/dist/commands/env/add.js +406 -0
- package/dist/commands/env/auth.js +189 -0
- package/dist/commands/env/current.js +21 -0
- package/dist/commands/env/info.js +202 -0
- package/dist/commands/env/list.js +43 -0
- package/dist/commands/env/remove.js +174 -0
- package/dist/commands/env/shared.js +204 -0
- package/dist/commands/env/status.js +93 -0
- package/dist/commands/env/update.js +448 -0
- package/dist/commands/env/use.js +38 -0
- package/dist/commands/examples/prompts-stages.js +150 -0
- package/dist/commands/examples/prompts-test.js +181 -0
- package/dist/commands/init.js +1390 -0
- package/dist/commands/install.js +2609 -0
- package/dist/commands/license/activate.js +179 -0
- package/dist/commands/license/env.js +94 -0
- package/dist/commands/license/generate-id.js +108 -0
- package/dist/commands/license/id.js +70 -0
- package/dist/commands/license/index.js +20 -0
- package/dist/commands/license/plugins/clean.js +115 -0
- package/dist/commands/license/plugins/index.js +20 -0
- package/dist/commands/license/plugins/list.js +64 -0
- package/dist/commands/license/plugins/shared.js +382 -0
- package/dist/commands/license/plugins/sync.js +314 -0
- package/dist/commands/license/shared.js +423 -0
- package/dist/commands/license/status.js +64 -0
- package/dist/commands/logs.js +12 -0
- package/dist/commands/plugin/disable.js +86 -0
- package/dist/commands/plugin/enable.js +86 -0
- package/dist/commands/plugin/import.js +108 -0
- package/dist/commands/plugin/list.js +82 -0
- package/dist/commands/pm/disable.js +12 -0
- package/dist/commands/pm/enable.js +12 -0
- package/dist/commands/pm/list.js +12 -0
- package/dist/commands/proxy/caddy/current.js +17 -0
- package/dist/commands/proxy/caddy/generate.js +69 -0
- package/dist/commands/proxy/caddy/index.js +28 -0
- package/dist/commands/proxy/caddy/info.js +31 -0
- package/dist/commands/proxy/caddy/reload.js +30 -0
- package/dist/commands/proxy/caddy/restart.js +28 -0
- package/dist/commands/proxy/caddy/start.js +30 -0
- package/dist/commands/proxy/caddy/status.js +19 -0
- package/dist/commands/proxy/caddy/stop.js +30 -0
- package/dist/commands/proxy/caddy/use.js +26 -0
- package/dist/commands/proxy/index.js +28 -0
- package/dist/commands/proxy/nginx/current.js +18 -0
- package/dist/commands/proxy/nginx/generate.js +68 -0
- package/dist/commands/proxy/nginx/index.js +28 -0
- package/dist/commands/proxy/nginx/info.js +34 -0
- package/dist/commands/proxy/nginx/reload.js +30 -0
- package/dist/commands/proxy/nginx/restart.js +28 -0
- package/dist/commands/proxy/nginx/start.js +30 -0
- package/dist/commands/proxy/nginx/status.js +19 -0
- package/dist/commands/proxy/nginx/stop.js +30 -0
- package/dist/commands/proxy/nginx/use.js +31 -0
- package/dist/commands/restart.js +12 -0
- package/dist/commands/revision/create.js +118 -0
- package/dist/commands/scaffold/migration.js +38 -0
- package/dist/commands/scaffold/plugin.js +37 -0
- package/dist/commands/self/check.js +71 -0
- package/dist/commands/self/index.js +20 -0
- package/dist/commands/self/update.js +152 -0
- package/dist/commands/session/id.js +24 -0
- package/dist/commands/session/remove.js +57 -0
- package/dist/commands/session/setup.js +62 -0
- package/dist/commands/skills/check.js +69 -0
- package/dist/commands/skills/index.js +20 -0
- package/dist/commands/skills/install.js +80 -0
- package/dist/commands/skills/remove.js +80 -0
- package/dist/commands/skills/update.js +87 -0
- package/dist/commands/source/build.js +58 -0
- package/dist/commands/source/dev.js +182 -0
- package/dist/commands/source/download.js +884 -0
- package/dist/commands/source/publish.js +109 -0
- package/dist/commands/source/registry/logs.js +70 -0
- package/dist/commands/source/registry/start.js +57 -0
- package/dist/commands/source/registry/status.js +33 -0
- package/dist/commands/source/registry/stop.js +48 -0
- package/dist/commands/source/test.js +476 -0
- package/dist/commands/start.js +12 -0
- package/dist/commands/stop.js +12 -0
- package/dist/commands/test.js +12 -0
- package/dist/commands/upgrade.js +12 -0
- package/dist/commands/v1.js +210 -0
- package/dist/generated/command-registry.js +134 -0
- package/dist/help/runtime-help.js +23 -0
- package/dist/lib/api-client.js +335 -0
- package/dist/lib/api-command-compat.js +641 -0
- package/dist/lib/app-health.js +139 -0
- package/dist/lib/app-managed-resources.js +337 -0
- package/dist/lib/app-public-path.js +80 -0
- package/dist/lib/app-runtime.js +189 -0
- package/dist/lib/auth-store.js +528 -0
- package/dist/lib/backup.js +171 -0
- package/dist/lib/bootstrap.js +409 -0
- package/dist/lib/build-config.js +18 -0
- package/dist/lib/builtin-db.js +86 -0
- package/dist/lib/cli-config.js +569 -0
- package/dist/lib/cli-entry-error.js +52 -0
- package/dist/lib/cli-home.js +47 -0
- package/dist/lib/cli-locale.js +141 -0
- package/dist/lib/command-discovery.js +39 -0
- package/dist/lib/command-log.js +284 -0
- package/dist/lib/db-connection-check.js +219 -0
- package/dist/lib/docker-env-file.js +60 -0
- package/dist/lib/docker-image.js +37 -0
- package/dist/lib/docker-log-stream.js +45 -0
- package/dist/lib/env-auth.js +963 -0
- package/dist/lib/env-command-config.js +45 -0
- package/dist/lib/env-config.js +108 -0
- package/dist/lib/env-guard.js +61 -0
- package/dist/lib/env-paths.js +101 -0
- package/dist/lib/env-proxy.js +1325 -0
- package/dist/lib/generated-command.js +203 -0
- package/dist/lib/http-request.js +49 -0
- package/dist/lib/inquirer-theme.js +17 -0
- package/dist/lib/inquirer.js +243 -0
- package/dist/lib/managed-env-file.js +101 -0
- package/dist/lib/managed-init-env.js +32 -0
- package/dist/lib/naming.js +70 -0
- package/dist/lib/object-utils.js +76 -0
- package/dist/lib/openapi.js +62 -0
- package/dist/lib/plugin-import.js +279 -0
- package/dist/lib/plugin-storage.js +64 -0
- package/dist/lib/post-processors.js +23 -0
- package/dist/lib/prompt-catalog-core.js +186 -0
- package/dist/lib/prompt-catalog-terminal.js +374 -0
- package/{src/index.js → dist/lib/prompt-catalog.js} +2 -6
- package/dist/lib/prompt-validators.js +278 -0
- package/dist/lib/prompt-web-ui.js +2234 -0
- package/dist/lib/proxy-caddy.js +274 -0
- package/dist/lib/proxy-nginx.js +330 -0
- package/dist/lib/resource-command.js +357 -0
- package/dist/lib/resource-request.js +104 -0
- package/dist/lib/run-npm.js +429 -0
- package/dist/lib/runtime-env-vars.js +32 -0
- package/dist/lib/runtime-generator.js +498 -0
- package/dist/lib/runtime-store.js +56 -0
- package/dist/lib/self-manager.js +301 -0
- package/dist/lib/session-id.js +17 -0
- package/dist/lib/session-integration.js +703 -0
- package/dist/lib/session-store.js +118 -0
- package/dist/lib/skills-manager.js +438 -0
- package/dist/lib/source-publish.js +326 -0
- package/dist/lib/source-registry.js +188 -0
- package/dist/lib/startup-update.js +309 -0
- package/dist/lib/ui.js +159 -0
- package/dist/locale/en-US.json +526 -0
- package/dist/locale/zh-CN.json +526 -0
- package/dist/post-processors/data-modeling.js +84 -0
- package/dist/post-processors/data-source-manager.js +138 -0
- package/dist/post-processors/index.js +19 -0
- package/nocobase-ctl.config.json +388 -0
- package/package.json +128 -24
- package/scripts/build.mjs +34 -0
- package/scripts/clean.mjs +9 -0
- package/tsconfig.json +19 -0
- package/bin/index.js +0 -39
- package/nocobase.conf.tpl +0 -95
- package/src/commands/benchmark.js +0 -73
- package/src/commands/build.js +0 -49
- package/src/commands/clean.js +0 -30
- package/src/commands/client.js +0 -166
- package/src/commands/create-nginx-conf.js +0 -37
- package/src/commands/create-plugin.js +0 -33
- package/src/commands/dev.js +0 -200
- package/src/commands/doc.js +0 -76
- package/src/commands/e2e.js +0 -265
- package/src/commands/global.js +0 -43
- package/src/commands/index.js +0 -45
- package/src/commands/instance-id.js +0 -47
- package/src/commands/locale/cronstrue.js +0 -122
- package/src/commands/locale/react-js-cron/en-US.json +0 -75
- package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
- package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
- package/src/commands/locale.js +0 -81
- package/src/commands/p-test.js +0 -88
- package/src/commands/perf.js +0 -63
- package/src/commands/pkg.js +0 -321
- package/src/commands/pm2.js +0 -37
- package/src/commands/postinstall.js +0 -88
- package/src/commands/start.js +0 -148
- package/src/commands/tar.js +0 -36
- package/src/commands/test-coverage.js +0 -55
- package/src/commands/test.js +0 -107
- package/src/commands/umi.js +0 -33
- package/src/commands/update-deps.js +0 -72
- package/src/commands/upgrade.js +0 -47
- package/src/commands/view-license-key.js +0 -44
- package/src/license.js +0 -76
- package/src/logger.js +0 -75
- package/src/plugin-generator.js +0 -80
- package/src/util.js +0 -517
- package/templates/bundle-status.html +0 -338
- package/templates/create-app-package.json +0 -39
- package/templates/plugin/.npmignore.tpl +0 -2
- package/templates/plugin/README.md.tpl +0 -1
- package/templates/plugin/client.d.ts +0 -2
- package/templates/plugin/client.js +0 -1
- package/templates/plugin/package.json.tpl +0 -11
- package/templates/plugin/server.d.ts +0 -2
- package/templates/plugin/server.js +0 -1
- package/templates/plugin/src/client/client.d.ts +0 -249
- package/templates/plugin/src/client/index.tsx.tpl +0 -1
- package/templates/plugin/src/client/locale.ts +0 -21
- package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
- package/templates/plugin/src/index.ts +0 -2
- package/templates/plugin/src/locale/en-US.json +0 -1
- package/templates/plugin/src/locale/zh-CN.json +0 -1
- package/templates/plugin/src/server/collections/.gitkeep +0 -0
- package/templates/plugin/src/server/index.ts.tpl +0 -1
- package/templates/plugin/src/server/plugin.ts.tpl +0 -19
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Command, Flags } from '@oclif/core';
|
|
10
|
+
import { BACKUP_RUNTIME_COMMANDS, buildBackupEnvArgv, ensureBackupRuntimeCommands, resolveBackupRestoreFilePath, resolveBackupTargetEnv, resolveBackupWaitApiBaseUrl, runBackupCliCommand, } from '../../lib/backup.js';
|
|
11
|
+
import { waitForAppReady } from '../../lib/app-health.js';
|
|
12
|
+
import { ensureCrossEnvConfirmed, hasExplicitEnvSelection } from '../../lib/env-guard.js';
|
|
13
|
+
import { confirm } from "../../lib/inquirer.js";
|
|
14
|
+
import { announceTargetEnv, failTask, isInteractiveTerminal, startTask, stopTask, succeedTask } from '../../lib/ui.js';
|
|
15
|
+
async function confirmBackupRestore(envName, filePath, force) {
|
|
16
|
+
if (force) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (!isInteractiveTerminal()) {
|
|
20
|
+
throw new Error(`\`nb backup restore\` needs confirmation. Re-run with \`--force\` to restore ${filePath} into "${envName}" in non-interactive mode.`);
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
return await confirm({
|
|
24
|
+
message: `Restore backup "${filePath}" into "${envName}"? This will overwrite application data.`,
|
|
25
|
+
default: false,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export default class BackupRestore extends Command {
|
|
33
|
+
static summary = 'Restore a backup file into the selected env';
|
|
34
|
+
static examples = [
|
|
35
|
+
'<%= config.bin %> <%= command.id %> --file ./fixtures/base.nbdump --force',
|
|
36
|
+
'<%= config.bin %> <%= command.id %> --env e2e --file ./fixtures/base.nbdump --yes --force',
|
|
37
|
+
];
|
|
38
|
+
static flags = {
|
|
39
|
+
env: Flags.string({
|
|
40
|
+
char: 'e',
|
|
41
|
+
description: 'CLI env name to restore into. Defaults to the current env when omitted',
|
|
42
|
+
}),
|
|
43
|
+
yes: Flags.boolean({
|
|
44
|
+
char: 'y',
|
|
45
|
+
description: 'Confirm using --env when it targets a different env than the current env',
|
|
46
|
+
default: false,
|
|
47
|
+
}),
|
|
48
|
+
file: Flags.string({
|
|
49
|
+
char: 'f',
|
|
50
|
+
description: 'Local backup file to upload and restore',
|
|
51
|
+
required: true,
|
|
52
|
+
}),
|
|
53
|
+
force: Flags.boolean({
|
|
54
|
+
description: 'Confirm overwriting application data during restore',
|
|
55
|
+
default: false,
|
|
56
|
+
}),
|
|
57
|
+
};
|
|
58
|
+
async run() {
|
|
59
|
+
const { flags } = await this.parse(BackupRestore);
|
|
60
|
+
const requestedEnv = flags.env?.trim() || undefined;
|
|
61
|
+
const explicitEnvSelection = Boolean(requestedEnv && hasExplicitEnvSelection(this.argv));
|
|
62
|
+
if (explicitEnvSelection) {
|
|
63
|
+
const confirmed = await ensureCrossEnvConfirmed({
|
|
64
|
+
command: this,
|
|
65
|
+
requestedEnv,
|
|
66
|
+
yes: flags.yes,
|
|
67
|
+
});
|
|
68
|
+
if (!confirmed) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const filePath = await resolveBackupRestoreFilePath(flags.file);
|
|
73
|
+
const { envName, env } = await resolveBackupTargetEnv(requestedEnv);
|
|
74
|
+
const restoreConfirmed = await confirmBackupRestore(envName, filePath, flags.force);
|
|
75
|
+
if (!restoreConfirmed) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const envArgv = buildBackupEnvArgv({
|
|
79
|
+
requestedEnv,
|
|
80
|
+
explicitEnvSelection,
|
|
81
|
+
yes: flags.yes,
|
|
82
|
+
});
|
|
83
|
+
announceTargetEnv(envName);
|
|
84
|
+
await ensureBackupRuntimeCommands({
|
|
85
|
+
envName,
|
|
86
|
+
env,
|
|
87
|
+
commandIds: [BACKUP_RUNTIME_COMMANDS.restoreUpload],
|
|
88
|
+
});
|
|
89
|
+
startTask(`Restoring backup for "${envName}" from ${filePath}...`);
|
|
90
|
+
try {
|
|
91
|
+
await runBackupCliCommand(['api', 'backup', 'restore-upload', '--file', filePath, '--force', ...envArgv], { errorName: 'nb api backup restore-upload' });
|
|
92
|
+
stopTask();
|
|
93
|
+
await waitForAppReady({
|
|
94
|
+
envName,
|
|
95
|
+
apiBaseUrl: resolveBackupWaitApiBaseUrl(env),
|
|
96
|
+
});
|
|
97
|
+
succeedTask(`Backup restored for "${envName}" from ${filePath}`);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
stopTask();
|
|
101
|
+
failTask(`Failed to restore backup for "${envName}".`);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -6,14 +6,7 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const cli = new Command();
|
|
14
|
-
|
|
15
|
-
cli.version(require('../package.json').version);
|
|
16
|
-
|
|
17
|
-
commands(cli);
|
|
18
|
-
|
|
19
|
-
module.exports = cli;
|
|
9
|
+
import SourceBuild from './source/build.js';
|
|
10
|
+
export default class Build extends SourceBuild {
|
|
11
|
+
static hidden = true;
|
|
12
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Args, Command } from '@oclif/core';
|
|
10
|
+
import { assertSupportedCliConfigKey, deleteCliConfigValue } from '../../lib/cli-config.js';
|
|
11
|
+
import { clearLegacyStartupUpdatePolicyForCurrentInstall } from '../../lib/startup-update.js';
|
|
12
|
+
export default class ConfigDelete extends Command {
|
|
13
|
+
static summary = 'Delete an explicitly configured CLI setting';
|
|
14
|
+
static examples = [
|
|
15
|
+
'<%= config.bin %> <%= command.id %> locale',
|
|
16
|
+
'<%= config.bin %> <%= command.id %> update.policy',
|
|
17
|
+
'<%= config.bin %> <%= command.id %> docker.network',
|
|
18
|
+
'<%= config.bin %> <%= command.id %> docker.container-prefix',
|
|
19
|
+
'<%= config.bin %> <%= command.id %> bin.docker',
|
|
20
|
+
'<%= config.bin %> <%= command.id %> bin.caddy',
|
|
21
|
+
'<%= config.bin %> <%= command.id %> bin.git',
|
|
22
|
+
'<%= config.bin %> <%= command.id %> bin.nginx',
|
|
23
|
+
'<%= config.bin %> <%= command.id %> proxy.nb-cli-root',
|
|
24
|
+
'<%= config.bin %> <%= command.id %> proxy.upstream-host',
|
|
25
|
+
'<%= config.bin %> <%= command.id %> bin.yarn',
|
|
26
|
+
'<%= config.bin %> <%= command.id %> log.enabled',
|
|
27
|
+
'<%= config.bin %> <%= command.id %> log.retention-days',
|
|
28
|
+
];
|
|
29
|
+
static args = {
|
|
30
|
+
key: Args.string({
|
|
31
|
+
description: 'Configuration key',
|
|
32
|
+
required: true,
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
async run() {
|
|
36
|
+
const { args } = await this.parse(ConfigDelete);
|
|
37
|
+
const key = assertSupportedCliConfigKey(args.key);
|
|
38
|
+
const removed = await deleteCliConfigValue(key);
|
|
39
|
+
const clearedLegacy = key === 'update.policy' ? await clearLegacyStartupUpdatePolicyForCurrentInstall() : false;
|
|
40
|
+
this.log(removed || clearedLegacy ? `Deleted ${key}` : `${key} was not set`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Args, Command } from '@oclif/core';
|
|
10
|
+
import { assertSupportedCliConfigKey, getCliConfigValue } from '../../lib/cli-config.js';
|
|
11
|
+
export default class ConfigGet extends Command {
|
|
12
|
+
static summary = 'Get the effective CLI configuration value for a key';
|
|
13
|
+
static examples = [
|
|
14
|
+
'<%= config.bin %> <%= command.id %> locale',
|
|
15
|
+
'<%= config.bin %> <%= command.id %> update.policy',
|
|
16
|
+
'<%= config.bin %> <%= command.id %> docker.network',
|
|
17
|
+
'<%= config.bin %> <%= command.id %> docker.container-prefix',
|
|
18
|
+
'<%= config.bin %> <%= command.id %> bin.docker',
|
|
19
|
+
'<%= config.bin %> <%= command.id %> bin.caddy',
|
|
20
|
+
'<%= config.bin %> <%= command.id %> bin.git',
|
|
21
|
+
'<%= config.bin %> <%= command.id %> bin.nginx',
|
|
22
|
+
'<%= config.bin %> <%= command.id %> proxy.nb-cli-root',
|
|
23
|
+
'<%= config.bin %> <%= command.id %> proxy.upstream-host',
|
|
24
|
+
'<%= config.bin %> <%= command.id %> bin.yarn',
|
|
25
|
+
'<%= config.bin %> <%= command.id %> log.enabled',
|
|
26
|
+
'<%= config.bin %> <%= command.id %> log.retention-days',
|
|
27
|
+
];
|
|
28
|
+
static args = {
|
|
29
|
+
key: Args.string({
|
|
30
|
+
description: 'Configuration key',
|
|
31
|
+
required: true,
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
async run() {
|
|
35
|
+
const { args } = await this.parse(ConfigGet);
|
|
36
|
+
const key = assertSupportedCliConfigKey(args.key);
|
|
37
|
+
this.log(await getCliConfigValue(key));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Command, loadHelpClass } from '@oclif/core';
|
|
10
|
+
export default class Config extends Command {
|
|
11
|
+
static summary = 'Manage CLI configuration defaults';
|
|
12
|
+
async run() {
|
|
13
|
+
await this.parse(Config);
|
|
14
|
+
const Help = await loadHelpClass(this.config);
|
|
15
|
+
await new Help(this.config, this.config.pjson.oclif.helpOptions ?? this.config.pjson.helpOptions).showHelp([
|
|
16
|
+
this.id ?? 'config',
|
|
17
|
+
...this.argv,
|
|
18
|
+
]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Command } from '@oclif/core';
|
|
10
|
+
import { listExplicitCliConfigValues, SUPPORTED_CLI_CONFIG_KEYS } from '../../lib/cli-config.js';
|
|
11
|
+
import { renderTable } from '../../lib/ui.js';
|
|
12
|
+
export default class ConfigList extends Command {
|
|
13
|
+
static summary = 'List explicitly configured CLI settings';
|
|
14
|
+
static examples = [
|
|
15
|
+
'<%= config.bin %> <%= command.id %>',
|
|
16
|
+
];
|
|
17
|
+
async run() {
|
|
18
|
+
await this.parse(ConfigList);
|
|
19
|
+
const values = await listExplicitCliConfigValues();
|
|
20
|
+
const rows = SUPPORTED_CLI_CONFIG_KEYS
|
|
21
|
+
.filter((key) => Boolean(values[key]))
|
|
22
|
+
.map((key) => [key, values[key] ?? '']);
|
|
23
|
+
if (!rows.length) {
|
|
24
|
+
this.log('No CLI config values are set.');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.log(renderTable(['Key', 'Value'], rows));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Args, Command } from '@oclif/core';
|
|
10
|
+
import { assertSupportedCliConfigKey, setCliConfigValue } from '../../lib/cli-config.js';
|
|
11
|
+
import { clearLegacyStartupUpdatePolicyForCurrentInstall } from '../../lib/startup-update.js';
|
|
12
|
+
export default class ConfigSet extends Command {
|
|
13
|
+
static summary = 'Set a CLI configuration value';
|
|
14
|
+
static description = 'Set a CLI configuration value for a supported configuration key.';
|
|
15
|
+
static examples = [
|
|
16
|
+
'<%= config.bin %> <%= command.id %> locale zh-CN',
|
|
17
|
+
'<%= config.bin %> <%= command.id %> update.policy prompt',
|
|
18
|
+
'<%= config.bin %> <%= command.id %> docker.network nocobase',
|
|
19
|
+
'<%= config.bin %> <%= command.id %> docker.container-prefix nb',
|
|
20
|
+
'<%= config.bin %> <%= command.id %> bin.docker /usr/local/bin/docker',
|
|
21
|
+
'<%= config.bin %> <%= command.id %> bin.caddy /usr/bin/caddy',
|
|
22
|
+
'<%= config.bin %> <%= command.id %> bin.git /usr/bin/git',
|
|
23
|
+
'<%= config.bin %> <%= command.id %> bin.nginx /usr/sbin/nginx',
|
|
24
|
+
'<%= config.bin %> <%= command.id %> proxy.nb-cli-root /workspace',
|
|
25
|
+
'<%= config.bin %> <%= command.id %> proxy.upstream-host host.docker.internal',
|
|
26
|
+
'<%= config.bin %> <%= command.id %> bin.yarn yarn',
|
|
27
|
+
'<%= config.bin %> <%= command.id %> log.enabled false',
|
|
28
|
+
'<%= config.bin %> <%= command.id %> log.retention-days 14',
|
|
29
|
+
];
|
|
30
|
+
static args = {
|
|
31
|
+
key: Args.string({
|
|
32
|
+
description: 'Configuration key',
|
|
33
|
+
required: true,
|
|
34
|
+
}),
|
|
35
|
+
value: Args.string({
|
|
36
|
+
description: 'Configuration value',
|
|
37
|
+
required: true,
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
40
|
+
async run() {
|
|
41
|
+
const { args } = await this.parse(ConfigSet);
|
|
42
|
+
const key = assertSupportedCliConfigKey(args.key);
|
|
43
|
+
const value = await setCliConfigValue(key, args.value);
|
|
44
|
+
if (key === 'update.policy') {
|
|
45
|
+
await clearLegacyStartupUpdatePolicyForCurrentInstall();
|
|
46
|
+
}
|
|
47
|
+
this.log(`${key}=${value}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Command, Flags } from '@oclif/core';
|
|
10
|
+
import { formatMissingManagedAppEnvMessage, resolveManagedAppRuntime } from '../../lib/app-runtime.js';
|
|
11
|
+
import { resolveBuiltinDbConnection } from '../../lib/builtin-db.js';
|
|
12
|
+
import { checkExternalDbConnection, formatDbCheckAddress, readExternalDbConnectionConfig, } from "../../lib/db-connection-check.js";
|
|
13
|
+
import { DEFAULT_DOCKER_REGISTRY, DEFAULT_DOCKER_VERSION, resolveDockerImageRef, } from "../../lib/docker-image.js";
|
|
14
|
+
import { commandOutput } from '../../lib/run-npm.js';
|
|
15
|
+
import { validateTcpPort } from "../../lib/prompt-validators.js";
|
|
16
|
+
function trimValue(value) {
|
|
17
|
+
const text = String(value ?? '').trim();
|
|
18
|
+
return text || undefined;
|
|
19
|
+
}
|
|
20
|
+
function resolveRequiredDbField(flagValue, envValue) {
|
|
21
|
+
return trimValue(flagValue) ?? trimValue(envValue);
|
|
22
|
+
}
|
|
23
|
+
function normalizeDockerPlatform(value) {
|
|
24
|
+
const text = trimValue(value);
|
|
25
|
+
if (!text || text === 'auto') {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
if (text === 'linux/amd64' || text === 'linux/arm64') {
|
|
29
|
+
return text;
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
function formatMissingFieldsMessage(missing, hasEnv) {
|
|
34
|
+
return [
|
|
35
|
+
'Missing database settings for connectivity check.',
|
|
36
|
+
`Required: ${missing.join(', ')}.`,
|
|
37
|
+
hasEnv
|
|
38
|
+
? 'Pass `--env <name>` to reuse a saved env, or provide the missing `--db-*` flags explicitly.'
|
|
39
|
+
: 'Provide all required `--db-*` flags explicitly, or pass `--env <name>` to reuse a saved env.',
|
|
40
|
+
].join('\n');
|
|
41
|
+
}
|
|
42
|
+
function resolveDbConfigFromFlags(flags, envConfig) {
|
|
43
|
+
return {
|
|
44
|
+
builtinDb: false,
|
|
45
|
+
dbDialect: resolveRequiredDbField(flags['db-dialect'], envConfig?.dbDialect),
|
|
46
|
+
dbHost: resolveRequiredDbField(flags['db-host'], envConfig?.dbHost),
|
|
47
|
+
dbPort: resolveRequiredDbField(flags['db-port'], envConfig?.dbPort),
|
|
48
|
+
dbDatabase: resolveRequiredDbField(flags['db-database'], envConfig?.dbDatabase),
|
|
49
|
+
dbUser: resolveRequiredDbField(flags['db-user'], envConfig?.dbUser),
|
|
50
|
+
dbPassword: flags['db-password'] !== undefined
|
|
51
|
+
? String(flags['db-password'] ?? '')
|
|
52
|
+
: envConfig?.dbPassword !== undefined
|
|
53
|
+
? String(envConfig.dbPassword ?? '')
|
|
54
|
+
: undefined,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function validateDbConfigOrThrow(command, dbConfig, hasEnv) {
|
|
58
|
+
const missing = [];
|
|
59
|
+
if (!dbConfig.dbDialect) {
|
|
60
|
+
missing.push('--db-dialect');
|
|
61
|
+
}
|
|
62
|
+
if (!dbConfig.dbHost) {
|
|
63
|
+
missing.push('--db-host');
|
|
64
|
+
}
|
|
65
|
+
if (!dbConfig.dbPort) {
|
|
66
|
+
missing.push('--db-port');
|
|
67
|
+
}
|
|
68
|
+
if (!dbConfig.dbDatabase) {
|
|
69
|
+
missing.push('--db-database');
|
|
70
|
+
}
|
|
71
|
+
if (!dbConfig.dbUser) {
|
|
72
|
+
missing.push('--db-user');
|
|
73
|
+
}
|
|
74
|
+
if (!dbConfig.dbPassword) {
|
|
75
|
+
missing.push('--db-password');
|
|
76
|
+
}
|
|
77
|
+
if (missing.length > 0) {
|
|
78
|
+
command.error(formatMissingFieldsMessage(missing, hasEnv));
|
|
79
|
+
}
|
|
80
|
+
const portError = validateTcpPort(dbConfig.dbPort);
|
|
81
|
+
if (portError) {
|
|
82
|
+
command.error(portError);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function resolveDbCheckInput(command, flags) {
|
|
86
|
+
const envName = flags.env?.trim() || undefined;
|
|
87
|
+
if (!envName) {
|
|
88
|
+
const dbConfig = resolveDbConfigFromFlags(flags);
|
|
89
|
+
validateDbConfigOrThrow(command, dbConfig, false);
|
|
90
|
+
return {
|
|
91
|
+
dbConfig,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const runtime = await resolveManagedAppRuntime(envName);
|
|
95
|
+
if (!runtime) {
|
|
96
|
+
command.error(formatMissingManagedAppEnvMessage(envName));
|
|
97
|
+
}
|
|
98
|
+
const envConfig = { ...runtime.env.config };
|
|
99
|
+
if ((runtime.kind === 'local' || runtime.kind === 'docker') && runtime.env.config.builtinDb) {
|
|
100
|
+
const builtinDbConnection = await resolveBuiltinDbConnection(runtime);
|
|
101
|
+
envConfig.dbHost = builtinDbConnection.dbHost;
|
|
102
|
+
envConfig.dbPort = builtinDbConnection.dbPort;
|
|
103
|
+
envConfig.dbDialect = builtinDbConnection.dbDialect;
|
|
104
|
+
}
|
|
105
|
+
const dbConfig = resolveDbConfigFromFlags(flags, envConfig);
|
|
106
|
+
validateDbConfigOrThrow(command, dbConfig, true);
|
|
107
|
+
return {
|
|
108
|
+
envName: runtime.envName,
|
|
109
|
+
kind: runtime.kind,
|
|
110
|
+
runtime: runtime,
|
|
111
|
+
dbConfig,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function buildConnectionConfigOrThrow(command, dbConfig) {
|
|
115
|
+
const connectionConfig = readExternalDbConnectionConfig(dbConfig);
|
|
116
|
+
if (!connectionConfig) {
|
|
117
|
+
command.error('Unsupported or incomplete database settings for connectivity check.');
|
|
118
|
+
}
|
|
119
|
+
return connectionConfig;
|
|
120
|
+
}
|
|
121
|
+
async function runExplicitDbCheck(command, dbConfig) {
|
|
122
|
+
const connectionConfig = buildConnectionConfigOrThrow(command, dbConfig);
|
|
123
|
+
const address = formatDbCheckAddress(connectionConfig);
|
|
124
|
+
const validationError = await checkExternalDbConnection(connectionConfig);
|
|
125
|
+
return {
|
|
126
|
+
ok: !validationError,
|
|
127
|
+
dialect: connectionConfig.dialect,
|
|
128
|
+
address,
|
|
129
|
+
error: validationError ?? null,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async function runDockerDbCheck(command, runtime, dbConfig) {
|
|
133
|
+
const connectionConfig = buildConnectionConfigOrThrow(command, dbConfig);
|
|
134
|
+
const config = runtime.env.config ?? {};
|
|
135
|
+
const imageRef = resolveDockerImageRef(config.dockerRegistry, config.downloadVersion, {
|
|
136
|
+
defaultRegistry: DEFAULT_DOCKER_REGISTRY,
|
|
137
|
+
defaultVersion: DEFAULT_DOCKER_VERSION,
|
|
138
|
+
});
|
|
139
|
+
const args = [
|
|
140
|
+
'run',
|
|
141
|
+
'--rm',
|
|
142
|
+
'--network',
|
|
143
|
+
runtime.dockerNetworkName || runtime.workspaceName,
|
|
144
|
+
];
|
|
145
|
+
const dockerPlatform = normalizeDockerPlatform(config.dockerPlatform);
|
|
146
|
+
if (dockerPlatform) {
|
|
147
|
+
args.push('--platform', dockerPlatform);
|
|
148
|
+
}
|
|
149
|
+
args.push('--entrypoint', 'nb', imageRef, 'db', 'check', '--db-dialect', connectionConfig.dialect, '--db-host', connectionConfig.host, '--db-port', String(connectionConfig.port), '--db-database', connectionConfig.database, '--db-user', connectionConfig.user, '--db-password', connectionConfig.password, '--json');
|
|
150
|
+
const output = await commandOutput('docker', args, {
|
|
151
|
+
errorName: 'docker run',
|
|
152
|
+
});
|
|
153
|
+
let payload;
|
|
154
|
+
try {
|
|
155
|
+
payload = JSON.parse(output);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
command.error(`Failed to parse database check response from Docker: ${output}`);
|
|
159
|
+
}
|
|
160
|
+
const ok = Boolean(payload.ok);
|
|
161
|
+
const dialect = trimValue(payload.dialect) || connectionConfig.dialect;
|
|
162
|
+
const address = trimValue(payload.address) || formatDbCheckAddress(connectionConfig);
|
|
163
|
+
const error = trimValue(payload.error) || null;
|
|
164
|
+
return {
|
|
165
|
+
ok,
|
|
166
|
+
dialect,
|
|
167
|
+
address,
|
|
168
|
+
error,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
async function runDbCheckForRuntime(command, runtime, dbConfig) {
|
|
172
|
+
if (runtime.kind === 'docker') {
|
|
173
|
+
return await runDockerDbCheck(command, runtime, dbConfig);
|
|
174
|
+
}
|
|
175
|
+
if (runtime.kind === 'local') {
|
|
176
|
+
return await runExplicitDbCheck(command, dbConfig);
|
|
177
|
+
}
|
|
178
|
+
command.error(`Env "${runtime.envName}" does not support automatic database connectivity checks.`);
|
|
179
|
+
}
|
|
180
|
+
export default class DbCheck extends Command {
|
|
181
|
+
static description = 'Check whether a database is reachable using the selected env settings or explicit `--db-*` flags.';
|
|
182
|
+
static examples = [
|
|
183
|
+
'<%= config.bin %> <%= command.id %> --env app1',
|
|
184
|
+
'<%= config.bin %> <%= command.id %> --env app1 --db-password new-secret --json',
|
|
185
|
+
'<%= config.bin %> <%= command.id %> --db-dialect postgres --db-host 127.0.0.1 --db-port 5432 --db-database nocobase --db-user nocobase --db-password secret',
|
|
186
|
+
];
|
|
187
|
+
static flags = {
|
|
188
|
+
env: Flags.string({
|
|
189
|
+
char: 'e',
|
|
190
|
+
description: 'CLI env name to read saved database settings from. Defaults to the current env when omitted',
|
|
191
|
+
}),
|
|
192
|
+
'db-dialect': Flags.string({
|
|
193
|
+
description: 'Database dialect: postgres, kingbase, mysql, or mariadb.',
|
|
194
|
+
options: ['postgres', 'kingbase', 'mysql', 'mariadb'],
|
|
195
|
+
}),
|
|
196
|
+
'db-host': Flags.string({
|
|
197
|
+
description: 'Database host name or IP address.',
|
|
198
|
+
}),
|
|
199
|
+
'db-port': Flags.string({
|
|
200
|
+
description: 'Database TCP port.',
|
|
201
|
+
}),
|
|
202
|
+
'db-database': Flags.string({
|
|
203
|
+
description: 'Database name.',
|
|
204
|
+
}),
|
|
205
|
+
'db-user': Flags.string({
|
|
206
|
+
description: 'Database username.',
|
|
207
|
+
}),
|
|
208
|
+
'db-password': Flags.string({
|
|
209
|
+
description: 'Database password.',
|
|
210
|
+
}),
|
|
211
|
+
json: Flags.boolean({
|
|
212
|
+
description: 'Output the check result as JSON.',
|
|
213
|
+
default: false,
|
|
214
|
+
}),
|
|
215
|
+
};
|
|
216
|
+
async run() {
|
|
217
|
+
const { flags } = await this.parse(DbCheck);
|
|
218
|
+
const input = await resolveDbCheckInput(this, flags);
|
|
219
|
+
const result = input.runtime
|
|
220
|
+
? await runDbCheckForRuntime(this, input.runtime, input.dbConfig)
|
|
221
|
+
: await runExplicitDbCheck(this, input.dbConfig);
|
|
222
|
+
if (flags.json) {
|
|
223
|
+
this.log(JSON.stringify({
|
|
224
|
+
ok: result.ok,
|
|
225
|
+
env: input.envName,
|
|
226
|
+
kind: input.kind,
|
|
227
|
+
dialect: result.dialect,
|
|
228
|
+
address: result.address,
|
|
229
|
+
error: result.error,
|
|
230
|
+
}, null, 2));
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (!result.ok) {
|
|
234
|
+
this.error(result.error ?? 'Database check failed.');
|
|
235
|
+
}
|
|
236
|
+
this.log(input.envName
|
|
237
|
+
? `Database check passed for env "${input.envName}" (${result.dialect} ${result.address}).`
|
|
238
|
+
: `Database check passed (${result.dialect} ${result.address}).`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Command, Flags } from '@oclif/core';
|
|
10
|
+
import { formatMissingManagedAppEnvMessage } from '../../lib/app-runtime.js';
|
|
11
|
+
import { run } from '../../lib/run-npm.js';
|
|
12
|
+
import { printInfo } from '../../lib/ui.js';
|
|
13
|
+
import { formatUnmanagedDbLogsMessage, resolveDbRuntime } from './shared.js';
|
|
14
|
+
function formatDbLogsFailure(envName, message) {
|
|
15
|
+
if (/does not exist/i.test(message)) {
|
|
16
|
+
return [
|
|
17
|
+
`Can't show database logs for "${envName}" yet.`,
|
|
18
|
+
'The saved built-in database container for this env could not be found on this machine.',
|
|
19
|
+
'Try reinstalling the env, or check whether the container was removed outside the CLI.',
|
|
20
|
+
`Details: ${message}`,
|
|
21
|
+
].join('\n');
|
|
22
|
+
}
|
|
23
|
+
return [
|
|
24
|
+
`Couldn't show database logs for "${envName}".`,
|
|
25
|
+
'Check that the built-in database runtime for this env is still available, then try again.',
|
|
26
|
+
`Details: ${message}`,
|
|
27
|
+
].join('\n');
|
|
28
|
+
}
|
|
29
|
+
export default class DbLogs extends Command {
|
|
30
|
+
static description = 'Show logs for the built-in database container of the selected env.';
|
|
31
|
+
static examples = [
|
|
32
|
+
'<%= config.bin %> <%= command.id %>',
|
|
33
|
+
'<%= config.bin %> <%= command.id %> --env app1',
|
|
34
|
+
'<%= config.bin %> <%= command.id %> --env app1 --tail 200',
|
|
35
|
+
'<%= config.bin %> <%= command.id %> --env app1 --no-follow',
|
|
36
|
+
];
|
|
37
|
+
static flags = {
|
|
38
|
+
env: Flags.string({
|
|
39
|
+
char: 'e',
|
|
40
|
+
description: 'CLI env name to inspect built-in database logs for. Defaults to the current env when omitted',
|
|
41
|
+
}),
|
|
42
|
+
tail: Flags.integer({
|
|
43
|
+
description: 'Number of recent log lines to show before following',
|
|
44
|
+
default: 100,
|
|
45
|
+
min: 0,
|
|
46
|
+
}),
|
|
47
|
+
follow: Flags.boolean({
|
|
48
|
+
char: 'f',
|
|
49
|
+
description: 'Keep streaming new log lines',
|
|
50
|
+
default: false,
|
|
51
|
+
allowNo: true,
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
async run() {
|
|
55
|
+
const { flags } = await this.parse(DbLogs);
|
|
56
|
+
const requestedEnv = flags.env?.trim() || undefined;
|
|
57
|
+
const runtime = await resolveDbRuntime(requestedEnv);
|
|
58
|
+
if (!runtime) {
|
|
59
|
+
this.error(formatMissingManagedAppEnvMessage(requestedEnv));
|
|
60
|
+
}
|
|
61
|
+
if (runtime.kind !== 'builtin') {
|
|
62
|
+
this.error(formatUnmanagedDbLogsMessage(runtime));
|
|
63
|
+
}
|
|
64
|
+
const tail = String(flags.tail ?? 100);
|
|
65
|
+
const follow = flags.follow === true;
|
|
66
|
+
printInfo(follow
|
|
67
|
+
? `Showing built-in database logs for "${runtime.envName}" (press Ctrl+C to stop).`
|
|
68
|
+
: `Showing recent built-in database logs for "${runtime.envName}".`);
|
|
69
|
+
const dockerArgs = ['logs', '--tail', tail];
|
|
70
|
+
if (follow) {
|
|
71
|
+
dockerArgs.push('--follow');
|
|
72
|
+
}
|
|
73
|
+
dockerArgs.push(runtime.containerName);
|
|
74
|
+
try {
|
|
75
|
+
await run('docker', dockerArgs, {
|
|
76
|
+
errorName: 'docker logs',
|
|
77
|
+
stdio: 'inherit',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
82
|
+
this.error(formatDbLogsFailure(runtime.envName, message));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|