@basaltkit/deploy 0.5.0 → 0.5.2

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 CHANGED
@@ -10,6 +10,11 @@ and [RFC 0007](https://github.com/basaltkit/basalt/blob/main/docs/rfcs/0007-depl
10
10
  pnpm add -D @basaltkit/deploy
11
11
  ```
12
12
 
13
+ **Illustrated guide:** [Deploying to a server](https://basaltkit-docs.pages.dev/guide/deploy)
14
+ walks through a first server, everyday deploys from the terminal and the local
15
+ UI, with screenshots and a troubleshooting table
16
+ ([Português](https://basaltkit-docs.pages.dev/pt/guide/deploy)).
17
+
13
18
  ## The config
14
19
 
15
20
  `deploy.config.ts` at the app root, committed. It holds **no secrets**.
@@ -480,7 +485,15 @@ checks C2 and C1 on each vhost on every deploy and never writes them.
480
485
  the preflight warns (`dumps`) when git does not ignore the directory or a
481
486
  Docker build would copy it. `backup.dir` (relative to the checkout) keeps
482
487
  the old place; dumps left in `backups/predeploy`, the old default, are
483
- pointed out until they are moved or deleted.
488
+ pointed out until they are moved or deleted. When `/var/lib/basalt` exists
489
+ but `/var/lib/basalt/<app>` is missing or not reachable by the app user (a
490
+ parent only root can enter), the preflight says so (`state-dir`) instead of
491
+ falling back to the checkout in silence; `install` makes `/var/lib/basalt`
492
+ 0755 (each app's own directory below stays 0700).
493
+ - The node it runs on, first on `PATH` for everything it starts (`pnpm`,
494
+ `node`, the app's scripts). With nvm, fnm or volta, a non-interactive shell
495
+ (`ssh host cmd`, cron, the local UI) does not have them on `PATH`; starting
496
+ the deploy with that node's absolute path is enough.
484
497
  With external infra in a container, `backup: { container: 'myapp-postgres' }`
485
498
  runs `pg_dump` inside it (`docker exec`), as the user and database of the
486
499
  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);
@@ -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}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basaltkit/deploy",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "engines": {
5
5
  "node": ">=22.5.0"
6
6
  },
@@ -25,9 +25,9 @@
25
25
  "dist"
26
26
  ],
27
27
  "devDependencies": {
28
- "@types/node": "^26.6.1",
28
+ "@types/node": "^26.6.5",
29
29
  "typescript": "^7.0.2",
30
- "vitest": "^5.0.1",
30
+ "vitest": "^5.0.3",
31
31
  "@basaltkit/tsconfig": "^0.24.0"
32
32
  },
33
33
  "publishConfig": {