@hideandseeklab/aoox 0.1.0-alpha.11 → 0.1.0-alpha.13

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.
Files changed (64) hide show
  1. package/README.md +179 -45
  2. package/assets/install/docker-compose.dist.yml +15 -1
  3. package/bin/dev.js +8 -2
  4. package/bin/run.js +6 -2
  5. package/dist/commands/deploy.js +8 -7
  6. package/dist/commands/domain/clear.d.ts +16 -0
  7. package/dist/commands/domain/clear.js +61 -0
  8. package/dist/commands/domain/set.d.ts +1 -0
  9. package/dist/commands/domain/set.js +15 -3
  10. package/dist/commands/env/promote.js +2 -1
  11. package/dist/commands/env/pull.js +4 -3
  12. package/dist/commands/env/push.js +3 -2
  13. package/dist/commands/env/set.js +2 -1
  14. package/dist/commands/env/unset.js +3 -2
  15. package/dist/commands/install.d.ts +19 -0
  16. package/dist/commands/install.js +232 -82
  17. package/dist/commands/link.js +4 -3
  18. package/dist/commands/login.js +4 -3
  19. package/dist/commands/registry/build.d.ts +3 -1
  20. package/dist/commands/registry/build.js +12 -6
  21. package/dist/commands/registry/domain.js +3 -2
  22. package/dist/commands/registry/password.d.ts +19 -0
  23. package/dist/commands/registry/password.js +74 -0
  24. package/dist/commands/registry/push.d.ts +2 -1
  25. package/dist/commands/registry/push.js +6 -3
  26. package/dist/commands/reinstall.js +26 -20
  27. package/dist/commands/run.js +7 -2
  28. package/dist/commands/update/panel.js +28 -5
  29. package/dist/commands/update.js +6 -5
  30. package/dist/commands/whoami.js +2 -1
  31. package/dist/lib/api.js +2 -2
  32. package/dist/lib/compose-version.d.ts +26 -0
  33. package/dist/lib/compose-version.js +61 -0
  34. package/dist/lib/discovery.d.ts +24 -2
  35. package/dist/lib/discovery.js +97 -3
  36. package/dist/lib/docker.d.ts +1 -1
  37. package/dist/lib/docker.js +2 -2
  38. package/dist/lib/env-command.d.ts +1 -1
  39. package/dist/lib/env-command.js +4 -3
  40. package/dist/lib/image-confirm.d.ts +38 -0
  41. package/dist/lib/image-confirm.js +102 -0
  42. package/dist/lib/image-source.d.ts +59 -0
  43. package/dist/lib/image-source.js +261 -0
  44. package/dist/lib/install-plan.d.ts +69 -0
  45. package/dist/lib/install-plan.js +86 -0
  46. package/dist/lib/interrupt.d.ts +19 -0
  47. package/dist/lib/interrupt.js +42 -0
  48. package/dist/lib/leftover-volumes.d.ts +18 -0
  49. package/dist/lib/leftover-volumes.js +69 -0
  50. package/dist/lib/manifest-parsers.d.ts +23 -0
  51. package/dist/lib/manifest-parsers.js +152 -0
  52. package/dist/lib/registry-image-command.d.ts +20 -3
  53. package/dist/lib/registry-image-command.js +56 -14
  54. package/dist/lib/reinstall.d.ts +7 -0
  55. package/dist/lib/reinstall.js +28 -0
  56. package/dist/lib/run-banner.d.ts +3 -12
  57. package/dist/lib/run-banner.js +2 -23
  58. package/dist/lib/style.d.ts +34 -0
  59. package/dist/lib/style.js +75 -0
  60. package/dist/lib/system-ca.d.ts +20 -0
  61. package/dist/lib/system-ca.js +29 -0
  62. package/dist/lib/types.d.ts +2 -0
  63. package/oclif.manifest.json +174 -13
  64. package/package.json +1 -1
