@basaltkit/deploy 0.5.0 → 0.5.1
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 +9 -1
- package/dist/backup.js +8 -1
- package/dist/env-step.js +3 -0
- package/dist/host.d.ts +8 -0
- package/dist/host.js +15 -1
- package/dist/install-plan.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -480,7 +480,15 @@ checks C2 and C1 on each vhost on every deploy and never writes them.
|
|
|
480
480
|
the preflight warns (`dumps`) when git does not ignore the directory or a
|
|
481
481
|
Docker build would copy it. `backup.dir` (relative to the checkout) keeps
|
|
482
482
|
the old place; dumps left in `backups/predeploy`, the old default, are
|
|
483
|
-
pointed out until they are moved or deleted.
|
|
483
|
+
pointed out until they are moved or deleted. When `/var/lib/basalt` exists
|
|
484
|
+
but `/var/lib/basalt/<app>` is missing or not reachable by the app user (a
|
|
485
|
+
parent only root can enter), the preflight says so (`state-dir`) instead of
|
|
486
|
+
falling back to the checkout in silence; `install` makes `/var/lib/basalt`
|
|
487
|
+
0755 (each app's own directory below stays 0700).
|
|
488
|
+
- The node it runs on, first on `PATH` for everything it starts (`pnpm`,
|
|
489
|
+
`node`, the app's scripts). With nvm, fnm or volta, a non-interactive shell
|
|
490
|
+
(`ssh host cmd`, cron, the local UI) does not have them on `PATH`; starting
|
|
491
|
+
the deploy with that node's absolute path is enough.
|
|
484
492
|
With external infra in a container, `backup: { container: 'myapp-postgres' }`
|
|
485
493
|
runs `pg_dump` inside it (`docker exec`), as the user and database of the
|
|
486
494
|
URL at `backup.urlKey` — the server's own pg_dump, none needed on the host.
|
package/dist/backup.js
CHANGED
|
@@ -47,11 +47,18 @@ export async function backupPlaceFindings(ctx) {
|
|
|
47
47
|
findings.push({ id: 'dumps', level: 'warning', message: `database dumps go to ${dir}, inside the Docker build context: a COPY . . puts them in the image`, fix: `add ${top} to .dockerignore, or ${fix}` });
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
// /var/lib/basalt is there (another app's install, or this one's with a
|
|
51
|
+
// parent the app user cannot enter) but this app's state is not: the deploy
|
|
52
|
+
// falls back to the checkout, which is easy to miss.
|
|
53
|
+
const system = `/var/lib/basalt/${ctx.config.app}`;
|
|
54
|
+
if (ctx.stateDir !== system && (await host.stat('/var/lib/basalt'))?.kind === 'dir') {
|
|
55
|
+
findings.push({ id: 'state-dir', level: 'warning', message: `${system} is missing or not reachable by this user: the deploy's state (release history, lock, dumps) stays in ${ctx.stateDir}, inside the checkout`, fix: 'run install-plan, then the root command it prints: install makes it yours (0700) and its parent enterable' });
|
|
56
|
+
}
|
|
50
57
|
if (!ctx.config.backup?.dir) {
|
|
51
58
|
const legacy = join(ctx.dir, 'backups', 'predeploy');
|
|
52
59
|
const left = (await host.list(legacy)).filter((name) => name.endsWith('.dump'));
|
|
53
60
|
if (left.length > 0) {
|
|
54
|
-
findings.push({ id: 'dumps', level: 'warning', message: `${left.length} dump(s) left in ${legacy} (the old place): new dumps go to ${dir}, and nothing prunes these`, fix: `move them next to the new ones (mv ${legacy}/*.dump ${dir}/) or delete them` });
|
|
61
|
+
findings.push({ id: 'dumps', level: 'warning', message: `${left.length} dump(s) left in ${legacy} (the old place): new dumps go to ${dir}, and nothing prunes these`, fix: `move them next to the new ones (install -d -m 700 ${dir} && mv ${legacy}/*.dump ${dir}/) or delete them` });
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
64
|
return findings;
|
package/dist/env-step.js
CHANGED
|
@@ -148,6 +148,9 @@ export async function writeEnv(ctx, plan) {
|
|
|
148
148
|
await writeMirrors(ctx, text);
|
|
149
149
|
plan.document = parseEnv(text);
|
|
150
150
|
plan.values = envValues(plan.document);
|
|
151
|
+
// compose's passEnv reads ctx.values: it must see what was just written,
|
|
152
|
+
// not the .env before it (a recreated Redis left the worker on the old URL).
|
|
153
|
+
ctx.values = plan.values;
|
|
151
154
|
plan.changes = [];
|
|
152
155
|
}
|
|
153
156
|
/** Rewrites every mirror as an exact copy of the file (0600). */
|
package/dist/host.d.ts
CHANGED
|
@@ -227,6 +227,14 @@ export declare const secondSignalMessage: (signal: string) => string;
|
|
|
227
227
|
* that program's group.
|
|
228
228
|
*/
|
|
229
229
|
export declare function stopOwnGroup(pid?: number, kill?: (pid: number, signal: NodeJS.Signals | 0) => void): boolean;
|
|
230
|
+
/**
|
|
231
|
+
* `PATH` with the directory of the node running the deploy first. A version
|
|
232
|
+
* manager (nvm, fnm, volta) puts node and its pnpm/corepack shims on `PATH`
|
|
233
|
+
* only in an interactive shell, so over `ssh host cmd`, in cron or under the
|
|
234
|
+
* local UI the children (`pnpm`, `node`) would not be found, or would be
|
|
235
|
+
* another node than the one the deploy runs on.
|
|
236
|
+
*/
|
|
237
|
+
export declare function withOwnNode(path: string | undefined, execPath: string): string;
|
|
230
238
|
export declare function nodeHost(output?: Output): Host;
|
|
231
239
|
/**
|
|
232
240
|
* Readline echoes what is typed through its internal `_writeToOutput`; a
|
package/dist/host.js
CHANGED
|
@@ -5,7 +5,7 @@ import { chmod, copyFile, lstat, mkdir, open, readFile, readdir, readlink, realp
|
|
|
5
5
|
import http from 'node:http';
|
|
6
6
|
import https from 'node:https';
|
|
7
7
|
import { hostname } from 'node:os';
|
|
8
|
-
import { dirname } from 'node:path';
|
|
8
|
+
import { delimiter, dirname } from 'node:path';
|
|
9
9
|
import { createInterface } from 'node:readline';
|
|
10
10
|
import { StringDecoder } from 'node:string_decoder';
|
|
11
11
|
import tls from 'node:tls';
|
|
@@ -46,6 +46,18 @@ export function stopOwnGroup(pid = process.pid, kill = (p, s) => { process.kill(
|
|
|
46
46
|
return false;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* `PATH` with the directory of the node running the deploy first. A version
|
|
51
|
+
* manager (nvm, fnm, volta) puts node and its pnpm/corepack shims on `PATH`
|
|
52
|
+
* only in an interactive shell, so over `ssh host cmd`, in cron or under the
|
|
53
|
+
* local UI the children (`pnpm`, `node`) would not be found, or would be
|
|
54
|
+
* another node than the one the deploy runs on.
|
|
55
|
+
*/
|
|
56
|
+
export function withOwnNode(path, execPath) {
|
|
57
|
+
const own = dirname(execPath);
|
|
58
|
+
const entries = (path ?? '').split(delimiter).filter((entry) => entry !== '' && entry !== own);
|
|
59
|
+
return [own, ...entries].join(delimiter);
|
|
60
|
+
}
|
|
49
61
|
export function nodeHost(output = consoleOutput()) {
|
|
50
62
|
return {
|
|
51
63
|
out: output,
|
|
@@ -109,6 +121,8 @@ export function nodeHost(output = consoleOutput()) {
|
|
|
109
121
|
for (const key of options.unset ?? [])
|
|
110
122
|
delete base[key];
|
|
111
123
|
const env = { ...base, ...options.env };
|
|
124
|
+
if (options.env?.['PATH'] === undefined)
|
|
125
|
+
env['PATH'] = withOwnNode(env['PATH'], process.execPath);
|
|
112
126
|
let fd;
|
|
113
127
|
if (options.stdoutFile) {
|
|
114
128
|
fd = openSync(options.stdoutFile, constants.O_WRONLY | constants.O_CREAT | constants.O_TRUNC, 0o600);
|
package/dist/install-plan.js
CHANGED
|
@@ -234,6 +234,10 @@ export async function install(host, plan, user, options = {}) {
|
|
|
234
234
|
const stateRoot = options.stateRoot ?? '/var/lib/basalt';
|
|
235
235
|
await host.mkdir(stateRoot, 0o755);
|
|
236
236
|
await assertRootOwnedDir(host, stateRoot, 'state directory');
|
|
237
|
+
// Enterable by every app user (each app's own directory below is 0700): one
|
|
238
|
+
// created 0700 by hand or an older install hides the app's state, and the
|
|
239
|
+
// deploy then keeps it in the checkout.
|
|
240
|
+
await secure(host, stateRoot, { uid: 0, gid: 0, mode: 0o755, kind: 'dir' });
|
|
237
241
|
const stateDir = join(stateRoot, plan.app);
|
|
238
242
|
const backups = join(stateRoot, `${plan.app}.install-backups`);
|
|
239
243
|
host.out.step(`state directory ${stateDir}`);
|