hazo_env 0.16.0 → 0.18.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/CHANGE_LOG.md +71 -0
- package/README.md +21 -4
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +17 -0
- package/dist/cli.js +76 -3
- package/dist/deploy/build.d.ts +1 -1
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +39 -4
- package/dist/deploy/help.d.ts.map +1 -1
- package/dist/deploy/help.js +28 -9
- package/dist/deploy/idle-slots.d.ts +42 -0
- package/dist/deploy/idle-slots.d.ts.map +1 -0
- package/dist/deploy/idle-slots.js +136 -0
- package/dist/deploy/index.d.ts +2 -0
- package/dist/deploy/index.d.ts.map +1 -1
- package/dist/deploy/index.js +2 -0
- package/dist/deploy/init.d.ts +6 -0
- package/dist/deploy/init.d.ts.map +1 -1
- package/dist/deploy/init.js +12 -2
- package/dist/deploy/peer.d.ts +9 -0
- package/dist/deploy/peer.d.ts.map +1 -1
- package/dist/deploy/peer.js +16 -0
- package/dist/deploy/preflight.d.ts +33 -0
- package/dist/deploy/preflight.d.ts.map +1 -0
- package/dist/deploy/preflight.js +109 -0
- package/dist/deploy/verify.d.ts.map +1 -1
- package/dist/deploy/verify.js +7 -1
- package/dist/peer-hint.d.ts +8 -0
- package/dist/peer-hint.d.ts.map +1 -0
- package/dist/peer-hint.js +49 -0
- package/dist/resolve/config-hint.d.ts +2 -0
- package/dist/resolve/config-hint.d.ts.map +1 -0
- package/dist/resolve/config-hint.js +23 -0
- package/dist/resolve/connect.d.ts.map +1 -1
- package/dist/resolve/connect.js +2 -1
- package/dist/resolve/deploy.d.ts.map +1 -1
- package/dist/resolve/deploy.js +10 -4
- package/package.json +2 -2
package/CHANGE_LOG.md
CHANGED
|
@@ -1,5 +1,76 @@
|
|
|
1
1
|
# hazo_env — Change Log
|
|
2
2
|
|
|
3
|
+
## 0.18.0 — 2026-11-27
|
|
4
|
+
|
|
5
|
+
New: `config/hazo_env_config.ini` can be committed to git. From the Kinstripe
|
|
6
|
+
prod deploy — the operator wants every INI change (e.g. `min_memory_mb`) to
|
|
7
|
+
ship through git, not be hand-edited per slot.
|
|
8
|
+
|
|
9
|
+
- **`[deploy] dir_suffix` is now optional.** When omitted, `resolveDeployConfig()`
|
|
10
|
+
infers it from the slot directory name (`<app>-blue` → `blue`, `<app>-green`
|
|
11
|
+
→ `green`, new `inferColorFromDir()` in `src/deploy/peer.ts`). Both slots
|
|
12
|
+
then hold a byte-identical INI. An explicit `dir_suffix` still wins; an
|
|
13
|
+
unsuffixed directory with no `dir_suffix` still throws
|
|
14
|
+
`HAZO_ENV_CONFIG_MISSING_DEPLOY_DIR_SUFFIX` (message now explains both fixes).
|
|
15
|
+
- **`deploy build` "config-untracked" pre-flight** now only aborts when the
|
|
16
|
+
tracked INI also pins `dir_suffix` (new `deployConfigPinsDirSuffix()` in
|
|
17
|
+
`src/deploy/preflight.ts`). A tracked INI without it passes, with detail
|
|
18
|
+
"tracked by git without dir_suffix". Step name unchanged. The abort message
|
|
19
|
+
offers both fixes (delete the `dir_suffix` line, or untrack).
|
|
20
|
+
- **`deploy init`** copies an INI with no `dir_suffix` line unchanged (no
|
|
21
|
+
swap, no "Could not find a dir_suffix line" error) and skips the
|
|
22
|
+
`.git/info/exclude` entry for it.
|
|
23
|
+
- Fully backwards compatible: an INI that sets `dir_suffix` behaves exactly
|
|
24
|
+
as in 0.17.0.
|
|
25
|
+
|
|
26
|
+
## 0.17.0 — 2026-11-25
|
|
27
|
+
|
|
28
|
+
New: deploy pre-flight checks and `deploy clean --idle-slots`, from the first
|
|
29
|
+
GoTimer prod deploy on hazo_env (every item below was a real failure there).
|
|
30
|
+
|
|
31
|
+
- **`hazo-env` bin is now `dist/bin.js`**, a thin wrapper that dynamic-imports
|
|
32
|
+
`dist/cli.js`. `npx hazo_env ...` run outside the app (or in an app that
|
|
33
|
+
doesn't list hazo_env as a dependency) used to die with a raw
|
|
34
|
+
`ERR_MODULE_NOT_FOUND` stack for the `hazo_core` peer; it now prints the
|
|
35
|
+
fix (`cd` into the app, `npm i -D hazo_env`, `npx hazo_env <command>`). The
|
|
36
|
+
CLI's own top-level catch uses the same message (`src/peer-hint.ts`).
|
|
37
|
+
- **`deploy build` "cli-dependency" warning step** (also printed by `deploy
|
|
38
|
+
verify`/`deploy switch`) when `hazo_env` is missing from the app's
|
|
39
|
+
`package.json` — the build's own `npm ci` removes a hand-installed copy and
|
|
40
|
+
breaks the next run. Warning only. `BuildStepStatus` gains `'warn'`
|
|
41
|
+
(additive).
|
|
42
|
+
- **`deploy build` "config-untracked" pre-flight**: aborts before `git pull`
|
|
43
|
+
(so `last_build` is untouched) when `config/hazo_env_config.ini` is tracked
|
|
44
|
+
in git — it is per-slot (`dir_suffix` differs), so a tracked copy is
|
|
45
|
+
overwritten by the pull or blocks it. The message gives the `git rm
|
|
46
|
+
--cached` / `.gitignore` fix.
|
|
47
|
+
- **`deploy init`** adds `config/hazo_env_config.ini` to `.git/info/exclude`
|
|
48
|
+
in both slots (local to each clone; never dirties a tracked `.gitignore`).
|
|
49
|
+
New `RunInitResult.configExcludedFrom` (additive).
|
|
50
|
+
- **Missing-config hint**: `HAZO_ENV_CONFIG_FILE_MISSING` from a `-blue`/`-green`
|
|
51
|
+
slot now gives the exact `sed` command to copy the peer slot's INI with
|
|
52
|
+
`dir_suffix` swapped (`src/resolve/config-hint.ts`).
|
|
53
|
+
- **Restored the `git stash` step before `git pull`** (shipped in 0.15.3, lost
|
|
54
|
+
from the 0.16.0 source). It now compares the stash count before and after, so
|
|
55
|
+
older stash entries no longer produce a false "stashed local changes".
|
|
56
|
+
- **Failed build/install steps show the command's output**: the last 40 lines
|
|
57
|
+
of captured stdout+stderr are appended to the failing step (e.g. the real
|
|
58
|
+
`tsc` errors behind Next's bare "Failed to type check.", which go to
|
|
59
|
+
stdout). The CLI prints multi-line step details indented, and no longer
|
|
60
|
+
repeats the whole message in the "Build aborted" line.
|
|
61
|
+
- **`deploy verify` health hint**: a `curl_exit_7` (connection refused) failure
|
|
62
|
+
now says nothing is listening on `staging_port` — run `hazo-env deploy build`
|
|
63
|
+
first (it starts `<app>-staging`), or check `pm2 ls`.
|
|
64
|
+
- **New: `hazo-env deploy clean --idle-slots [--yes]`** (`src/deploy/idle-slots.ts`):
|
|
65
|
+
reclaims `node_modules` + `.next` from every app's idle standby slot listed in
|
|
66
|
+
`~/.hazo-deploy/*.json`. Runs from any directory (no `[deploy]` config
|
|
67
|
+
needed). Dry run unless `--yes`. Skips, with the reason printed, any slot
|
|
68
|
+
that is a `live_dir`, contains the cwd, has a PM2 process `pm_cwd` inside
|
|
69
|
+
it, or has `last_build` newer than `last_switch` (pending switch). Never
|
|
70
|
+
touches `data/`, config, `.env*` or shared dirs, and leaves symlinked
|
|
71
|
+
targets alone. Aborts without cleaning anything if `pm2 jlist` can't be
|
|
72
|
+
read. `deploy build`'s disk-check failure now suggests it.
|
|
73
|
+
|
|
3
74
|
## 0.16.0 — 2026-11-25
|
|
4
75
|
|
|
5
76
|
New: shared dirs — upload folders (photos, blog images, composer exports, ...)
|
package/README.md
CHANGED
|
@@ -227,11 +227,12 @@ If `shared_dirs` is configured, also creates the peer's shared-dir symlinks so t
|
|
|
227
227
|
|
|
228
228
|
**Writes:**
|
|
229
229
|
- external: a new sibling directory — `git clone <origin>` into `<app>-<opposite dir_suffix>`
|
|
230
|
-
- standby slot: `config/hazo_env_config.ini`, with `dir_suffix` swapped blue↔green
|
|
230
|
+
- standby slot: `config/hazo_env_config.ini`, with `dir_suffix` swapped blue↔green (copied unchanged when the INI has no `dir_suffix` line — the suffix is then inferred from each slot's directory name)
|
|
231
231
|
- standby slot: the `[data] root` directory, when the app is sqlite-backed (`db_strategy` resolves to `copy`)
|
|
232
232
|
- standby slot: each found `env_files` entry, copied in (gitignored secrets never travel through `git clone`)
|
|
233
233
|
- shared root + standby slot: shared-dir symlinks — `ensureLinks(standbyDir, { allowCreate: true })` creates `shared_root/<dir>` and the standby's `<dir>` symlink for every `shared_dirs` entry not already linked
|
|
234
234
|
- state file: `~/.hazo-deploy/<app_name>.json` written fresh (`live_dir` = current dir, `standby_dir` = the new peer)
|
|
235
|
+
- live + standby slot: `.git/info/exclude` gains a `config/hazo_env_config.ini` entry when the INI pins `dir_suffix` (it is then per-slot, so it must never be committed; the exclude file is local to each clone and never dirties a tracked `.gitignore`). Skipped when the INI has no `dir_suffix` line — that file is identical in both slots and meant to be committed.
|
|
235
236
|
|
|
236
237
|
**Config keys used:** `app_name`, `dir_suffix`, `env_files`, `shared_root`, `shared_dirs`
|
|
237
238
|
|
|
@@ -254,7 +255,9 @@ hazo-env deploy init
|
|
|
254
255
|
|
|
255
256
|
Must be run FROM the standby directory — a "standby-dir-guard" step aborts immediately if the state file says `cwd` isn't the recorded `standby_dir`, because running the pipeline against the live dir would git-pull/rebuild the running production tree and, for a sqlite "copy" `db_strategy`, overwrite the live database with the standby's stale one.
|
|
256
257
|
|
|
257
|
-
Steps run in order and any failure aborts immediately: standby-dir-guard → clean → disk-check → memory-check (→ stop-prod, only if `--stop-prod` and memory is still low) → db-resolve → shared-dirs → git-pull → install → pre-build → build → db-setup → migrate → clean-stale-staging → start-staging → health-check.
|
|
258
|
+
Steps run in order and any failure aborts immediately: standby-dir-guard → (cli-dependency warning) → clean → disk-check → memory-check (→ stop-prod, only if `--stop-prod` and memory is still low) → db-resolve → shared-dirs → config-untracked → (git-stash) → git-pull → install → pre-build → build → db-setup → migrate → clean-stale-staging → start-staging → health-check.
|
|
259
|
+
|
|
260
|
+
Run it via the app's own install (`npm i -D hazo_env`, then `npx hazo_env deploy build`): a "cli-dependency" warning step appears when `hazo_env` is missing from `package.json`, because the build's own `npm ci` would remove a hand-installed copy and break the next run. Uncommitted changes in the standby slot are stashed (never discarded) before `git pull`. A failing install/build step prints the last 40 lines of the command's output (e.g. the actual `tsc` errors behind Next's "Failed to type check.").
|
|
258
261
|
|
|
259
262
|
The "shared-dirs" step runs BEFORE git-pull (the first destructive step) specifically so a shared-dir problem never marks `last_build` as attempted — see the failure modes below.
|
|
260
263
|
|
|
@@ -265,11 +268,12 @@ The "shared-dirs" step runs BEFORE git-pull (the first destructive step) specifi
|
|
|
265
268
|
- standby slot: `resolveConnectConfig()` (or `--db`) to resolve `db_strategy: "auto"` to `copy`/`shared`
|
|
266
269
|
- live slot: the sqlite db file (copy strategy only, to back up from)
|
|
267
270
|
- standby slot: its own shared-dir link state (inspected internally by the `ensureLinks` call below)
|
|
271
|
+
- standby slot: `package.json` (is `hazo_env` a dependency?) and `git ls-files --error-unmatch config/hazo_env_config.ini` (is the per-slot INI tracked?)
|
|
268
272
|
|
|
269
273
|
**Writes:**
|
|
270
274
|
- standby slot: cache cleanup (same targets as `deploy clean`) then a disk-free check
|
|
271
275
|
- live slot: `pm2 stop <app_name>` (only with `--stop-prod`, only if memory is still low after cleanup)
|
|
272
|
-
- standby slot: `git pull` on `branch`, then `install_cmd`, `pre_build_cmd`, `build_cmd`
|
|
276
|
+
- standby slot: `git stash` of any uncommitted changes (recover with `git stash pop`), then `git pull` on `branch`, then `install_cmd`, `pre_build_cmd`, `build_cmd`
|
|
273
277
|
- standby slot: sqlite backup copy from the live slot (copy strategy) — or nothing, for the "shared" strategy (same Postgres DB, no copy)
|
|
274
278
|
- standby slot: `migrate_cmd`, only if non-empty
|
|
275
279
|
- shared root + standby slot: shared-dir self-heal — `ensureLinks(standbyDir, { allowCreate: true, allowReplaceEmpty: true })`. This is the ONLY deploy command that auto-creates a missing link or auto-replaces an empty real directory; everywhere else that's left to `deploy share`.
|
|
@@ -281,6 +285,9 @@ The "shared-dirs" step runs BEFORE git-pull (the first destructive step) specifi
|
|
|
281
285
|
|
|
282
286
|
**Failure modes:**
|
|
283
287
|
- BuildAbortError (any step name above) — aborts on the first failing step; the error carries every step completed so far for reporting. If `--stop-prod` already stopped production before the abort, the message is prefixed "⚠ PRODUCTION IS DOWN" with the exact `pm2 start` command to bring it back up by hand.
|
|
288
|
+
- BuildAbortError at "config-untracked" — `config/hazo_env_config.ini` is tracked in git AND pins `dir_suffix` (which differs per slot), so a pull would overwrite or conflict with the slot's copy. Either delete the `dir_suffix` line (it is then inferred from the slot directory name, so one committed file serves both slots), or `git rm --cached` it, add it to `.gitignore`, commit, and keep each slot's local copy. A tracked INI without `dir_suffix` passes. Checked before `git-pull`, so `last_build` is untouched.
|
|
289
|
+
- BuildAbortError at "disk-check" — free disk still below `min_disk_mb` after cleanup; the message suggests `hazo-env deploy clean --idle-slots` to reclaim other apps' idle standby `node_modules`/`.next`.
|
|
290
|
+
- HazoConfigError "HAZO_ENV_CONFIG_FILE_MISSING" — no `config/hazo_env_config.ini` in the slot; when the cwd is a `-blue`/`-green` dir and the peer has one, the message gives the exact `sed` command to copy it with `dir_suffix` swapped.
|
|
284
291
|
- SharedDirError "HAZO_ENV_SHARED_DIR_REAL_DIR" / "HAZO_ENV_SHARED_DIR_WRONG_LINK" (surfaces as the "shared-dirs" build step's failure) — a non-empty real directory, or a symlink to the wrong target, is sitting where a shared-dir link belongs; build refuses and its message points at "hazo-env deploy share". ("HAZO_ENV_SHARED_DIR_MISSING" / "_EMPTY_DIR" never surface here — build always passes `allowCreate` and `allowReplaceEmpty`.)
|
|
285
292
|
|
|
286
293
|
**Examples:**
|
|
@@ -308,6 +315,7 @@ Never throws on a failed check: each of the three checks (`health`, `typescript`
|
|
|
308
315
|
|
|
309
316
|
**Failure modes:**
|
|
310
317
|
- (no thrown error) — failures are reported per-check in `checks[]`; the process exits 1 if `allPassed` is false.
|
|
318
|
+
- `health` fail with "curl_exit_7" (connection refused) — nothing is listening on `staging_port`; the detail tells you to run `hazo-env deploy build` first (it starts `<app_name>-staging`) or check `pm2 ls`.
|
|
311
319
|
|
|
312
320
|
**Examples:**
|
|
313
321
|
```
|
|
@@ -406,28 +414,37 @@ hazo-env deploy status
|
|
|
406
414
|
#### `deploy clean`
|
|
407
415
|
|
|
408
416
|
- `--aggressive` — Also PRINT (never run) system-level cleanup suggestions (apt/journalctl/docker) that need sudo.
|
|
417
|
+
- `--idle-slots` — Instead: reclaim `node_modules` + `.next` from EVERY app's idle standby slot listed in `~/.hazo-deploy/*.json`. Runs from any directory (no `[deploy]` config needed). Dry run unless `--yes`.
|
|
418
|
+
- `--yes` — With `--idle-slots`: actually delete (default is a dry run that only lists slots and sizes).
|
|
409
419
|
|
|
410
420
|
Deletes `.next.rollback`, `.next.staging`, and `node_modules/.cache`, and runs `npm cache clean --force`. Also called automatically as the first step of `deploy build`.
|
|
411
421
|
|
|
412
422
|
Never deletes through a shared-dir symlink: any clean target that equals, contains, or is contained by a configured `shared_dirs` entry is skipped with a warning instead of being touched.
|
|
413
423
|
|
|
424
|
+
`--idle-slots` mode: for every state file in `~/.hazo-deploy`, takes its `standby_dir` and removes only `node_modules` and `.next` (never `data/`, config, `.env*`, or shared dirs; a target that is a symlink is left alone). A slot is skipped, with the reason printed, if it is any app's `live_dir`, is the current directory, has a PM2 process whose `pm_cwd` is inside it, or has `last_build` newer than `last_switch` (built but not yet switched — clearing it would force a rebuild before `deploy switch`). The next `deploy build` on a cleaned slot reinstalls and rebuilds as usual.
|
|
425
|
+
|
|
414
426
|
**Reads:**
|
|
415
427
|
- current slot: `du -sk` on each clean target
|
|
416
428
|
- external: `npm config get cache`, free memory
|
|
429
|
+
- state file (`--idle-slots`): every `~/.hazo-deploy/*.json`; external: `pm2 jlist` for each process's `pm_cwd`; each eligible slot: `test -L` and `du -sk` on `node_modules`/`.next`
|
|
417
430
|
|
|
418
431
|
**Writes:**
|
|
419
432
|
- current slot: `rm -rf` on the three targets above (each skipped individually if it overlaps a shared dir)
|
|
420
433
|
- external: `npm cache clean --force`
|
|
434
|
+
- each eligible idle standby slot (`--idle-slots --yes` only): `rm -rf` on `node_modules` and `.next`
|
|
421
435
|
|
|
422
436
|
**Config keys used:** `shared_dirs`, `min_memory_mb`
|
|
423
437
|
|
|
424
438
|
**Failure modes:**
|
|
425
439
|
- (no thrown error) — a target that fails to clean records `targets[].error` and a warning; "overlaps a configured shared dir" is also a warning, never an abort.
|
|
440
|
+
- IdleSlotsAbortError (`--idle-slots`) — `pm2 jlist` failed or returned unparsable output; nothing is cleaned, since no slot can be proven idle.
|
|
426
441
|
|
|
427
442
|
**Examples:**
|
|
428
443
|
```
|
|
429
444
|
hazo-env deploy clean
|
|
430
445
|
hazo-env deploy clean --aggressive
|
|
446
|
+
hazo-env deploy clean --idle-slots
|
|
447
|
+
hazo-env deploy clean --idle-slots --yes
|
|
431
448
|
```
|
|
432
449
|
|
|
433
450
|
#### `deploy share`
|
|
@@ -467,7 +484,7 @@ hazo-env deploy share
|
|
|
467
484
|
| Key | Default | Meaning |
|
|
468
485
|
|---|---|---|
|
|
469
486
|
| `app_name` | (none — required) | Logical app name. Also names the state file: ~/.hazo-deploy/<app_name>.json. |
|
|
470
|
-
| `dir_suffix` | (
|
|
487
|
+
| `dir_suffix` | inferred from the slot directory name ("<app>-blue" → blue, "<app>-green" → green) | Which color suffix THIS directory is (must be exactly "blue" or "green"). The peer is resolved by swapping it on the current directory's basename. Omit it to have it inferred from the directory name — the INI is then identical in both slots and can be committed to git. Set it only for an unsuffixed checkout (e.g. `~/myapp`), and then keep the INI out of git. |
|
|
471
488
|
| `prod_port` | 3000 | Production PM2 port. |
|
|
472
489
|
| `staging_port` | 3001 | Staging port used by `deploy build`/`deploy verify` before switching. |
|
|
473
490
|
| `health_url` | /api/health | Path hit for health checks during build/verify/status. |
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// hazo_env/src/bin.ts — `hazo-env` bin entry.
|
|
3
|
+
//
|
|
4
|
+
// Thin wrapper: dynamic-imports the real CLI so a peer dependency that can't
|
|
5
|
+
// be resolved at module-link time (cli.ts statically imports modules that
|
|
6
|
+
// import hazo_core) surfaces as a readable fix instead of a raw stack trace.
|
|
7
|
+
import { missingPeerMessage } from './peer-hint.js';
|
|
8
|
+
try {
|
|
9
|
+
await import('./cli.js');
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
const message = missingPeerMessage(e);
|
|
13
|
+
if (!message)
|
|
14
|
+
throw e;
|
|
15
|
+
console.error(`\n${message}\n`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import { getEnv } from './index.client.js';
|
|
|
5
5
|
import { describeEnv, getEnvRole, getPattern } from './env.server.js';
|
|
6
6
|
import { doctor } from './doctor.js';
|
|
7
7
|
import { DEPLOY_SUBCOMMAND_NAMES, renderDeploySummaryList, renderDeploySubcommandHelpText, renderDeployConfigHelpText, } from './deploy/help.js';
|
|
8
|
+
import { missingPeerMessage } from './peer-hint.js';
|
|
8
9
|
const [, , command, ...args] = process.argv;
|
|
9
10
|
function statusIcon(status) {
|
|
10
11
|
if (status === 'ok')
|
|
@@ -304,6 +305,9 @@ async function runDeployInit() {
|
|
|
304
305
|
if (result.envFilesMissing.length) {
|
|
305
306
|
console.log(` ${pc.yellow('⚠')} Env files not found (copy manually): ${result.envFilesMissing.join(', ')}`);
|
|
306
307
|
}
|
|
308
|
+
if (result.configExcludedFrom.length) {
|
|
309
|
+
console.log(` ${pc.green('✓')} config/hazo_env_config.ini excluded from git in: ${result.configExcludedFrom.join(', ')}`);
|
|
310
|
+
}
|
|
307
311
|
console.log('');
|
|
308
312
|
console.log(` Next steps:`);
|
|
309
313
|
console.log(` cd ${result.peerDir}`);
|
|
@@ -325,7 +329,57 @@ function formatBytes(bytes) {
|
|
|
325
329
|
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
326
330
|
return `${bytes} B`;
|
|
327
331
|
}
|
|
332
|
+
async function runDeployCleanIdleSlots() {
|
|
333
|
+
const { runCleanIdleSlots, IdleSlotsAbortError } = await import('./deploy/idle-slots.js');
|
|
334
|
+
const { nodeCommandRunner } = await import('./deploy/runner.js');
|
|
335
|
+
const yes = args.includes('--yes');
|
|
336
|
+
console.log(`\n${pc.bold('hazo-env deploy clean --idle-slots')}${yes ? '' : pc.dim(' (dry run — re-run with --yes to delete)')}\n`);
|
|
337
|
+
let result;
|
|
338
|
+
try {
|
|
339
|
+
result = runCleanIdleSlots(nodeCommandRunner, { yes });
|
|
340
|
+
}
|
|
341
|
+
catch (e) {
|
|
342
|
+
if (e instanceof IdleSlotsAbortError) {
|
|
343
|
+
console.error(` ${pc.red('✗')} ${e.message}\n`);
|
|
344
|
+
process.exit(1);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
throw e;
|
|
348
|
+
}
|
|
349
|
+
if (result.slots.length === 0) {
|
|
350
|
+
console.log(` ${pc.dim('No deploy state files found in ~/.hazo-deploy — nothing to clean.')}\n`);
|
|
351
|
+
}
|
|
352
|
+
for (const slot of result.slots) {
|
|
353
|
+
if (!slot.eligible) {
|
|
354
|
+
console.log(` ${pc.dim('·')} ${slot.app_name.padEnd(16)} ${slot.slot_dir} ${pc.yellow(`skipped: ${slot.skipReason}`)}`);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
console.log(` ${pc.green('✓')} ${slot.app_name.padEnd(16)} ${slot.slot_dir} ${pc.bold(formatBytes(slot.bytes))}`);
|
|
358
|
+
for (const t of slot.targets) {
|
|
359
|
+
const status = t.error
|
|
360
|
+
? pc.red(t.error)
|
|
361
|
+
: t.skipped
|
|
362
|
+
? pc.dim(t.skipReason ?? 'skipped')
|
|
363
|
+
: t.removed
|
|
364
|
+
? `reclaimed ${formatBytes(t.bytes)}`
|
|
365
|
+
: `${formatBytes(t.bytes)} (would delete)`;
|
|
366
|
+
console.log(` ${t.name.padEnd(14)} ${status}`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
console.log('');
|
|
370
|
+
console.log(` ${pc.bold(result.dryRun ? 'total reclaimable:' : 'total reclaimed:')} ${formatBytes(result.totalBytes)}`);
|
|
371
|
+
if (result.dryRun && result.totalBytes > 0) {
|
|
372
|
+
console.log(` ${pc.dim('Nothing was deleted. Re-run with --yes to delete node_modules/.next from the slots above.')}`);
|
|
373
|
+
}
|
|
374
|
+
for (const warning of result.warnings)
|
|
375
|
+
console.log(` ${pc.yellow('⚠')} ${warning}`);
|
|
376
|
+
console.log('');
|
|
377
|
+
}
|
|
328
378
|
async function runDeployClean() {
|
|
379
|
+
if (args.includes('--idle-slots')) {
|
|
380
|
+
await runDeployCleanIdleSlots();
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
329
383
|
const { resolveDeployConfig } = await import('./resolve/deploy.js');
|
|
330
384
|
const { runClean } = await import('./deploy/clean.js');
|
|
331
385
|
const { nodeCommandRunner } = await import('./deploy/runner.js');
|
|
@@ -389,9 +443,12 @@ async function runDeployBuild() {
|
|
|
389
443
|
console.log(`\n${pc.bold('hazo-env deploy build')} ${pc.dim(config.app_name)}\n`);
|
|
390
444
|
function printSteps(steps) {
|
|
391
445
|
for (const step of steps) {
|
|
392
|
-
const icon = step.status === 'pass' ? pc.green('✓') : pc.red('✗');
|
|
393
|
-
const
|
|
446
|
+
const icon = step.status === 'pass' ? pc.green('✓') : step.status === 'warn' ? pc.yellow('⚠') : pc.red('✗');
|
|
447
|
+
const [first = '', ...rest] = (step.detail ?? '').split('\n');
|
|
448
|
+
const detail = first ? ` ${step.status === 'pass' ? pc.dim(first) : first}` : '';
|
|
394
449
|
console.log(` ${icon} ${step.name.padEnd(16)}${detail}`);
|
|
450
|
+
for (const line of rest)
|
|
451
|
+
console.log(` ${line}`);
|
|
395
452
|
}
|
|
396
453
|
}
|
|
397
454
|
try {
|
|
@@ -411,7 +468,10 @@ async function runDeployBuild() {
|
|
|
411
468
|
console.log('');
|
|
412
469
|
printSteps(e.steps);
|
|
413
470
|
console.log('');
|
|
414
|
-
|
|
471
|
+
const failedStep = e.steps.find((s) => s.status === 'fail');
|
|
472
|
+
console.error(failedStep
|
|
473
|
+
? ` ${pc.red('✗ Build aborted')} at step "${failedStep.name}" — see its output above.\n`
|
|
474
|
+
: ` ${pc.red('✗ Build aborted:')} ${e.message}\n`);
|
|
415
475
|
process.exit(1);
|
|
416
476
|
return;
|
|
417
477
|
}
|
|
@@ -427,12 +487,19 @@ function verifyStatusIcon(status) {
|
|
|
427
487
|
return pc.yellow('–');
|
|
428
488
|
return pc.red('✗');
|
|
429
489
|
}
|
|
490
|
+
async function printCliDependencyWarning() {
|
|
491
|
+
const { cliDependencyWarning } = await import('./deploy/preflight.js');
|
|
492
|
+
const warning = cliDependencyWarning(process.cwd());
|
|
493
|
+
if (warning)
|
|
494
|
+
console.log(` ${pc.yellow('⚠')} ${warning}\n`);
|
|
495
|
+
}
|
|
430
496
|
async function runDeployVerify() {
|
|
431
497
|
const { resolveDeployConfig } = await import('./resolve/deploy.js');
|
|
432
498
|
const { runVerify } = await import('./deploy/verify.js');
|
|
433
499
|
const { nodeCommandRunner } = await import('./deploy/runner.js');
|
|
434
500
|
const config = resolveDeployConfig();
|
|
435
501
|
console.log(`\n${pc.bold('hazo-env deploy verify')} ${pc.dim(config.app_name)}\n`);
|
|
502
|
+
await printCliDependencyWarning();
|
|
436
503
|
const result = runVerify(config, nodeCommandRunner, { tscCmd: config.verify_tsc_cmd });
|
|
437
504
|
const nameWidth = Math.max(...result.checks.map((c) => c.name.length)) + 2;
|
|
438
505
|
for (const check of result.checks) {
|
|
@@ -455,6 +522,7 @@ async function runDeploySwitch() {
|
|
|
455
522
|
const force = args.includes('--force');
|
|
456
523
|
const config = resolveDeployConfig();
|
|
457
524
|
console.log(`\n${pc.bold('hazo-env deploy switch')} ${pc.dim(config.app_name)}\n`);
|
|
525
|
+
await printCliDependencyWarning();
|
|
458
526
|
try {
|
|
459
527
|
const result = runSwitch(config, nodeCommandRunner, { force });
|
|
460
528
|
console.log(` ${pc.green('✓')} deleted live PM2 registration "${config.app_name}" in ${result.previousLiveDir}`);
|
|
@@ -695,6 +763,11 @@ Usage:
|
|
|
695
763
|
}
|
|
696
764
|
}
|
|
697
765
|
catch (e) {
|
|
766
|
+
const peerMessage = missingPeerMessage(e);
|
|
767
|
+
if (peerMessage) {
|
|
768
|
+
console.error(`\n${peerMessage}\n`);
|
|
769
|
+
process.exit(1);
|
|
770
|
+
}
|
|
698
771
|
const msg = e instanceof Error ? e.message : String(e);
|
|
699
772
|
console.error(`\n${pc.red('Error:')} ${msg}\n`);
|
|
700
773
|
process.exit(1);
|
package/dist/deploy/build.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface RunBuildOptions {
|
|
|
15
15
|
/** Delay between health check retries, in ms. Default: 1500. */
|
|
16
16
|
healthCheckDelayMs?: number;
|
|
17
17
|
}
|
|
18
|
-
export type BuildStepStatus = 'pass' | 'fail';
|
|
18
|
+
export type BuildStepStatus = 'pass' | 'warn' | 'fail';
|
|
19
19
|
export interface BuildStepResult {
|
|
20
20
|
name: string;
|
|
21
21
|
status: BuildStepStatus;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/deploy/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/deploy/build.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI9D,MAAM,WAAW,eAAe;IAC9B,gGAAgG;IAChG,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gEAAgE;IAChE,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,MAAM,GAAG,QAAQ,CAAC;IACtC,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,6FAA6F;AAC7F,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,KAAK,EAAE,eAAe,EAAE,CAAC;gBAEtB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE;CAKtD;AAKD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAMjF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAErE;AAiBD,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,iBAAiB,CASpH;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,GAAE,eAAoB,GAAG,cAAc,CA8WhH"}
|
package/dist/deploy/build.js
CHANGED
|
@@ -30,6 +30,7 @@ import { readState, updateState } from './state.js';
|
|
|
30
30
|
import { SWAP_INCREASE_SUGGESTIONS } from './clean.js';
|
|
31
31
|
import { startNamedPm2Process, isPm2ProcessNotFound } from './pm2-start.js';
|
|
32
32
|
import { ensureLinks } from './shared-dirs.js';
|
|
33
|
+
import { cliDependencyWarning, commandFailureDetail, isDeployConfigGitTracked, deployConfigPinsDirSuffix, TRACKED_DEPLOY_CONFIG_MESSAGE, } from './preflight.js';
|
|
33
34
|
import { resolveConnectConfig } from '../resolve/connect.js';
|
|
34
35
|
/** Thrown when any pipeline step fails. Carries the steps completed so far for reporting. */
|
|
35
36
|
export class BuildAbortError extends Error {
|
|
@@ -147,6 +148,10 @@ export function runBuild(config, runner, opts = {}) {
|
|
|
147
148
|
function pass(name, detail) {
|
|
148
149
|
steps.push({ name, status: 'pass', detail });
|
|
149
150
|
}
|
|
151
|
+
function warn(name, detail) {
|
|
152
|
+
steps.push({ name, status: 'warn', detail });
|
|
153
|
+
warnings.push(detail);
|
|
154
|
+
}
|
|
150
155
|
function abort(name, message) {
|
|
151
156
|
const finalMessage = productionStopped
|
|
152
157
|
? `${message}\n\n` +
|
|
@@ -174,8 +179,10 @@ export function runBuild(config, runner, opts = {}) {
|
|
|
174
179
|
catch (e) {
|
|
175
180
|
if (e instanceof BuildAbortError)
|
|
176
181
|
throw e;
|
|
177
|
-
|
|
178
|
-
|
|
182
|
+
// commandFailureDetail appends the tail of the command's captured
|
|
183
|
+
// stdout+stderr — `next build` prints its tsc errors to stdout, which
|
|
184
|
+
// execSync keeps on the error object, not in its message.
|
|
185
|
+
return abort(name, commandFailureDetail(e));
|
|
179
186
|
}
|
|
180
187
|
}
|
|
181
188
|
let buildStatus = 'failed';
|
|
@@ -198,13 +205,20 @@ export function runBuild(config, runner, opts = {}) {
|
|
|
198
205
|
: state
|
|
199
206
|
? path.resolve(state.live_dir)
|
|
200
207
|
: resolvePeerDir(cwd, undefined, config.dir_suffix);
|
|
208
|
+
// Warning only: hazo_env missing from package.json means this run's own
|
|
209
|
+
// `npm ci` (install step) removes it, breaking the NEXT `npx hazo_env`.
|
|
210
|
+
const dependencyWarning = cliDependencyWarning(cwd);
|
|
211
|
+
if (dependencyWarning)
|
|
212
|
+
warn('cli-dependency', dependencyWarning);
|
|
201
213
|
// Step 1: auto-clean, then check disk free against min_disk_mb.
|
|
202
214
|
const cleanResult = autoClean(config, runner);
|
|
203
215
|
pass('clean', `reclaimed ${cleanResult.totalBytesReclaimed} bytes across ${cleanResult.targets.length} targets`);
|
|
204
216
|
warnings.push(...cleanResult.warnings);
|
|
205
217
|
const diskFreeMb = queryDiskFreeMb(runner, cwd, warnings);
|
|
206
218
|
if (diskFreeMb !== undefined && diskFreeMb < config.min_disk_mb) {
|
|
207
|
-
abort('disk-check', `Disk free (${diskFreeMb} MB) is still below min_disk_mb (${config.min_disk_mb}) after cleanup
|
|
219
|
+
abort('disk-check', `Disk free (${diskFreeMb} MB) is still below min_disk_mb (${config.min_disk_mb}) after cleanup. ` +
|
|
220
|
+
`Run "hazo-env deploy clean --idle-slots" to reclaim space from other apps' idle standby slots ` +
|
|
221
|
+
`(dry run first; add --yes to delete).`);
|
|
208
222
|
}
|
|
209
223
|
pass('disk-check', diskFreeMb !== undefined ? `${diskFreeMb} MB free` : 'unknown — skipping check');
|
|
210
224
|
// Step 2/3: memory check, optionally freed by stopping the live PM2 process.
|
|
@@ -256,6 +270,16 @@ export function runBuild(config, runner, opts = {}) {
|
|
|
256
270
|
else {
|
|
257
271
|
pass('shared-dirs', 'no shared_dirs configured — skipping');
|
|
258
272
|
}
|
|
273
|
+
// Pre-flight (read-only, so before the destructive marker below): a
|
|
274
|
+
// git-tracked INI is only a problem when it pins the per-slot
|
|
275
|
+
// `dir_suffix` — see preflight.ts. (Step name kept for compatibility.)
|
|
276
|
+
const configTracked = runStep('config-untracked', () => isDeployConfigGitTracked(runner, cwd));
|
|
277
|
+
if (configTracked && deployConfigPinsDirSuffix(cwd)) {
|
|
278
|
+
abort('config-untracked', TRACKED_DEPLOY_CONFIG_MESSAGE);
|
|
279
|
+
}
|
|
280
|
+
pass('config-untracked', configTracked
|
|
281
|
+
? 'config/hazo_env_config.ini is tracked by git without dir_suffix (inferred from the slot dir name)'
|
|
282
|
+
: 'config/hazo_env_config.ini is not tracked by git');
|
|
259
283
|
// Fix 3: write a provisional/pessimistic `last_build` marker right
|
|
260
284
|
// before the first DESTRUCTIVE step (git pull) — everything above this
|
|
261
285
|
// point (guard, disk/memory checks, db-resolve) is read-only, so an
|
|
@@ -277,7 +301,18 @@ export function runBuild(config, runner, opts = {}) {
|
|
|
277
301
|
catch {
|
|
278
302
|
// No state file yet — best-effort, same as the finally block below.
|
|
279
303
|
}
|
|
280
|
-
// Step
|
|
304
|
+
// Step 4a: stash any local changes so git pull doesn't fail. The standby
|
|
305
|
+
// dir is a disposable clone; uncommitted edits there are leftover
|
|
306
|
+
// artifacts (npm-install-time package.json rewrites, hand patches), never
|
|
307
|
+
// intentional work. Best-effort: a failed stash just lets the pull
|
|
308
|
+
// report the real conflict. (Shipped in 0.15.3, lost in 0.16.0.)
|
|
309
|
+
const countStashes = () => (runner.spawn('git stash list', { cwd }).stdout ?? '').split('\n').filter((l) => l.trim().length > 0).length;
|
|
310
|
+
const stashesBefore = countStashes();
|
|
311
|
+
const stashResult = runner.spawn('git stash --quiet', { cwd });
|
|
312
|
+
if (stashResult.code === 0 && countStashes() > stashesBefore) {
|
|
313
|
+
pass('git-stash', 'stashed local changes (recover with "git stash list" / "git stash pop")');
|
|
314
|
+
}
|
|
315
|
+
// Step 4b: git pull
|
|
281
316
|
runStep('git-pull', () => runner.exec(`git pull origin ${branch}`, { cwd }));
|
|
282
317
|
pass('git-pull', `origin ${branch}`);
|
|
283
318
|
// Step 5: install
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../src/deploy/help.ts"],"names":[],"mappings":"AA0BA,gGAAgG;AAChG,eAAO,MAAM,uBAAuB,wFAS1B,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5E,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,2FAA2F;IAC3F,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,yGAAyG;IACzG,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,0IAA0I;IAC1I,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,yEAAyE;IACzE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,iDAAiD;IACjD,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,qIAAqI;IACrI,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,uDAAuD;IACvD,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,oBAAoB,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../src/deploy/help.ts"],"names":[],"mappings":"AA0BA,gGAAgG;AAChG,eAAO,MAAM,uBAAuB,wFAS1B,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5E,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,2FAA2F;IAC3F,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,yGAAyG;IACzG,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,0IAA0I;IAC1I,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,yEAAyE;IACzE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,iDAAiD;IACjD,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,qIAAqI;IACrI,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,uDAAuD;IACvD,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,oBAAoB,EAAE,oBAAoB,CAsPrF,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,EAAE,mBAAmB,EAsInD,CAAC;AAQF,kHAAkH;AAClH,wBAAgB,uBAAuB,IAAI,MAAM,CAahD;AAED,8CAA8C;AAC9C,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,oBAAoB,GAAG,MAAM,CAwBjF;AAED,8EAA8E;AAC9E,wBAAgB,0BAA0B,IAAI,MAAM,CAUnD;AASD,eAAO,MAAM,0BAA0B,sEAAsE,CAAC;AAC9G,eAAO,MAAM,wBAAwB,2CAA2C,CAAC;AA4BjF,uGAAuG;AACvG,wBAAgB,yBAAyB,IAAI,MAAM,CAwClD"}
|
package/dist/deploy/help.js
CHANGED
|
@@ -50,11 +50,12 @@ export const DEPLOY_SUBCOMMAND_HELP = {
|
|
|
50
50
|
],
|
|
51
51
|
writes: [
|
|
52
52
|
'external: a new sibling directory — `git clone <origin>` into `<app>-<opposite dir_suffix>`',
|
|
53
|
-
'standby slot: `config/hazo_env_config.ini`, with `dir_suffix` swapped blue↔green',
|
|
53
|
+
'standby slot: `config/hazo_env_config.ini`, with `dir_suffix` swapped blue↔green (copied unchanged when the INI has no `dir_suffix` line — the suffix is then inferred from each slot\'s directory name)',
|
|
54
54
|
'standby slot: the `[data] root` directory, when the app is sqlite-backed (`db_strategy` resolves to `copy`)',
|
|
55
55
|
'standby slot: each found `env_files` entry, copied in (gitignored secrets never travel through `git clone`)',
|
|
56
56
|
'shared root + standby slot: shared-dir symlinks — `ensureLinks(standbyDir, { allowCreate: true })` creates `shared_root/<dir>` and the standby\'s `<dir>` symlink for every `shared_dirs` entry not already linked',
|
|
57
57
|
'state file: `~/.hazo-deploy/<app_name>.json` written fresh (`live_dir` = current dir, `standby_dir` = the new peer)',
|
|
58
|
+
'live + standby slot: `.git/info/exclude` gains a `config/hazo_env_config.ini` entry when the INI pins `dir_suffix` (it is then per-slot, so it must never be committed; the exclude file is local to each clone and never dirties a tracked `.gitignore`). Skipped when the INI has no `dir_suffix` line — that file is identical in both slots and meant to be committed.',
|
|
58
59
|
],
|
|
59
60
|
configKeys: ['app_name', 'dir_suffix', 'env_files', 'shared_root', 'shared_dirs'],
|
|
60
61
|
failureModes: [
|
|
@@ -75,7 +76,8 @@ export const DEPLOY_SUBCOMMAND_HELP = {
|
|
|
75
76
|
],
|
|
76
77
|
description: [
|
|
77
78
|
'Must be run FROM the standby directory — a "standby-dir-guard" step aborts immediately if the state file says `cwd` isn\'t the recorded `standby_dir`, because running the pipeline against the live dir would git-pull/rebuild the running production tree and, for a sqlite "copy" `db_strategy`, overwrite the live database with the standby\'s stale one.',
|
|
78
|
-
'Steps run in order and any failure aborts immediately: standby-dir-guard → clean → disk-check → memory-check (→ stop-prod, only if `--stop-prod` and memory is still low) → db-resolve → shared-dirs → git-pull → install → pre-build → build → db-setup → migrate → clean-stale-staging → start-staging → health-check.',
|
|
79
|
+
'Steps run in order and any failure aborts immediately: standby-dir-guard → (cli-dependency warning) → clean → disk-check → memory-check (→ stop-prod, only if `--stop-prod` and memory is still low) → db-resolve → shared-dirs → config-untracked → (git-stash) → git-pull → install → pre-build → build → db-setup → migrate → clean-stale-staging → start-staging → health-check.',
|
|
80
|
+
'Run it via the app\'s own install (`npm i -D hazo_env`, then `npx hazo_env deploy build`): a "cli-dependency" warning step appears when `hazo_env` is missing from `package.json`, because the build\'s own `npm ci` would remove a hand-installed copy and break the next run. Uncommitted changes in the standby slot are stashed (never discarded) before `git pull`. A failing install/build step prints the last 40 lines of the command\'s output (e.g. the actual `tsc` errors behind Next\'s "Failed to type check.").',
|
|
79
81
|
'The "shared-dirs" step runs BEFORE git-pull (the first destructive step) specifically so a shared-dir problem never marks `last_build` as attempted — see the failure modes below.',
|
|
80
82
|
],
|
|
81
83
|
reads: [
|
|
@@ -85,11 +87,12 @@ export const DEPLOY_SUBCOMMAND_HELP = {
|
|
|
85
87
|
'standby slot: `resolveConnectConfig()` (or `--db`) to resolve `db_strategy: "auto"` to `copy`/`shared`',
|
|
86
88
|
'live slot: the sqlite db file (copy strategy only, to back up from)',
|
|
87
89
|
'standby slot: its own shared-dir link state (inspected internally by the `ensureLinks` call below)',
|
|
90
|
+
'standby slot: `package.json` (is `hazo_env` a dependency?) and `git ls-files --error-unmatch config/hazo_env_config.ini` (is the per-slot INI tracked?)',
|
|
88
91
|
],
|
|
89
92
|
writes: [
|
|
90
93
|
'standby slot: cache cleanup (same targets as `deploy clean`) then a disk-free check',
|
|
91
94
|
'live slot: `pm2 stop <app_name>` (only with `--stop-prod`, only if memory is still low after cleanup)',
|
|
92
|
-
'standby slot: `git pull` on `branch`, then `install_cmd`, `pre_build_cmd`, `build_cmd`',
|
|
95
|
+
'standby slot: `git stash` of any uncommitted changes (recover with `git stash pop`), then `git pull` on `branch`, then `install_cmd`, `pre_build_cmd`, `build_cmd`',
|
|
93
96
|
'standby slot: sqlite backup copy from the live slot (copy strategy) — or nothing, for the "shared" strategy (same Postgres DB, no copy)',
|
|
94
97
|
'standby slot: `migrate_cmd`, only if non-empty',
|
|
95
98
|
'shared root + standby slot: shared-dir self-heal — `ensureLinks(standbyDir, { allowCreate: true, allowReplaceEmpty: true })`. This is the ONLY deploy command that auto-creates a missing link or auto-replaces an empty real directory; everywhere else that\'s left to `deploy share`.',
|
|
@@ -103,6 +106,9 @@ export const DEPLOY_SUBCOMMAND_HELP = {
|
|
|
103
106
|
],
|
|
104
107
|
failureModes: [
|
|
105
108
|
'BuildAbortError (any step name above) — aborts on the first failing step; the error carries every step completed so far for reporting. If `--stop-prod` already stopped production before the abort, the message is prefixed "⚠ PRODUCTION IS DOWN" with the exact `pm2 start` command to bring it back up by hand.',
|
|
109
|
+
'BuildAbortError at "config-untracked" — `config/hazo_env_config.ini` is tracked in git AND pins `dir_suffix` (which differs per slot), so a pull would overwrite or conflict with the slot\'s copy. Either delete the `dir_suffix` line (it is then inferred from the slot directory name, so one committed file serves both slots), or `git rm --cached` it, add it to `.gitignore`, commit, and keep each slot\'s local copy. A tracked INI without `dir_suffix` passes. Checked before `git-pull`, so `last_build` is untouched.',
|
|
110
|
+
'BuildAbortError at "disk-check" — free disk still below `min_disk_mb` after cleanup; the message suggests `hazo-env deploy clean --idle-slots` to reclaim other apps\' idle standby `node_modules`/`.next`.',
|
|
111
|
+
'HazoConfigError "HAZO_ENV_CONFIG_FILE_MISSING" — no `config/hazo_env_config.ini` in the slot; when the cwd is a `-blue`/`-green` dir and the peer has one, the message gives the exact `sed` command to copy it with `dir_suffix` swapped.',
|
|
106
112
|
'SharedDirError "HAZO_ENV_SHARED_DIR_REAL_DIR" / "HAZO_ENV_SHARED_DIR_WRONG_LINK" (surfaces as the "shared-dirs" build step\'s failure) — a non-empty real directory, or a symlink to the wrong target, is sitting where a shared-dir link belongs; build refuses and its message points at "hazo-env deploy share". ("HAZO_ENV_SHARED_DIR_MISSING" / "_EMPTY_DIR" never surface here — build always passes `allowCreate` and `allowReplaceEmpty`.)',
|
|
107
113
|
],
|
|
108
114
|
examples: ['hazo-env deploy build', 'hazo-env deploy build --stop-prod --branch=release'],
|
|
@@ -125,6 +131,7 @@ export const DEPLOY_SUBCOMMAND_HELP = {
|
|
|
125
131
|
configKeys: ['staging_port', 'health_url', 'verify_tsc_cmd', 'db_strategy'],
|
|
126
132
|
failureModes: [
|
|
127
133
|
'(no thrown error) — failures are reported per-check in `checks[]`; the process exits 1 if `allPassed` is false.',
|
|
134
|
+
'`health` fail with "curl_exit_7" (connection refused) — nothing is listening on `staging_port`; the detail tells you to run `hazo-env deploy build` first (it starts `<app_name>-staging`) or check `pm2 ls`.',
|
|
128
135
|
],
|
|
129
136
|
examples: ['hazo-env deploy verify'],
|
|
130
137
|
},
|
|
@@ -213,18 +220,30 @@ export const DEPLOY_SUBCOMMAND_HELP = {
|
|
|
213
220
|
summary: 'Reclaim disk space from old builds and caches',
|
|
214
221
|
flags: [
|
|
215
222
|
{ flag: '--aggressive', description: 'Also PRINT (never run) system-level cleanup suggestions (apt/journalctl/docker) that need sudo.' },
|
|
223
|
+
{ flag: '--idle-slots', description: 'Instead: reclaim `node_modules` + `.next` from EVERY app\'s idle standby slot listed in `~/.hazo-deploy/*.json`. Runs from any directory (no `[deploy]` config needed). Dry run unless `--yes`.' },
|
|
224
|
+
{ flag: '--yes', description: 'With `--idle-slots`: actually delete (default is a dry run that only lists slots and sizes).' },
|
|
216
225
|
],
|
|
217
226
|
description: [
|
|
218
227
|
'Deletes `.next.rollback`, `.next.staging`, and `node_modules/.cache`, and runs `npm cache clean --force`. Also called automatically as the first step of `deploy build`.',
|
|
219
228
|
'Never deletes through a shared-dir symlink: any clean target that equals, contains, or is contained by a configured `shared_dirs` entry is skipped with a warning instead of being touched.',
|
|
229
|
+
'`--idle-slots` mode: for every state file in `~/.hazo-deploy`, takes its `standby_dir` and removes only `node_modules` and `.next` (never `data/`, config, `.env*`, or shared dirs; a target that is a symlink is left alone). A slot is skipped, with the reason printed, if it is any app\'s `live_dir`, is the current directory, has a PM2 process whose `pm_cwd` is inside it, or has `last_build` newer than `last_switch` (built but not yet switched — clearing it would force a rebuild before `deploy switch`). The next `deploy build` on a cleaned slot reinstalls and rebuilds as usual.',
|
|
230
|
+
],
|
|
231
|
+
reads: [
|
|
232
|
+
'current slot: `du -sk` on each clean target',
|
|
233
|
+
'external: `npm config get cache`, free memory',
|
|
234
|
+
'state file (`--idle-slots`): every `~/.hazo-deploy/*.json`; external: `pm2 jlist` for each process\'s `pm_cwd`; each eligible slot: `test -L` and `du -sk` on `node_modules`/`.next`',
|
|
235
|
+
],
|
|
236
|
+
writes: [
|
|
237
|
+
'current slot: `rm -rf` on the three targets above (each skipped individually if it overlaps a shared dir)',
|
|
238
|
+
'external: `npm cache clean --force`',
|
|
239
|
+
'each eligible idle standby slot (`--idle-slots --yes` only): `rm -rf` on `node_modules` and `.next`',
|
|
220
240
|
],
|
|
221
|
-
reads: ['current slot: `du -sk` on each clean target', 'external: `npm config get cache`, free memory'],
|
|
222
|
-
writes: ['current slot: `rm -rf` on the three targets above (each skipped individually if it overlaps a shared dir)', 'external: `npm cache clean --force`'],
|
|
223
241
|
configKeys: ['shared_dirs', 'min_memory_mb'],
|
|
224
242
|
failureModes: [
|
|
225
243
|
'(no thrown error) — a target that fails to clean records `targets[].error` and a warning; "overlaps a configured shared dir" is also a warning, never an abort.',
|
|
244
|
+
'IdleSlotsAbortError (`--idle-slots`) — `pm2 jlist` failed or returned unparsable output; nothing is cleaned, since no slot can be proven idle.',
|
|
226
245
|
],
|
|
227
|
-
examples: ['hazo-env deploy clean', 'hazo-env deploy clean --aggressive'],
|
|
246
|
+
examples: ['hazo-env deploy clean', 'hazo-env deploy clean --aggressive', 'hazo-env deploy clean --idle-slots', 'hazo-env deploy clean --idle-slots --yes'],
|
|
228
247
|
},
|
|
229
248
|
share: {
|
|
230
249
|
name: 'share',
|
|
@@ -275,9 +294,9 @@ export const DEPLOY_CONFIG_HELP = [
|
|
|
275
294
|
},
|
|
276
295
|
{
|
|
277
296
|
key: 'dir_suffix',
|
|
278
|
-
type: 'string
|
|
279
|
-
default: '(
|
|
280
|
-
meaning: 'Which color suffix THIS directory is (must be exactly "blue" or "green"). The peer is resolved by swapping it on the current directory\'s basename.',
|
|
297
|
+
type: 'string',
|
|
298
|
+
default: 'inferred from the slot directory name ("<app>-blue" → blue, "<app>-green" → green)',
|
|
299
|
+
meaning: 'Which color suffix THIS directory is (must be exactly "blue" or "green"). The peer is resolved by swapping it on the current directory\'s basename. Omit it to have it inferred from the directory name — the INI is then identical in both slots and can be committed to git. Set it only for an unsuffixed checkout (e.g. `~/myapp`), and then keep the INI out of git.',
|
|
281
300
|
example: 'dir_suffix = green',
|
|
282
301
|
},
|
|
283
302
|
{
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CommandRunner } from './types.js';
|
|
2
|
+
export declare const IDLE_SLOT_TARGETS: readonly ["node_modules", ".next"];
|
|
3
|
+
export interface IdleSlotTargetResult {
|
|
4
|
+
name: (typeof IDLE_SLOT_TARGETS)[number];
|
|
5
|
+
path: string;
|
|
6
|
+
/** Measured size in bytes (0 when absent). */
|
|
7
|
+
bytes: number;
|
|
8
|
+
/** True when the target was absent, or left alone because it is a symlink. */
|
|
9
|
+
skipped: boolean;
|
|
10
|
+
skipReason?: string;
|
|
11
|
+
/** True once actually removed (only with `yes`). */
|
|
12
|
+
removed: boolean;
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface IdleSlotResult {
|
|
16
|
+
app_name: string;
|
|
17
|
+
slot_dir: string;
|
|
18
|
+
eligible: boolean;
|
|
19
|
+
/** Why the slot was skipped (only when !eligible). */
|
|
20
|
+
skipReason?: string;
|
|
21
|
+
targets: IdleSlotTargetResult[];
|
|
22
|
+
/** Measured bytes (dry run) or bytes actually reclaimed (`yes`). */
|
|
23
|
+
bytes: number;
|
|
24
|
+
}
|
|
25
|
+
export interface RunCleanIdleSlotsOptions {
|
|
26
|
+
/** Actually delete. Default false (dry run: measure and report only). */
|
|
27
|
+
yes?: boolean;
|
|
28
|
+
/** Directory treated as "current" for the cwd safety check. Defaults to process.cwd(). */
|
|
29
|
+
cwd?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface RunCleanIdleSlotsResult {
|
|
32
|
+
dryRun: boolean;
|
|
33
|
+
slots: IdleSlotResult[];
|
|
34
|
+
totalBytes: number;
|
|
35
|
+
warnings: string[];
|
|
36
|
+
}
|
|
37
|
+
export declare class IdleSlotsAbortError extends Error {
|
|
38
|
+
constructor(message: string);
|
|
39
|
+
}
|
|
40
|
+
/** See this file's header. Throws IdleSlotsAbortError only when PM2 state can't be read. */
|
|
41
|
+
export declare function runCleanIdleSlots(runner: CommandRunner, opts?: RunCleanIdleSlotsOptions): RunCleanIdleSlotsResult;
|
|
42
|
+
//# sourceMappingURL=idle-slots.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idle-slots.d.ts","sourceRoot":"","sources":["../../src/deploy/idle-slots.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,YAAY,CAAC;AAE7D,eAAO,MAAM,iBAAiB,oCAAqC,CAAC;AAEpE,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,oBAAoB,EAAE,CAAC;IAChC,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,wBAAwB;IACvC,yEAAyE;IACzE,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,0FAA0F;IAC1F,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAuGD,4FAA4F;AAC5F,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,GAAE,wBAA6B,GAAG,uBAAuB,CAoBrH"}
|