@@ -0,0 +1,61 @@
1
+ import { confirm } from '@inquirer/prompts';
2
+ import { Command, Flags } from '@oclif/core';
3
+ import { api, ApiError } from '../../lib/api.js';
4
+ import { MissingCredentialsError } from '../../lib/config.js';
5
+ import { connectionFlags, loadCredentials } from '../../lib/flags.js';
6
+ import { warnIfOutdated } from '../../lib/outdated.js';
7
+ import { successLine, warnLine } from '../../lib/style.js';
8
+ /**
9
+ * Counterpart of `aoox domain set`: calls the panel's `DELETE /instance/domain`,
10
+ * which takes the dashboard and API back to plain IP access and recreates the
11
+ * web/api containers. The reverse proxy and application domains are untouched.
12
+ */
13
+ export default class DomainClear extends Command {
14
+ static description = 'Remove the custom domain of the panel itself and go back to IP access (IP:3000) through the running panel API';
15
+ static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> --yes'];
16
+ static flags = {
17
+ ...connectionFlags,
18
+ yes: Flags.boolean({ char: 'y', default: false, description: 'Do not ask for confirmation' }),
19
+ };
20
+ async run() {
21
+ const { flags } = await this.parse(DomainClear);
22
+ let config;
23
+ try {
24
+ config = await loadCredentials(this.config.configDir, flags);
25
+ }
26
+ catch (error) {
27
+ if (error instanceof MissingCredentialsError) {
28
+ this.error(error.message, { suggestions: ['Run `aoox login` against this panel first.'] });
29
+ }
30
+ throw error;
31
+ }
32
+ await warnIfOutdated((m) => this.logToStderr(warnLine(m)), this.config.version, config);
33
+ if (!flags.yes) {
34
+ const ok = await confirm({
35
+ default: false,
36
+ message: 'Remove the panel domain? The dashboard and API go back to http://<server IP>:3000 / :3001 after a short restart, and this domain stops working. Applications and their domains are not touched.',
37
+ });
38
+ if (!ok)
39
+ this.exit(0);
40
+ }
41
+ let result;
42
+ try {
43
+ result = await api(config, '/instance/domain', { method: 'DELETE' });
44
+ }
45
+ catch (error) {
46
+ if (error instanceof ApiError && error.status === 400) {
47
+ this.error(error.message, {
48
+ suggestions: ['If INSTALL_DIR is missing, set it in the panel .env.dist, restart the stack and try again.'],
49
+ });
50
+ }
51
+ if (error instanceof ApiError && error.status === 502) {
52
+ this.error(error.message, { suggestions: ['Start Docker on the panel host and try again.'] });
53
+ }
54
+ throw error;
55
+ }
56
+ this.log(successLine('Panel domain removed.'));
57
+ this.log('The panel will restart for a few seconds to go back to IP access — the connection to this API will drop briefly.');
58
+ this.log(`Reopen the dashboard at ${result.reopenUrl ?? 'http://<server IP>:3000'} afterwards.`);
59
+ this.log('Run `aoox login` again with that address if you used the domain to sign in.');
60
+ }
61
+ }
@@ -11,6 +11,7 @@ export default class DomainSet extends Command {
11
11
  static flags: {
12
12
  'acme-email': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
13
  api: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
14
+ 'domain-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
15
  web: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
15
16
  token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
17
  url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -3,6 +3,7 @@ import { api, ApiError } from '../../lib/api.js';
3
3
  import { MissingCredentialsError } from '../../lib/config.js';
4
4
  import { connectionFlags, loadCredentials } from '../../lib/flags.js';
5
5
  import { warnIfOutdated } from '../../lib/outdated.js';
6
+ import { successLine, warnLine } from '../../lib/style.js';
6
7
  /**
7
8
  * Post-install alternative to hand-editing docker-compose.domain.yml/.env.dist
8
9
  * over SSH (see the aoox-api AGENTS.md "Domains for the panel itself"):
@@ -14,11 +15,16 @@ export default class DomainSet extends Command {
14
15
  static examples = [
15
16
  '<%= config.bin %> <%= command.id %> --web panel.example.com --api api.example.com',
16
17
  '<%= config.bin %> <%= command.id %> --web panel.example.com --api api.example.com --acme-email you@example.com',
18
+ '<%= config.bin %> <%= command.id %> --web panel.example.com --api api.example.com --domain-only',
17
19
  ];
18
20
  static flags = {
19
21
  ...connectionFlags,
20
22
  'acme-email': Flags.string({ description: "Email for the Let's Encrypt certificate" }),
21
23
  api: Flags.string({ description: 'Domain for the panel API', required: true }),
24
+ 'domain-only': Flags.boolean({
25
+ allowNo: true,
26
+ description: 'Only allow access through the domain: ports 3000/3001 listen on 127.0.0.1 only (default: keep the current setting). Use --no-domain-only to open them again. Make sure the domain works first, or you lose IP:port access',
27
+ }),
22
28
  web: Flags.string({ description: 'Domain for the panel dashboard', required: true }),
23
29
  };
24
30
  async run() {
@@ -33,13 +39,14 @@ export default class DomainSet extends Command {
33
39
  }
34
40
  throw error;
35
41
  }
36
- await warnIfOutdated((m) => this.warn(m), this.config.version, config);
42
+ await warnIfOutdated((m) => this.logToStderr(warnLine(m)), this.config.version, config);
37
43
  let result;
38
44
  try {
39
45
  result = await api(config, '/instance/domain', {
40
46
  body: {
41
47
  ...(flags['acme-email'] ? { acmeEmail: flags['acme-email'] } : {}),
42
48
  apiHost: flags.api,
49
+ ...(flags['domain-only'] === undefined ? {} : { restrictPorts: flags['domain-only'] }),
43
50
  webHost: flags.web,
44
51
  },
45
52
  method: 'PATCH',
@@ -53,11 +60,16 @@ export default class DomainSet extends Command {
53
60
  }
54
61
  throw error;
55
62
  }
56
- this.log(`Domain saved: ${flags.web} (dashboard), ${flags.api} (API).`);
63
+ this.log(successLine(`Domain saved: ${flags.web} (dashboard), ${flags.api} (API).`));
57
64
  this.log('The panel will restart for a few seconds to apply it — the connection to this API will drop briefly.');
65
+ if (result.restrictPortsNote) {
66
+ this.log('');
67
+ this.logToStderr(warnLine('Access through IP:3000 / IP:3001 is closed once the panel restarts — use the domains above.'));
68
+ this.log(result.restrictPortsNote);
69
+ }
58
70
  if (result.proxyAutoProvisioned) {
59
71
  this.log('');
60
- this.warn('The reverse proxy was not running before — it has been enabled automatically.');
72
+ this.logToStderr(warnLine('The reverse proxy was not running before — it has been enabled automatically.'));
61
73
  this.log('The new domains will be reachable only if these three things are also correct:');
62
74
  this.log(` 1. DNS A records for ${flags.web} and ${flags.api} point to this server's IP.`);
63
75
  this.log(' 2. Ports 80 and 443 are open to the public (both the OS firewall and the VPS provider security group).');
@@ -4,6 +4,7 @@ import { EnvCommand, ownerFlags, selectorFlags } from '../../lib/env-command.js'
4
4
  import { planPromotion } from '../../lib/env-plan.js';
5
5
  import { EnvInputError, parseKeys } from '../../lib/env-text.js';
6
6
  import { connectionFlags } from '../../lib/flags.js';
7
+ import { successLine } from '../../lib/style.js';
7
8
  export default class EnvPromote extends EnvCommand {
8
9
  static description = 'Copy variables (and their secret flag) from one environment of a variable set to another (name them, or use --all). Needs the right to read the source and to change the target. The target keeps its comments and order; new variables are appended. Shows what changes and asks before writing (unless --yes)';
9
10
  static examples = [
@@ -71,7 +72,7 @@ export default class EnvPromote extends EnvCommand {
71
72
  this.fail(error.message);
72
73
  return this.failFromApi(error, { environment: target.label, verb: 'change' });
73
74
  }
74
- this.log(`${target.label}: promoted ${send.length} variable${send.length === 1 ? '' : 's'} from ${from.name} (a version was recorded)`);
75
+ this.log(successLine(`${target.label}: promoted ${send.length} variable${send.length === 1 ? '' : 's'} from ${from.name} (a version was recorded)`));
75
76
  this.usedByNote(saved.environment);
76
77
  }
77
78
  /** The variable names to promote (or 'all'); ends the command on a wrong combination. */
@@ -4,6 +4,7 @@ import { resolve } from 'node:path';
4
4
  import { EnvCommand, environmentCommandFlags } from '../../lib/env-command.js';
5
5
  import { FileExistsError, gitIgnoreStatus, writeEnvFile } from '../../lib/env-file.js';
6
6
  import { defaultFileFor, formatEnv, hasReferences, keysOf, REFERENCE_NOTE } from '../../lib/env-text.js';
7
+ import { successLine, warnLine } from '../../lib/style.js';
7
8
  export default class EnvPull extends EnvCommand {
8
9
  static description = 'Write the variables of a variable set environment to a local file (mode 0600), or to standard output with --file -. Refuses to overwrite unless --force. The read is recorded in the audit log';
9
10
  static examples = [
@@ -57,12 +58,12 @@ export default class EnvPull extends EnvCommand {
57
58
  throw error;
58
59
  }
59
60
  const count = keysOf(revealed.variables).length;
60
- this.log(`Wrote ${count} variable${count === 1 ? '' : 's'} from "${resolved.label}" to ${file}`);
61
+ this.log(successLine(`Wrote ${count} variable${count === 1 ? '' : 's'} from "${resolved.label}" to ${file}`));
61
62
  if (hasReferences(revealed.variables)) {
62
- this.warn(REFERENCE_NOTE);
63
+ this.logToStderr(warnLine(REFERENCE_NOTE));
63
64
  }
64
65
  if ((await gitIgnoreStatus(file, cwd)) === 'not-ignored') {
65
- this.warn(`${file} is not covered by .gitignore, so it could be committed with its secrets. Add it, e.g.: echo "${file}" >> .gitignore`);
66
+ this.logToStderr(warnLine(`${file} is not covered by .gitignore, so it could be committed with its secrets. Add it, e.g.: echo "${file}" >> .gitignore`));
66
67
  }
67
68
  }
68
69
  }
@@ -3,6 +3,7 @@ import { readFile } from 'node:fs/promises';
3
3
  import { resolve } from 'node:path';
4
4
  import { EnvCommand, environmentCommandFlags } from '../../lib/env-command.js';
5
5
  import { checkEnvFile, isEmptyChange, summarizeChange } from '../../lib/env-text.js';
6
+ import { successLine, warnLine } from '../../lib/style.js';
6
7
  export default class EnvPush extends EnvCommand {
7
8
  static description = 'Replace the whole text of a variable set environment with a local .env file. Shows what is added, changed and removed and asks before writing (unless --yes); the write fails if someone else changed the environment in between';
8
9
  static examples = [
@@ -31,7 +32,7 @@ export default class EnvPush extends EnvCommand {
31
32
  this.fail(`${flags.file} cannot be uploaded:`, ...check.problems.slice(0, 10).map((p) => ` ${p}`), ...more);
32
33
  }
33
34
  for (const w of check.warnings.slice(0, 5))
34
- this.warn(w);
35
+ this.logToStderr(warnLine(w));
35
36
  const resolved = await this.resolveEnvironment(flags);
36
37
  const current = await this.reveal(resolved, 'change');
37
38
  const summary = summarizeChange(current.variables, check.text);
@@ -59,7 +60,7 @@ export default class EnvPush extends EnvCommand {
59
60
  expectedUpdatedAt: current.updatedAt,
60
61
  variables: check.text,
61
62
  });
62
- this.log(`${resolved.label}: pushed ${saved.keys.length} variable${saved.keys.length === 1 ? '' : 's'} (a version was recorded)`);
63
+ this.log(successLine(`${resolved.label}: pushed ${saved.keys.length} variable${saved.keys.length === 1 ? '' : 's'} (a version was recorded)`));
63
64
  this.usedByNote(saved);
64
65
  }
65
66
  show(sign, label, names) {
@@ -1,6 +1,7 @@
1
1
  import { Args, Flags } from '@oclif/core';
2
2
  import { EnvCommand, environmentCommandFlags } from '../../lib/env-command.js';
3
3
  import { ENV_TEXT_MAX, EnvInputError, parseAssignments, setVariables } from '../../lib/env-text.js';
4
+ import { successLine } from '../../lib/style.js';
4
5
  import { PROJECT_REFERENCE_HINT, projectReferenceKeys } from '../../lib/variable-sets.js';
5
6
  export default class EnvSet extends EnvCommand {
6
7
  static args = {
@@ -53,7 +54,7 @@ export default class EnvSet extends EnvCommand {
53
54
  ].filter(Boolean);
54
55
  if (parts.length > 0)
55
56
  parts[parts.length - 1] += mark;
56
- this.log(`${resolved.label}: ${parts.join('; ')} (${saved.keys.length} variable${saved.keys.length === 1 ? '' : 's'} now)`);
57
+ this.log(successLine(`${resolved.label}: ${parts.join('; ')} (${saved.keys.length} variable${saved.keys.length === 1 ? '' : 's'} now)`));
57
58
  this.usedByNote(saved);
58
59
  }
59
60
  }
@@ -1,6 +1,7 @@
1
1
  import { Args } from '@oclif/core';
2
2
  import { EnvCommand, environmentCommandFlags } from '../../lib/env-command.js';
3
3
  import { EnvInputError, parseKeys, unsetVariables } from '../../lib/env-text.js';
4
+ import { successLine, warnLine } from '../../lib/style.js';
4
5
  export default class EnvUnset extends EnvCommand {
5
6
  static args = {
6
7
  keys: Args.string({ description: 'Variable name(s) to remove', required: true }),
@@ -27,7 +28,7 @@ export default class EnvUnset extends EnvCommand {
27
28
  const current = await this.reveal(resolved, 'change');
28
29
  const result = unsetVariables(current.variables, keys);
29
30
  if (result.missing.length > 0) {
30
- this.warn(`Not set in ${resolved.label}: ${result.missing.join(', ')}`);
31
+ this.logToStderr(warnLine(`Not set in ${resolved.label}: ${result.missing.join(', ')}`));
31
32
  }
32
33
  if (result.removed.length === 0) {
33
34
  this.log('Nothing to remove.');
@@ -38,7 +39,7 @@ export default class EnvUnset extends EnvCommand {
38
39
  expectedUpdatedAt: current.updatedAt,
39
40
  variables: result.text,
40
41
  });
41
- this.log(`${resolved.label}: removed ${result.removed.join(', ')} (${saved.keys.length} variable${saved.keys.length === 1 ? '' : 's'} left)`);
42
+ this.log(successLine(`${resolved.label}: removed ${result.removed.join(', ')} (${saved.keys.length} variable${saved.keys.length === 1 ? '' : 's'} left)`));
42
43
  this.usedByNote(saved);
43
44
  }
44
45
  }
@@ -8,11 +8,14 @@ export default class Install extends Command {
8
8
  'admin-name': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
9
  'admin-password': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
10
  'api-domain': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'confirm-wipe': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
12
  dir: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
12
13
  force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
+ 'new-secrets': import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
15
  'no-terminal-authorize': import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
16
  'terminal-ssh-user': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
17
  'web-domain': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ 'wipe-data': import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
19
  yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
17
20
  };
18
21
  run(): Promise<void>;
@@ -23,6 +26,22 @@ export default class Install extends Command {
23
26
  private chownNode;
24
27
  private confirmPlan;
25
28
  private ensureDocker;
29
+ /**
30
+ * Data volumes of an earlier installation that are still on this Docker host while the install folder is
31
+ * empty. Only asked when Docker already runs: without Docker there cannot be any.
32
+ */
33
+ private findLeftoverVolumes;
34
+ private presentFiles;
35
+ /**
36
+ * Volumes from an earlier installation whose folder is gone (so there is no compose file to `down -v` with).
37
+ * Removes the stack's own containers that still hold them, then the volumes. A volume that is still in use by
38
+ * anything else makes docker refuse, and the install stops there with docker's own message.
39
+ */
40
+ private removeLeftoverVolumes;
41
+ /** Reuse mode: the existing `.env.dist` is merged, never regenerated; only explicit flags replace values. */
42
+ private reuseEnv;
26
43
  /** Polls the API's own setup-status endpoint — migrations run on boot, so "up" isn't "ready". */
27
44
  private waitReady;
45
+ /** `docker compose down -v` for the existing stack (dist + domain file only: the override just changes ports/labels). */
46
+ private wipe;
28
47
  }