@nocobase/cli 2.1.0-beta.46 → 2.1.0-beta.47
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/commands/app/destroy.js +3 -3
- 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 +28 -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 +28 -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/revision/create.js +31 -2
- package/dist/lib/auth-store.js +8 -0
- package/dist/lib/cli-config.js +73 -1
- package/dist/lib/env-proxy.js +105 -75
- package/dist/lib/proxy-caddy.js +274 -0
- package/dist/lib/proxy-nginx.js +330 -0
- package/dist/locale/en-US.json +2 -2
- package/dist/locale/zh-CN.json +2 -2
- package/package.json +2 -2
- package/dist/commands/env/proxy/caddy.js +0 -28
- package/dist/commands/env/proxy/index.js +0 -353
- package/dist/commands/env/proxy/nginx.js +0 -28
|
@@ -53,7 +53,7 @@ function buildDestroyPrompt(runtime, options) {
|
|
|
53
53
|
if (options.removesManagedLocalAppFiles) {
|
|
54
54
|
lines.push('CLI-managed local app files will also be removed.');
|
|
55
55
|
}
|
|
56
|
-
lines.push('Env-specific proxy entry files generated by `nb
|
|
56
|
+
lines.push('Env-specific proxy entry files generated by `nb proxy` will also be removed when present.');
|
|
57
57
|
if (options.removesStorageData) {
|
|
58
58
|
lines.push('Storage data will be removed.');
|
|
59
59
|
}
|
|
@@ -204,11 +204,11 @@ export default class AppDestroy extends Command {
|
|
|
204
204
|
resolveEnvProxyEntryDir(runtime.envName, { provider: 'caddy' }),
|
|
205
205
|
path.dirname(resolveLegacyNginxEnvProxyAppOutputPath(runtime.envName)),
|
|
206
206
|
];
|
|
207
|
-
startTask(`Removing
|
|
207
|
+
startTask(`Removing proxy entry files for "${runtime.envName}"...`);
|
|
208
208
|
for (const proxyEntryDir of proxyEntryDirs) {
|
|
209
209
|
await removePathIfExists(proxyEntryDir, `proxy entry files for "${runtime.envName}"`);
|
|
210
210
|
}
|
|
211
|
-
succeedTask(`
|
|
211
|
+
succeedTask(`Proxy entry files removed for "${runtime.envName}".`);
|
|
212
212
|
const configuredStoragePath = resolveConfiguredStoragePath(runtime.env.config);
|
|
213
213
|
if (configuredStoragePath) {
|
|
214
214
|
startTask(`Removing storage data for "${runtime.envName}"...`);
|
|
@@ -0,0 +1,17 @@
|
|
|
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 { getCaddyProxyDriver } from '../../../lib/proxy-caddy.js';
|
|
11
|
+
export default class ProxyCaddyCurrent extends Command {
|
|
12
|
+
static summary = 'Print the current caddy runtime driver';
|
|
13
|
+
async run() {
|
|
14
|
+
await this.parse(ProxyCaddyCurrent);
|
|
15
|
+
this.log(await getCaddyProxyDriver());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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 { getCaddyProxyDriver, writeCaddyProxyBundle, resolveCaddyProxyRuntimeContext, } from '../../../lib/proxy-caddy.js';
|
|
12
|
+
import { normalizeProxyListenPort } from '../../../lib/proxy-nginx.js';
|
|
13
|
+
import { announceTargetEnv, failTask, startTask, succeedTask } from '../../../lib/ui.js';
|
|
14
|
+
export default class ProxyCaddyGenerate extends Command {
|
|
15
|
+
static summary = 'Generate caddy proxy files for one managed env';
|
|
16
|
+
static examples = [
|
|
17
|
+
'<%= config.bin %> proxy caddy generate --env app1 --host app1.example.com',
|
|
18
|
+
'<%= config.bin %> proxy caddy generate --env app1 --host app1.example.com --port 8080',
|
|
19
|
+
];
|
|
20
|
+
static flags = {
|
|
21
|
+
env: Flags.string({
|
|
22
|
+
char: 'e',
|
|
23
|
+
description: 'CLI env name to generate proxy files for',
|
|
24
|
+
required: true,
|
|
25
|
+
}),
|
|
26
|
+
host: Flags.string({
|
|
27
|
+
description: 'Host exposed by the caddy site block, such as example.com or localhost',
|
|
28
|
+
}),
|
|
29
|
+
port: Flags.string({
|
|
30
|
+
description: 'Port exposed by the caddy site block, not the upstream NocoBase app port',
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
async run() {
|
|
34
|
+
const { flags } = await this.parse(ProxyCaddyGenerate);
|
|
35
|
+
const requestedEnv = flags.env?.trim() || undefined;
|
|
36
|
+
const requestedPort = flags.port?.trim() || undefined;
|
|
37
|
+
const normalizedPort = normalizeProxyListenPort(requestedPort);
|
|
38
|
+
if (requestedPort && !normalizedPort) {
|
|
39
|
+
this.error(`Invalid proxy entry port "${requestedPort}". Use an integer between 1 and 65535.`);
|
|
40
|
+
}
|
|
41
|
+
const runtime = await resolveManagedAppRuntime(requestedEnv);
|
|
42
|
+
if (!runtime) {
|
|
43
|
+
this.error(formatMissingManagedAppEnvMessage(requestedEnv));
|
|
44
|
+
}
|
|
45
|
+
if (runtime.kind === 'http') {
|
|
46
|
+
this.error(`Can't generate a caddy proxy config for "${runtime.envName}" from this machine because the env only has an API connection.`);
|
|
47
|
+
}
|
|
48
|
+
if (runtime.kind === 'ssh') {
|
|
49
|
+
this.error(`Can't generate a caddy proxy config for "${runtime.envName}" yet because SSH envs are not implemented.`);
|
|
50
|
+
}
|
|
51
|
+
const driver = await getCaddyProxyDriver();
|
|
52
|
+
const runtimeContext = await resolveCaddyProxyRuntimeContext();
|
|
53
|
+
announceTargetEnv(runtime.envName);
|
|
54
|
+
startTask(`Generating caddy proxy config for env "${runtime.envName}" with the ${driver} driver...`);
|
|
55
|
+
try {
|
|
56
|
+
const { bundle, status } = await writeCaddyProxyBundle(runtime, {
|
|
57
|
+
host: flags.host?.trim() || undefined,
|
|
58
|
+
port: normalizedPort,
|
|
59
|
+
}, runtimeContext);
|
|
60
|
+
succeedTask(status === 'created'
|
|
61
|
+
? `Saved caddy proxy files for env "${runtime.envName}" under ${bundle.entryDir}, and created app.caddy at ${bundle.appConfigPath}.`
|
|
62
|
+
: `Saved caddy proxy files for env "${runtime.envName}" under ${bundle.entryDir}, and refreshed app.caddy at ${bundle.appConfigPath}.`);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
failTask(`Failed to generate caddy proxy config for env "${runtime.envName}".`);
|
|
66
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 ProxyCaddy extends Command {
|
|
11
|
+
static summary = 'Manage caddy proxy generation and runtime selection';
|
|
12
|
+
static examples = [
|
|
13
|
+
'<%= config.bin %> proxy caddy current',
|
|
14
|
+
'<%= config.bin %> proxy caddy use local',
|
|
15
|
+
'<%= config.bin %> proxy caddy generate --env app1 --host app1.example.com',
|
|
16
|
+
'<%= config.bin %> proxy caddy start',
|
|
17
|
+
'<%= config.bin %> proxy caddy status',
|
|
18
|
+
'<%= config.bin %> proxy caddy info',
|
|
19
|
+
];
|
|
20
|
+
async run() {
|
|
21
|
+
await this.parse(ProxyCaddy);
|
|
22
|
+
const Help = await loadHelpClass(this.config);
|
|
23
|
+
await new Help(this.config, this.config.pjson.oclif.helpOptions ?? this.config.pjson.helpOptions).showHelp([
|
|
24
|
+
this.id ?? 'proxy caddy',
|
|
25
|
+
...this.argv,
|
|
26
|
+
]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 { getCliConfigValue } from '../../../lib/cli-config.js';
|
|
11
|
+
import { mapProxyPathFromCliRoot, resolveEnvProxyMainOutputPath } from '../../../lib/env-proxy.js';
|
|
12
|
+
import { formatCaddyProxyInfoLines, resolveCaddyProxyContainerName, resolveCaddyProxyImage, resolveCaddyProxyRuntimeContext, } from '../../../lib/proxy-caddy.js';
|
|
13
|
+
export default class ProxyCaddyInfo extends Command {
|
|
14
|
+
static summary = 'Show current caddy proxy driver and generated path info';
|
|
15
|
+
async run() {
|
|
16
|
+
await this.parse(ProxyCaddyInfo);
|
|
17
|
+
const runtimeContext = await resolveCaddyProxyRuntimeContext();
|
|
18
|
+
const lines = formatCaddyProxyInfoLines({
|
|
19
|
+
driver: runtimeContext.driver,
|
|
20
|
+
configFile: await mapProxyPathFromCliRoot(resolveEnvProxyMainOutputPath({ provider: 'caddy' }), {
|
|
21
|
+
runtimeCliRoot: runtimeContext.runtimeCliRoot,
|
|
22
|
+
}),
|
|
23
|
+
upstreamHost: runtimeContext.upstreamHost,
|
|
24
|
+
caddyBinary: await getCliConfigValue('bin.caddy'),
|
|
25
|
+
runtimeRoot: runtimeContext.runtimeCliRoot,
|
|
26
|
+
containerName: await resolveCaddyProxyContainerName(),
|
|
27
|
+
image: resolveCaddyProxyImage(),
|
|
28
|
+
});
|
|
29
|
+
this.log(lines.join('\n'));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { getCaddyProxyDriver, reloadCaddyProxy, resolveCaddyProxyRuntimeContext } from '../../../lib/proxy-caddy.js';
|
|
11
|
+
import { failTask, startTask, succeedTask } from '../../../lib/ui.js';
|
|
12
|
+
export default class ProxyCaddyReload extends Command {
|
|
13
|
+
static summary = 'Reload the managed caddy proxy';
|
|
14
|
+
async run() {
|
|
15
|
+
await this.parse(ProxyCaddyReload);
|
|
16
|
+
const driver = await getCaddyProxyDriver();
|
|
17
|
+
const runtimeContext = await resolveCaddyProxyRuntimeContext();
|
|
18
|
+
startTask(`Reloading caddy proxy with the ${driver} driver...`);
|
|
19
|
+
try {
|
|
20
|
+
await reloadCaddyProxy(runtimeContext);
|
|
21
|
+
succeedTask(`Caddy proxy reloaded with the ${driver} driver.`);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
failTask(`Failed to reload caddy proxy with the ${driver} driver.`);
|
|
25
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { getCaddyProxyDriver, resolveCaddyProxyRuntimeContext, restartCaddyProxy } from '../../../lib/proxy-caddy.js';
|
|
11
|
+
import { failTask, startTask, succeedTask } from '../../../lib/ui.js';
|
|
12
|
+
export default class ProxyCaddyRestart extends Command {
|
|
13
|
+
static summary = 'Restart the managed caddy proxy';
|
|
14
|
+
async run() {
|
|
15
|
+
await this.parse(ProxyCaddyRestart);
|
|
16
|
+
const driver = await getCaddyProxyDriver();
|
|
17
|
+
const runtimeContext = await resolveCaddyProxyRuntimeContext();
|
|
18
|
+
startTask(`Restarting caddy proxy with the ${driver} driver...`);
|
|
19
|
+
try {
|
|
20
|
+
await restartCaddyProxy(runtimeContext);
|
|
21
|
+
succeedTask(`Caddy proxy restarted with the ${driver} driver.`);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
failTask(`Failed to restart caddy proxy with the ${driver} driver.`);
|
|
25
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { getCaddyProxyDriver, resolveCaddyProxyRuntimeContext, startCaddyProxy } from '../../../lib/proxy-caddy.js';
|
|
11
|
+
import { failTask, startTask, succeedTask } from '../../../lib/ui.js';
|
|
12
|
+
export default class ProxyCaddyStart extends Command {
|
|
13
|
+
static summary = 'Start the managed caddy proxy';
|
|
14
|
+
async run() {
|
|
15
|
+
await this.parse(ProxyCaddyStart);
|
|
16
|
+
const driver = await getCaddyProxyDriver();
|
|
17
|
+
const runtimeContext = await resolveCaddyProxyRuntimeContext();
|
|
18
|
+
startTask(`Starting caddy proxy with the ${driver} driver...`);
|
|
19
|
+
try {
|
|
20
|
+
const result = await startCaddyProxy(runtimeContext);
|
|
21
|
+
succeedTask(result === 'already-running'
|
|
22
|
+
? `Caddy proxy is already running with the ${driver} driver.`
|
|
23
|
+
: `Caddy proxy started with the ${driver} driver.`);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
failTask(`Failed to start caddy proxy with the ${driver} driver.`);
|
|
27
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { formatCaddyProxyStatusLines, getCaddyProxyStatus, resolveCaddyProxyRuntimeContext, } from '../../../lib/proxy-caddy.js';
|
|
11
|
+
export default class ProxyCaddyStatus extends Command {
|
|
12
|
+
static summary = 'Show the current caddy proxy runtime status';
|
|
13
|
+
async run() {
|
|
14
|
+
await this.parse(ProxyCaddyStatus);
|
|
15
|
+
const runtimeContext = await resolveCaddyProxyRuntimeContext();
|
|
16
|
+
const status = await getCaddyProxyStatus(runtimeContext);
|
|
17
|
+
this.log(formatCaddyProxyStatusLines(status).join('\n'));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { getCaddyProxyDriver, resolveCaddyProxyRuntimeContext, stopCaddyProxy } from '../../../lib/proxy-caddy.js';
|
|
11
|
+
import { failTask, startTask, succeedTask } from '../../../lib/ui.js';
|
|
12
|
+
export default class ProxyCaddyStop extends Command {
|
|
13
|
+
static summary = 'Stop the managed caddy proxy';
|
|
14
|
+
async run() {
|
|
15
|
+
await this.parse(ProxyCaddyStop);
|
|
16
|
+
const driver = await getCaddyProxyDriver();
|
|
17
|
+
const runtimeContext = await resolveCaddyProxyRuntimeContext();
|
|
18
|
+
startTask(`Stopping caddy proxy with the ${driver} driver...`);
|
|
19
|
+
try {
|
|
20
|
+
const result = await stopCaddyProxy(runtimeContext);
|
|
21
|
+
succeedTask(result === 'already-stopped'
|
|
22
|
+
? `Caddy proxy is already stopped with the ${driver} driver.`
|
|
23
|
+
: `Caddy proxy stopped with the ${driver} driver.`);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
failTask(`Failed to stop caddy proxy with the ${driver} driver.`);
|
|
27
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 { CADDY_PROXY_DRIVER_OPTIONS } from '../../../lib/cli-config.js';
|
|
11
|
+
import { setCaddyProxyDriver } from '../../../lib/proxy-caddy.js';
|
|
12
|
+
export default class ProxyCaddyUse extends Command {
|
|
13
|
+
static summary = 'Select the caddy runtime driver';
|
|
14
|
+
static args = {
|
|
15
|
+
driver: Args.string({
|
|
16
|
+
description: 'caddy runtime driver',
|
|
17
|
+
options: [...CADDY_PROXY_DRIVER_OPTIONS],
|
|
18
|
+
required: true,
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
async run() {
|
|
22
|
+
const { args } = await this.parse(ProxyCaddyUse);
|
|
23
|
+
const driver = await setCaddyProxyDriver(args.driver);
|
|
24
|
+
this.log(driver);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 Proxy extends Command {
|
|
11
|
+
static summary = 'Manage reverse proxy providers for CLI-managed apps';
|
|
12
|
+
static description = 'Use `nb proxy nginx` or `nb proxy caddy` to manage reverse proxy workflows.';
|
|
13
|
+
static examples = [
|
|
14
|
+
'<%= config.bin %> proxy nginx current',
|
|
15
|
+
'<%= config.bin %> proxy nginx use docker',
|
|
16
|
+
'<%= config.bin %> proxy nginx generate --env app1 --host app1.example.com',
|
|
17
|
+
'<%= config.bin %> proxy caddy current',
|
|
18
|
+
'<%= config.bin %> proxy caddy use docker',
|
|
19
|
+
];
|
|
20
|
+
async run() {
|
|
21
|
+
await this.parse(Proxy);
|
|
22
|
+
const Help = await loadHelpClass(this.config);
|
|
23
|
+
await new Help(this.config, this.config.pjson.oclif.helpOptions ?? this.config.pjson.helpOptions).showHelp([
|
|
24
|
+
this.id ?? 'proxy',
|
|
25
|
+
...this.argv,
|
|
26
|
+
]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 { getNginxProxyDriver } from '../../../lib/proxy-nginx.js';
|
|
11
|
+
export default class ProxyNginxCurrent extends Command {
|
|
12
|
+
static summary = 'Print the current nginx runtime driver';
|
|
13
|
+
async run() {
|
|
14
|
+
await this.parse(ProxyNginxCurrent);
|
|
15
|
+
const driver = await getNginxProxyDriver();
|
|
16
|
+
this.log(driver);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { getNginxProxyDriver, normalizeProxyListenPort, resolveNginxProxyRuntimeContext, writeNginxProxyBundle, } from '../../../lib/proxy-nginx.js';
|
|
12
|
+
import { announceTargetEnv, failTask, startTask, succeedTask } from '../../../lib/ui.js';
|
|
13
|
+
export default class ProxyNginxGenerate extends Command {
|
|
14
|
+
static summary = 'Generate nginx proxy files for one managed env';
|
|
15
|
+
static examples = [
|
|
16
|
+
'<%= config.bin %> proxy nginx generate --env app1 --host app1.example.com',
|
|
17
|
+
'<%= config.bin %> proxy nginx generate --env app1 --host app1.example.com --port 8080',
|
|
18
|
+
];
|
|
19
|
+
static flags = {
|
|
20
|
+
env: Flags.string({
|
|
21
|
+
char: 'e',
|
|
22
|
+
description: 'CLI env name to generate proxy files for',
|
|
23
|
+
required: true,
|
|
24
|
+
}),
|
|
25
|
+
host: Flags.string({
|
|
26
|
+
description: 'Host exposed by the nginx entry config, such as example.com or localhost',
|
|
27
|
+
}),
|
|
28
|
+
port: Flags.string({
|
|
29
|
+
description: 'Port exposed by the nginx entry config, not the upstream NocoBase app port',
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
async run() {
|
|
33
|
+
const { flags } = await this.parse(ProxyNginxGenerate);
|
|
34
|
+
const requestedEnv = flags.env?.trim() || undefined;
|
|
35
|
+
const requestedPort = flags.port?.trim() || undefined;
|
|
36
|
+
const normalizedPort = normalizeProxyListenPort(requestedPort);
|
|
37
|
+
if (requestedPort && !normalizedPort) {
|
|
38
|
+
this.error(`Invalid proxy entry port "${requestedPort}". Use an integer between 1 and 65535.`);
|
|
39
|
+
}
|
|
40
|
+
const runtime = await resolveManagedAppRuntime(requestedEnv);
|
|
41
|
+
if (!runtime) {
|
|
42
|
+
this.error(formatMissingManagedAppEnvMessage(requestedEnv));
|
|
43
|
+
}
|
|
44
|
+
if (runtime.kind === 'http') {
|
|
45
|
+
this.error(`Can't generate an nginx proxy config for "${runtime.envName}" from this machine because the env only has an API connection.`);
|
|
46
|
+
}
|
|
47
|
+
if (runtime.kind === 'ssh') {
|
|
48
|
+
this.error(`Can't generate an nginx proxy config for "${runtime.envName}" yet because SSH envs are not implemented.`);
|
|
49
|
+
}
|
|
50
|
+
const driver = await getNginxProxyDriver();
|
|
51
|
+
const runtimeContext = await resolveNginxProxyRuntimeContext();
|
|
52
|
+
announceTargetEnv(runtime.envName);
|
|
53
|
+
startTask(`Generating nginx proxy config for env "${runtime.envName}" with the ${driver} driver...`);
|
|
54
|
+
try {
|
|
55
|
+
const { bundle, status } = await writeNginxProxyBundle(runtime, {
|
|
56
|
+
host: flags.host?.trim() || undefined,
|
|
57
|
+
port: normalizedPort,
|
|
58
|
+
}, runtimeContext);
|
|
59
|
+
succeedTask(status === 'created'
|
|
60
|
+
? `Saved nginx proxy files for env "${runtime.envName}" under ${bundle.entryDir}, and created editable app entry config at ${bundle.appConfigPath}.`
|
|
61
|
+
: `Saved nginx proxy files for env "${runtime.envName}" under ${bundle.entryDir}, and refreshed editable app entry config at ${bundle.appConfigPath}.`);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
failTask(`Failed to generate nginx proxy config for env "${runtime.envName}".`);
|
|
65
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 ProxyNginx extends Command {
|
|
11
|
+
static summary = 'Manage nginx proxy generation and runtime selection';
|
|
12
|
+
static examples = [
|
|
13
|
+
'<%= config.bin %> proxy nginx current',
|
|
14
|
+
'<%= config.bin %> proxy nginx use local',
|
|
15
|
+
'<%= config.bin %> proxy nginx generate --env app1 --host app1.example.com',
|
|
16
|
+
'<%= config.bin %> proxy nginx start',
|
|
17
|
+
'<%= config.bin %> proxy nginx status',
|
|
18
|
+
'<%= config.bin %> proxy nginx info',
|
|
19
|
+
];
|
|
20
|
+
async run() {
|
|
21
|
+
await this.parse(ProxyNginx);
|
|
22
|
+
const Help = await loadHelpClass(this.config);
|
|
23
|
+
await new Help(this.config, this.config.pjson.oclif.helpOptions ?? this.config.pjson.helpOptions).showHelp([
|
|
24
|
+
this.id ?? 'proxy nginx',
|
|
25
|
+
...this.argv,
|
|
26
|
+
]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { getCliConfigValue } from '../../../lib/cli-config.js';
|
|
11
|
+
import { mapProxyPathFromCliRoot, resolveEnvProxyMainOutputPath, resolveEnvProxyNginxSnippetsOutputDir, } from '../../../lib/env-proxy.js';
|
|
12
|
+
import { formatNginxProxyInfoLines, resolveNginxProxyContainerName, resolveNginxProxyImage, resolveNginxProxyRuntimeContext, } from '../../../lib/proxy-nginx.js';
|
|
13
|
+
export default class ProxyNginxInfo extends Command {
|
|
14
|
+
static summary = 'Show current nginx proxy driver and generated path info';
|
|
15
|
+
async run() {
|
|
16
|
+
await this.parse(ProxyNginxInfo);
|
|
17
|
+
const runtimeContext = await resolveNginxProxyRuntimeContext();
|
|
18
|
+
const lines = formatNginxProxyInfoLines({
|
|
19
|
+
driver: runtimeContext.driver,
|
|
20
|
+
configFile: await mapProxyPathFromCliRoot(resolveEnvProxyMainOutputPath(), {
|
|
21
|
+
runtimeCliRoot: runtimeContext.runtimeCliRoot,
|
|
22
|
+
}),
|
|
23
|
+
snippetsDir: await mapProxyPathFromCliRoot(resolveEnvProxyNginxSnippetsOutputDir(), {
|
|
24
|
+
runtimeCliRoot: runtimeContext.runtimeCliRoot,
|
|
25
|
+
}),
|
|
26
|
+
upstreamHost: runtimeContext.upstreamHost,
|
|
27
|
+
nginxBinary: await getCliConfigValue('bin.nginx'),
|
|
28
|
+
runtimeRoot: runtimeContext.runtimeCliRoot,
|
|
29
|
+
containerName: await resolveNginxProxyContainerName(),
|
|
30
|
+
image: resolveNginxProxyImage(),
|
|
31
|
+
});
|
|
32
|
+
this.log(lines.join('\n'));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { getNginxProxyDriver, reloadNginxProxy, resolveNginxProxyRuntimeContext } from '../../../lib/proxy-nginx.js';
|
|
11
|
+
import { failTask, startTask, succeedTask } from '../../../lib/ui.js';
|
|
12
|
+
export default class ProxyNginxReload extends Command {
|
|
13
|
+
static summary = 'Reload the managed nginx proxy';
|
|
14
|
+
async run() {
|
|
15
|
+
await this.parse(ProxyNginxReload);
|
|
16
|
+
const driver = await getNginxProxyDriver();
|
|
17
|
+
const runtimeContext = await resolveNginxProxyRuntimeContext();
|
|
18
|
+
startTask(`Reloading nginx proxy with the ${driver} driver...`);
|
|
19
|
+
try {
|
|
20
|
+
await reloadNginxProxy(runtimeContext);
|
|
21
|
+
succeedTask(`Nginx proxy reloaded with the ${driver} driver.`);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
failTask(`Failed to reload nginx proxy with the ${driver} driver.`);
|
|
25
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { getNginxProxyDriver, resolveNginxProxyRuntimeContext, restartNginxProxy } from '../../../lib/proxy-nginx.js';
|
|
11
|
+
import { failTask, startTask, succeedTask } from '../../../lib/ui.js';
|
|
12
|
+
export default class ProxyNginxRestart extends Command {
|
|
13
|
+
static summary = 'Restart the managed nginx proxy';
|
|
14
|
+
async run() {
|
|
15
|
+
await this.parse(ProxyNginxRestart);
|
|
16
|
+
const driver = await getNginxProxyDriver();
|
|
17
|
+
const runtimeContext = await resolveNginxProxyRuntimeContext();
|
|
18
|
+
startTask(`Restarting nginx proxy with the ${driver} driver...`);
|
|
19
|
+
try {
|
|
20
|
+
await restartNginxProxy(runtimeContext);
|
|
21
|
+
succeedTask(`Nginx proxy restarted with the ${driver} driver.`);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
failTask(`Failed to restart nginx proxy with the ${driver} driver.`);
|
|
25
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { getNginxProxyDriver, resolveNginxProxyRuntimeContext, startNginxProxy } from '../../../lib/proxy-nginx.js';
|
|
11
|
+
import { failTask, startTask, succeedTask } from '../../../lib/ui.js';
|
|
12
|
+
export default class ProxyNginxStart extends Command {
|
|
13
|
+
static summary = 'Start the managed nginx proxy';
|
|
14
|
+
async run() {
|
|
15
|
+
await this.parse(ProxyNginxStart);
|
|
16
|
+
const driver = await getNginxProxyDriver();
|
|
17
|
+
const runtimeContext = await resolveNginxProxyRuntimeContext();
|
|
18
|
+
startTask(`Starting nginx proxy with the ${driver} driver...`);
|
|
19
|
+
try {
|
|
20
|
+
const result = await startNginxProxy(runtimeContext);
|
|
21
|
+
succeedTask(result === 'already-running'
|
|
22
|
+
? `Nginx proxy is already running with the ${driver} driver.`
|
|
23
|
+
: `Nginx proxy started with the ${driver} driver.`);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
failTask(`Failed to start nginx proxy with the ${driver} driver.`);
|
|
27
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { formatNginxProxyStatusLines, getNginxProxyStatus, resolveNginxProxyRuntimeContext, } from '../../../lib/proxy-nginx.js';
|
|
11
|
+
export default class ProxyNginxStatus extends Command {
|
|
12
|
+
static summary = 'Show the current nginx proxy runtime status';
|
|
13
|
+
async run() {
|
|
14
|
+
await this.parse(ProxyNginxStatus);
|
|
15
|
+
const runtimeContext = await resolveNginxProxyRuntimeContext();
|
|
16
|
+
const status = await getNginxProxyStatus(runtimeContext);
|
|
17
|
+
this.log(formatNginxProxyStatusLines(status).join('\n'));
|
|
18
|
+
}
|
|
19
|
+
}
|