ramdb2-cli 2.0.0-alpha.2 → 2.0.0-alpha.3
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/CHANGELOG.md +6 -0
- package/README.md +11 -0
- package/package.json +2 -2
- package/src/cli.js +15 -1
- package/src/index.js +1 -0
- package/src/infra/down.js +19 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -444,6 +444,17 @@ not point to the server yet) does not stop the others; the exit code is then 1.
|
|
|
444
444
|
The decrypted secrets live in `build/<server>/.secrets-*` (only you can read it) while a command runs, and are
|
|
445
445
|
deleted at the end, even on an error. Not in `/tmp`: Docker installed as a snap cannot read it.
|
|
446
446
|
|
|
447
|
+
### Stop a server
|
|
448
|
+
|
|
449
|
+
```sh
|
|
450
|
+
ramdb2-cli infra down ovh1 # asks first; --yes to skip the question
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
`down` runs `docker compose down --remove-orphans` on the server: the containers of all its sites (ramdb2 and
|
|
454
|
+
custom) and its network are removed. The volumes (the databases, the backup queues), the images and the
|
|
455
|
+
certificates stay: `ramdb2-cli infra deploy ovh1` starts the server again as it was. Like every command that talks
|
|
456
|
+
to a server, it decrypts the secrets: Compose needs them to read `compose.yaml`.
|
|
457
|
+
|
|
447
458
|
### Secrets: sops and age, once
|
|
448
459
|
|
|
449
460
|
```sh
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ramdb2-cli",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.3",
|
|
4
4
|
"description": "Code generator and project scaffolding for ramdb2 and ramdb2-server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./src/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@vitejs/plugin-vue": "^6.0.10",
|
|
31
|
-
"ramdb2-core": "^2.0.0-alpha.
|
|
31
|
+
"ramdb2-core": "^2.0.0-alpha.3",
|
|
32
32
|
"vite": "^8.3.5",
|
|
33
33
|
"vue": "^3.5.44",
|
|
34
34
|
"vue-router": "^5.4.0"
|
package/src/cli.js
CHANGED
|
@@ -9,6 +9,7 @@ import { query } from './query.js'
|
|
|
9
9
|
import { readInfra } from './infra/config.js'
|
|
10
10
|
import { buildInfra } from './infra/build.js'
|
|
11
11
|
import { deploy } from './infra/deploy.js'
|
|
12
|
+
import { down } from './infra/down.js'
|
|
12
13
|
import { keygen } from './infra/keygen.js'
|
|
13
14
|
import { fetch as fetchBackup, listBackups, restore } from './infra/backups.js'
|
|
14
15
|
import { createInterface } from 'node:readline/promises'
|
|
@@ -50,6 +51,10 @@ const HELP = `ramdb2-cli: code generator of ramdb2
|
|
|
50
51
|
on the server (DOCKER_HOST=ssh://...), the missing Let's Encrypt certificates, and nginx reloaded.
|
|
51
52
|
--staging: the test certificates of Let's Encrypt, not trusted by browsers.
|
|
52
53
|
|
|
54
|
+
ramdb2-cli infra down <server> [--yes]
|
|
55
|
+
Stops the server: docker compose down, its containers and its network removed. The volumes (the
|
|
56
|
+
databases), the images and the certificates stay: infra deploy starts it again. Asks first, unless --yes.
|
|
57
|
+
|
|
53
58
|
ramdb2-cli infra keygen <server> [--force]
|
|
54
59
|
Creates the SSH key of the server for its backups: secrets/<server>.key, encrypted by sops (.sops.yaml),
|
|
55
60
|
and secrets/<server>.pub, printed, to install on the backup server. --force replaces an existing key.
|
|
@@ -129,7 +134,7 @@ function report({ written, kept, warnings }) {
|
|
|
129
134
|
}
|
|
130
135
|
|
|
131
136
|
async function infra(values, [action, ...args]) {
|
|
132
|
-
const actions = ['build', 'deploy', 'keygen', 'backups', 'restore', 'fetch']
|
|
137
|
+
const actions = ['build', 'deploy', 'down', 'keygen', 'backups', 'restore', 'fetch']
|
|
133
138
|
if (!actions.includes(action)) return usage(`infra needs an action: ${actions.join(', ')}`)
|
|
134
139
|
const infra = readInfra(values.config ?? 'infra.yaml')
|
|
135
140
|
switch (action) {
|
|
@@ -145,6 +150,15 @@ async function infra(values, [action, ...args]) {
|
|
|
145
150
|
if (certificates.some(certificate => !certificate.ok)) process.exitCode = 1
|
|
146
151
|
return
|
|
147
152
|
}
|
|
153
|
+
case 'down':
|
|
154
|
+
if (args.length !== 1) return usage('infra down needs one server')
|
|
155
|
+
if (!infra.servers.some(server => server.name === args[0])) throw new Error(`No server ${args[0]} in infra.yaml`)
|
|
156
|
+
if (!values.yes && !(await confirm(`Stop all the sites of ${args[0]}? Their data stays. [y/N] `))) {
|
|
157
|
+
console.log('Nothing done')
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
await down(infra, args[0])
|
|
161
|
+
return
|
|
148
162
|
case 'keygen':
|
|
149
163
|
if (args.length !== 1) return usage('infra keygen needs one server')
|
|
150
164
|
await keygen(infra, args[0], { force: values.force ?? false })
|
package/src/index.js
CHANGED
|
@@ -9,5 +9,6 @@ export { operationNames } from './generate/operations.js'
|
|
|
9
9
|
export { readInfra, InfraError } from './infra/config.js'
|
|
10
10
|
export { buildInfra, serverFiles, certificates } from './infra/build.js'
|
|
11
11
|
export { deploy } from './infra/deploy.js'
|
|
12
|
+
export { down } from './infra/down.js'
|
|
12
13
|
export { keygen } from './infra/keygen.js'
|
|
13
14
|
export { listBackups, restore, fetch as fetchBackup } from './infra/backups.js'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// ramdb2-cli infra down (D55): stops and removes the containers and the network of a server. The volumes (the
|
|
2
|
+
// databases), the images and the certificates stay: infra deploy starts the server again as it was.
|
|
3
|
+
import { check, runCommand, withServer } from './server.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Stops one server. Its secrets are decrypted too: Compose needs them to read compose.yaml.
|
|
7
|
+
* @param {import('./config.js').Infra} infra
|
|
8
|
+
* @param {string} name the server
|
|
9
|
+
* @param {object} [options]
|
|
10
|
+
* @param {import('./server.js').Runner} [options.run]
|
|
11
|
+
* @param {(line: string) => void} [options.print]
|
|
12
|
+
*/
|
|
13
|
+
export async function down(infra, name, { run = runCommand, print = console.log } = {}) {
|
|
14
|
+
return withServer(infra, name, run, async ({ server, compose, env }) => {
|
|
15
|
+
print(`${name}: docker compose down on ${server.host} (the volumes stay)`)
|
|
16
|
+
await check(run('docker', [...compose, 'down', '--remove-orphans'], { env }), 'docker compose down')
|
|
17
|
+
print(`${name}: stopped`)
|
|
18
|
+
})
|
|
19
|
+
}
|