@basaltkit/deploy 0.6.0 → 0.7.0
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 +31 -1
- package/dist/bootstrap.d.ts +13 -4
- package/dist/bootstrap.js +20 -3
- package/dist/cli.js +3 -2
- package/dist/config.d.ts +16 -0
- package/dist/config.js +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/infra.js +6 -1
- package/dist/install-plan.js +48 -2
- package/dist/pipeline.d.ts +3 -0
- package/dist/pipeline.js +18 -1
- package/dist/protocol.d.ts +5 -1
- package/dist/system.d.ts +50 -0
- package/dist/system.js +95 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,7 +109,8 @@ Node at `engines.node` (NodeSource), the pnpm the lockfile records — gives the
|
|
|
109
109
|
checkout and the `docker` group to the user (said plainly: that group is root on
|
|
110
110
|
the machine; rootless Docker is a later step), then, **as the user, in the
|
|
111
111
|
checkout**: `pnpm install`, `env` (it asks what it cannot generate) and
|
|
112
|
-
`install-plan`. From that plan (data, validated) it
|
|
112
|
+
`install-plan`. From that plan (data, validated) it installs the app's
|
|
113
|
+
[system packages](#system-packages), adds swap when RAM is under
|
|
113
114
|
6 GB (`bootstrap.swapGb`), ufw with SSH and 80/443 (turned on only when nothing
|
|
114
115
|
else listens; `--no-firewall`), Caddy when the proxy is `caddy()`, and runs
|
|
115
116
|
`install`. It never loads `deploy.config.ts` itself. A step that fails stops it;
|
|
@@ -167,6 +168,34 @@ import line. `caddy validate` runs before the reload; a failure puts every file
|
|
|
167
168
|
back. Deploys diff the site and never rewrite it; C1, C2 (not imported) and C8
|
|
168
169
|
(no `ask`) are checked as for Apache.
|
|
169
170
|
|
|
171
|
+
### System packages
|
|
172
|
+
|
|
173
|
+
What the app runs from the operating system — binaries it spawns, libraries
|
|
174
|
+
it loads — is declared with the app, as Debian/Ubuntu apt package names:
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
system: { packages: ['tesseract-ocr', 'poppler-utils', 'unzip'] },
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Each name matches `[a-z0-9][a-z0-9.+-]{1,62}` (no option, no version, no shell
|
|
181
|
+
syntax) and appears once. Every deploy checks them as the app user
|
|
182
|
+
(`dpkg-query -W -f='${Status}' <pkg>`, no shell): a missing one is a **C12**
|
|
183
|
+
error that stops the run before anything is built and prints the fix,
|
|
184
|
+
`sudo apt-get install -y <missing>` — not the first user who reaches the
|
|
185
|
+
feature. Without `dpkg-query` (not Debian/Ubuntu) it is a warning: nothing
|
|
186
|
+
could be checked. `plan` prints `system: tesseract-ocr, poppler-utils, unzip
|
|
187
|
+
(installed)` or `(missing: …)`.
|
|
188
|
+
|
|
189
|
+
A deploy never installs them (it is not root). Root does, from the install
|
|
190
|
+
plan, which carries the names as data: `bootstrap` (after the user's
|
|
191
|
+
`install-plan`) and `install` run `apt-get update` and `apt-get install -y
|
|
192
|
+
--no-install-recommends` for the missing ones, non-interactively, from the
|
|
193
|
+
server's own apt sources. The app user chose the names and a package's install
|
|
194
|
+
scripts run as root, so the list is shown and needs a "yes" at the terminal;
|
|
195
|
+
when nothing is missing nothing is asked. Adding a package later: commit it,
|
|
196
|
+
then `install-plan` and `install` once (or the `apt-get` line the deploy
|
|
197
|
+
printed).
|
|
198
|
+
|
|
170
199
|
## Commands
|
|
171
200
|
|
|
172
201
|
As the app user, in the checkout (`node node_modules/@basaltkit/deploy/dist/bin.js <command>`):
|
|
@@ -556,6 +585,7 @@ incident (RFC 0006 §5):
|
|
|
556
585
|
- **C9** run with a package manager major other than the one `packageManager` declares;
|
|
557
586
|
- **C10** keep a forbidden key, or a fixed key with another value.
|
|
558
587
|
- **C11** build a commit whose `packageManager` (pnpm ≥ 12) the lockfile does not record — checked in preflight and again on the commit the fetch brings, before any install. A lockfile the package manager rewrites during the deploy is put back to the committed version (with a warning), so the next deploy is not blocked; and no check runs the package manager inside the checkout.
|
|
588
|
+
- **C12** build when a `system.packages` entry is not installed (the fix is printed; a deploy never runs apt).
|
|
559
589
|
|
|
560
590
|
Secrets never reach a command line, the compose file, or the terminal: the
|
|
561
591
|
summary names keys, passwords travel in child-process environments only.
|
package/dist/bootstrap.d.ts
CHANGED
|
@@ -11,11 +11,13 @@ import type { Host } from './host.js';
|
|
|
11
11
|
* the user;
|
|
12
12
|
* 2. as the user, in the checkout: `pnpm install`, `env` (it may ask), then
|
|
13
13
|
* `install-plan`, whose JSON comes back as data;
|
|
14
|
-
* 3. as root, from that plan: swap (< 6 GB
|
|
15
|
-
* SSH listens), Caddy (proxy: caddy),
|
|
14
|
+
* 3. as root, from that plan: the app's `system.packages`, swap (< 6 GB
|
|
15
|
+
* RAM), ufw (only when nothing but SSH listens), Caddy (proxy: caddy),
|
|
16
|
+
* then `install`.
|
|
16
17
|
*
|
|
17
18
|
* `--dry-run` prints every command and runs none (phase 3 then assumes
|
|
18
|
-
* `--proxy`, or none
|
|
19
|
+
* `--proxy`, or none, and shows the system packages as a placeholder: the
|
|
20
|
+
* plan is not written in a dry run).
|
|
19
21
|
*/
|
|
20
22
|
export interface BootstrapOptions {
|
|
21
23
|
user: string | undefined;
|
|
@@ -36,6 +38,8 @@ export interface Action {
|
|
|
36
38
|
interactive?: boolean;
|
|
37
39
|
/** Asked at the terminal before a real run runs it; a "no" (or no terminal) stops bootstrap. */
|
|
38
40
|
confirm?: string;
|
|
41
|
+
/** With `confirm`: what the operator can do instead of answering, said when the answer is not "yes". */
|
|
42
|
+
otherwise?: string;
|
|
39
43
|
/** Runs as the app user: its output reaches root's terminal only through a pipe, line by line, sanitized. */
|
|
40
44
|
user?: boolean;
|
|
41
45
|
}
|
|
@@ -77,11 +81,16 @@ export declare function planSystem(host: Host, dir: string, user: string): Promi
|
|
|
77
81
|
export declare function userSteps(user: string, dir: string, tty: boolean): Action[];
|
|
78
82
|
/** The phase-2 command whose stdout is the install plan (JSON) — in its own session, like the other steps. */
|
|
79
83
|
export declare const planCommand: (user: string) => string[];
|
|
80
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Phase 3 — the app's system packages, swap, ufw, Caddy, from the plan (or
|
|
86
|
+
* the flags). `packages` undefined: a dry run, which has no plan — the
|
|
87
|
+
* install is shown with a placeholder for the names.
|
|
88
|
+
*/
|
|
81
89
|
export declare function planServer(host: Host, options: {
|
|
82
90
|
proxy: 'apache' | 'caddy' | 'none';
|
|
83
91
|
swapGb: number;
|
|
84
92
|
firewall: boolean;
|
|
93
|
+
packages?: string[];
|
|
85
94
|
}): Promise<{
|
|
86
95
|
actions: Action[];
|
|
87
96
|
notes: string[];
|
package/dist/bootstrap.js
CHANGED
|
@@ -3,8 +3,8 @@ import { below, lockedPnpm, minimumVersion } from './checks.js';
|
|
|
3
3
|
import { DeployError } from './context.js';
|
|
4
4
|
import { LineSplitter, sanitize } from './events.js';
|
|
5
5
|
import { install, parseInstallPlan } from './install-plan.js';
|
|
6
|
+
import { APT, aptInstall, fixCommand, packageStatus } from './system.js';
|
|
6
7
|
import { CHECKOUT_PATH, USER_NAME } from './trust.js';
|
|
7
|
-
const APT = ['env', 'DEBIAN_FRONTEND=noninteractive', 'apt-get'];
|
|
8
8
|
/** The oldest pnpm root installs globally (lockfile v9; the app user chooses the version, root sets the floor). */
|
|
9
9
|
export const MIN_PNPM = [9, 0, 0];
|
|
10
10
|
// `/`, never a world-writable directory: a tool that reads project config from its working directory finds none there.
|
|
@@ -107,6 +107,7 @@ export async function planSystem(host, dir, user) {
|
|
|
107
107
|
what: `${dir} owned by ${user}`,
|
|
108
108
|
commands: [['chown', '-R', `${user}:`, dir]],
|
|
109
109
|
confirm: `${dir} is ${owner || 'unknown'}'s: give it and everything in it to ${user} (chown -R)?`,
|
|
110
|
+
otherwise: `make ${dir} the user's first`,
|
|
110
111
|
});
|
|
111
112
|
}
|
|
112
113
|
const groups = (await host.exec('id', ['-nG', user], OUTSIDE)).stdout.split(/\s+/);
|
|
@@ -151,10 +152,25 @@ export function userSteps(user, dir, tty) {
|
|
|
151
152
|
}
|
|
152
153
|
/** The phase-2 command whose stdout is the install plan (JSON) — in its own session, like the other steps. */
|
|
153
154
|
export const planCommand = (user) => ['setsid', '-w', 'sudo', '-u', user, '-H', '--', 'node', BIN, 'install-plan', '--out=-'];
|
|
154
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* Phase 3 — the app's system packages, swap, ufw, Caddy, from the plan (or
|
|
157
|
+
* the flags). `packages` undefined: a dry run, which has no plan — the
|
|
158
|
+
* install is shown with a placeholder for the names.
|
|
159
|
+
*/
|
|
155
160
|
export async function planServer(host, options) {
|
|
156
161
|
const actions = [];
|
|
157
162
|
const notes = [];
|
|
163
|
+
if (options.packages === undefined) {
|
|
164
|
+
actions.push({ what: 'system packages: those of system.packages not installed (from the install plan)', commands: aptInstall(['<system.packages>']) });
|
|
165
|
+
}
|
|
166
|
+
else if (options.packages.length > 0) {
|
|
167
|
+
// Names the plan carries, validated by parseInstallPlan; apt only checked for (planSystem refused a server without it).
|
|
168
|
+
const { missing, unverified } = await packageStatus(host, options.packages, OUTSIDE.cwd);
|
|
169
|
+
const install = unverified ? options.packages : missing;
|
|
170
|
+
// The app user chose them and their install scripts run as root: asked, as install asks.
|
|
171
|
+
if (install.length)
|
|
172
|
+
actions.push({ what: `system packages: ${install.join(', ')}`, commands: aptInstall(install), confirm: `Install ${install.join(', ')} (system.packages) as root?`, otherwise: `install them first: ${fixCommand(install)}` });
|
|
173
|
+
}
|
|
158
174
|
const meminfo = (await host.readFile('/proc/meminfo')) ?? '';
|
|
159
175
|
const memGb = Number(/MemTotal:\s+(\d+)/.exec(meminfo)?.[1] ?? 0) / 1024 / 1024;
|
|
160
176
|
const swapKb = Number(/SwapTotal:\s+(\d+)/.exec(meminfo)?.[1] ?? 0);
|
|
@@ -237,7 +253,7 @@ async function runActions(host, actions, dryRun) {
|
|
|
237
253
|
for (const action of actions) {
|
|
238
254
|
host.out.info(action.what);
|
|
239
255
|
if (action.confirm && !dryRun && !(await host.confirm(action.confirm))) {
|
|
240
|
-
throw new DeployError(`${action.what}: not confirmed — nothing more was done (a terminal must answer
|
|
256
|
+
throw new DeployError(`${action.what}: not confirmed — nothing more was done (a terminal must answer${action.otherwise ? `; or ${action.otherwise}` : ''})`);
|
|
241
257
|
}
|
|
242
258
|
for (const command of action.commands) {
|
|
243
259
|
host.out.info(` + ${command.join(' ')}${action.cwd ? ` (in ${action.cwd})` : ''}`);
|
|
@@ -297,6 +313,7 @@ export async function bootstrap(host, dir, options, tool) {
|
|
|
297
313
|
proxy: options.proxy ?? plan.proxy.kind,
|
|
298
314
|
swapGb: options.swapGb ?? plan.bootstrap?.swapGb ?? 4,
|
|
299
315
|
firewall: options.firewall ?? plan.bootstrap?.firewall ?? true,
|
|
316
|
+
packages: plan.system?.packages ?? [],
|
|
300
317
|
});
|
|
301
318
|
await runActions(host, server.actions, false);
|
|
302
319
|
await install(host, plan, user);
|
package/dist/cli.js
CHANGED
|
@@ -45,9 +45,10 @@ As root, with a copy of the tool root owns — never the checkout's node_modules
|
|
|
45
45
|
cd / && sudo -H npx --yes --package=@basaltkit/deploy@<exact version> -- basalt-deploy <command>
|
|
46
46
|
bootstrap --user=<name> --dir=<checkout> [--dry-run] [--proxy=…] [--swap-gb=<n>] [--no-firewall]
|
|
47
47
|
a fresh Ubuntu/Debian server, once: Docker, Node, pnpm; as the user
|
|
48
|
-
pnpm install, env, install-plan; then swap, ufw, Caddy and install
|
|
48
|
+
pnpm install, env, install-plan; then system packages, swap, ufw, Caddy and install
|
|
49
49
|
install --plan=<file> --user=<name>
|
|
50
|
-
once per server: state directory, proxy site, env file ownership
|
|
50
|
+
once per server: state directory, proxy site, env file ownership,
|
|
51
|
+
the app's missing system packages (apt, after a yes)
|
|
51
52
|
|
|
52
53
|
Run the app user's commands with \`node\`, not \`pnpm exec\`: pnpm ≥ 12 may rewrite
|
|
53
54
|
pnpm-lock.yaml on any command it runs. As root, nothing loads deploy.config.ts.
|
package/dist/config.d.ts
CHANGED
|
@@ -81,6 +81,13 @@ export interface DeployConfig<E extends object = EnvShape> {
|
|
|
81
81
|
audit?: {
|
|
82
82
|
syslog?: boolean;
|
|
83
83
|
};
|
|
84
|
+
/**
|
|
85
|
+
* What the app needs from the operating system, outside node_modules
|
|
86
|
+
* (RFC 0007 §12, system packages). Checked on every deploy (C12, before
|
|
87
|
+
* anything is built); installed by root — `bootstrap` and `install` — from
|
|
88
|
+
* the install plan, never by a deploy.
|
|
89
|
+
*/
|
|
90
|
+
system?: SystemConfig;
|
|
84
91
|
/** What `basalt-deploy bootstrap` sets up on a fresh server (RFC 0007 §7). */
|
|
85
92
|
bootstrap?: {
|
|
86
93
|
/** Swap created when RAM is under 6 GB and there is none; 0 = never. @default 4 */
|
|
@@ -89,6 +96,15 @@ export interface DeployConfig<E extends object = EnvShape> {
|
|
|
89
96
|
firewall?: boolean;
|
|
90
97
|
};
|
|
91
98
|
}
|
|
99
|
+
export interface SystemConfig {
|
|
100
|
+
/**
|
|
101
|
+
* Debian/Ubuntu apt package names the app runs (binaries it spawns, shared
|
|
102
|
+
* libraries it loads): `[a-z0-9][a-z0-9.+-]{1,62}`, each once — names only,
|
|
103
|
+
* no version, no release.
|
|
104
|
+
* @example ['tesseract-ocr', 'tesseract-ocr-por', 'poppler-utils', 'unzip']
|
|
105
|
+
*/
|
|
106
|
+
packages?: string[];
|
|
107
|
+
}
|
|
92
108
|
export interface VerifyConfig {
|
|
93
109
|
/**
|
|
94
110
|
* Per compose service, text that must not appear in its logs since the
|
package/dist/config.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* its own module. A config can therefore be printed, diffed and validated
|
|
6
6
|
* without running anything.
|
|
7
7
|
*/
|
|
8
|
+
import { systemPackageProblems } from './system.js';
|
|
8
9
|
import { API_PREFIX, ASK_PATH, caddyExtraProblem, CERT_NAME, envLocationProblem, isConfigRoot, isWebRoot, vhostFileProblem } from './trust.js';
|
|
9
10
|
/** The entries of an env record, without the keys a mapped type left `undefined`. */
|
|
10
11
|
export function definedEntries(record) {
|
|
@@ -291,6 +292,9 @@ export function validateConfig(typed) {
|
|
|
291
292
|
if (problem)
|
|
292
293
|
problems.push(`env file ${problem}`);
|
|
293
294
|
}
|
|
295
|
+
// Root installs these from the plan: a name is never an option, never shell syntax.
|
|
296
|
+
if (config.system?.packages !== undefined)
|
|
297
|
+
problems.push(...systemPackageProblems(config.system.packages, 'system.packages'));
|
|
294
298
|
if (config.proxy?.kind === 'caddy' && config.tenants === 'subdomain' && !config.proxy.onDemandTls) {
|
|
295
299
|
problems.push(`tenants: 'subdomain' behind caddy() needs onDemandTls: { ask: '/…' } — a certificate per tenant host, issued only for hosts the app vouches for`);
|
|
296
300
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { defineDeploy, secret, ask, pm2, compose, apache, caddy, none, external, bucketName, dockerInfra, validateConfig, applyOverrides, parseOverrides, processName, DeployConfigError, SEAWEEDFS_IMAGE, type DeployConfig, type EnvShape, type EnvKey, type EnvValue, type EnvConfig, type DeriveContext, type SecretSpec, type Question, type InfraConfig, type DockerInfra, type DockerInfraOptions, type ExternalInfra, type ExternalPostgres, type AppRole, type Bucket, type VerifyConfig, type ComposeJob, type PostgresService, type RedisService, type SeaweedfsService, type ExternalS3, type S3Keys, type BuildConfig, type MigrateConfig, type BackupConfig, type RuntimeConfig, type Pm2Runtime, type ComposeRuntime, type ComposeImage, type HooksConfig, type ProxyConfig, type ApacheProxy, type CaddyProxy, type NoProxy, type HealthConfig, type ServerOverrides, } from './config.js';
|
|
1
|
+
export { defineDeploy, secret, ask, pm2, compose, apache, caddy, none, external, bucketName, dockerInfra, validateConfig, applyOverrides, parseOverrides, processName, DeployConfigError, SEAWEEDFS_IMAGE, type DeployConfig, type EnvShape, type EnvKey, type EnvValue, type EnvConfig, type DeriveContext, type SecretSpec, type Question, type InfraConfig, type DockerInfra, type DockerInfraOptions, type ExternalInfra, type ExternalPostgres, type AppRole, type Bucket, type SystemConfig, type VerifyConfig, type ComposeJob, type PostgresService, type RedisService, type SeaweedfsService, type ExternalS3, type S3Keys, type BuildConfig, type MigrateConfig, type BackupConfig, type RuntimeConfig, type Pm2Runtime, type ComposeRuntime, type ComposeImage, type HooksConfig, type ProxyConfig, type ApacheProxy, type CaddyProxy, type NoProxy, type HealthConfig, type ServerOverrides, } from './config.js';
|
|
2
2
|
export { main, loadConfig, createContext, processIO, USAGE, type CliIO } from './cli.js';
|
|
3
3
|
export { nodeHost, consoleOutput, type Host, type ExecOptions, type ExecResult, type FileStat, type Output, type TlsCertificate, type PromptMeta, type LogHandle, type FileRange } from './host.js';
|
|
4
4
|
export { DeployAbortedError, DeployError, INSTALL_COMMAND, RUN_COMMAND, rootInstallCommand, type DeployContext, type Finding } from './context.js';
|
package/dist/infra.js
CHANGED
|
@@ -222,7 +222,12 @@ export function renderCompose(app, infra, plan) {
|
|
|
222
222
|
// beyond the container's loopback: the others have no authentication,
|
|
223
223
|
// and `runtime.attach` puts this container on the app's networks.
|
|
224
224
|
// Iceberg and Lance are extra listeners nothing here uses.
|
|
225
|
-
|
|
225
|
+
// Volumes: each bucket gets its own, seven at a time, and by default
|
|
226
|
+
// SeaweedFS allows (free disk / 30 GB) of them — on a server with less
|
|
227
|
+
// than ~60 GB free the second bucket had none and every write was a
|
|
228
|
+
// 500 (`No writable volumes and no free volumes left`). 1 GB volumes
|
|
229
|
+
// and an explicit count; a volume takes no disk until it holds data.
|
|
230
|
+
" command: ['server', '-dir=/data', '-s3', '-s3.port=8333', '-ip=127.0.0.1', '-ip.bind=127.0.0.1', '-s3.ip.bind=0.0.0.0', '-s3.port.iceberg=0', '-s3.port.lance=0', '-master.volumeSizeLimitMB=1024', '-volume.max=1000']", ` ports: ['127.0.0.1:${service.port}:8333']`, ' environment:', ' AWS_ACCESS_KEY_ID: ${BASALT_S3_ACCESS_KEY:?missing}', ' AWS_SECRET_ACCESS_KEY: ${BASALT_S3_SECRET_KEY:?missing}', ' WEED_JWT_FILER_SIGNING_KEY: ${BASALT_S3_SIGNING_KEY:?missing}', ` volumes: ['${key}:/data']`, ' healthcheck:',
|
|
226
231
|
// `/healthz` answers before the volume server has joined: reads fail
|
|
227
232
|
// for a few seconds more. Healthy = a data node registered too.
|
|
228
233
|
` test: ['CMD-SHELL', 'wget -q -O /dev/null http://127.0.0.1:8333/healthz && wget -q -O- http://127.0.0.1:9333/dir/status | grep -q Url']`, ' interval: 10s', ' timeout: 5s', ' retries: 12', ' start_period: 30s');
|
package/dist/install-plan.js
CHANGED
|
@@ -7,6 +7,7 @@ import { envValues } from './dotenv.js';
|
|
|
7
7
|
import { envFile, envMirrors, readEnv } from './env-step.js';
|
|
8
8
|
import { acquireLock } from './lock.js';
|
|
9
9
|
import { covers } from './checks.js';
|
|
10
|
+
import { aptInstall, fixCommand, packageStatus, systemPackageProblems } from './system.js';
|
|
10
11
|
import { API_PREFIX, ASK_PATH, assertRootOwnedDir, caddyExtraProblem, CERT_NAME, CHECKOUT_PATH, envLocationProblem, isConfigRoot, isWebRoot, untrustedAncestor, USER_NAME, vhostFileProblem } from './trust.js';
|
|
11
12
|
/**
|
|
12
13
|
* `install` in two halves (RFC 0006 §11.4), so that root never runs code the
|
|
@@ -46,6 +47,8 @@ export async function buildInstallPlan(ctx, tool) {
|
|
|
46
47
|
envFiles: [envFile(ctx), ...envMirrors(ctx)].filter((f) => !f.startsWith(`${ctx.dir}/`)),
|
|
47
48
|
docker: config.infra?.kind === 'docker' || config.runtime.kind === 'compose',
|
|
48
49
|
...(config.bootstrap ? { bootstrap: { ...config.bootstrap } } : {}),
|
|
50
|
+
// Names only: root installs them from this list, validated again, never from the config.
|
|
51
|
+
...(config.system?.packages?.length ? { system: { packages: [...config.system.packages] } } : {}),
|
|
49
52
|
tool,
|
|
50
53
|
};
|
|
51
54
|
// Root will run exactly these checks: refuse now, where the fix is.
|
|
@@ -89,7 +92,7 @@ export function parseInstallPlan(text, source) {
|
|
|
89
92
|
if (!keys.includes(key))
|
|
90
93
|
problems.push(`${where}: unknown key "${key}"`);
|
|
91
94
|
};
|
|
92
|
-
known(plan, ['kind', 'version', 'app', 'domain', 'tenants', 'dir', 'port', 'proxy', 'envFiles', 'docker', 'bootstrap', 'tool'], 'plan');
|
|
95
|
+
known(plan, ['kind', 'version', 'app', 'domain', 'tenants', 'dir', 'port', 'proxy', 'envFiles', 'docker', 'bootstrap', 'system', 'tool'], 'plan');
|
|
93
96
|
if (plan['kind'] !== PLAN_KIND || plan['version'] !== 1)
|
|
94
97
|
problems.push(`not a version-1 ${PLAN_KIND}`);
|
|
95
98
|
const app = typeof plan['app'] === 'string' && APP_NAME.test(plan['app']) ? plan['app'] : undefined;
|
|
@@ -133,6 +136,16 @@ export function parseInstallPlan(text, source) {
|
|
|
133
136
|
problems.push('bootstrap.firewall must be true or false');
|
|
134
137
|
}
|
|
135
138
|
}
|
|
139
|
+
const system = plan['system'];
|
|
140
|
+
if (system !== undefined) {
|
|
141
|
+
if (typeof system !== 'object' || system === null || Array.isArray(system))
|
|
142
|
+
problems.push('system must be an object');
|
|
143
|
+
else {
|
|
144
|
+
known(system, ['packages'], 'system');
|
|
145
|
+
// What root hands to apt-get as arguments: names only, never an option.
|
|
146
|
+
problems.push(...systemPackageProblems(system['packages'], 'system.packages'));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
136
149
|
const proxy = (typeof plan['proxy'] === 'object' && plan['proxy'] !== null ? plan['proxy'] : {});
|
|
137
150
|
const kind = proxy['kind'];
|
|
138
151
|
if (kind === 'none')
|
|
@@ -263,6 +276,7 @@ export async function install(host, plan, user, options = {}) {
|
|
|
263
276
|
}
|
|
264
277
|
const ctx = contextOf(host, plan, stateDir);
|
|
265
278
|
summary(host, plan, user, stateDir, ctx);
|
|
279
|
+
await systemPackages(host, plan.system?.packages ?? []);
|
|
266
280
|
await envOwnership(host, plan, owner);
|
|
267
281
|
if (plan.proxy.kind === 'apache' && plan.proxy.managed) {
|
|
268
282
|
const root = plan.proxy.root ?? '/etc/apache2';
|
|
@@ -315,7 +329,39 @@ function summary(host, plan, user, stateDir, ctx) {
|
|
|
315
329
|
? `Caddy ${caddyPaths(ctx).site} for ${names} → 127.0.0.1:${plan.port}, ${join(plan.dir, plan.proxy.webRoot)} served`
|
|
316
330
|
: 'no proxy site';
|
|
317
331
|
host.out.info(`install for "${plan.app}" (plan by @basaltkit/deploy ${plan.tool}), for ${user}, checkout ${plan.dir}:`);
|
|
318
|
-
host.out.info(` state ${stateDir} · ${site}${plan.envFiles.length ? ` · env ${plan.envFiles.join(', ')}` : ''}`);
|
|
332
|
+
host.out.info(` state ${stateDir} · ${site}${plan.envFiles.length ? ` · env ${plan.envFiles.join(', ')}` : ''}${plan.system?.packages.length ? ` · system packages ${plan.system.packages.join(', ')}` : ''}`);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* `system.packages`: the missing ones, installed with apt — names the plan
|
|
336
|
+
* carries (validated: never an option), as argv, from this server's own apt
|
|
337
|
+
* sources. The app user chose them, and a package's install scripts run as
|
|
338
|
+
* root: the list is shown and needs a "yes", as Caddy `extra` does. Already
|
|
339
|
+
* installed, nothing is asked. Not Debian/Ubuntu: said, and left to the
|
|
340
|
+
* administrator.
|
|
341
|
+
*/
|
|
342
|
+
async function systemPackages(host, packages) {
|
|
343
|
+
if (packages.length === 0)
|
|
344
|
+
return;
|
|
345
|
+
host.out.step('system packages');
|
|
346
|
+
const { missing, unverified } = await packageStatus(host, packages, '/');
|
|
347
|
+
if (unverified) {
|
|
348
|
+
host.out.warn(`no dpkg-query here (not Debian/Ubuntu): ${packages.join(', ')} not checked nor installed — install them by hand`);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (missing.length === 0) {
|
|
352
|
+
host.out.ok(`${packages.join(', ')} installed`);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
host.out.info(`not installed: ${missing.join(', ')} — apt-get install, as root, from this server's apt sources`);
|
|
356
|
+
if (!(await host.confirm(`Install ${missing.join(', ')} as root?`)))
|
|
357
|
+
throw new DeployError(`system packages not confirmed — nothing installed (a terminal must answer; or, by hand: ${fixCommand(missing)})`);
|
|
358
|
+
for (const command of aptInstall(missing)) {
|
|
359
|
+
host.out.info(` + ${command.join(' ')}`);
|
|
360
|
+
const result = await host.exec(command[0], command.slice(1), { cwd: '/', stream: true });
|
|
361
|
+
if (result.code !== 0)
|
|
362
|
+
throw new DeployError(`system packages: \`${command.join(' ')}\` failed (exit ${result.code})`);
|
|
363
|
+
}
|
|
364
|
+
host.out.ok(`${missing.join(', ')} installed`);
|
|
319
365
|
}
|
|
320
366
|
/** The host names a proxy config file serves: Apache ServerName/ServerAlias, Caddy site addresses. */
|
|
321
367
|
export function servedNames(text, kind) {
|
package/dist/pipeline.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type DeployContext, type Finding } from './context.js';
|
|
2
|
+
import { type PackageStatus } from './system.js';
|
|
2
3
|
/**
|
|
3
4
|
* The pipeline (RFC 0006 §4): preflight → fetch → env → infra → build →
|
|
4
5
|
* validate → backup → migrate → release → proxy → health → record.
|
|
@@ -65,6 +66,8 @@ export interface Preflight {
|
|
|
65
66
|
findings: Finding[];
|
|
66
67
|
port: number;
|
|
67
68
|
values: Map<string, string>;
|
|
69
|
+
/** `system.packages` as this server has them; undefined when none are declared. */
|
|
70
|
+
system?: PackageStatus;
|
|
68
71
|
}
|
|
69
72
|
export declare function preflight(ctx: DeployContext, options?: RunOptions): Promise<Preflight>;
|
|
70
73
|
/** `prisma migrate deploy` runs when asked to, or — unsaid — when the app generates a Prisma client. */
|
package/dist/pipeline.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { tmpdir } from 'node:os';
|
|
1
2
|
import { apachePreflight } from './apache.js';
|
|
2
3
|
import { caddyPreflight } from './caddy.js';
|
|
3
4
|
import { backupDatabase, backupDir, backupPlaceFindings, restoreCommand } from './backup.js';
|
|
@@ -16,6 +17,7 @@ import { acquireLock, describeHolder, readLock } from './lock.js';
|
|
|
16
17
|
import { auditOf } from './audit.js';
|
|
17
18
|
import { questionDescriptors } from './env-step.js';
|
|
18
19
|
import { activeRun, lastRun } from './runs.js';
|
|
20
|
+
import { describeSystem, packageStatus, systemFindings } from './system.js';
|
|
19
21
|
export const SKIPPABLE = ['fetch', 'backup', 'tls'];
|
|
20
22
|
/** run, env and rollback are the app user's (RFC 0006 §11.4): never root unless asked. */
|
|
21
23
|
export function refuseRoot(host, command, allowRoot = false) {
|
|
@@ -166,6 +168,9 @@ export async function preflight(ctx, options = {}) {
|
|
|
166
168
|
const port = await resolvePort(ctx, values);
|
|
167
169
|
findings.push(...await toolingFindings(ctx));
|
|
168
170
|
findings.push(...await lockfileFindings(ctx));
|
|
171
|
+
const system = await systemStatus(ctx);
|
|
172
|
+
if (system)
|
|
173
|
+
findings.push(...systemFindings(ctx.config.system?.packages ?? [], system));
|
|
169
174
|
const head = (await ctx.host.exec('git', ['rev-parse', 'HEAD'], { cwd: ctx.dir })).stdout.trim();
|
|
170
175
|
findings.push(...await runtimePreflight(ctx, port, head));
|
|
171
176
|
findings.push(...await mirrorFindings(ctx));
|
|
@@ -176,7 +181,18 @@ export async function preflight(ctx, options = {}) {
|
|
|
176
181
|
if (!options.skip?.includes('tls'))
|
|
177
182
|
findings.push(...await tlsFindings(ctx));
|
|
178
183
|
findings.push(...await backupFindings(ctx, values, options));
|
|
179
|
-
return { findings, port, values };
|
|
184
|
+
return { findings, port, values, ...(system ? { system } : {}) };
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* C12's probe, as the app user: read-only, outside the checkout. Installing
|
|
188
|
+
* needs root, so a deploy never does — it stops before the build and prints
|
|
189
|
+
* the command an administrator runs.
|
|
190
|
+
*/
|
|
191
|
+
async function systemStatus(ctx) {
|
|
192
|
+
const packages = ctx.config.system?.packages ?? [];
|
|
193
|
+
if (packages.length === 0)
|
|
194
|
+
return undefined;
|
|
195
|
+
return packageStatus(ctx.host, packages, tmpdir());
|
|
180
196
|
}
|
|
181
197
|
/** The dump's container running — found now, not after the build, minutes later. */
|
|
182
198
|
async function backupFindings(ctx, values, options) {
|
|
@@ -536,6 +552,7 @@ function planLines(ctx, options, checked, env, infra) {
|
|
|
536
552
|
const lines = [
|
|
537
553
|
options.skip?.includes('fetch') ? 'fetch: skipped' : ((t) => `fetch: git ${fetchArgs(t).filter((a) => a !== '--quiet').join(' ')} && git merge --ff-only ${t.tracking}`)(gitTarget(ctx)),
|
|
538
554
|
...describeEnv(env).map((l) => `env: ${l}`),
|
|
555
|
+
...describeSystem(config.system?.packages ?? [], checked.system).map((l) => `system: ${l}`),
|
|
539
556
|
...describeInfra(infra).map((l) => `infra: ${l}`),
|
|
540
557
|
...describeServices(config).map((l) => `infra: ${l}`),
|
|
541
558
|
`build: ${pm} install (frozen), ${(config.build?.prisma ?? []).map((c) => `prisma generate --config ${c}`).join(', ') || 'no prisma'}${config.build?.script ? `, ${pm} run ${config.build.script}` : ''}${config.build?.web ? `, ${config.build.web} build` : ''}${isCompose(ctx) ? `, docker build ${composeOf(ctx).images.map((i) => i.tag).join(', ')} (skipped when the commit's tag exists)` : ''}`,
|
package/dist/protocol.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* imports it as `@basaltkit/deploy/protocol` without loading the CLI.
|
|
9
9
|
*/
|
|
10
10
|
export interface Finding {
|
|
11
|
-
/** The RFC 0006 §5 check id (`C1`…`
|
|
11
|
+
/** The RFC 0006 §5 check id (`C1`…`C12`) or a step name. */
|
|
12
12
|
id: string;
|
|
13
13
|
level: 'error' | 'warning';
|
|
14
14
|
message: string;
|
|
@@ -103,6 +103,10 @@ export interface InstallPlan {
|
|
|
103
103
|
swapGb?: number;
|
|
104
104
|
firewall?: boolean;
|
|
105
105
|
};
|
|
106
|
+
/** `system.packages`: apt package names root installs when missing (bootstrap, install). */
|
|
107
|
+
system?: {
|
|
108
|
+
packages: string[];
|
|
109
|
+
};
|
|
106
110
|
/** The @basaltkit/deploy version that wrote the plan (informational). */
|
|
107
111
|
tool: string;
|
|
108
112
|
}
|
package/dist/system.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Finding } from './context.js';
|
|
2
|
+
import type { Host } from './host.js';
|
|
3
|
+
/**
|
|
4
|
+
* `system.packages` — the OS binaries the app runs (OCR, PDF tools, `unzip`):
|
|
5
|
+
* Debian/Ubuntu apt package names, declared in deploy.config.ts so that a
|
|
6
|
+
* server without them fails the preflight, not the first user who reaches the
|
|
7
|
+
* feature.
|
|
8
|
+
*
|
|
9
|
+
* Two sides, as everywhere else (RFC 0006 §11.4): the app user only checks
|
|
10
|
+
* (`dpkg-query`, C12) and prints the fix; root installs — `bootstrap` and
|
|
11
|
+
* `install` — from the install plan's list, a field it validates again. The
|
|
12
|
+
* names reach apt as arguments, never through a shell.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* An apt package name (Debian Policy §5.6.1, lowercase only): never an option
|
|
16
|
+
* (`-…`), never a path, a version (`=`), a release (`/`), a glob or shell syntax.
|
|
17
|
+
*/
|
|
18
|
+
export declare const SYSTEM_PACKAGE: RegExp;
|
|
19
|
+
/** More than any app needs; a cap on what root is asked to install. */
|
|
20
|
+
export declare const MAX_SYSTEM_PACKAGES = 64;
|
|
21
|
+
/** apt as root: no question can block it (there may be no terminal). */
|
|
22
|
+
export declare const APT: string[];
|
|
23
|
+
/** Every problem with a package list, as `where` names it (`system.packages`); none → []. */
|
|
24
|
+
export declare function systemPackageProblems(value: unknown, where: string): string[];
|
|
25
|
+
export interface PackageStatus {
|
|
26
|
+
/** Declared and not installed. */
|
|
27
|
+
missing: string[];
|
|
28
|
+
/** No `dpkg-query` here (not Debian/Ubuntu): nothing could be checked. */
|
|
29
|
+
unverified: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Which declared packages are not installed: `dpkg-query -W -f=${Status} <pkg>`,
|
|
33
|
+
* one argv per package. The status is "<want> <flag> <status>"; installed is
|
|
34
|
+
* the third word (`install ok installed`, or `hold ok installed`). An unknown
|
|
35
|
+
* package exits non-zero: missing. A package of several architectures prints
|
|
36
|
+
* one status each, run together: installed when one of them is.
|
|
37
|
+
*/
|
|
38
|
+
export declare function packageStatus(host: Host, packages: readonly string[], cwd: string): Promise<PackageStatus>;
|
|
39
|
+
/** The command an administrator runs for the missing packages — printed, never run by the app user. */
|
|
40
|
+
export declare const fixCommand: (missing: readonly string[]) => string;
|
|
41
|
+
/**
|
|
42
|
+
* C12 — the declared OS packages are installed. Missing is an error: the
|
|
43
|
+
* release would build and start, then fail on the first request that needs
|
|
44
|
+
* one. No `dpkg-query` is a warning: the deploy cannot tell, and cannot fix it.
|
|
45
|
+
*/
|
|
46
|
+
export declare function systemFindings(packages: readonly string[], status: PackageStatus): Finding[];
|
|
47
|
+
/** What `plan` prints for the packages. */
|
|
48
|
+
export declare function describeSystem(packages: readonly string[], status: PackageStatus | undefined): string[];
|
|
49
|
+
/** Root's commands: the index refreshed once, then the packages — argv, no shell, no recommends. */
|
|
50
|
+
export declare const aptInstall: (packages: readonly string[]) => string[][];
|
package/dist/system.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `system.packages` — the OS binaries the app runs (OCR, PDF tools, `unzip`):
|
|
3
|
+
* Debian/Ubuntu apt package names, declared in deploy.config.ts so that a
|
|
4
|
+
* server without them fails the preflight, not the first user who reaches the
|
|
5
|
+
* feature.
|
|
6
|
+
*
|
|
7
|
+
* Two sides, as everywhere else (RFC 0006 §11.4): the app user only checks
|
|
8
|
+
* (`dpkg-query`, C12) and prints the fix; root installs — `bootstrap` and
|
|
9
|
+
* `install` — from the install plan's list, a field it validates again. The
|
|
10
|
+
* names reach apt as arguments, never through a shell.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* An apt package name (Debian Policy §5.6.1, lowercase only): never an option
|
|
14
|
+
* (`-…`), never a path, a version (`=`), a release (`/`), a glob or shell syntax.
|
|
15
|
+
*/
|
|
16
|
+
export const SYSTEM_PACKAGE = /^[a-z0-9][a-z0-9.+-]{1,62}$/;
|
|
17
|
+
/** More than any app needs; a cap on what root is asked to install. */
|
|
18
|
+
export const MAX_SYSTEM_PACKAGES = 64;
|
|
19
|
+
/** apt as root: no question can block it (there may be no terminal). */
|
|
20
|
+
export const APT = ['env', 'DEBIAN_FRONTEND=noninteractive', 'apt-get'];
|
|
21
|
+
/** Every problem with a package list, as `where` names it (`system.packages`); none → []. */
|
|
22
|
+
export function systemPackageProblems(value, where) {
|
|
23
|
+
if (!Array.isArray(value))
|
|
24
|
+
return [`${where} must be a list of apt package names`];
|
|
25
|
+
const problems = [];
|
|
26
|
+
if (value.length > MAX_SYSTEM_PACKAGES)
|
|
27
|
+
problems.push(`${where}: at most ${MAX_SYSTEM_PACKAGES} packages`);
|
|
28
|
+
for (const name of value) {
|
|
29
|
+
if (typeof name !== 'string' || !SYSTEM_PACKAGE.test(name))
|
|
30
|
+
problems.push(`${where}: "${String(name)}" is not an apt package name (${SYSTEM_PACKAGE})`);
|
|
31
|
+
}
|
|
32
|
+
if (new Set(value).size !== value.length)
|
|
33
|
+
problems.push(`${where}: each package once`);
|
|
34
|
+
return problems;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* dpkg's "<want> <error> <status>", matched by its closed vocabularies: with
|
|
38
|
+
* no separator in the format, two architectures' statuses run together
|
|
39
|
+
* (`hold ok installedinstall ok installed`), and `\S+` would read one word.
|
|
40
|
+
*/
|
|
41
|
+
const STATUS = /(unknown|install|hold|deinstall|purge) (ok|reinstreq) (not-installed|config-files|half-installed|unpacked|half-configured|triggers-awaited|triggers-pending|installed)/g;
|
|
42
|
+
/**
|
|
43
|
+
* Which declared packages are not installed: `dpkg-query -W -f=${Status} <pkg>`,
|
|
44
|
+
* one argv per package. The status is "<want> <flag> <status>"; installed is
|
|
45
|
+
* the third word (`install ok installed`, or `hold ok installed`). An unknown
|
|
46
|
+
* package exits non-zero: missing. A package of several architectures prints
|
|
47
|
+
* one status each, run together: installed when one of them is.
|
|
48
|
+
*/
|
|
49
|
+
export async function packageStatus(host, packages, cwd) {
|
|
50
|
+
const missing = [];
|
|
51
|
+
for (const name of packages) {
|
|
52
|
+
const result = await host.exec('dpkg-query', ['-W', '-f=${Status}', name], { cwd });
|
|
53
|
+
// 127: the command itself is absent (spawn failed) — not a Debian system.
|
|
54
|
+
if (result.code === 127)
|
|
55
|
+
return { missing: [], unverified: true };
|
|
56
|
+
const statuses = [...result.stdout.matchAll(STATUS)].map((m) => m[3]);
|
|
57
|
+
if (result.code !== 0 || statuses.length === 0 || !statuses.includes('installed'))
|
|
58
|
+
missing.push(name);
|
|
59
|
+
}
|
|
60
|
+
return { missing, unverified: false };
|
|
61
|
+
}
|
|
62
|
+
/** The command an administrator runs for the missing packages — printed, never run by the app user. */
|
|
63
|
+
export const fixCommand = (missing) => `sudo apt-get install -y ${missing.join(' ')}`;
|
|
64
|
+
/**
|
|
65
|
+
* C12 — the declared OS packages are installed. Missing is an error: the
|
|
66
|
+
* release would build and start, then fail on the first request that needs
|
|
67
|
+
* one. No `dpkg-query` is a warning: the deploy cannot tell, and cannot fix it.
|
|
68
|
+
*/
|
|
69
|
+
export function systemFindings(packages, status) {
|
|
70
|
+
if (packages.length === 0)
|
|
71
|
+
return [];
|
|
72
|
+
if (status.unverified) {
|
|
73
|
+
return [{ id: 'C12', level: 'warning', message: `system.packages (${packages.join(', ')}) cannot be verified: no dpkg-query on this server (Debian/Ubuntu only)` }];
|
|
74
|
+
}
|
|
75
|
+
if (status.missing.length === 0)
|
|
76
|
+
return [];
|
|
77
|
+
return [{
|
|
78
|
+
id: 'C12',
|
|
79
|
+
level: 'error',
|
|
80
|
+
message: `system package${status.missing.length > 1 ? 's' : ''} not installed: ${status.missing.join(', ')}`,
|
|
81
|
+
fix: fixCommand(status.missing),
|
|
82
|
+
}];
|
|
83
|
+
}
|
|
84
|
+
/** What `plan` prints for the packages. */
|
|
85
|
+
export function describeSystem(packages, status) {
|
|
86
|
+
if (packages.length === 0)
|
|
87
|
+
return [];
|
|
88
|
+
const state = !status || status.unverified ? 'not verified: no dpkg-query' : status.missing.length ? `missing: ${status.missing.join(', ')}` : 'installed';
|
|
89
|
+
return [`${packages.join(', ')} (${state})`];
|
|
90
|
+
}
|
|
91
|
+
/** Root's commands: the index refreshed once, then the packages — argv, no shell, no recommends. */
|
|
92
|
+
export const aptInstall = (packages) => [
|
|
93
|
+
[...APT, 'update', '-qq'],
|
|
94
|
+
[...APT, 'install', '-y', '-qq', '--no-install-recommends', ...packages],
|
|
95
|
+
];
|