@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.
- package/README.md +179 -45
- package/assets/install/docker-compose.dist.yml +15 -1
- package/bin/dev.js +8 -2
- package/bin/run.js +6 -2
- package/dist/commands/deploy.js +8 -7
- package/dist/commands/domain/clear.d.ts +16 -0
- package/dist/commands/domain/clear.js +61 -0
- package/dist/commands/domain/set.d.ts +1 -0
- package/dist/commands/domain/set.js +15 -3
- package/dist/commands/env/promote.js +2 -1
- package/dist/commands/env/pull.js +4 -3
- package/dist/commands/env/push.js +3 -2
- package/dist/commands/env/set.js +2 -1
- package/dist/commands/env/unset.js +3 -2
- package/dist/commands/install.d.ts +19 -0
- package/dist/commands/install.js +232 -82
- package/dist/commands/link.js +4 -3
- package/dist/commands/login.js +4 -3
- package/dist/commands/registry/build.d.ts +3 -1
- package/dist/commands/registry/build.js +12 -6
- package/dist/commands/registry/domain.js +3 -2
- package/dist/commands/registry/password.d.ts +19 -0
- package/dist/commands/registry/password.js +74 -0
- package/dist/commands/registry/push.d.ts +2 -1
- package/dist/commands/registry/push.js +6 -3
- package/dist/commands/reinstall.js +26 -20
- package/dist/commands/run.js +7 -2
- package/dist/commands/update/panel.js +28 -5
- package/dist/commands/update.js +6 -5
- package/dist/commands/whoami.js +2 -1
- package/dist/lib/api.js +2 -2
- package/dist/lib/compose-version.d.ts +26 -0
- package/dist/lib/compose-version.js +61 -0
- package/dist/lib/discovery.d.ts +24 -2
- package/dist/lib/discovery.js +97 -3
- package/dist/lib/docker.d.ts +1 -1
- package/dist/lib/docker.js +2 -2
- package/dist/lib/env-command.d.ts +1 -1
- package/dist/lib/env-command.js +4 -3
- package/dist/lib/image-confirm.d.ts +38 -0
- package/dist/lib/image-confirm.js +102 -0
- package/dist/lib/image-source.d.ts +59 -0
- package/dist/lib/image-source.js +261 -0
- package/dist/lib/install-plan.d.ts +69 -0
- package/dist/lib/install-plan.js +86 -0
- package/dist/lib/interrupt.d.ts +19 -0
- package/dist/lib/interrupt.js +42 -0
- package/dist/lib/leftover-volumes.d.ts +18 -0
- package/dist/lib/leftover-volumes.js +69 -0
- package/dist/lib/manifest-parsers.d.ts +23 -0
- package/dist/lib/manifest-parsers.js +152 -0
- package/dist/lib/registry-image-command.d.ts +20 -3
- package/dist/lib/registry-image-command.js +56 -14
- package/dist/lib/reinstall.d.ts +7 -0
- package/dist/lib/reinstall.js +28 -0
- package/dist/lib/run-banner.d.ts +3 -12
- package/dist/lib/run-banner.js +2 -23
- package/dist/lib/style.d.ts +34 -0
- package/dist/lib/style.js +75 -0
- package/dist/lib/system-ca.d.ts +20 -0
- package/dist/lib/system-ca.js +29 -0
- package/dist/lib/types.d.ts +2 -0
- package/oclif.manifest.json +174 -13
- package/package.json +1 -1
package/dist/commands/install.js
CHANGED
|
@@ -1,23 +1,36 @@
|
|
|
1
|
-
import { confirm } from '@inquirer/prompts';
|
|
1
|
+
import { confirm, input } from '@inquirer/prompts';
|
|
2
2
|
import { Command, Flags } from '@oclif/core';
|
|
3
3
|
import { randomBytes } from 'node:crypto';
|
|
4
|
-
import { copyFile, mkdir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { chmod, copyFile, mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
5
5
|
import { resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
|
-
import { dockerInherit } from '../lib/docker.js';
|
|
7
|
+
import { dockerCapture, dockerInherit } from '../lib/docker.js';
|
|
8
8
|
import { buildEnvFile, resolveTerminalSshUser } from '../lib/install-env.js';
|
|
9
|
-
import {
|
|
9
|
+
import { explicitOverrides, planInstall, wipeWarning } from '../lib/install-plan.js';
|
|
10
|
+
import { composeProjectName, declaredVolumeNames, latestEnvBackup, leftoverVolumes } from '../lib/leftover-volumes.js';
|
|
11
|
+
import { backupInstallFiles, backupStamp, chooseComposeFiles, composeArgs, composeDefaults, composeVariables, DIST_FILE, DOMAIN_FILE, mergeEnv, MissingSecretsError, OVERRIDE_FILE, parseEnv, repairDefaults, REQUIRED_SECRETS, } from '../lib/reinstall.js';
|
|
12
|
+
import { stepLine, successLine, warnLine } from '../lib/style.js';
|
|
10
13
|
import { commandExists, detectPublicIp, dockerRunning, dockerSocketGid, isRoot, runShellInherit } from '../lib/system.js';
|
|
11
14
|
import { authorizeTerminalKey, skipReason } from '../lib/terminal-key.js';
|
|
12
15
|
const DOCKER_INSTALL_SCRIPT = 'curl -fsSL https://get.docker.com | sh';
|
|
13
16
|
/** How long to wait for the API to answer after `docker compose up -d` (migrations run on boot). */
|
|
14
17
|
const READY_TIMEOUT_MS = 120_000;
|
|
15
18
|
const READY_POLL_MS = 2000;
|
|
19
|
+
async function readIfExists(path) {
|
|
20
|
+
try {
|
|
21
|
+
return await readFile(path, 'utf8');
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
16
27
|
export default class Install extends Command {
|
|
17
28
|
static description = 'Install aoox (postgres + api + web) on a fresh VPS with Docker Compose';
|
|
18
29
|
static examples = [
|
|
19
30
|
'sudo <%= config.bin %> <%= command.id %>',
|
|
20
31
|
'sudo <%= config.bin %> <%= command.id %> --web-domain panel.example.com --api-domain api.panel.example.com --acme-email me@example.com',
|
|
32
|
+
'sudo <%= config.bin %> <%= command.id %> --force # reinstall over an existing install, keeping data and secrets',
|
|
33
|
+
'sudo <%= config.bin %> <%= command.id %> --force --new-secrets --wipe-data # start from scratch (deletes all panel data)',
|
|
21
34
|
];
|
|
22
35
|
static flags = {
|
|
23
36
|
'acme-email': Flags.string({ description: 'Required with --web-domain/--api-domain (Let’s Encrypt)' }),
|
|
@@ -25,8 +38,18 @@ export default class Install extends Command {
|
|
|
25
38
|
'admin-name': Flags.string({ dependsOn: ['admin-email'], description: 'Name of the first owner' }),
|
|
26
39
|
'admin-password': Flags.string({ dependsOn: ['admin-email'], description: 'Password of the first owner (min. 8 characters)' }),
|
|
27
40
|
'api-domain': Flags.string({ dependsOn: ['web-domain'], description: 'Domain for the API, served through the bundled proxy' }),
|
|
41
|
+
'confirm-wipe': Flags.string({
|
|
42
|
+
description: 'Non-interactive confirmation for --wipe-data: must be exactly the install directory (--yes alone is not enough)',
|
|
43
|
+
}),
|
|
28
44
|
dir: Flags.string({ default: '/opt/aoox', description: 'Installation directory' }),
|
|
29
|
-
force: Flags.boolean({
|
|
45
|
+
force: Flags.boolean({
|
|
46
|
+
default: false,
|
|
47
|
+
description: 'Reinstall over an existing installation in --dir: previous files are backed up to <dir>/backups/ and existing secrets and values are kept (data survives)',
|
|
48
|
+
}),
|
|
49
|
+
'new-secrets': Flags.boolean({
|
|
50
|
+
default: false,
|
|
51
|
+
description: 'Only with --force --wipe-data: generate new secrets for a completely fresh install (DELETES all panel data)',
|
|
52
|
+
}),
|
|
30
53
|
'no-terminal-authorize': Flags.boolean({
|
|
31
54
|
default: false,
|
|
32
55
|
description: 'Do not create/authorize the web Terminal SSH key automatically (do it in Settings > Terminal instead)',
|
|
@@ -35,61 +58,111 @@ export default class Install extends Command {
|
|
|
35
58
|
description: 'SSH user the web Terminal uses to log in to this host (default: the user running sudo, or root if there is none)',
|
|
36
59
|
}),
|
|
37
60
|
'web-domain': Flags.string({ dependsOn: ['api-domain'], description: 'Domain for the web panel, served through the bundled proxy' }),
|
|
38
|
-
|
|
61
|
+
'wipe-data': Flags.boolean({
|
|
62
|
+
default: false,
|
|
63
|
+
description: 'Only with --force --new-secrets: run `docker compose down -v` first, removing the panel database volume (and any leftover panel volumes from an earlier install) (DELETES all panel data)',
|
|
64
|
+
}),
|
|
65
|
+
yes: Flags.boolean({ char: 'y', default: false, description: 'Do not ask for any confirmation (does not confirm a wipe)' }),
|
|
39
66
|
};
|
|
67
|
+
// eslint-disable-next-line complexity -- linear orchestration: plan, confirm, backup, (wipe), write, up
|
|
40
68
|
async run() {
|
|
41
69
|
const { flags } = await this.parse(Install);
|
|
42
70
|
this.assertPreconditions(flags);
|
|
71
|
+
const dir = resolve(flags.dir);
|
|
72
|
+
const existingEnv = await readIfExists(`${dir}/.env.dist`);
|
|
73
|
+
const existingCompose = await readIfExists(`${dir}/${DIST_FILE}`);
|
|
74
|
+
const present = await this.presentFiles(dir);
|
|
75
|
+
const assets = fileURLToPath(new URL('../../assets/install/', import.meta.url));
|
|
76
|
+
const leftover = existingEnv === undefined && existingCompose === undefined ? await this.findLeftoverVolumes(assets) : [];
|
|
77
|
+
const plan = planInstall({
|
|
78
|
+
composeExists: existingCompose !== undefined,
|
|
79
|
+
confirmWipe: flags['confirm-wipe'] === undefined ? undefined : resolve(flags['confirm-wipe']),
|
|
80
|
+
dir,
|
|
81
|
+
envExists: existingEnv !== undefined,
|
|
82
|
+
force: flags.force,
|
|
83
|
+
hasSecrets: existingEnv !== undefined && REQUIRED_SECRETS.every((k) => Boolean(parseEnv(existingEnv).get(k))),
|
|
84
|
+
interactive: Boolean(process.stdin.isTTY),
|
|
85
|
+
latestBackup: leftover.length > 0 ? await latestEnvBackup(dir) : undefined,
|
|
86
|
+
leftoverVolumes: leftover,
|
|
87
|
+
newSecrets: flags['new-secrets'],
|
|
88
|
+
wipeData: flags['wipe-data'],
|
|
89
|
+
yes: flags.yes,
|
|
90
|
+
});
|
|
91
|
+
if (plan.kind === 'error')
|
|
92
|
+
this.error(plan.message, { suggestions: plan.suggestions });
|
|
43
93
|
await this.ensureDocker(flags.yes);
|
|
44
|
-
|
|
45
|
-
|
|
94
|
+
await this.confirmPlan(plan, dir, flags.yes, leftover);
|
|
95
|
+
// Never overwrite an existing install without a copy of what is being replaced.
|
|
96
|
+
if (plan.kind !== 'fresh' && (present.size > 0 || existingEnv !== undefined)) {
|
|
97
|
+
const backupDir = `${dir}/backups/${backupStamp()}`;
|
|
98
|
+
await backupInstallFiles(dir, backupDir, present);
|
|
99
|
+
this.log(stepLine('Backed up the previous files to', backupDir));
|
|
100
|
+
}
|
|
101
|
+
if (plan.kind === 'wipe')
|
|
102
|
+
await this.wipe(dir, present, existingEnv !== undefined, leftover);
|
|
46
103
|
await mkdir(dir, { recursive: true });
|
|
47
|
-
|
|
48
|
-
await copyFile(`${assets}docker-compose.dist.yml`, `${dir}/docker-compose.dist.yml`);
|
|
104
|
+
await copyFile(`${assets}${DIST_FILE}`, `${dir}/${DIST_FILE}`);
|
|
49
105
|
const domainMode = Boolean(flags['web-domain']);
|
|
50
|
-
|
|
51
|
-
|
|
106
|
+
// A reinstall that keeps data also keeps (and refreshes) a domain compose file that is already there.
|
|
107
|
+
const keepDomain = plan.kind === 'reuse' && present.has(DOMAIN_FILE);
|
|
108
|
+
if (domainMode || keepDomain)
|
|
109
|
+
await copyFile(`${assets}${DOMAIN_FILE}`, `${dir}/${DOMAIN_FILE}`);
|
|
52
110
|
const secretsDir = `${dir}/secrets`;
|
|
53
111
|
await mkdir(secretsDir, { recursive: true });
|
|
54
112
|
// The api container writes its terminal SSH key here as uid 1000 (the
|
|
55
113
|
// `node` user) — chown it now so first use doesn't hit EACCES.
|
|
56
114
|
await this.chownNode(secretsDir);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
115
|
+
let env;
|
|
116
|
+
let webOrigin;
|
|
117
|
+
if (plan.kind === 'reuse') {
|
|
118
|
+
env = await this.reuseEnv(existingEnv ?? '', dir, assets, flags);
|
|
119
|
+
const vars = parseEnv(env);
|
|
120
|
+
webOrigin = vars.get('WEB_ORIGIN') || `http://localhost:${vars.get('WEB_PORT') || '3000'}`;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
this.log(stepLine('Detecting the server public IP'));
|
|
124
|
+
const publicIp = await detectPublicIp();
|
|
125
|
+
webOrigin = domainMode ? `https://${flags['web-domain']}` : `http://${publicIp ?? 'localhost'}:3000`;
|
|
126
|
+
const publicApiUrl = domainMode ? `https://${flags['api-domain']}` : `http://${publicIp ?? 'localhost'}:3001`;
|
|
127
|
+
env = buildEnvFile({
|
|
128
|
+
acmeEmail: flags['acme-email'],
|
|
129
|
+
adminEmail: flags['admin-email'],
|
|
130
|
+
adminName: flags['admin-name'],
|
|
131
|
+
adminPassword: flags['admin-password'],
|
|
132
|
+
apiDomain: flags['api-domain'],
|
|
133
|
+
dockerGid: dockerSocketGid(),
|
|
134
|
+
encryptionKey: randomBytes(32).toString('hex'),
|
|
135
|
+
installDir: dir,
|
|
136
|
+
jwtSecret: randomBytes(32).toString('hex'),
|
|
137
|
+
postgresPassword: randomBytes(24).toString('hex'),
|
|
138
|
+
publicApiUrl,
|
|
139
|
+
publicIp,
|
|
140
|
+
terminalSshUser: resolveTerminalSshUser(flags['terminal-ssh-user'], process.env),
|
|
141
|
+
webDomain: flags['web-domain'],
|
|
142
|
+
webOrigin,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
78
145
|
await writeFile(`${dir}/.env.dist`, env, { mode: 0o600 });
|
|
146
|
+
await chmod(`${dir}/.env.dist`, 0o600);
|
|
79
147
|
this.authorizeTerminal(dir, env, flags['no-terminal-authorize']);
|
|
80
|
-
this.log('
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
148
|
+
this.log(stepLine('Running docker compose up -d'));
|
|
149
|
+
let files = [DIST_FILE];
|
|
150
|
+
if (plan.kind === 'reuse')
|
|
151
|
+
files = chooseComposeFiles({ present: await this.presentFiles(dir) });
|
|
152
|
+
else if (domainMode)
|
|
153
|
+
files = [DIST_FILE, DOMAIN_FILE];
|
|
154
|
+
await dockerInherit(composeArgs(files, 'up', '-d'), dir);
|
|
155
|
+
this.log(stepLine('Waiting for the API to be ready'));
|
|
87
156
|
await this.waitReady();
|
|
88
157
|
this.log('');
|
|
89
|
-
this.log(`aoox is installed in ${dir}.`);
|
|
158
|
+
this.log(successLine(`aoox is installed in ${dir}.`));
|
|
90
159
|
this.log(`Open: ${webOrigin}`);
|
|
91
|
-
if (
|
|
160
|
+
if (plan.kind === 'reuse') {
|
|
161
|
+
this.log('Existing data and secrets were kept. The previous files are in the backups folder of the install directory.');
|
|
162
|
+
}
|
|
163
|
+
else if (!flags['admin-email']) {
|
|
92
164
|
this.log('Create the first owner account at /setup.');
|
|
165
|
+
}
|
|
93
166
|
}
|
|
94
167
|
assertPreconditions(flags) {
|
|
95
168
|
if (process.platform !== 'linux') {
|
|
@@ -116,15 +189,15 @@ export default class Install extends Command {
|
|
|
116
189
|
});
|
|
117
190
|
if (reason) {
|
|
118
191
|
if (optOut)
|
|
119
|
-
this.log(
|
|
192
|
+
this.log(stepLine(`Terminal: key was not authorized automatically (${reason}).`));
|
|
120
193
|
return;
|
|
121
194
|
}
|
|
122
|
-
this.log('
|
|
195
|
+
this.log(stepLine('Preparing the SSH key for the web Terminal'));
|
|
123
196
|
const outcome = authorizeTerminalKey({ installDir: resolve(dir), user: vars.get('TERMINAL_SSH_USER') });
|
|
124
197
|
if (outcome.ok)
|
|
125
198
|
this.log(outcome.message);
|
|
126
199
|
else
|
|
127
|
-
this.
|
|
200
|
+
this.logToStderr(warnLine(outcome.message));
|
|
128
201
|
}
|
|
129
202
|
/** `numeric:numeric` works even without a matching /etc/passwd entry on the host. */
|
|
130
203
|
async chownNode(dir) {
|
|
@@ -132,47 +205,32 @@ export default class Install extends Command {
|
|
|
132
205
|
await import('node:child_process').then(({ execFileSync }) => execFileSync('chown', ['1000:1000', dir]));
|
|
133
206
|
}
|
|
134
207
|
catch (error) {
|
|
135
|
-
this.
|
|
208
|
+
this.logToStderr(warnLine(`Cannot chown ${dir} (${String(error)}) — the web terminal may need this done manually later.`));
|
|
136
209
|
}
|
|
137
210
|
}
|
|
138
|
-
async confirmPlan(dir,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
if (exists && !flags.force) {
|
|
148
|
-
this.error(`An installation already exists in ${dir}.`, { suggestions: [
|
|
149
|
-
'To repair/refresh the existing installation without losing data: `sudo aoox reinstall`.',
|
|
150
|
-
'Use --force only for a clean reinstall from scratch — it creates new secrets and cuts off access to the existing data.',
|
|
151
|
-
],
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
let hasSecrets = false;
|
|
155
|
-
if (exists) {
|
|
156
|
-
try {
|
|
157
|
-
hasSecrets = /^\s*(POSTGRES_PASSWORD|JWT_SECRET|ENCRYPTION_KEY)=\S/m.test(await readFile(`${dir}/.env.dist`, 'utf8'));
|
|
158
|
-
}
|
|
159
|
-
catch {
|
|
160
|
-
/* no .env.dist — nothing to overwrite */
|
|
211
|
+
async confirmPlan(plan, dir, yes, leftover) {
|
|
212
|
+
if (plan.kind === 'wipe') {
|
|
213
|
+
for (const line of wipeWarning(dir, leftover))
|
|
214
|
+
this.logToStderr(warnLine(line));
|
|
215
|
+
if (plan.confirm === 'typed') {
|
|
216
|
+
const typed = await input({ message: `Type the install directory (${dir}) to confirm that all panel data is deleted:` });
|
|
217
|
+
if (resolve(typed.trim()) !== dir)
|
|
218
|
+
this.error('The typed path does not match — nothing was changed.');
|
|
161
219
|
}
|
|
220
|
+
return;
|
|
162
221
|
}
|
|
163
|
-
if (
|
|
164
|
-
this.
|
|
165
|
-
|
|
166
|
-
|
|
222
|
+
if (plan.kind === 'reuse') {
|
|
223
|
+
this.logToStderr(warnLine(`--force reinstalls over the existing installation in ${dir}: the previous files are backed up first and existing secrets and values are kept, so your data stays readable.`));
|
|
224
|
+
if (yes)
|
|
225
|
+
return;
|
|
226
|
+
const ok = await confirm({ default: true, message: `Reinstall in ${dir} (data and secrets are kept) and run docker compose up -d?` });
|
|
227
|
+
if (!ok)
|
|
228
|
+
this.exit(0);
|
|
229
|
+
return;
|
|
167
230
|
}
|
|
168
|
-
if (
|
|
231
|
+
if (yes)
|
|
169
232
|
return;
|
|
170
|
-
const ok = await confirm({
|
|
171
|
-
default: !hasSecrets,
|
|
172
|
-
message: hasSecrets
|
|
173
|
-
? `Still overwrite .env.dist and create new secrets in ${dir} (the existing data will not be readable)?`
|
|
174
|
-
: `Install aoox in ${dir}${exists ? ' (overwriting the existing one)' : ''} and run docker compose up -d?`,
|
|
175
|
-
});
|
|
233
|
+
const ok = await confirm({ default: true, message: `Install aoox in ${dir} and run docker compose up -d?` });
|
|
176
234
|
if (!ok)
|
|
177
235
|
this.exit(0);
|
|
178
236
|
}
|
|
@@ -185,7 +243,7 @@ export default class Install extends Command {
|
|
|
185
243
|
if (!ok)
|
|
186
244
|
this.error('Docker is required to continue.');
|
|
187
245
|
}
|
|
188
|
-
this.log(
|
|
246
|
+
this.log(stepLine(`${DOCKER_INSTALL_SCRIPT}`));
|
|
189
247
|
await runShellInherit(DOCKER_INSTALL_SCRIPT);
|
|
190
248
|
if (!(commandExists('docker') && dockerRunning())) {
|
|
191
249
|
this.error('Docker still cannot be started after installation.', {
|
|
@@ -193,6 +251,79 @@ export default class Install extends Command {
|
|
|
193
251
|
});
|
|
194
252
|
}
|
|
195
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Data volumes of an earlier installation that are still on this Docker host while the install folder is
|
|
256
|
+
* empty. Only asked when Docker already runs: without Docker there cannot be any.
|
|
257
|
+
*/
|
|
258
|
+
async findLeftoverVolumes(assets) {
|
|
259
|
+
if (!(commandExists('docker') && dockerRunning()))
|
|
260
|
+
return [];
|
|
261
|
+
const declared = declaredVolumeNames(await readFile(`${assets}${DIST_FILE}`, 'utf8'));
|
|
262
|
+
const existing = (await dockerCapture(['volume', 'ls', '--format', '{{.Name}}'])).split(/\r?\n/).filter(Boolean);
|
|
263
|
+
return leftoverVolumes(declared, existing);
|
|
264
|
+
}
|
|
265
|
+
async presentFiles(dir) {
|
|
266
|
+
const found = new Set();
|
|
267
|
+
for (const name of [DIST_FILE, DOMAIN_FILE, OVERRIDE_FILE]) {
|
|
268
|
+
try {
|
|
269
|
+
// eslint-disable-next-line no-await-in-loop
|
|
270
|
+
await stat(`${dir}/${name}`);
|
|
271
|
+
found.add(name);
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
/* absent */
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return found;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Volumes from an earlier installation whose folder is gone (so there is no compose file to `down -v` with).
|
|
281
|
+
* Removes the stack's own containers that still hold them, then the volumes. A volume that is still in use by
|
|
282
|
+
* anything else makes docker refuse, and the install stops there with docker's own message.
|
|
283
|
+
*/
|
|
284
|
+
async removeLeftoverVolumes(volumes) {
|
|
285
|
+
const assets = fileURLToPath(new URL('../../assets/install/', import.meta.url));
|
|
286
|
+
const project = composeProjectName(await readFile(`${assets}${DIST_FILE}`, 'utf8'));
|
|
287
|
+
this.log(stepLine(`Removing leftover volumes: ${volumes.join(', ')}`));
|
|
288
|
+
for (const volume of volumes) {
|
|
289
|
+
const holders = (
|
|
290
|
+
// eslint-disable-next-line no-await-in-loop
|
|
291
|
+
await dockerCapture(['ps', '-aq', '--filter', `volume=${volume}`, '--filter', `label=com.docker.compose.project=${project}`]))
|
|
292
|
+
.split(/\r?\n/)
|
|
293
|
+
.filter(Boolean);
|
|
294
|
+
// eslint-disable-next-line no-await-in-loop
|
|
295
|
+
if (holders.length > 0)
|
|
296
|
+
await dockerInherit(['rm', '-f', ...holders], '/');
|
|
297
|
+
// eslint-disable-next-line no-await-in-loop
|
|
298
|
+
await dockerInherit(['volume', 'rm', volume], '/');
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/** Reuse mode: the existing `.env.dist` is merged, never regenerated; only explicit flags replace values. */
|
|
302
|
+
async reuseEnv(existing, dir, assets, flags) {
|
|
303
|
+
const dist = await readFile(`${assets}${DIST_FILE}`, 'utf8');
|
|
304
|
+
const domain = await readIfExists(`${dir}/${DOMAIN_FILE}`);
|
|
305
|
+
try {
|
|
306
|
+
const defaults = repairDefaults(composeVariables(dist, domain ?? ''), { dockerGid: dockerSocketGid(), installDir: dir }, composeDefaults(dist, domain ?? ''));
|
|
307
|
+
const overrides = explicitOverrides({
|
|
308
|
+
acmeEmail: flags['acme-email'],
|
|
309
|
+
adminEmail: flags['admin-email'],
|
|
310
|
+
adminName: flags['admin-name'],
|
|
311
|
+
adminPassword: flags['admin-password'],
|
|
312
|
+
apiDomain: flags['api-domain'],
|
|
313
|
+
terminalSshUser: flags['terminal-ssh-user'],
|
|
314
|
+
webDomain: flags['web-domain'],
|
|
315
|
+
});
|
|
316
|
+
const merged = mergeEnv(existing, defaults, overrides);
|
|
317
|
+
for (const w of merged.warnings)
|
|
318
|
+
this.logToStderr(warnLine(w));
|
|
319
|
+
return merged.content;
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
if (error instanceof MissingSecretsError)
|
|
323
|
+
this.error(error.message);
|
|
324
|
+
throw error;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
196
327
|
/** Polls the API's own setup-status endpoint — migrations run on boot, so "up" isn't "ready". */
|
|
197
328
|
async waitReady(deadline = Date.now() + READY_TIMEOUT_MS) {
|
|
198
329
|
try {
|
|
@@ -204,7 +335,7 @@ export default class Install extends Command {
|
|
|
204
335
|
/* API not answering yet */
|
|
205
336
|
}
|
|
206
337
|
if (Date.now() >= deadline) {
|
|
207
|
-
this.
|
|
338
|
+
this.logToStderr(warnLine('The API did not respond in the expected time — check `docker compose logs api` in the installation directory.'));
|
|
208
339
|
return;
|
|
209
340
|
}
|
|
210
341
|
await new Promise((resolve) => {
|
|
@@ -212,4 +343,23 @@ export default class Install extends Command {
|
|
|
212
343
|
});
|
|
213
344
|
return this.waitReady(deadline);
|
|
214
345
|
}
|
|
346
|
+
/** `docker compose down -v` for the existing stack (dist + domain file only: the override just changes ports/labels). */
|
|
347
|
+
async wipe(dir, present, hasEnv, leftover) {
|
|
348
|
+
this.log(stepLine('Removing the existing stack and its volumes (docker compose down -v)'));
|
|
349
|
+
if (present.has(DIST_FILE)) {
|
|
350
|
+
const files = [DIST_FILE, ...(present.has(DOMAIN_FILE) ? [DOMAIN_FILE] : [])];
|
|
351
|
+
// Without a .env.dist the required secrets cannot be interpolated: placeholders are enough to remove the stack.
|
|
352
|
+
await (hasEnv
|
|
353
|
+
? dockerInherit(composeArgs(files, 'down', '-v', '--remove-orphans'), dir)
|
|
354
|
+
: dockerInherit(['compose', ...files.flatMap((f) => ['-f', f]), 'down', '-v', '--remove-orphans'], dir, {
|
|
355
|
+
JWT_SECRET: 'x',
|
|
356
|
+
POSTGRES_PASSWORD: 'x',
|
|
357
|
+
}));
|
|
358
|
+
}
|
|
359
|
+
if (leftover.length > 0)
|
|
360
|
+
await this.removeLeftoverVolumes(leftover);
|
|
361
|
+
// Settings of the wiped database no longer exist; the backup keeps the old copies.
|
|
362
|
+
await rm(`${dir}/${OVERRIDE_FILE}`, { force: true });
|
|
363
|
+
await rm(`${dir}/${DOMAIN_FILE}`, { force: true });
|
|
364
|
+
}
|
|
215
365
|
}
|
package/dist/commands/link.js
CHANGED
|
@@ -5,6 +5,7 @@ import { MissingCredentialsError } from '../lib/config.js';
|
|
|
5
5
|
import { connectionFlags, loadCredentials } from '../lib/flags.js';
|
|
6
6
|
import { writeLink } from '../lib/link.js';
|
|
7
7
|
import { warnIfOutdated } from '../lib/outdated.js';
|
|
8
|
+
import { hintLine, successLine, warnLine } from '../lib/style.js';
|
|
8
9
|
export default class Link extends Command {
|
|
9
10
|
static description = 'Link this folder to an application in the panel (used by `aoox deploy`, `aoox run` without `--set`/`--env`, and the `aoox env` defaults and links)';
|
|
10
11
|
static examples = [
|
|
@@ -37,9 +38,9 @@ export default class Link extends Command {
|
|
|
37
38
|
projectName: project.name,
|
|
38
39
|
url: config.url,
|
|
39
40
|
});
|
|
40
|
-
this.log(`Linked: ${project.name} / ${application.name} (${application.appName})`);
|
|
41
|
-
this.log(`Written to ${path} — safe to commit, contains no secrets.`);
|
|
42
|
-
await warnIfOutdated((m) => this.
|
|
41
|
+
this.log(successLine(`Linked: ${project.name} / ${application.name} (${application.appName})`));
|
|
42
|
+
this.log(hintLine(`Written to ${path} — safe to commit, contains no secrets.`));
|
|
43
|
+
await warnIfOutdated((m) => this.logToStderr(warnLine(m)), this.config.version, config);
|
|
43
44
|
}
|
|
44
45
|
async pickApplication(config, project, appId) {
|
|
45
46
|
const apps = await api(config, `/applications?projectId=${project.id}`);
|
package/dist/commands/login.js
CHANGED
|
@@ -5,6 +5,7 @@ import { readConfig, writeConfig } from '../lib/config.js';
|
|
|
5
5
|
import { discover, DiscoveryError } from '../lib/discovery.js';
|
|
6
6
|
import { connectionFlags } from '../lib/flags.js';
|
|
7
7
|
import { warnIfOutdated } from '../lib/outdated.js';
|
|
8
|
+
import { hintLine, successLine, warnLine } from '../lib/style.js';
|
|
8
9
|
const DEFAULT_URL = 'http://localhost:3000';
|
|
9
10
|
export default class Login extends Command {
|
|
10
11
|
static description = 'Save the dashboard address and API token for other commands (the API address is discovered automatically)';
|
|
@@ -35,9 +36,9 @@ export default class Login extends Command {
|
|
|
35
36
|
url: found.apiUrl,
|
|
36
37
|
...(found.webUrl ? { webUrl: found.webUrl } : {}),
|
|
37
38
|
});
|
|
38
|
-
this.log(`Logged in as ${user.email} (${user.role}) at ${found.webUrl ?? found.apiUrl}`);
|
|
39
|
-
this.log(`Token saved to ${path}`);
|
|
40
|
-
await warnIfOutdated((m) => this.
|
|
39
|
+
this.log(successLine(`Logged in as ${user.email} (${user.role}) at ${found.webUrl ?? found.apiUrl}`));
|
|
40
|
+
this.log(hintLine(`Token saved to ${path}`));
|
|
41
|
+
await warnIfOutdated((m) => this.logToStderr(warnLine(m)), this.config.version, { token, url: found.apiUrl }, user.version);
|
|
41
42
|
}
|
|
42
43
|
async discoverOrFail(raw) {
|
|
43
44
|
ux.action.start('Looking for the panel');
|
|
@@ -4,10 +4,11 @@ import { RegistryImageCommand } from '../../lib/registry-image-command.js';
|
|
|
4
4
|
* after checking that the version is not already in the registry. `--push`
|
|
5
5
|
* pushes it right after (the same steps as `aoox registry push`); without it,
|
|
6
6
|
* pushing is the separate `aoox registry push`. Neither deploys anything.
|
|
7
|
+
* Without a name or version, they come from package.json in the context.
|
|
7
8
|
*/
|
|
8
9
|
export default class RegistryBuild extends RegistryImageCommand {
|
|
9
10
|
static args: {
|
|
10
|
-
image: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
11
|
+
image: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
11
12
|
};
|
|
12
13
|
static description: string;
|
|
13
14
|
static examples: string[];
|
|
@@ -17,6 +18,7 @@ export default class RegistryBuild extends RegistryImageCommand {
|
|
|
17
18
|
push: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
19
|
force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
19
20
|
registry: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
|
+
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
20
22
|
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
23
|
url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
22
24
|
};
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import { Args, Flags } from '@oclif/core';
|
|
2
2
|
import { dockerInherit } from '../../lib/docker.js';
|
|
3
3
|
import { RegistryImageCommand, registryImageFlags } from '../../lib/registry-image-command.js';
|
|
4
|
+
import { hintLine, stepLine, successLine } from '../../lib/style.js';
|
|
4
5
|
/**
|
|
5
6
|
* Builds ./Dockerfile into a local image named `<registry host>/<name>:<version>`
|
|
6
7
|
* after checking that the version is not already in the registry. `--push`
|
|
7
8
|
* pushes it right after (the same steps as `aoox registry push`); without it,
|
|
8
9
|
* pushing is the separate `aoox registry push`. Neither deploys anything.
|
|
10
|
+
* Without a name or version, they come from package.json in the context.
|
|
9
11
|
*/
|
|
10
12
|
export default class RegistryBuild extends RegistryImageCommand {
|
|
11
13
|
static args = {
|
|
12
|
-
image: Args.string({ description: 'Image name and version, e.g. myapp:1.0.0
|
|
14
|
+
image: Args.string({ description: 'Image name and version, e.g. myapp:1.0.0. Omit it (or the version) to read them from the project in the build context: package.json, pyproject.toml, Cargo.toml, composer.json, pubspec.yaml, *.csproj, pom.xml, a VERSION file or a git tag',
|
|
15
|
+
required: false }),
|
|
13
16
|
};
|
|
14
|
-
static description = 'Build an image from a Dockerfile, named for the aoox registry (refuses a version that already exists there)';
|
|
17
|
+
static description = 'Build an image from a Dockerfile, named for the aoox registry (refuses a version that already exists there). A name or version you leave out is taken from the project (you confirm it first, or pass --yes)';
|
|
15
18
|
static examples = [
|
|
16
19
|
'<%= config.bin %> <%= command.id %> myapp:1.0.0',
|
|
20
|
+
'<%= config.bin %> <%= command.id %> --push',
|
|
21
|
+
'<%= config.bin %> <%= command.id %> myapp --context ./app',
|
|
22
|
+
'<%= config.bin %> <%= command.id %> --push --yes',
|
|
17
23
|
'<%= config.bin %> <%= command.id %> myapp:1.0.0 --push',
|
|
18
24
|
'<%= config.bin %> <%= command.id %> team/api:2.1.0 -f docker/Dockerfile --context .',
|
|
19
25
|
'<%= config.bin %> <%= command.id %> myapp:1.0.0 --force',
|
|
@@ -26,17 +32,17 @@ export default class RegistryBuild extends RegistryImageCommand {
|
|
|
26
32
|
};
|
|
27
33
|
async run() {
|
|
28
34
|
const { args, flags } = await this.parse(RegistryBuild);
|
|
29
|
-
const image = await this.resolveImage(args.image, flags, '
|
|
35
|
+
const image = await this.resolveImage(args.image, flags, 'Build', flags.context);
|
|
30
36
|
await this.requireDocker();
|
|
31
37
|
await this.refuseExisting(image, { force: flags.force, verb: 'overwrite' });
|
|
32
|
-
this.log(
|
|
38
|
+
this.log(stepLine('Build', image.fullRef));
|
|
33
39
|
await dockerInherit(['build', '-t', image.fullRef, '-f', flags.dockerfile, flags.context], process.cwd());
|
|
34
|
-
this.log(
|
|
40
|
+
this.log(successLine('Built', image.fullRef));
|
|
35
41
|
if (flags.push) {
|
|
36
42
|
// The version was already checked against the registry before the build.
|
|
37
43
|
await this.pushImage(image);
|
|
38
44
|
return;
|
|
39
45
|
}
|
|
40
|
-
this.log(`Next: aoox registry push ${image.shortRef} (or build with --push next time)`);
|
|
46
|
+
this.log(hintLine(`Next: aoox registry push ${image.shortRef} (or build with --push next time)`));
|
|
41
47
|
}
|
|
42
48
|
}
|
|
@@ -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
|
* Puts the self-hosted registry behind the built-in proxy on its own domain
|
|
8
9
|
* (`PATCH /registries/:id/domain`) — the CLI equivalent of Settings ->
|
|
@@ -35,7 +36,7 @@ export default class RegistryDomain extends Command {
|
|
|
35
36
|
}
|
|
36
37
|
throw error;
|
|
37
38
|
}
|
|
38
|
-
await warnIfOutdated((m) => this.
|
|
39
|
+
await warnIfOutdated((m) => this.logToStderr(warnLine(m)), this.config.version, config);
|
|
39
40
|
const registries = await api(config, '/registries');
|
|
40
41
|
const registry = registries.find((r) => r.type === 'self-hosted');
|
|
41
42
|
if (!registry) {
|
|
@@ -48,7 +49,7 @@ export default class RegistryDomain extends Command {
|
|
|
48
49
|
body: { domain: flags.clear ? null : flags.set },
|
|
49
50
|
method: 'PATCH',
|
|
50
51
|
});
|
|
51
|
-
this.log(flags.clear ? `Domain removed. Registry is back at ${updated.url}.` : `Domain applied: ${updated.url}`);
|
|
52
|
+
this.log(successLine(flags.clear ? `Domain removed. Registry is back at ${updated.url}.` : `Domain applied: ${updated.url}`));
|
|
52
53
|
}
|
|
53
54
|
catch (error) {
|
|
54
55
|
if (error instanceof ApiError && error.status === 400) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
/**
|
|
3
|
+
* Shows or resets the self-hosted registry's password — the CLI equivalent of
|
|
4
|
+
* Settings -> Registry -> "Show password" / "Reset password". A reset keeps
|
|
5
|
+
* every image (only the login changes), but every client using the old
|
|
6
|
+
* password has to `docker login` again.
|
|
7
|
+
*/
|
|
8
|
+
export default class RegistryPassword extends Command {
|
|
9
|
+
static description: string;
|
|
10
|
+
static examples: string[];
|
|
11
|
+
static flags: {
|
|
12
|
+
reset: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
show: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
14
|
+
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
};
|
|
18
|
+
run(): Promise<void>;
|
|
19
|
+
}
|