@hideandseeklab/aoox 0.1.0-alpha.3 → 0.1.0-alpha.5
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 +70 -10
- package/assets/install/README.md +4 -0
- package/assets/install/docker-compose.dist.yml +12 -0
- package/dist/commands/install.js +24 -4
- package/dist/commands/reinstall.d.ts +25 -0
- package/dist/commands/reinstall.js +235 -0
- package/dist/lib/docker.d.ts +2 -0
- package/dist/lib/docker.js +12 -0
- package/dist/lib/reinstall.d.ts +66 -0
- package/dist/lib/reinstall.js +204 -0
- package/dist/lib/system.d.ts +2 -0
- package/dist/lib/system.js +22 -1
- package/oclif.manifest.json +61 -1
- package/package.json +35 -12
package/README.md
CHANGED
|
@@ -3,6 +3,12 @@ aoox
|
|
|
3
3
|
|
|
4
4
|
CLI for [aoox](https://github.com/hideandseeklab/aoox-api), a self-hosted PaaS — build and deploy
|
|
5
5
|
|
|
6
|
+
Website: [aoox.dev](https://aoox.dev) · Docs: [aoox.dev/docs](https://aoox.dev/docs) · Changelog: [aoox.dev/changelog](https://aoox.dev/changelog)
|
|
7
|
+
|
|
8
|
+
Related repos: [aoox-api](https://github.com/hideandseeklab/aoox-api) (backend) ·
|
|
9
|
+
[aoox-web](https://github.com/hideandseeklab/aoox-web) (dashboard) ·
|
|
10
|
+
[aoox-landing](https://github.com/hideandseeklab/aoox-landing) (website and docs).
|
|
11
|
+
|
|
6
12
|
|
|
7
13
|
[](https://oclif.io)
|
|
8
14
|
[](https://npmjs.org/package/@hideandseeklab/aoox)
|
|
@@ -21,7 +27,7 @@ $ npm install -g @hideandseeklab/aoox
|
|
|
21
27
|
$ aoox COMMAND
|
|
22
28
|
running command...
|
|
23
29
|
$ aoox (--version)
|
|
24
|
-
@hideandseeklab/aoox/0.1.0-alpha.
|
|
30
|
+
@hideandseeklab/aoox/0.1.0-alpha.5 linux-x64 node-v24.21.0
|
|
25
31
|
$ aoox --help [COMMAND]
|
|
26
32
|
USAGE
|
|
27
33
|
$ aoox COMMAND
|
|
@@ -31,6 +37,26 @@ USAGE
|
|
|
31
37
|
|
|
32
38
|
# Installation
|
|
33
39
|
|
|
40
|
+
## Linux / macOS (no Node.js required)
|
|
41
|
+
|
|
42
|
+
A standalone install script downloads a tarball with its own bundled Node.js runtime — nothing
|
|
43
|
+
to install first, works even on a machine that will never otherwise touch Node.js (e.g. a bare
|
|
44
|
+
VPS before running `aoox install` on it):
|
|
45
|
+
|
|
46
|
+
```sh-session
|
|
47
|
+
curl -fsSL https://aoox.dev/install-cli.sh | sh
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
This installs to `/usr/local/lib/aoox` + `/usr/local/bin/aoox` when run as root or with
|
|
51
|
+
passwordless `sudo` available, or `~/.local/lib/aoox` + `~/.local/bin/aoox` otherwise (a `curl |
|
|
52
|
+
sh` pipe can't relay an interactive `sudo` password prompt safely, so the script never tries).
|
|
53
|
+
Re-running it upgrades in place. Supports Linux (glibc — not Alpine/musl) and macOS on x64/arm64;
|
|
54
|
+
anything else needs the npm install below instead. See the comment header of
|
|
55
|
+
[`install-cli.sh`](https://github.com/hideandseeklab/aoox-landing/blob/main/public/install-cli.sh)
|
|
56
|
+
for every environment variable it accepts (pinning a version, a custom install directory, etc).
|
|
57
|
+
|
|
58
|
+
## npm (Windows, Alpine, or if you already have Node.js)
|
|
59
|
+
|
|
34
60
|
`aoox` is still in **alpha** — published to npm under the `alpha` dist-tag, not `latest`
|
|
35
61
|
(the package has never had a stable release, so `npm install -g @hideandseeklab/aoox` without a
|
|
36
62
|
tag will fail to find a version). Install explicitly with this tag:
|
|
@@ -41,7 +67,10 @@ npm install -g @hideandseeklab/aoox@alpha
|
|
|
41
67
|
|
|
42
68
|
`aoox` is then available globally. This also applies to `aoox install` on a new VPS —
|
|
43
69
|
Node ≥22 must already be installed on that VPS **before** the step above (`aoox install`
|
|
44
|
-
itself needs Node to run, so it cannot install Node for you first)
|
|
70
|
+
itself needs Node to run, so it cannot install Node for you first) — or use the install script
|
|
71
|
+
above, which needs no Node.js on the VPS at all.
|
|
72
|
+
|
|
73
|
+
## From source
|
|
45
74
|
|
|
46
75
|
To install from source (e.g. to contribute, or to get the latest `main` before it is
|
|
47
76
|
released to npm):
|
|
@@ -73,6 +102,7 @@ npm link # or: npm install -g .
|
|
|
73
102
|
* [`aoox plugins unlink [PLUGIN]`](#aoox-plugins-unlink-plugin)
|
|
74
103
|
* [`aoox plugins update`](#aoox-plugins-update)
|
|
75
104
|
* [`aoox registry domain`](#aoox-registry-domain)
|
|
105
|
+
* [`aoox reinstall`](#aoox-reinstall)
|
|
76
106
|
* [`aoox update`](#aoox-update)
|
|
77
107
|
* [`aoox whoami`](#aoox-whoami)
|
|
78
108
|
|
|
@@ -102,7 +132,7 @@ EXAMPLES
|
|
|
102
132
|
$ aoox deploy --tag v1.2.3
|
|
103
133
|
```
|
|
104
134
|
|
|
105
|
-
_See code: [src/commands/deploy.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.
|
|
135
|
+
_See code: [src/commands/deploy.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.5/src/commands/deploy.ts)_
|
|
106
136
|
|
|
107
137
|
## `aoox domain set`
|
|
108
138
|
|
|
@@ -128,7 +158,7 @@ EXAMPLES
|
|
|
128
158
|
$ aoox domain set --web panel.example.com --api api.example.com --acme-email you@example.com
|
|
129
159
|
```
|
|
130
160
|
|
|
131
|
-
_See code: [src/commands/domain/set.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.
|
|
161
|
+
_See code: [src/commands/domain/set.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.5/src/commands/domain/set.ts)_
|
|
132
162
|
|
|
133
163
|
## `aoox help [COMMAND]`
|
|
134
164
|
|
|
@@ -181,7 +211,7 @@ EXAMPLES
|
|
|
181
211
|
sudo aoox install --web-domain panel.example.com --api-domain api.panel.example.com --acme-email me@example.com
|
|
182
212
|
```
|
|
183
213
|
|
|
184
|
-
_See code: [src/commands/install.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.
|
|
214
|
+
_See code: [src/commands/install.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.5/src/commands/install.ts)_
|
|
185
215
|
|
|
186
216
|
## `aoox link`
|
|
187
217
|
|
|
@@ -206,7 +236,7 @@ EXAMPLES
|
|
|
206
236
|
$ aoox link --project <id> --app <id>
|
|
207
237
|
```
|
|
208
238
|
|
|
209
|
-
_See code: [src/commands/link.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.
|
|
239
|
+
_See code: [src/commands/link.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.5/src/commands/link.ts)_
|
|
210
240
|
|
|
211
241
|
## `aoox login`
|
|
212
242
|
|
|
@@ -229,7 +259,7 @@ EXAMPLES
|
|
|
229
259
|
$ aoox login --url https://panel.example.com --token aoox_xxx
|
|
230
260
|
```
|
|
231
261
|
|
|
232
|
-
_See code: [src/commands/login.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.
|
|
262
|
+
_See code: [src/commands/login.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.5/src/commands/login.ts)_
|
|
233
263
|
|
|
234
264
|
## `aoox plugins`
|
|
235
265
|
|
|
@@ -544,7 +574,37 @@ EXAMPLES
|
|
|
544
574
|
$ aoox registry domain --clear
|
|
545
575
|
```
|
|
546
576
|
|
|
547
|
-
_See code: [src/commands/registry/domain.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.
|
|
577
|
+
_See code: [src/commands/registry/domain.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.5/src/commands/registry/domain.ts)_
|
|
578
|
+
|
|
579
|
+
## `aoox reinstall`
|
|
580
|
+
|
|
581
|
+
Perbaiki/segarkan instalasi aoox yang sudah ada tanpa kehilangan data: tulis ulang compose, gabungkan .env.dist (secret tidak pernah dibuat ulang), lalu pull + recreate
|
|
582
|
+
|
|
583
|
+
```
|
|
584
|
+
USAGE
|
|
585
|
+
$ aoox reinstall [--dir <value>] [--dry-run] [--no-pull] [--terminal-ssh-user <value>] [-y]
|
|
586
|
+
|
|
587
|
+
FLAGS
|
|
588
|
+
-y, --yes Jangan tanya konfirmasi
|
|
589
|
+
--dir=<value> [default: /opt/aoox] Folder instalasi
|
|
590
|
+
--dry-run Cetak rencana (file yang berubah, key yang ditambah, perintah compose) tanpa mengubah
|
|
591
|
+
apa pun
|
|
592
|
+
--no-pull Lewati docker compose pull (pakai image yang sudah ada)
|
|
593
|
+
--terminal-ssh-user=<value> Isi/timpa TERMINAL_SSH_USER di .env.dist saat repair
|
|
594
|
+
|
|
595
|
+
DESCRIPTION
|
|
596
|
+
Perbaiki/segarkan instalasi aoox yang sudah ada tanpa kehilangan data: tulis ulang compose, gabungkan .env.dist
|
|
597
|
+
(secret tidak pernah dibuat ulang), lalu pull + recreate
|
|
598
|
+
|
|
599
|
+
EXAMPLES
|
|
600
|
+
sudo aoox reinstall --dry-run
|
|
601
|
+
|
|
602
|
+
sudo aoox reinstall
|
|
603
|
+
|
|
604
|
+
sudo aoox reinstall --yes --terminal-ssh-user root
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
_See code: [src/commands/reinstall.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.5/src/commands/reinstall.ts)_
|
|
548
608
|
|
|
549
609
|
## `aoox update`
|
|
550
610
|
|
|
@@ -568,7 +628,7 @@ EXAMPLES
|
|
|
568
628
|
$ aoox update --apply
|
|
569
629
|
```
|
|
570
630
|
|
|
571
|
-
_See code: [src/commands/update.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.
|
|
631
|
+
_See code: [src/commands/update.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.5/src/commands/update.ts)_
|
|
572
632
|
|
|
573
633
|
## `aoox whoami`
|
|
574
634
|
|
|
@@ -594,7 +654,7 @@ EXAMPLES
|
|
|
594
654
|
$ aoox whoami --json
|
|
595
655
|
```
|
|
596
656
|
|
|
597
|
-
_See code: [src/commands/whoami.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.
|
|
657
|
+
_See code: [src/commands/whoami.ts](https://github.com/hideandseeklab/aoox-cli/blob/v0.1.0-alpha.5/src/commands/whoami.ts)_
|
|
598
658
|
<!-- commandsstop -->
|
|
599
659
|
|
|
600
660
|
## Versioning
|
package/assets/install/README.md
CHANGED
|
@@ -8,3 +8,7 @@ Copies of `aoox-api`'s distribution compose files, bundled here so
|
|
|
8
8
|
|
|
9
9
|
**Keep these in sync by hand** when the source files change — there is no
|
|
10
10
|
automated check for drift yet.
|
|
11
|
+
|
|
12
|
+
`aoox reinstall` also reads these copies (it rewrites an existing install's compose
|
|
13
|
+
files from them and derives which `.env.dist` keys it may add from their `${VAR}`
|
|
14
|
+
references) — so a stale copy here means stale repairs, too.
|
|
@@ -109,6 +109,18 @@ services:
|
|
|
109
109
|
# SSH). Leave empty to keep configuring the panel's own domain manually
|
|
110
110
|
# via docker-compose.domain.yml (see its header).
|
|
111
111
|
INSTALL_DIR: ${INSTALL_DIR:-}
|
|
112
|
+
# The image references this stack was started from, same defaults as the
|
|
113
|
+
# `image:` lines below. Settings -> "Update aoox" reads API_IMAGE to tell
|
|
114
|
+
# whether the install follows :latest (a pinned tag never gets an "update
|
|
115
|
+
# available" badge), so keep them identical to the `image:` values.
|
|
116
|
+
API_IMAGE: ${API_IMAGE:-hideandseeklab/aoox-api:latest}
|
|
117
|
+
WEB_IMAGE: ${WEB_IMAGE:-hideandseeklab/aoox-web:latest}
|
|
118
|
+
# Optional switches, empty = off/unset. WEBHOOK_VERIFY_GITHUB_IP=true also
|
|
119
|
+
# requires GitHub deliveries to come from GitHub's published IP ranges;
|
|
120
|
+
# PREVIEW_DOMAIN is the base domain for pull-request previews
|
|
121
|
+
# (<app>-pr<N>.<domain>, needs a wildcard DNS record).
|
|
122
|
+
WEBHOOK_VERIFY_GITHUB_IP: ${WEBHOOK_VERIFY_GITHUB_IP:-}
|
|
123
|
+
PREVIEW_DOMAIN: ${PREVIEW_DOMAIN:-}
|
|
112
124
|
# The api container runs as the unprivileged `node` user; add the gid that
|
|
113
125
|
# owns the docker socket on the host (stat -c %g /var/run/docker.sock).
|
|
114
126
|
group_add:
|
package/dist/commands/install.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { confirm } from '@inquirer/prompts';
|
|
2
2
|
import { Command, Flags } from '@oclif/core';
|
|
3
3
|
import { randomBytes } from 'node:crypto';
|
|
4
|
-
import { copyFile, mkdir, stat, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { copyFile, mkdir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
5
5
|
import { resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { dockerInherit } from '../lib/docker.js';
|
|
@@ -117,13 +117,33 @@ export default class Install extends Command {
|
|
|
117
117
|
/* not installed yet, as expected */
|
|
118
118
|
}
|
|
119
119
|
if (exists && !flags.force) {
|
|
120
|
-
this.error(`Sudah ada instalasi di ${dir}.`, { suggestions: [
|
|
120
|
+
this.error(`Sudah ada instalasi di ${dir}.`, { suggestions: [
|
|
121
|
+
'Untuk memperbaiki/menyegarkan instalasi yang ada tanpa kehilangan data: `sudo aoox reinstall`.',
|
|
122
|
+
'Beri --force hanya untuk instalasi ulang dari nol — itu membuat secret baru dan memutus akses ke data lama.',
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
let hasSecrets = false;
|
|
127
|
+
if (exists) {
|
|
128
|
+
try {
|
|
129
|
+
hasSecrets = /^\s*(POSTGRES_PASSWORD|JWT_SECRET|ENCRYPTION_KEY)=\S/m.test(await readFile(`${dir}/.env.dist`, 'utf8'));
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
/* no .env.dist — nothing to overwrite */
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (hasSecrets) {
|
|
136
|
+
this.warn(`--force MENIMPA ${dir}/.env.dist dengan secret acak baru (POSTGRES_PASSWORD, JWT_SECRET, ENCRYPTION_KEY): ` +
|
|
137
|
+
'database lama tidak bisa diakses lagi dan semua kredensial tersimpan (registry, git, S3, notifikasi, 2FA) tidak bisa didekripsi. ' +
|
|
138
|
+
'Untuk memperbaiki instalasi yang ada tanpa kehilangan data, batalkan dan jalankan `sudo aoox reinstall`.');
|
|
121
139
|
}
|
|
122
140
|
if (flags.yes)
|
|
123
141
|
return;
|
|
124
142
|
const ok = await confirm({
|
|
125
|
-
default:
|
|
126
|
-
message:
|
|
143
|
+
default: !hasSecrets,
|
|
144
|
+
message: hasSecrets
|
|
145
|
+
? `Tetap timpa .env.dist dan buat secret baru di ${dir} (data lama tidak akan terbaca)?`
|
|
146
|
+
: `Pasang aoox di ${dir}${exists ? ' (menimpa yang ada)' : ''} dan jalankan docker compose up -d?`,
|
|
127
147
|
});
|
|
128
148
|
if (!ok)
|
|
129
149
|
this.exit(0);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class Reinstall extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
dir: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
|
+
'no-pull': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
'terminal-ssh-user': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
private assertPreconditions;
|
|
14
|
+
private atomicWrite;
|
|
15
|
+
private backup;
|
|
16
|
+
private ensureDocker;
|
|
17
|
+
private presentFiles;
|
|
18
|
+
private printPlan;
|
|
19
|
+
/**
|
|
20
|
+
* Config files the api container is running with — only trusted when its
|
|
21
|
+
* working_dir label is this install folder (another stack named `aoox`
|
|
22
|
+
* elsewhere must not steer our `-f` list).
|
|
23
|
+
*/
|
|
24
|
+
private runningStack;
|
|
25
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { confirm } from '@inquirer/prompts';
|
|
2
|
+
import { Command, Flags } from '@oclif/core';
|
|
3
|
+
import { chmod, copyFile, mkdir, readFile, rename, stat, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { dockerCapture, dockerInherit } from '../lib/docker.js';
|
|
7
|
+
import { backupStamp, chooseComposeFiles, composeArgs, composeDefaults, composeVariables, DIST_FILE, DOMAIN_FILE, mergeEnv, MissingSecretsError, OVERRIDE_FILE, parseEnv, repairDefaults, runningFileNames, summarizeDiff, } from '../lib/reinstall.js';
|
|
8
|
+
import { commandExists, dockerRunning, dockerSocketGid, isRoot, waitForApi } from '../lib/system.js';
|
|
9
|
+
const READY_TIMEOUT_MS = 120_000;
|
|
10
|
+
async function readIfExists(path) {
|
|
11
|
+
try {
|
|
12
|
+
return await readFile(path, 'utf8');
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export default class Reinstall extends Command {
|
|
19
|
+
static description = 'Perbaiki/segarkan instalasi aoox yang sudah ada tanpa kehilangan data: tulis ulang compose, gabungkan .env.dist (secret tidak pernah dibuat ulang), lalu pull + recreate';
|
|
20
|
+
static examples = [
|
|
21
|
+
'sudo <%= config.bin %> <%= command.id %> --dry-run',
|
|
22
|
+
'sudo <%= config.bin %> <%= command.id %>',
|
|
23
|
+
'sudo <%= config.bin %> <%= command.id %> --yes --terminal-ssh-user root',
|
|
24
|
+
];
|
|
25
|
+
static flags = {
|
|
26
|
+
dir: Flags.string({ default: '/opt/aoox', description: 'Folder instalasi' }),
|
|
27
|
+
'dry-run': Flags.boolean({ default: false, description: 'Cetak rencana (file yang berubah, key yang ditambah, perintah compose) tanpa mengubah apa pun' }),
|
|
28
|
+
'no-pull': Flags.boolean({ default: false, description: 'Lewati docker compose pull (pakai image yang sudah ada)' }),
|
|
29
|
+
'terminal-ssh-user': Flags.string({ description: 'Isi/timpa TERMINAL_SSH_USER di .env.dist saat repair' }),
|
|
30
|
+
yes: Flags.boolean({ char: 'y', default: false, description: 'Jangan tanya konfirmasi' }),
|
|
31
|
+
};
|
|
32
|
+
// eslint-disable-next-line complexity -- linear orchestration: plan, confirm, backup, apply, report
|
|
33
|
+
async run() {
|
|
34
|
+
const { flags } = await this.parse(Reinstall);
|
|
35
|
+
const dir = resolve(flags.dir);
|
|
36
|
+
this.assertPreconditions();
|
|
37
|
+
const envPath = `${dir}/.env.dist`;
|
|
38
|
+
const currentEnv = await readIfExists(envPath);
|
|
39
|
+
const currentCompose = await readIfExists(`${dir}/${DIST_FILE}`);
|
|
40
|
+
if (currentEnv === undefined || currentCompose === undefined) {
|
|
41
|
+
this.error(`Tidak ada instalasi aoox di ${dir} (${DIST_FILE} dan .env.dist harus ada).`, {
|
|
42
|
+
suggestions: ['Untuk instalasi baru: `sudo aoox install`. Folder lain: --dir <folder>.'],
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const assets = fileURLToPath(new URL('../../assets/install/', import.meta.url));
|
|
46
|
+
const newCompose = await readFile(`${assets}${DIST_FILE}`, 'utf8');
|
|
47
|
+
const currentDomain = await readIfExists(`${dir}/${DOMAIN_FILE}`);
|
|
48
|
+
const newDomain = currentDomain === undefined ? undefined : await readFile(`${assets}${DOMAIN_FILE}`, 'utf8');
|
|
49
|
+
let merge;
|
|
50
|
+
try {
|
|
51
|
+
const vars = composeVariables(newCompose, newDomain ?? '');
|
|
52
|
+
const defaults = repairDefaults(vars, { dockerGid: dockerSocketGid(), installDir: dir }, composeDefaults(newCompose, newDomain ?? ''));
|
|
53
|
+
merge = mergeEnv(currentEnv, defaults, flags['terminal-ssh-user'] ? { TERMINAL_SSH_USER: flags['terminal-ssh-user'] } : {});
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error instanceof MissingSecretsError)
|
|
57
|
+
this.error(error.message);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
const running = await this.runningStack(dir);
|
|
61
|
+
const present = await this.presentFiles(dir, runningFileNames(running));
|
|
62
|
+
const files = chooseComposeFiles({ present, runningConfigFiles: running });
|
|
63
|
+
const pull = flags['no-pull'] ? undefined : composeArgs(files, 'pull');
|
|
64
|
+
const up = composeArgs(files, 'up', '-d', '--force-recreate');
|
|
65
|
+
const composeChanged = newCompose !== currentCompose;
|
|
66
|
+
const domainChanged = newDomain !== undefined && newDomain !== currentDomain;
|
|
67
|
+
const envChanged = merge.content !== currentEnv;
|
|
68
|
+
const anyChange = composeChanged || domainChanged || envChanged;
|
|
69
|
+
this.printPlan({
|
|
70
|
+
composeDiff: composeChanged ? summarizeDiff(currentCompose, newCompose) : undefined,
|
|
71
|
+
dir,
|
|
72
|
+
domainDiff: domainChanged ? summarizeDiff(currentDomain ?? '', newDomain ?? '') : undefined,
|
|
73
|
+
files,
|
|
74
|
+
merge,
|
|
75
|
+
pull,
|
|
76
|
+
running,
|
|
77
|
+
up,
|
|
78
|
+
});
|
|
79
|
+
if (flags['dry-run']) {
|
|
80
|
+
this.log('\n(dry-run) Tidak ada yang diubah.');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
await this.ensureDocker();
|
|
84
|
+
if (!flags.yes) {
|
|
85
|
+
const ok = await confirm({
|
|
86
|
+
default: true,
|
|
87
|
+
message: `Terapkan di ${dir} (data & secret tidak disentuh) lalu recreate container?`,
|
|
88
|
+
});
|
|
89
|
+
if (!ok)
|
|
90
|
+
this.exit(0);
|
|
91
|
+
}
|
|
92
|
+
let backupDir;
|
|
93
|
+
if (anyChange) {
|
|
94
|
+
backupDir = `${dir}/backups/${backupStamp()}`;
|
|
95
|
+
await this.backup(dir, backupDir, present);
|
|
96
|
+
if (composeChanged)
|
|
97
|
+
await this.atomicWrite(`${dir}/${DIST_FILE}`, newCompose, 0o644);
|
|
98
|
+
if (domainChanged && newDomain !== undefined)
|
|
99
|
+
await this.atomicWrite(`${dir}/${DOMAIN_FILE}`, newDomain, 0o644);
|
|
100
|
+
if (envChanged)
|
|
101
|
+
await this.atomicWrite(envPath, merge.content, 0o600);
|
|
102
|
+
}
|
|
103
|
+
if (pull) {
|
|
104
|
+
this.log('==> docker compose pull');
|
|
105
|
+
await dockerInherit(pull, dir);
|
|
106
|
+
}
|
|
107
|
+
this.log('==> docker compose up -d --force-recreate');
|
|
108
|
+
await dockerInherit(up, dir);
|
|
109
|
+
const env = parseEnv(merge.content);
|
|
110
|
+
this.log('==> Menunggu API siap');
|
|
111
|
+
const ready = await waitForApi(env.get('API_PORT') || '3001', READY_TIMEOUT_MS);
|
|
112
|
+
if (!ready)
|
|
113
|
+
this.warn(`API belum menjawab dalam waktu yang diharapkan — cek \`docker compose ${files.map((f) => `-f ${f}`).join(' ')} logs api\` di ${dir}.`);
|
|
114
|
+
const version = await dockerCapture([...composeArgs(files, 'exec', '-T', 'api', 'node', '-p', "require('./package.json').version")], dir);
|
|
115
|
+
this.log('');
|
|
116
|
+
this.log(`Selesai. aoox di ${dir} disegarkan${version ? ` (versi ${version})` : ''}.`);
|
|
117
|
+
this.log(` Key .env.dist ditambahkan: ${merge.added.length > 0 ? merge.added.join(', ') : '(tidak ada)'}`);
|
|
118
|
+
this.log(` Backup file lama: ${backupDir ?? '(tidak ada perubahan file, tidak perlu backup)'}`);
|
|
119
|
+
this.log(` Buka: ${env.get('WEB_ORIGIN') || 'http://localhost:3000'}`);
|
|
120
|
+
}
|
|
121
|
+
assertPreconditions() {
|
|
122
|
+
if (process.platform !== 'linux') {
|
|
123
|
+
this.error('aoox reinstall hanya untuk VPS Linux (dijalankan langsung di server tujuan).');
|
|
124
|
+
}
|
|
125
|
+
if (!isRoot()) {
|
|
126
|
+
this.error('Perlu root — perintah ini membaca .env.dist (izin 600) dan mengelola Docker.', {
|
|
127
|
+
suggestions: [
|
|
128
|
+
'sudo aoox reinstall …',
|
|
129
|
+
'Kalau `sudo: aoox: command not found` (terpasang di ~/.local/bin): sudo "$(command -v aoox)" reinstall …',
|
|
130
|
+
],
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async atomicWrite(path, content, mode) {
|
|
135
|
+
const tmp = `${path}.tmp-${process.pid}`;
|
|
136
|
+
await writeFile(tmp, content, { mode });
|
|
137
|
+
await rename(tmp, path);
|
|
138
|
+
}
|
|
139
|
+
async backup(dir, backupDir, present) {
|
|
140
|
+
await mkdir(backupDir, { mode: 0o700, recursive: true });
|
|
141
|
+
for (const name of ['.env.dist', ...present]) {
|
|
142
|
+
const src = `${dir}/${name}`;
|
|
143
|
+
// eslint-disable-next-line no-await-in-loop
|
|
144
|
+
await copyFile(src, `${backupDir}/${name}`);
|
|
145
|
+
// .env.dist holds the secrets — the copy must be just as private.
|
|
146
|
+
// eslint-disable-next-line no-await-in-loop
|
|
147
|
+
if (name === '.env.dist')
|
|
148
|
+
await chmod(`${backupDir}/${name}`, 0o600);
|
|
149
|
+
}
|
|
150
|
+
this.log(`==> Backup file lama ke ${backupDir}`);
|
|
151
|
+
}
|
|
152
|
+
async ensureDocker() {
|
|
153
|
+
if (!commandExists('docker') || !dockerRunning()) {
|
|
154
|
+
this.error('Docker tidak ditemukan atau tidak berjalan (atau tidak ada akses ke socket-nya).', {
|
|
155
|
+
suggestions: ['Jalankan dengan sudo, dan pastikan `systemctl status docker` aktif.'],
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async presentFiles(dir, extra) {
|
|
160
|
+
const found = new Set();
|
|
161
|
+
for (const name of new Set([DIST_FILE, DOMAIN_FILE, OVERRIDE_FILE, ...extra])) {
|
|
162
|
+
try {
|
|
163
|
+
// eslint-disable-next-line no-await-in-loop
|
|
164
|
+
await stat(`${dir}/${name}`);
|
|
165
|
+
found.add(name);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
/* absent */
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return found;
|
|
172
|
+
}
|
|
173
|
+
printPlan(p) {
|
|
174
|
+
this.log(`Instalasi: ${p.dir}`);
|
|
175
|
+
const show = (name, diff) => {
|
|
176
|
+
if (!diff) {
|
|
177
|
+
this.log(`\n${name}: tidak berubah`);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
this.log(`\n${name}: ditulis ulang dari salinan yang dibundel (+${diff.added} −${diff.removed} baris)`);
|
|
181
|
+
for (const l of diff.lines)
|
|
182
|
+
this.log(` ${l}`);
|
|
183
|
+
};
|
|
184
|
+
show(DIST_FILE, p.composeDiff);
|
|
185
|
+
if (p.files.includes(DOMAIN_FILE))
|
|
186
|
+
show(DOMAIN_FILE, p.domainDiff);
|
|
187
|
+
this.log(`\n.env.dist: ${p.merge.added.length + p.merge.overridden.length > 0 ? 'digabung (secret & nilai lama dipertahankan)' : 'tidak berubah'}`);
|
|
188
|
+
for (const k of p.merge.added)
|
|
189
|
+
this.log(` + ${k} (ditambahkan)`);
|
|
190
|
+
for (const k of p.merge.overridden)
|
|
191
|
+
this.log(` ~ ${k} (diganti sesuai flag)`);
|
|
192
|
+
for (const w of p.merge.warnings)
|
|
193
|
+
this.warn(w);
|
|
194
|
+
this.log(`\n${OVERRIDE_FILE}: tidak disentuh`);
|
|
195
|
+
this.log(`File compose: ${p.files.join(' + ')}${p.running ? ' (sama seperti stack yang berjalan)' : ' (container api tidak ditemukan — pakai aturan bawaan)'}`);
|
|
196
|
+
const dropped = runningFileNames(p.running).filter((n) => !p.files.includes(n));
|
|
197
|
+
if (dropped.length > 0)
|
|
198
|
+
this.warn(`File compose dari stack berjalan tidak ditemukan lagi di folder dan dilewati: ${dropped.join(', ')}`);
|
|
199
|
+
this.log('Perintah:');
|
|
200
|
+
if (p.pull)
|
|
201
|
+
this.log(` docker ${p.pull.join(' ')}`);
|
|
202
|
+
this.log(` docker ${p.up.join(' ')}`);
|
|
203
|
+
this.log('Volume tidak disentuh.');
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Config files the api container is running with — only trusted when its
|
|
207
|
+
* working_dir label is this install folder (another stack named `aoox`
|
|
208
|
+
* elsewhere must not steer our `-f` list).
|
|
209
|
+
*/
|
|
210
|
+
async runningStack(dir) {
|
|
211
|
+
const id = await dockerCapture([
|
|
212
|
+
'ps',
|
|
213
|
+
'-a',
|
|
214
|
+
'--filter',
|
|
215
|
+
'label=com.docker.compose.project=aoox',
|
|
216
|
+
'--filter',
|
|
217
|
+
'label=com.docker.compose.service=api',
|
|
218
|
+
'--format',
|
|
219
|
+
'{{.ID}}',
|
|
220
|
+
]);
|
|
221
|
+
const first = id?.split('\n')[0];
|
|
222
|
+
if (!first)
|
|
223
|
+
return undefined;
|
|
224
|
+
const out = await dockerCapture([
|
|
225
|
+
'inspect',
|
|
226
|
+
'-f',
|
|
227
|
+
'{{index .Config.Labels "com.docker.compose.project.working_dir"}}|{{index .Config.Labels "com.docker.compose.project.config_files"}}',
|
|
228
|
+
first,
|
|
229
|
+
]);
|
|
230
|
+
if (!out)
|
|
231
|
+
return undefined;
|
|
232
|
+
const [workdir, files] = out.split('|');
|
|
233
|
+
return workdir && resolve(workdir) === dir && files ? files : undefined;
|
|
234
|
+
}
|
|
235
|
+
}
|
package/dist/lib/docker.d.ts
CHANGED
|
@@ -9,3 +9,5 @@ export declare function dockerInherit(args: string[], cwd: string): Promise<void
|
|
|
9
9
|
* touches argv (visible in `ps`/Task Manager) or shell history.
|
|
10
10
|
*/
|
|
11
11
|
export declare function dockerLogin(registryUrl: string, username: string, password: string, cwd: string): Promise<void>;
|
|
12
|
+
/** `docker <args>` capturing stdout; empty string on any failure (missing docker, non-zero exit). */
|
|
13
|
+
export declare function dockerCapture(args: string[], cwd?: string): Promise<string>;
|
package/dist/lib/docker.js
CHANGED
|
@@ -49,3 +49,15 @@ export function dockerLogin(registryUrl, username, password, cwd) {
|
|
|
49
49
|
child.stdin.end();
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
+
/** `docker <args>` capturing stdout; empty string on any failure (missing docker, non-zero exit). */
|
|
53
|
+
export function dockerCapture(args, cwd) {
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
const child = spawn('docker', args, { cwd, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
56
|
+
let out = '';
|
|
57
|
+
child.stdout.on('data', (chunk) => {
|
|
58
|
+
out += String(chunk);
|
|
59
|
+
});
|
|
60
|
+
child.on('error', () => resolve(''));
|
|
61
|
+
child.on('close', (code) => resolve(code === 0 ? out.trim() : ''));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Secrets `aoox reinstall` must never invent — losing them means the old database/credentials are unreachable. */
|
|
2
|
+
export declare const REQUIRED_SECRETS: readonly ["POSTGRES_PASSWORD", "JWT_SECRET", "ENCRYPTION_KEY"];
|
|
3
|
+
export declare class MissingSecretsError extends Error {
|
|
4
|
+
readonly missing: string[];
|
|
5
|
+
constructor(missing: string[]);
|
|
6
|
+
}
|
|
7
|
+
/** Active (non-comment) `KEY=value` lines. Later duplicates win, as in `docker compose --env-file`. */
|
|
8
|
+
export declare function parseEnv(text: string): Map<string, string>;
|
|
9
|
+
/** Every `${VAR}` / `${VAR:-x}` / `${VAR:?msg}` the given compose texts read. */
|
|
10
|
+
export declare function composeVariables(...composeTexts: string[]): Set<string>;
|
|
11
|
+
/** `${VAR:-default}` fallbacks the compose files already apply (first occurrence wins). */
|
|
12
|
+
export declare function composeDefaults(...composeTexts: string[]): Map<string, string>;
|
|
13
|
+
export interface DefaultsContext {
|
|
14
|
+
dockerGid: string;
|
|
15
|
+
installDir: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The safe-default values a repair may add, taken from `buildEnvFile` (the
|
|
19
|
+
* single source of truth for what a fresh install writes) and restricted to
|
|
20
|
+
* keys the bundled compose actually reads.
|
|
21
|
+
*/
|
|
22
|
+
export declare function repairDefaults(composeVars: Set<string>, ctx: DefaultsContext, fallbacks?: Map<string, string>): Map<string, string>;
|
|
23
|
+
export interface MergeResult {
|
|
24
|
+
/** Keys appended (in file order) — does not include overrides of existing keys. */
|
|
25
|
+
added: string[];
|
|
26
|
+
content: string;
|
|
27
|
+
/** Existing keys whose value was replaced by an explicit override. */
|
|
28
|
+
overridden: string[];
|
|
29
|
+
warnings: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Merges `defaults` into an existing `.env.dist` without regenerating anything:
|
|
33
|
+
* every existing line (values, order, comments, unknown keys) is kept byte for
|
|
34
|
+
* byte; missing keys are appended at the end; `overrides` (explicit user
|
|
35
|
+
* flags) replace the value of an existing key in place. Refuses when a required
|
|
36
|
+
* secret is absent — see {@link REQUIRED_SECRETS}.
|
|
37
|
+
*/
|
|
38
|
+
export declare function mergeEnv(existing: string, defaults: Map<string, string>, overrides?: Record<string, string>, stamp?: string): MergeResult;
|
|
39
|
+
export declare const DIST_FILE = "docker-compose.dist.yml";
|
|
40
|
+
export declare const DOMAIN_FILE = "docker-compose.domain.yml";
|
|
41
|
+
export declare const OVERRIDE_FILE = "docker-compose.override.yml";
|
|
42
|
+
export interface ComposeFilesInput {
|
|
43
|
+
/** Which compose files exist in the install folder (basenames). */
|
|
44
|
+
present: Iterable<string>;
|
|
45
|
+
/** `com.docker.compose.project.config_files` of the running api container, if any. */
|
|
46
|
+
runningConfigFiles?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Which `-f` files to pass. Preferred: exactly the set the running stack was
|
|
50
|
+
* started with (same basenames, only those still present, dist always first).
|
|
51
|
+
* Fallback: dist, the manual domain override if the folder has it, then
|
|
52
|
+
* `docker-compose.override.yml` if present — Compose only auto-includes that
|
|
53
|
+
* one when the main file is literally `docker-compose.yml`, so it must be
|
|
54
|
+
* passed explicitly.
|
|
55
|
+
*/
|
|
56
|
+
/** Basenames listed in the running stack's `config_files` label, in order. */
|
|
57
|
+
export declare function runningFileNames(configFiles?: string): string[];
|
|
58
|
+
export declare function chooseComposeFiles({ present, runningConfigFiles }: ComposeFilesInput): string[];
|
|
59
|
+
export declare function composeArgs(files: string[], ...rest: string[]): string[];
|
|
60
|
+
/** Line-set diff (not an LCS diff — enough for "what changed" in a dry-run). */
|
|
61
|
+
export declare function summarizeDiff(before: string, after: string, max?: number): {
|
|
62
|
+
added: number;
|
|
63
|
+
lines: string[];
|
|
64
|
+
removed: number;
|
|
65
|
+
};
|
|
66
|
+
export declare function backupStamp(d?: Date): string;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { buildEnvFile } from './install-env.js';
|
|
2
|
+
/** Secrets `aoox reinstall` must never invent — losing them means the old database/credentials are unreachable. */
|
|
3
|
+
export const REQUIRED_SECRETS = ['POSTGRES_PASSWORD', 'JWT_SECRET', 'ENCRYPTION_KEY'];
|
|
4
|
+
/**
|
|
5
|
+
* Keys `buildEnvFile` writes that are specific to one installation (or a
|
|
6
|
+
* secret). A repair never adds these: it can't know the right value, and the
|
|
7
|
+
* compose file already has a safe fallback for the ones it reads.
|
|
8
|
+
*/
|
|
9
|
+
const NEVER_ADDED = new Set([
|
|
10
|
+
'ADMIN_EMAIL',
|
|
11
|
+
'ADMIN_NAME',
|
|
12
|
+
'ADMIN_PASSWORD',
|
|
13
|
+
'API_DOMAIN',
|
|
14
|
+
'ENCRYPTION_KEY',
|
|
15
|
+
'JWT_SECRET',
|
|
16
|
+
'POSTGRES_PASSWORD',
|
|
17
|
+
'PROXY_ACME_EMAIL',
|
|
18
|
+
'PUBLIC_API_URL',
|
|
19
|
+
'PUBLIC_IP',
|
|
20
|
+
'WEB_DOMAIN',
|
|
21
|
+
'WEB_ORIGIN',
|
|
22
|
+
]);
|
|
23
|
+
export class MissingSecretsError extends Error {
|
|
24
|
+
missing;
|
|
25
|
+
constructor(missing) {
|
|
26
|
+
super(`.env.dist tidak punya ${missing.join(', ')}. Ini rahasia yang tidak boleh dibuat ulang (akses ke database/kredensial lama akan putus) — pulihkan dari backup Anda lalu ulangi.`);
|
|
27
|
+
this.missing = missing;
|
|
28
|
+
this.name = 'MissingSecretsError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Active (non-comment) `KEY=value` lines. Later duplicates win, as in `docker compose --env-file`. */
|
|
32
|
+
export function parseEnv(text) {
|
|
33
|
+
const out = new Map();
|
|
34
|
+
for (const line of text.split(/\r?\n/)) {
|
|
35
|
+
const m = /^\s*([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.exec(line);
|
|
36
|
+
if (m)
|
|
37
|
+
out.set(m[1], m[2]);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
/** Every `${VAR}` / `${VAR:-x}` / `${VAR:?msg}` the given compose texts read. */
|
|
42
|
+
export function composeVariables(...composeTexts) {
|
|
43
|
+
const referenced = new Set();
|
|
44
|
+
for (const text of composeTexts) {
|
|
45
|
+
for (const m of text.matchAll(/\$\{([A-Z_][A-Z0-9_]*)(?::[?-][^}]*)?\}/g))
|
|
46
|
+
referenced.add(m[1]);
|
|
47
|
+
}
|
|
48
|
+
return referenced;
|
|
49
|
+
}
|
|
50
|
+
/** `${VAR:-default}` fallbacks the compose files already apply (first occurrence wins). */
|
|
51
|
+
export function composeDefaults(...composeTexts) {
|
|
52
|
+
const out = new Map();
|
|
53
|
+
for (const text of composeTexts) {
|
|
54
|
+
for (const m of text.matchAll(/\$\{([A-Z_][A-Z0-9_]*):-([^}]*)\}/g))
|
|
55
|
+
if (!out.has(m[1]))
|
|
56
|
+
out.set(m[1], m[2]);
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The safe-default values a repair may add, taken from `buildEnvFile` (the
|
|
62
|
+
* single source of truth for what a fresh install writes) and restricted to
|
|
63
|
+
* keys the bundled compose actually reads.
|
|
64
|
+
*/
|
|
65
|
+
export function repairDefaults(composeVars, ctx, fallbacks = new Map()) {
|
|
66
|
+
const fresh = parseEnv(buildEnvFile({
|
|
67
|
+
dockerGid: ctx.dockerGid,
|
|
68
|
+
encryptionKey: 'x',
|
|
69
|
+
installDir: ctx.installDir,
|
|
70
|
+
jwtSecret: 'x',
|
|
71
|
+
postgresPassword: 'x',
|
|
72
|
+
publicApiUrl: 'x',
|
|
73
|
+
webOrigin: 'x',
|
|
74
|
+
}));
|
|
75
|
+
const out = new Map();
|
|
76
|
+
for (const [key, value] of fresh) {
|
|
77
|
+
// A value equal to the compose's own fallback changes nothing — skip the noise.
|
|
78
|
+
if (composeVars.has(key) && !NEVER_ADDED.has(key) && fallbacks.get(key) !== value)
|
|
79
|
+
out.set(key, value);
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Merges `defaults` into an existing `.env.dist` without regenerating anything:
|
|
85
|
+
* every existing line (values, order, comments, unknown keys) is kept byte for
|
|
86
|
+
* byte; missing keys are appended at the end; `overrides` (explicit user
|
|
87
|
+
* flags) replace the value of an existing key in place. Refuses when a required
|
|
88
|
+
* secret is absent — see {@link REQUIRED_SECRETS}.
|
|
89
|
+
*/
|
|
90
|
+
export function mergeEnv(existing, defaults, overrides = {}, stamp = new Date().toISOString()) {
|
|
91
|
+
const present = parseEnv(existing);
|
|
92
|
+
const missing = REQUIRED_SECRETS.filter((k) => !present.get(k));
|
|
93
|
+
if (missing.length > 0)
|
|
94
|
+
throw new MissingSecretsError(missing);
|
|
95
|
+
const overridden = [];
|
|
96
|
+
let content = existing;
|
|
97
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
98
|
+
if (present.has(key)) {
|
|
99
|
+
if (present.get(key) !== value) {
|
|
100
|
+
content = replaceLastAssignment(content, key, value);
|
|
101
|
+
overridden.push(key);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
defaults = new Map(defaults).set(key, value);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const added = [...defaults.keys()].filter((k) => !present.has(k));
|
|
109
|
+
if (added.length > 0) {
|
|
110
|
+
if (!content.endsWith('\n'))
|
|
111
|
+
content += '\n';
|
|
112
|
+
content += `\n# Added by \`aoox reinstall\` (${stamp}).\n`;
|
|
113
|
+
for (const key of added)
|
|
114
|
+
content += `${key}=${overrides[key] ?? defaults.get(key)}\n`;
|
|
115
|
+
}
|
|
116
|
+
const warnings = [];
|
|
117
|
+
const sshUser = parseEnv(content).get('TERMINAL_SSH_USER');
|
|
118
|
+
if (sshUser === '') {
|
|
119
|
+
warnings.push('TERMINAL_SSH_USER kosong — Terminal web akan error. Isi lewat --terminal-ssh-user atau Settings → Environment.');
|
|
120
|
+
}
|
|
121
|
+
return { added, content, overridden, warnings };
|
|
122
|
+
}
|
|
123
|
+
function replaceLastAssignment(text, key, value) {
|
|
124
|
+
const lines = text.split('\n');
|
|
125
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
126
|
+
if (new RegExp(`^\\s*${key}=`).test(lines[i])) {
|
|
127
|
+
lines[i] = `${key}=${value}`;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return lines.join('\n');
|
|
132
|
+
}
|
|
133
|
+
export const DIST_FILE = 'docker-compose.dist.yml';
|
|
134
|
+
export const DOMAIN_FILE = 'docker-compose.domain.yml';
|
|
135
|
+
export const OVERRIDE_FILE = 'docker-compose.override.yml';
|
|
136
|
+
/**
|
|
137
|
+
* Which `-f` files to pass. Preferred: exactly the set the running stack was
|
|
138
|
+
* started with (same basenames, only those still present, dist always first).
|
|
139
|
+
* Fallback: dist, the manual domain override if the folder has it, then
|
|
140
|
+
* `docker-compose.override.yml` if present — Compose only auto-includes that
|
|
141
|
+
* one when the main file is literally `docker-compose.yml`, so it must be
|
|
142
|
+
* passed explicitly.
|
|
143
|
+
*/
|
|
144
|
+
/** Basenames listed in the running stack's `config_files` label, in order. */
|
|
145
|
+
export function runningFileNames(configFiles) {
|
|
146
|
+
if (!configFiles)
|
|
147
|
+
return [];
|
|
148
|
+
return configFiles
|
|
149
|
+
.split(',')
|
|
150
|
+
.map((p) => p.trim().split(/[/\\]/).pop() ?? '')
|
|
151
|
+
.filter(Boolean);
|
|
152
|
+
}
|
|
153
|
+
export function chooseComposeFiles({ present, runningConfigFiles }) {
|
|
154
|
+
const have = new Set(present);
|
|
155
|
+
if (runningConfigFiles) {
|
|
156
|
+
const fromRunning = runningFileNames(runningConfigFiles).filter((name) => have.has(name));
|
|
157
|
+
if (fromRunning.includes(DIST_FILE)) {
|
|
158
|
+
return [DIST_FILE, ...fromRunning.filter((n) => n !== DIST_FILE)];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return [DIST_FILE, ...[DOMAIN_FILE, OVERRIDE_FILE].filter((n) => have.has(n))];
|
|
162
|
+
}
|
|
163
|
+
export function composeArgs(files, ...rest) {
|
|
164
|
+
return ['compose', ...files.flatMap((f) => ['-f', f]), '--env-file', '.env.dist', ...rest];
|
|
165
|
+
}
|
|
166
|
+
function count(text) {
|
|
167
|
+
const m = new Map();
|
|
168
|
+
const normalized = text.replaceAll(String.fromCodePoint(13), '');
|
|
169
|
+
for (const line of normalized.split(String.fromCodePoint(10))) {
|
|
170
|
+
m.set(line, (m.get(line) ?? 0) + 1);
|
|
171
|
+
}
|
|
172
|
+
return m;
|
|
173
|
+
}
|
|
174
|
+
/** Line-set diff (not an LCS diff — enough for "what changed" in a dry-run). */
|
|
175
|
+
export function summarizeDiff(before, after, max = 30) {
|
|
176
|
+
const b = count(before);
|
|
177
|
+
const a = count(after);
|
|
178
|
+
const lines = [];
|
|
179
|
+
let removed = 0;
|
|
180
|
+
let added = 0;
|
|
181
|
+
for (const [l, n] of b) {
|
|
182
|
+
const extra = n - (a.get(l) ?? 0);
|
|
183
|
+
for (let i = 0; i < extra; i++) {
|
|
184
|
+
removed++;
|
|
185
|
+
if (l.trim())
|
|
186
|
+
lines.push(`- ${l}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
for (const [l, n] of a) {
|
|
190
|
+
const extra = n - (b.get(l) ?? 0);
|
|
191
|
+
for (let i = 0; i < extra; i++) {
|
|
192
|
+
added++;
|
|
193
|
+
if (l.trim())
|
|
194
|
+
lines.push(`+ ${l}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const shown = lines.slice(0, max);
|
|
198
|
+
if (lines.length > max)
|
|
199
|
+
shown.push(`… (${lines.length - max} baris lagi)`);
|
|
200
|
+
return { added, lines: shown, removed };
|
|
201
|
+
}
|
|
202
|
+
export function backupStamp(d = new Date()) {
|
|
203
|
+
return d.toISOString().replaceAll(/[:.]/g, '-');
|
|
204
|
+
}
|
package/dist/lib/system.d.ts
CHANGED
|
@@ -14,3 +14,5 @@ export declare function isIpv4(text: string): boolean;
|
|
|
14
14
|
* own idea of "this server's IP" agrees with what the installer printed.
|
|
15
15
|
*/
|
|
16
16
|
export declare function detectPublicIp(): Promise<string | undefined>;
|
|
17
|
+
/** Polls the API's own setup-status endpoint — migrations run on boot, so "container up" isn't "ready". */
|
|
18
|
+
export declare function waitForApi(port: string, timeoutMs: number, pollMs?: number): Promise<boolean>;
|
package/dist/lib/system.js
CHANGED
|
@@ -24,7 +24,7 @@ export function dockerRunning() {
|
|
|
24
24
|
/** gid that owns the host's docker socket — the api container needs it (see .env.dist.example). */
|
|
25
25
|
export function dockerSocketGid() {
|
|
26
26
|
try {
|
|
27
|
-
return execFileSync('stat', ['-c', '%g', '/var/run/docker.sock']).toString().trim() || '0';
|
|
27
|
+
return execFileSync('stat', ['-c', '%g', '/var/run/docker.sock'], { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim() || '0';
|
|
28
28
|
}
|
|
29
29
|
catch {
|
|
30
30
|
return '0';
|
|
@@ -64,3 +64,24 @@ export async function detectPublicIp() {
|
|
|
64
64
|
return undefined;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
+
/** Polls the API's own setup-status endpoint — migrations run on boot, so "container up" isn't "ready". */
|
|
68
|
+
export async function waitForApi(port, timeoutMs, pollMs = 2000) {
|
|
69
|
+
const deadline = Date.now() + timeoutMs;
|
|
70
|
+
for (;;) {
|
|
71
|
+
try {
|
|
72
|
+
// eslint-disable-next-line no-await-in-loop
|
|
73
|
+
const res = await fetch(`http://localhost:${port}/auth/setup-status`, { signal: AbortSignal.timeout(3000) });
|
|
74
|
+
if (res.ok)
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
/* API not answering yet */
|
|
79
|
+
}
|
|
80
|
+
if (Date.now() >= deadline)
|
|
81
|
+
return false;
|
|
82
|
+
// eslint-disable-next-line no-await-in-loop
|
|
83
|
+
await new Promise((resolve) => {
|
|
84
|
+
setTimeout(resolve, pollMs);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
package/oclif.manifest.json
CHANGED
|
@@ -282,6 +282,66 @@
|
|
|
282
282
|
"login.js"
|
|
283
283
|
]
|
|
284
284
|
},
|
|
285
|
+
"reinstall": {
|
|
286
|
+
"aliases": [],
|
|
287
|
+
"args": {},
|
|
288
|
+
"description": "Perbaiki/segarkan instalasi aoox yang sudah ada tanpa kehilangan data: tulis ulang compose, gabungkan .env.dist (secret tidak pernah dibuat ulang), lalu pull + recreate",
|
|
289
|
+
"examples": [
|
|
290
|
+
"sudo <%= config.bin %> <%= command.id %> --dry-run",
|
|
291
|
+
"sudo <%= config.bin %> <%= command.id %>",
|
|
292
|
+
"sudo <%= config.bin %> <%= command.id %> --yes --terminal-ssh-user root"
|
|
293
|
+
],
|
|
294
|
+
"flags": {
|
|
295
|
+
"dir": {
|
|
296
|
+
"description": "Folder instalasi",
|
|
297
|
+
"name": "dir",
|
|
298
|
+
"default": "/opt/aoox",
|
|
299
|
+
"hasDynamicHelp": false,
|
|
300
|
+
"multiple": false,
|
|
301
|
+
"type": "option"
|
|
302
|
+
},
|
|
303
|
+
"dry-run": {
|
|
304
|
+
"description": "Cetak rencana (file yang berubah, key yang ditambah, perintah compose) tanpa mengubah apa pun",
|
|
305
|
+
"name": "dry-run",
|
|
306
|
+
"allowNo": false,
|
|
307
|
+
"type": "boolean"
|
|
308
|
+
},
|
|
309
|
+
"no-pull": {
|
|
310
|
+
"description": "Lewati docker compose pull (pakai image yang sudah ada)",
|
|
311
|
+
"name": "no-pull",
|
|
312
|
+
"allowNo": false,
|
|
313
|
+
"type": "boolean"
|
|
314
|
+
},
|
|
315
|
+
"terminal-ssh-user": {
|
|
316
|
+
"description": "Isi/timpa TERMINAL_SSH_USER di .env.dist saat repair",
|
|
317
|
+
"name": "terminal-ssh-user",
|
|
318
|
+
"hasDynamicHelp": false,
|
|
319
|
+
"multiple": false,
|
|
320
|
+
"type": "option"
|
|
321
|
+
},
|
|
322
|
+
"yes": {
|
|
323
|
+
"char": "y",
|
|
324
|
+
"description": "Jangan tanya konfirmasi",
|
|
325
|
+
"name": "yes",
|
|
326
|
+
"allowNo": false,
|
|
327
|
+
"type": "boolean"
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
"hasDynamicHelp": false,
|
|
331
|
+
"hiddenAliases": [],
|
|
332
|
+
"id": "reinstall",
|
|
333
|
+
"pluginAlias": "@hideandseeklab/aoox",
|
|
334
|
+
"pluginName": "@hideandseeklab/aoox",
|
|
335
|
+
"pluginType": "core",
|
|
336
|
+
"strict": true,
|
|
337
|
+
"enableJsonFlag": false,
|
|
338
|
+
"isESM": true,
|
|
339
|
+
"relativePath": [
|
|
340
|
+
"dist",
|
|
341
|
+
"commands",
|
|
342
|
+
"reinstall.js"
|
|
343
|
+
]
|
|
344
|
+
},
|
|
285
345
|
"update": {
|
|
286
346
|
"aliases": [],
|
|
287
347
|
"args": {},
|
|
@@ -506,5 +566,5 @@
|
|
|
506
566
|
]
|
|
507
567
|
}
|
|
508
568
|
},
|
|
509
|
-
"version": "0.1.0-alpha.
|
|
569
|
+
"version": "0.1.0-alpha.5"
|
|
510
570
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hideandseeklab/aoox",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"version": "0.1.0-alpha.5",
|
|
4
|
+
"description": "aoox CLI — build, deploy and manage a self-hosted aoox PaaS from your terminal",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"oclif",
|
|
7
|
+
"aoox",
|
|
8
|
+
"self-hosted",
|
|
9
|
+
"paas",
|
|
10
|
+
"docker",
|
|
11
|
+
"deploy",
|
|
12
|
+
"git-deploy",
|
|
13
|
+
"cli",
|
|
14
|
+
"nixpacks",
|
|
15
|
+
"railpack",
|
|
16
|
+
"traefik"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://aoox.dev",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/hideandseeklab/aoox-cli.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/hideandseeklab/aoox-cli/issues"
|
|
25
|
+
},
|
|
5
26
|
"author": "hideandseeklab <hideandseek.developer@gmail.com>",
|
|
6
27
|
"publishConfig": {
|
|
7
28
|
"access": "public"
|
|
@@ -9,7 +30,6 @@
|
|
|
9
30
|
"bin": {
|
|
10
31
|
"aoox": "./bin/run.js"
|
|
11
32
|
},
|
|
12
|
-
"bugs": "https://github.com/hideandseeklab/aoox-cli/issues",
|
|
13
33
|
"dependencies": {
|
|
14
34
|
"@inquirer/prompts": "^8.7.2",
|
|
15
35
|
"@oclif/core": "^4",
|
|
@@ -42,10 +62,6 @@
|
|
|
42
62
|
"./dist",
|
|
43
63
|
"./oclif.manifest.json"
|
|
44
64
|
],
|
|
45
|
-
"homepage": "https://github.com/hideandseeklab/aoox-cli",
|
|
46
|
-
"keywords": [
|
|
47
|
-
"oclif"
|
|
48
|
-
],
|
|
49
65
|
"license": "Apache-2.0",
|
|
50
66
|
"main": "dist/index.js",
|
|
51
67
|
"type": "module",
|
|
@@ -57,11 +73,18 @@
|
|
|
57
73
|
"@oclif/plugin-help",
|
|
58
74
|
"@oclif/plugin-plugins"
|
|
59
75
|
],
|
|
60
|
-
"topicSeparator": " "
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
76
|
+
"topicSeparator": " ",
|
|
77
|
+
"update": {
|
|
78
|
+
"node": {
|
|
79
|
+
"version": "22.11.0",
|
|
80
|
+
"targets": [
|
|
81
|
+
"linux-x64",
|
|
82
|
+
"linux-arm64",
|
|
83
|
+
"darwin-x64",
|
|
84
|
+
"darwin-arm64"
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
65
88
|
},
|
|
66
89
|
"scripts": {
|
|
67
90
|
"build": "shx rm -rf dist && tsc -b",
|