@basaltkit/deploy 0.1.3 → 0.1.4
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 +10 -4
- package/dist/cli.js +4 -1
- package/dist/context.d.ts +11 -3
- package/dist/context.js +13 -3
- package/dist/pipeline.js +24 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,15 +51,21 @@ What is true of one server only (a port taken there, another branch) goes in
|
|
|
51
51
|
```sh
|
|
52
52
|
# as the app user (never root), in the checkout:
|
|
53
53
|
pnpm install
|
|
54
|
-
|
|
54
|
+
node node_modules/@basaltkit/deploy/dist/bin.js env # writes the .env (asks once), starts the containers, validates
|
|
55
55
|
|
|
56
|
-
# once, as an administrator
|
|
57
|
-
|
|
56
|
+
# once, as an administrator — the node path is resolved by YOUR shell, because
|
|
57
|
+
# with a per-user Node (nvm) root has none on its PATH:
|
|
58
|
+
sudo "$(command -v node)" node_modules/@basaltkit/deploy/dist/bin.js install --user="$USER"
|
|
58
59
|
|
|
59
60
|
# then, every deploy, as the app user:
|
|
60
|
-
|
|
61
|
+
node node_modules/@basaltkit/deploy/dist/bin.js run
|
|
61
62
|
```
|
|
62
63
|
|
|
64
|
+
Wrap it in a two-line `deploy.sh` if you like. Run it with `node`, not
|
|
65
|
+
`pnpm exec basalt-deploy`: pnpm ≥ 12 rewrites `pnpm-lock.yaml` on any command
|
|
66
|
+
in the checkout when the lockfile came from another pnpm, and the deploy
|
|
67
|
+
refuses a modified tree.
|
|
68
|
+
|
|
63
69
|
`run` pulls the code itself. Store the git credentials once
|
|
64
70
|
(`git config credential.helper store && git fetch`, or a read-only deploy key):
|
|
65
71
|
preflight probes the remote with prompts disabled, warns at a terminal and
|
package/dist/cli.js
CHANGED
|
@@ -12,9 +12,12 @@ export const USAGE = `basalt-deploy — deploy this Basalt app on this server (R
|
|
|
12
12
|
basalt-deploy env the .env and the dedicated infra only (first setup)
|
|
13
13
|
basalt-deploy rollback [--to=<sha>] back to the last healthy release (code only)
|
|
14
14
|
basalt-deploy status the last releases and the process
|
|
15
|
-
sudo node node_modules/@basaltkit/deploy/dist/bin.js install --user=<name>
|
|
15
|
+
sudo "$(command -v node)" node_modules/@basaltkit/deploy/dist/bin.js install --user=<name>
|
|
16
16
|
once per server, as root: vhost, state directory
|
|
17
17
|
|
|
18
|
+
Run it as \`node node_modules/@basaltkit/deploy/dist/bin.js <command>\`, not
|
|
19
|
+
\`pnpm exec\`: pnpm ≥ 12 may rewrite pnpm-lock.yaml on any command it runs.
|
|
20
|
+
|
|
18
21
|
Options:
|
|
19
22
|
--config=<file> default deploy.config.ts
|
|
20
23
|
--overrides=<file> server-local values, default /etc/basalt/<app>.json
|
package/dist/context.d.ts
CHANGED
|
@@ -20,10 +20,18 @@ export interface Finding {
|
|
|
20
20
|
fix?: string;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* How
|
|
24
|
-
*
|
|
23
|
+
* How the app user runs the deploy. Not `pnpm exec`: pnpm ≥ 12 rewrites
|
|
24
|
+
* `pnpm-lock.yaml` on any command in the checkout when the lockfile came from
|
|
25
|
+
* another pnpm, and the deploy then refuses its own dirty tree.
|
|
25
26
|
*/
|
|
26
|
-
export declare const
|
|
27
|
+
export declare const RUN_COMMAND = "node node_modules/@basaltkit/deploy/dist/bin.js run";
|
|
28
|
+
/**
|
|
29
|
+
* How an administrator runs `install`. The node binary is resolved by the
|
|
30
|
+
* operator's shell BEFORE sudo: with a per-user Node (nvm, fnm, volta) root
|
|
31
|
+
* has no `node` on its PATH — `sudo node` failed with "command not found" on
|
|
32
|
+
* the first server. Not `pnpm exec` either: root often has no pnpm.
|
|
33
|
+
*/
|
|
34
|
+
export declare const INSTALL_COMMAND = "sudo \"$(command -v node)\" node_modules/@basaltkit/deploy/dist/bin.js install --user=\"$USER\"";
|
|
27
35
|
export declare const errors: (findings: Finding[]) => Finding[];
|
|
28
36
|
export declare function report(host: Host, findings: Finding[]): void;
|
|
29
37
|
export declare function detectPackageManager(host: Host, dir: string): Promise<DeployContext['pm']>;
|
package/dist/context.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
|
+
/** The tool, run by `node` on its file — never `pnpm exec` (see {@link RUN_COMMAND}). */
|
|
3
|
+
const BIN = 'node_modules/@basaltkit/deploy/dist/bin.js';
|
|
2
4
|
/**
|
|
3
|
-
* How
|
|
4
|
-
*
|
|
5
|
+
* How the app user runs the deploy. Not `pnpm exec`: pnpm ≥ 12 rewrites
|
|
6
|
+
* `pnpm-lock.yaml` on any command in the checkout when the lockfile came from
|
|
7
|
+
* another pnpm, and the deploy then refuses its own dirty tree.
|
|
5
8
|
*/
|
|
6
|
-
export const
|
|
9
|
+
export const RUN_COMMAND = `node ${BIN} run`;
|
|
10
|
+
/**
|
|
11
|
+
* How an administrator runs `install`. The node binary is resolved by the
|
|
12
|
+
* operator's shell BEFORE sudo: with a per-user Node (nvm, fnm, volta) root
|
|
13
|
+
* has no `node` on its PATH — `sudo node` failed with "command not found" on
|
|
14
|
+
* the first server. Not `pnpm exec` either: root often has no pnpm.
|
|
15
|
+
*/
|
|
16
|
+
export const INSTALL_COMMAND = `sudo "$(command -v node)" ${BIN} install --user="$USER"`;
|
|
7
17
|
export const errors = (findings) => findings.filter((f) => f.level === 'error');
|
|
8
18
|
export function report(host, findings) {
|
|
9
19
|
for (const finding of findings) {
|
package/dist/pipeline.js
CHANGED
|
@@ -3,7 +3,7 @@ import { apacheInstall, apachePreflight, vhostPaths } from './apache.js';
|
|
|
3
3
|
import { backupDatabase, restoreCommand } from './backup.js';
|
|
4
4
|
import { lockfileFindings, tlsFindings, toolingFindings } from './checks.js';
|
|
5
5
|
import { processName } from './config.js';
|
|
6
|
-
import { DeployError, errors, INSTALL_COMMAND, report } from './context.js';
|
|
6
|
+
import { DeployError, errors, INSTALL_COMMAND, report, RUN_COMMAND } from './context.js';
|
|
7
7
|
import { checkSchema, coercionFindings, policyFindings } from './env-check.js';
|
|
8
8
|
import { answerQuestions, describeEnv, planEnv, readEnv, syntaxFindings, writeEnv } from './env-step.js';
|
|
9
9
|
import { envValues } from './dotenv.js';
|
|
@@ -445,20 +445,37 @@ export async function install(ctx, user) {
|
|
|
445
445
|
throw new DeployError('install needs the unprivileged user the deploys run as: --user=<name> (never root)');
|
|
446
446
|
const port = Number(envValues(await readEnv(ctx)).get('PORT'));
|
|
447
447
|
if (!Number.isInteger(port) || port <= 0)
|
|
448
|
-
throw new DeployError(
|
|
448
|
+
throw new DeployError(`no PORT in the .env yet: run \`${RUN_COMMAND.replace(/ run$/, ' env')}\` as the app user first`);
|
|
449
449
|
const stateDir = `/var/lib/basalt/${config.app}`;
|
|
450
450
|
await step(ctx, `state directory ${stateDir}`, async () => {
|
|
451
451
|
await host.mkdir(stateDir, 0o700);
|
|
452
452
|
await host.mkdir(join(stateDir, 'install-backups'), 0o700);
|
|
453
453
|
const local = await host.readFile(join(ctx.dir, '.basalt', 'releases.json'));
|
|
454
|
-
|
|
455
|
-
|
|
454
|
+
const target = join(stateDir, 'releases.json');
|
|
455
|
+
let history = 'no release history yet';
|
|
456
|
+
if (await host.exists(target)) {
|
|
457
|
+
history = 'release history kept as it was';
|
|
458
|
+
}
|
|
459
|
+
else if (local) {
|
|
460
|
+
await host.writeFile(target, local, 0o600);
|
|
461
|
+
const count = (() => { try {
|
|
462
|
+
const v = JSON.parse(local);
|
|
463
|
+
return Array.isArray(v) ? v.length : 0;
|
|
464
|
+
}
|
|
465
|
+
catch {
|
|
466
|
+
return 0;
|
|
467
|
+
} })();
|
|
468
|
+
history = `${count} release(s) copied from ${join(ctx.dir, '.basalt', 'releases.json')}`;
|
|
469
|
+
}
|
|
456
470
|
const chown = await host.exec('chown', ['-R', `${user}:`, stateDir]);
|
|
457
471
|
if (chown.code !== 0)
|
|
458
472
|
throw new DeployError(`chown ${user} ${stateDir}: ${chown.stderr.trim()}`);
|
|
459
|
-
|
|
473
|
+
host.out.ok(`${stateDir} (0700, owned by ${user}); ${history}`);
|
|
474
|
+
const overrides = `/etc/basalt/${config.app}.json`;
|
|
475
|
+
if (!(await host.exists(overrides))) {
|
|
460
476
|
await host.mkdir('/etc/basalt', 0o755);
|
|
461
|
-
await host.writeFile(
|
|
477
|
+
await host.writeFile(overrides, '{}\n', 0o644);
|
|
478
|
+
host.out.ok(`${overrides} created (server-local overrides, no secrets)`);
|
|
462
479
|
}
|
|
463
480
|
});
|
|
464
481
|
if (config.proxy?.kind === 'apache') {
|
|
@@ -473,6 +490,6 @@ export async function install(ctx, user) {
|
|
|
473
490
|
host.out.info(`dedicated infra runs under ${user}'s rootless Docker: dockerd-rootless-setuptool.sh install (as ${user}), then loginctl enable-linger ${user}`);
|
|
474
491
|
}
|
|
475
492
|
}
|
|
476
|
-
host.out.ok(`installed — from now on, as ${user}
|
|
493
|
+
host.out.ok(`installed — from now on, as ${user} (not root), in ${ctx.dir}: ${RUN_COMMAND}`);
|
|
477
494
|
return 0;
|
|
478
495
|
}
|