hazo_env 0.15.3 → 0.17.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 +120 -0
- package/README.md +333 -0
- 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 +178 -17
- package/dist/deploy/build.d.ts +1 -1
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +51 -14
- package/dist/deploy/clean.d.ts +2 -1
- package/dist/deploy/clean.d.ts.map +1 -1
- package/dist/deploy/clean.js +36 -6
- package/dist/deploy/generate-readme-cli.d.ts +3 -0
- package/dist/deploy/generate-readme-cli.d.ts.map +1 -0
- package/dist/deploy/generate-readme-cli.js +40 -0
- package/dist/deploy/help.d.ts +55 -0
- package/dist/deploy/help.d.ts.map +1 -0
- package/dist/deploy/help.js +545 -0
- 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 +5 -0
- package/dist/deploy/index.d.ts.map +1 -1
- package/dist/deploy/index.js +5 -0
- package/dist/deploy/init.d.ts +14 -0
- package/dist/deploy/init.d.ts.map +1 -1
- package/dist/deploy/init.js +14 -1
- package/dist/deploy/preflight.d.ts +26 -0
- package/dist/deploy/preflight.d.ts.map +1 -0
- package/dist/deploy/preflight.js +91 -0
- package/dist/deploy/rollback.d.ts +10 -1
- package/dist/deploy/rollback.d.ts.map +1 -1
- package/dist/deploy/rollback.js +25 -1
- package/dist/deploy/share.d.ts +28 -0
- package/dist/deploy/share.d.ts.map +1 -0
- package/dist/deploy/share.js +53 -0
- package/dist/deploy/shared-dirs.d.ts +128 -0
- package/dist/deploy/shared-dirs.d.ts.map +1 -0
- package/dist/deploy/shared-dirs.js +486 -0
- package/dist/deploy/status.d.ts +8 -0
- package/dist/deploy/status.d.ts.map +1 -1
- package/dist/deploy/status.js +6 -0
- package/dist/deploy/switch.d.ts.map +1 -1
- package/dist/deploy/switch.js +25 -0
- package/dist/deploy/types.d.ts +18 -0
- package/dist/deploy/types.d.ts.map +1 -1
- package/dist/deploy/verify.d.ts.map +1 -1
- package/dist/deploy/verify.js +7 -1
- package/dist/envsync/engine.d.ts.map +1 -1
- package/dist/envsync/engine.js +21 -7
- package/dist/envsync/paths.d.ts +22 -0
- package/dist/envsync/paths.d.ts.map +1 -1
- package/dist/envsync/paths.js +55 -0
- 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 +167 -1
- package/dist/resolve/envsync.d.ts +16 -0
- package/dist/resolve/envsync.d.ts.map +1 -1
- package/dist/resolve/envsync.js +19 -0
- package/package.json +4 -3
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** The 8 real `deploy` actions (excludes the documentation-only `config` pseudo-subcommand). */
|
|
2
|
+
export declare const DEPLOY_SUBCOMMAND_NAMES: readonly ["init", "build", "verify", "switch", "rollback", "status", "clean", "share"];
|
|
3
|
+
export type DeploySubcommandName = (typeof DEPLOY_SUBCOMMAND_NAMES)[number];
|
|
4
|
+
export interface DeployFlagHelp {
|
|
5
|
+
flag: string;
|
|
6
|
+
description: string;
|
|
7
|
+
}
|
|
8
|
+
export interface DeploySubcommandHelp {
|
|
9
|
+
name: DeploySubcommandName;
|
|
10
|
+
/** One-liner shown in `deploy --help`'s subcommand list and the README's summary table. */
|
|
11
|
+
summary: string;
|
|
12
|
+
flags: DeployFlagHelp[];
|
|
13
|
+
/** Prose paragraphs (rendered one per blank-line-separated block) for `deploy <cmd> --help` / README. */
|
|
14
|
+
description: string[];
|
|
15
|
+
/** What this command reads, as "<location>: <what>" lines (location = live slot / standby slot / shared root / state file / external). */
|
|
16
|
+
reads: string[];
|
|
17
|
+
/** What this command writes/mutates, same "<location>: <what>" shape. */
|
|
18
|
+
writes: string[];
|
|
19
|
+
/** `[deploy]` INI keys this command consults. */
|
|
20
|
+
configKeys: string[];
|
|
21
|
+
/** Every way this command can fail, as one line each — typed error + code where one exists, otherwise the literal thrown message. */
|
|
22
|
+
failureModes: string[];
|
|
23
|
+
/** Runnable example invocations, most useful first. */
|
|
24
|
+
examples: string[];
|
|
25
|
+
}
|
|
26
|
+
export declare const DEPLOY_SUBCOMMAND_HELP: Record<DeploySubcommandName, DeploySubcommandHelp>;
|
|
27
|
+
export interface DeployConfigKeyHelp {
|
|
28
|
+
key: string;
|
|
29
|
+
type: string;
|
|
30
|
+
default: string;
|
|
31
|
+
meaning: string;
|
|
32
|
+
example: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Every `[deploy]` INI key `resolveDeployConfig` parses, in the order
|
|
36
|
+
* declared on `DeployConfig` (src/deploy/types.ts). `post_switch_cmd` is
|
|
37
|
+
* documented once here even though the parser also accepts numbered
|
|
38
|
+
* `post_switch_cmd_2`, `_3`, ... suffixes — see its `meaning` text.
|
|
39
|
+
* `__tests__/deploy-help.test.ts` cross-checks this list's `key`s (mapped
|
|
40
|
+
* back from the field names `resolveDeployConfig` actually returns) against
|
|
41
|
+
* a fully-populated resolved config, so a new `DeployConfig` field with no
|
|
42
|
+
* matching entry here fails CI.
|
|
43
|
+
*/
|
|
44
|
+
export declare const DEPLOY_CONFIG_HELP: DeployConfigKeyHelp[];
|
|
45
|
+
/** Body of `hazo-env deploy --help` — one line per subcommand plus its flags, exactly as before but generated. */
|
|
46
|
+
export declare function renderDeploySummaryList(): string;
|
|
47
|
+
/** Body of `hazo-env deploy <cmd> --help`. */
|
|
48
|
+
export declare function renderDeploySubcommandHelpText(name: DeploySubcommandName): string;
|
|
49
|
+
/** Body of `hazo-env deploy config --help` (and `hazo-env deploy config`). */
|
|
50
|
+
export declare function renderDeployConfigHelpText(): string;
|
|
51
|
+
export declare const DEPLOY_README_MARKER_START = "<!-- BEGIN GENERATED: deploy section (see src/deploy/help.ts) -->";
|
|
52
|
+
export declare const DEPLOY_README_MARKER_END = "<!-- END GENERATED: deploy section -->";
|
|
53
|
+
/** The whole generated Markdown block, placed between DEPLOY_README_MARKER_START/_END in README.md. */
|
|
54
|
+
export declare function renderDeployReadmeSection(): string;
|
|
55
|
+
//# sourceMappingURL=help.d.ts.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
// hazo_env/src/deploy/help.ts — structured help metadata for `hazo-env deploy`
|
|
2
|
+
//
|
|
3
|
+
// Single source of truth for FOUR surfaces that must never drift apart:
|
|
4
|
+
// 1. `hazo-env deploy --help` — one-line-per-subcommand summary (DEPLOY_SUBCOMMAND_HELP)
|
|
5
|
+
// 2. `hazo-env deploy <cmd> --help` — detailed per-command reference (DEPLOY_SUBCOMMAND_HELP)
|
|
6
|
+
// 3. `hazo-env deploy config --help` — every `[deploy]` INI key (DEPLOY_CONFIG_HELP)
|
|
7
|
+
// 4. The generated "Deploy" section of README.md (`renderDeployReadmeSection`,
|
|
8
|
+
// written in place by `src/deploy/generate-readme-cli.ts` / `npm run docs:deploy`)
|
|
9
|
+
//
|
|
10
|
+
// `cli.ts` renders (1)-(3) from the data below via the `renderDeploy*HelpText`
|
|
11
|
+
// functions; nothing in cli.ts duplicates a summary, a flag description, a
|
|
12
|
+
// reads/writes line, a config default, or a failure-mode message — every one
|
|
13
|
+
// of those lives here exactly once. `__tests__/deploy-help.test.ts` asserts
|
|
14
|
+
// every deploy subcommand (DEPLOY_SUBCOMMAND_NAMES) and every parsed
|
|
15
|
+
// `[deploy]` key (cross-checked against `resolveDeployConfig`'s actual
|
|
16
|
+
// output) has a help entry, and that README.md's generated section matches
|
|
17
|
+
// `renderDeployReadmeSection()` byte for byte — so adding a step, a failure
|
|
18
|
+
// mode, or a config key without updating this file fails CI instead of
|
|
19
|
+
// silently drifting the docs from the code.
|
|
20
|
+
//
|
|
21
|
+
// Facts quoted below (error codes, exact thrown messages, step names, read/
|
|
22
|
+
// write lists) were verified by reading build.ts / switch.ts / rollback.ts /
|
|
23
|
+
// init.ts / clean.ts / verify.ts / status.ts / share.ts / shared-dirs.ts /
|
|
24
|
+
// resolve/deploy.ts directly — not paraphrased from memory — because this
|
|
25
|
+
// file is the thing an operator reads before running a command against prod.
|
|
26
|
+
/** The 8 real `deploy` actions (excludes the documentation-only `config` pseudo-subcommand). */
|
|
27
|
+
export const DEPLOY_SUBCOMMAND_NAMES = [
|
|
28
|
+
'init',
|
|
29
|
+
'build',
|
|
30
|
+
'verify',
|
|
31
|
+
'switch',
|
|
32
|
+
'rollback',
|
|
33
|
+
'status',
|
|
34
|
+
'clean',
|
|
35
|
+
'share',
|
|
36
|
+
];
|
|
37
|
+
export const DEPLOY_SUBCOMMAND_HELP = {
|
|
38
|
+
init: {
|
|
39
|
+
name: 'init',
|
|
40
|
+
summary: 'Create peer dir, clone repo, generate config, write state',
|
|
41
|
+
flags: [],
|
|
42
|
+
description: [
|
|
43
|
+
'Creates the sibling "standby" directory for a brand-new blue-green app: clones the current directory\'s git origin into `<app>-<opposite dir_suffix>`, rewrites the clone\'s own `dir_suffix`, copies gitignored env files across, and records both directories in the state file. Run once, from what becomes the "live" directory.',
|
|
44
|
+
'If `shared_dirs` is configured, also creates the peer\'s shared-dir symlinks so the freshly-cloned standby is correct before its first `deploy build` ever runs — see "Shared dirs" below.',
|
|
45
|
+
],
|
|
46
|
+
reads: [
|
|
47
|
+
'live slot: `config/hazo_env_config.ini` (the resolved `[deploy]` section)',
|
|
48
|
+
'live slot: `git remote get-url origin`',
|
|
49
|
+
'live slot: each `env_files` entry present on disk (best-effort — missing ones are reported, not fatal)',
|
|
50
|
+
],
|
|
51
|
+
writes: [
|
|
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',
|
|
54
|
+
'standby slot: the `[data] root` directory, when the app is sqlite-backed (`db_strategy` resolves to `copy`)',
|
|
55
|
+
'standby slot: each found `env_files` entry, copied in (gitignored secrets never travel through `git clone`)',
|
|
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
|
+
'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 (the INI is per-slot, so it must never be committed; the exclude file is local to each clone and never dirties a tracked `.gitignore`)',
|
|
59
|
+
],
|
|
60
|
+
configKeys: ['app_name', 'dir_suffix', 'env_files', 'shared_root', 'shared_dirs'],
|
|
61
|
+
failureModes: [
|
|
62
|
+
'(plain Error) "Peer directory already exists" — refuses to overwrite an existing peer; remove the stale directory by hand before retrying.',
|
|
63
|
+
'(plain Error) "Cannot swap dir_suffix ... expected \\"blue\\" or \\"green\\"" / "Could not find a \\"dir_suffix = ...\\" line" — `dir_suffix` must be exactly "blue" or "green" for the INI rewrite to find and flip it.',
|
|
64
|
+
'SharedDirError "HAZO_ENV_SHARED_DIR_REAL_DIR" / "HAZO_ENV_SHARED_DIR_WRONG_LINK" — the freshly-cloned peer already has a real or wrongly-linked `shared_dirs` path (stale debris from a prior partial `init`); run "hazo-env deploy share" to migrate it instead of re-running `init`.',
|
|
65
|
+
],
|
|
66
|
+
examples: ['hazo-env deploy init'],
|
|
67
|
+
},
|
|
68
|
+
build: {
|
|
69
|
+
name: 'build',
|
|
70
|
+
summary: 'Run the full build pipeline on the standby dir',
|
|
71
|
+
flags: [
|
|
72
|
+
{ flag: '--stop-prod', description: 'If the memory check fails, stop the live PM2 process first to free memory, then re-check.' },
|
|
73
|
+
{ flag: '--branch=<b>', description: 'Override `config.branch` for the git pull step.' },
|
|
74
|
+
{ flag: '--db=<env>', description: 'Resolve `[db.<env>]` instead of the current `HAZO_ENV` when validating a "shared" db strategy.' },
|
|
75
|
+
{ flag: '--peer-dir=<path>', description: 'Override which directory is treated as "live" for the `--stop-prod` target and the sqlite-copy source (the state file\'s `live_dir` is still used otherwise).' },
|
|
76
|
+
],
|
|
77
|
+
description: [
|
|
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.',
|
|
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.").',
|
|
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.',
|
|
82
|
+
],
|
|
83
|
+
reads: [
|
|
84
|
+
'state file: `standby_dir` must equal `cwd` (the guard above)',
|
|
85
|
+
'standby slot: free disk (`df`) compared against `min_disk_mb`',
|
|
86
|
+
'external: free memory compared against `min_memory_mb`',
|
|
87
|
+
'standby slot: `resolveConnectConfig()` (or `--db`) to resolve `db_strategy: "auto"` to `copy`/`shared`',
|
|
88
|
+
'live slot: the sqlite db file (copy strategy only, to back up from)',
|
|
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?)',
|
|
91
|
+
],
|
|
92
|
+
writes: [
|
|
93
|
+
'standby slot: cache cleanup (same targets as `deploy clean`) then a disk-free check',
|
|
94
|
+
'live slot: `pm2 stop <app_name>` (only with `--stop-prod`, only if memory is still low after cleanup)',
|
|
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`',
|
|
96
|
+
'standby slot: sqlite backup copy from the live slot (copy strategy) — or nothing, for the "shared" strategy (same Postgres DB, no copy)',
|
|
97
|
+
'standby slot: `migrate_cmd`, only if non-empty',
|
|
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`.',
|
|
99
|
+
'standby slot: stale `<app_name>-staging` pm2 process deleted, then a fresh one started on `staging_port`',
|
|
100
|
+
'external: health check against `health_url` on `staging_port` (retried)',
|
|
101
|
+
'state file: `last_build` / `last_build_status` — written once the pipeline reaches `git-pull` (so an early abort above that point never marks a build as attempted), and again with the final outcome when the pipeline finishes',
|
|
102
|
+
],
|
|
103
|
+
configKeys: [
|
|
104
|
+
'app_name', 'dir_suffix', 'branch', 'db_strategy', 'install_cmd', 'pre_build_cmd', 'build_cmd',
|
|
105
|
+
'migrate_cmd', 'min_disk_mb', 'min_memory_mb', 'staging_port', 'health_url', 'shared_root', 'shared_dirs',
|
|
106
|
+
],
|
|
107
|
+
failureModes: [
|
|
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. It is per-slot (`dir_suffix` differs), so a pull would overwrite or conflict with the slot\'s copy; `git rm --cached` it, add it to `.gitignore`, commit, and keep each slot\'s local copy. 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.',
|
|
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`.)',
|
|
113
|
+
],
|
|
114
|
+
examples: ['hazo-env deploy build', 'hazo-env deploy build --stop-prod --branch=release'],
|
|
115
|
+
},
|
|
116
|
+
verify: {
|
|
117
|
+
name: 'verify',
|
|
118
|
+
summary: 'Re-run health/typecheck/migration checks on standby',
|
|
119
|
+
flags: [],
|
|
120
|
+
description: [
|
|
121
|
+
'Re-checks the already-running staging process without rebuilding anything — the gate to run again after fixing something `deploy build` already succeeded past, right before `deploy switch`.',
|
|
122
|
+
'Never throws on a failed check: each of the three checks (`health`, `typescript`, `migration-parity`) reports `pass` / `fail` / `skipped` in the returned `checks[]` array; the CLI exits with status 1 if any check failed.',
|
|
123
|
+
],
|
|
124
|
+
reads: [
|
|
125
|
+
'state file: to find the standby dir and `staging_port`',
|
|
126
|
+
'external: `curl` against `health_url` on `staging_port` (2 attempts, 500ms apart — a smaller retry budget than `build`\'s, since the app should already be up)',
|
|
127
|
+
'standby slot: `verify_tsc_cmd`, run with `cwd` set to the standby dir',
|
|
128
|
+
'live + standby slot: each one\'s `_migrations` table (read-only), compared for parity — only when `db_strategy` resolves to "copy" (sqlite); `skipped` otherwise',
|
|
129
|
+
],
|
|
130
|
+
writes: ['(none — verify never mutates the filesystem, pm2, or the state file)'],
|
|
131
|
+
configKeys: ['staging_port', 'health_url', 'verify_tsc_cmd', 'db_strategy'],
|
|
132
|
+
failureModes: [
|
|
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`.',
|
|
135
|
+
],
|
|
136
|
+
examples: ['hazo-env deploy verify'],
|
|
137
|
+
},
|
|
138
|
+
switch: {
|
|
139
|
+
name: 'switch',
|
|
140
|
+
summary: 'Stop prod, start standby on the prod port, run post-switch hooks',
|
|
141
|
+
flags: [
|
|
142
|
+
{ flag: '--force', description: 'Bypass BOTH the build-recency check (standby must have a successful build since the last switch) AND the shared-dirs drift check below.' },
|
|
143
|
+
],
|
|
144
|
+
description: [
|
|
145
|
+
'Promotes the standby directory to live: deletes (not stops — a fresh `pm2 start` follows) the current live PM2 process, starts the standby fresh on `prod_port`, runs `post_switch_cmd(s)`, and swaps `live_dir`/`standby_dir` in the state file.',
|
|
146
|
+
'Refuses to promote a standby that has not had a successful `deploy build` since the last switch, and refuses to promote onto a slot with shared-dir drift — both only unless `--force` is passed.',
|
|
147
|
+
],
|
|
148
|
+
reads: [
|
|
149
|
+
'state file: `live_dir`/`standby_dir`, and `last_build`/`last_build_status`/`last_switch` for the build-recency check',
|
|
150
|
+
'standby slot: `git rev-parse HEAD` (recorded as `git_ref` in the new state)',
|
|
151
|
+
'live + standby slot: `inspectSharedDirs` (read-only) — skipped entirely when `shared_dirs` is empty or `--force` is passed',
|
|
152
|
+
],
|
|
153
|
+
writes: [
|
|
154
|
+
'live slot (old): `pm2 delete <app_name>`',
|
|
155
|
+
'standby slot (old): `pm2 delete <app_name>-staging`, then a fresh `pm2 start` on `prod_port` (this directory becomes the new live slot)',
|
|
156
|
+
'standby slot (old, now live): each `post_switch_cmd` / `post_switch_cmd_N`, run in order — a failing hook is reported, never fatal',
|
|
157
|
+
'state file: `live_dir`/`standby_dir` swapped, `previous_live_dir` set to the old live dir, `last_switch`, `git_ref`, `pm2_process`',
|
|
158
|
+
'external: `pm2 save` (failure is a warning, not fatal)',
|
|
159
|
+
'external: `sidecar_apps` reloaded/recreated to follow the new live dir (never throws — see sidecar.ts)',
|
|
160
|
+
],
|
|
161
|
+
configKeys: ['app_name', 'prod_port', 'post_switch_cmd', 'sidecar_apps', 'shared_dirs'],
|
|
162
|
+
failureModes: [
|
|
163
|
+
'(plain Error — SwitchAbortError) "No deploy state found for \\"<app>\\" — nothing to switch. Run \\"deploy init\\" first."',
|
|
164
|
+
'SwitchAbortError "standby has not had a successful build since the last switch — run \\"deploy build\\" first, or pass --force to override." (bypassed by `--force`)',
|
|
165
|
+
'SwitchAbortError "Shared dir(s) not fully linked in both slots: ... Run \\"hazo-env deploy share\\" to fix, or pass --force to override." (bypassed by `--force`; never fires when `shared_dirs` is empty)',
|
|
166
|
+
],
|
|
167
|
+
examples: ['hazo-env deploy switch', 'hazo-env deploy switch --force'],
|
|
168
|
+
},
|
|
169
|
+
rollback: {
|
|
170
|
+
name: 'rollback',
|
|
171
|
+
summary: 'Reverse the last switch',
|
|
172
|
+
flags: [
|
|
173
|
+
{ flag: '--force', description: 'Bypass the shared-dirs drift check only — the stale-build guard below has NO bypass.' },
|
|
174
|
+
],
|
|
175
|
+
description: [
|
|
176
|
+
'Reverses the most recent `deploy switch`: puts `previous_live_dir` back on `prod_port`. Only reverses a switch that hasn\'t already been rolled back — there is no history beyond one step.',
|
|
177
|
+
'Refuses unconditionally (no `--force`) if `deploy build` has run on the standby since the last switch, because the previous live build may no longer be intact on disk.',
|
|
178
|
+
],
|
|
179
|
+
reads: [
|
|
180
|
+
'state file: `previous_live_dir`, `last_build`, `last_switch`',
|
|
181
|
+
'live + standby slot: `inspectSharedDirs` (read-only), unless `--force`',
|
|
182
|
+
'the directory being restored: `git rev-parse HEAD`',
|
|
183
|
+
],
|
|
184
|
+
writes: [
|
|
185
|
+
'current live slot: `pm2 delete <app_name>`',
|
|
186
|
+
'restored slot: `pm2 delete <app_name>-staging` if present, then a fresh `pm2 start` on `prod_port`',
|
|
187
|
+
'state file: `live_dir`/`standby_dir` swapped back, `previous_live_dir` cleared (rollback is not itself reversible)',
|
|
188
|
+
'external: `pm2 save` (warning-only on failure), `sidecar_apps` reload/recreate (never throws)',
|
|
189
|
+
],
|
|
190
|
+
configKeys: ['app_name', 'prod_port', 'sidecar_apps', 'shared_dirs'],
|
|
191
|
+
failureModes: [
|
|
192
|
+
'RollbackAbortError "No deploy state found for \\"<app>\\" — nothing to roll back. Run \\"deploy init\\" first."',
|
|
193
|
+
'RollbackAbortError "No previous switch recorded for \\"<app>\\" — nothing to roll back. ..." — `deploy rollback` only reverses a switch that hasn\'t already been rolled back.',
|
|
194
|
+
'RollbackAbortError "A build has run on standby since the last switch (...) — ... Cannot safely roll back." — NO `--force` bypass exists for this one.',
|
|
195
|
+
'RollbackAbortError "Shared dir(s) not fully linked in both slots: ... Run \\"hazo-env deploy share\\" to fix, or pass --force to override." (bypassed by `--force`)',
|
|
196
|
+
],
|
|
197
|
+
examples: ['hazo-env deploy rollback', 'hazo-env deploy rollback --force'],
|
|
198
|
+
},
|
|
199
|
+
status: {
|
|
200
|
+
name: 'status',
|
|
201
|
+
summary: 'Show live/standby dirs, ports, PM2 state, disk/memory, shared dirs',
|
|
202
|
+
flags: [],
|
|
203
|
+
description: [
|
|
204
|
+
'Read-only snapshot: which directory is live/standby, whether their PM2 processes are actually running, sidecar freshness, disk/memory headroom, and — when `shared_dirs` is configured — a per-dir, per-slot shared-dirs table (linked / missing / empty-dir / real-dir(N files) / wrong-link).',
|
|
205
|
+
],
|
|
206
|
+
reads: [
|
|
207
|
+
'state file: `live_dir`/`standby_dir`/ports/`last_build`/`last_switch`',
|
|
208
|
+
'external: `pm2 jlist`, `df -k <cwd>`, `vm_stat` (darwin) or `/proc/meminfo` (linux)',
|
|
209
|
+
'live + standby slot: `inspectSharedDirs`, only when the state file exists and `shared_dirs` is non-empty',
|
|
210
|
+
],
|
|
211
|
+
writes: ['(none)'],
|
|
212
|
+
configKeys: ['min_memory_mb', 'sidecar_apps', 'shared_root', 'shared_dirs'],
|
|
213
|
+
failureModes: [
|
|
214
|
+
'(no thrown error) — a missing state file, or an unreachable `pm2`/`df`/`vm_stat`, each degrade to a `warnings[]` entry and an "(unknown)" field rather than aborting.',
|
|
215
|
+
],
|
|
216
|
+
examples: ['hazo-env deploy status'],
|
|
217
|
+
},
|
|
218
|
+
clean: {
|
|
219
|
+
name: 'clean',
|
|
220
|
+
summary: 'Reclaim disk space from old builds and caches',
|
|
221
|
+
flags: [
|
|
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).' },
|
|
225
|
+
],
|
|
226
|
+
description: [
|
|
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`.',
|
|
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`',
|
|
240
|
+
],
|
|
241
|
+
configKeys: ['shared_dirs', 'min_memory_mb'],
|
|
242
|
+
failureModes: [
|
|
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.',
|
|
245
|
+
],
|
|
246
|
+
examples: ['hazo-env deploy clean', 'hazo-env deploy clean --aggressive', 'hazo-env deploy clean --idle-slots', 'hazo-env deploy clean --idle-slots --yes'],
|
|
247
|
+
},
|
|
248
|
+
share: {
|
|
249
|
+
name: 'share',
|
|
250
|
+
summary: 'One-time migration: merge shared_dirs into shared_root + symlink',
|
|
251
|
+
flags: [
|
|
252
|
+
{ flag: '--dry-run', description: 'Produce the full report without writing, renaming, or linking anything.' },
|
|
253
|
+
],
|
|
254
|
+
description: [
|
|
255
|
+
'The one-time migration onto shared dirs for an app that already has real (per-slot) data sitting in what `shared_dirs` now names. Runnable from either slot — live/standby roles always come from the state file\'s own labels (whichever side wins a content conflict), never from `cwd`.',
|
|
256
|
+
'No-op (prints a message and exits) when `shared_dirs` is empty. Safe to re-run: already-linked dirs are reported as such and left untouched (idempotent).',
|
|
257
|
+
'Order: merge standby then live into `shared_root` (live wins on content conflict; standby\'s losing copy is parked, never overwritten or deleted) → swap the STANDBY slot\'s real dir for the symlink first → swap the LIVE slot\'s real dir for the symlink last (so the running app sees its folder replaced as late and as briefly as possible) → re-scan both renamed backup dirs for files written during that swap window and merge those too.',
|
|
258
|
+
],
|
|
259
|
+
reads: [
|
|
260
|
+
'state file: `live_dir`/`standby_dir` labels (never inferred from `cwd`\'s blue/green naming); the standby is used only if it still exists on disk — a missing peer, or no state file at all (pre-`deploy init`), means only the live/current dir is migrated',
|
|
261
|
+
'live + standby slot: every file under each configured `shared_dirs` entry (to merge, hash-compare, and copy)',
|
|
262
|
+
],
|
|
263
|
+
writes: [
|
|
264
|
+
'shared root: `shared_root/<dir>` created; files copied in preserving mtime and mode; conflicting incoming copies parked under `shared_root/.conflicts/<slot-basename>/<dir>/<relPath>` (never overwrites, never deletes a source file)',
|
|
265
|
+
'live + standby slot: each real/empty `<dir>` renamed aside to `<dir>.pre-share-<ISO timestamp>` (never deleted — left for the operator to verify and remove by hand), then replaced with a symlink to `shared_root/<dir>`',
|
|
266
|
+
'live + standby slot: the renamed `.pre-share-*` dirs are re-scanned once for files written during the rename race window, and those are merged too',
|
|
267
|
+
'state file: NOT written — `deploy share` never updates deploy state.',
|
|
268
|
+
],
|
|
269
|
+
configKeys: ['shared_root', 'shared_dirs'],
|
|
270
|
+
failureModes: [
|
|
271
|
+
'SharedDirError "HAZO_ENV_SHARED_DIR_WRONG_LINK" — a pre-flight check, before anything is written: if ANY configured dir is already a symlink to somewhere other than the expected target in EITHER slot, the ENTIRE run aborts untouched (atomic all-or-nothing, never partially migrates). Remove the stray link by hand first, or confirm it should point elsewhere.',
|
|
272
|
+
'(unwrapped) raw filesystem errors (permission denied, disk full, ...) propagate as-is.',
|
|
273
|
+
],
|
|
274
|
+
examples: ['hazo-env deploy share --dry-run', 'hazo-env deploy share'],
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Every `[deploy]` INI key `resolveDeployConfig` parses, in the order
|
|
279
|
+
* declared on `DeployConfig` (src/deploy/types.ts). `post_switch_cmd` is
|
|
280
|
+
* documented once here even though the parser also accepts numbered
|
|
281
|
+
* `post_switch_cmd_2`, `_3`, ... suffixes — see its `meaning` text.
|
|
282
|
+
* `__tests__/deploy-help.test.ts` cross-checks this list's `key`s (mapped
|
|
283
|
+
* back from the field names `resolveDeployConfig` actually returns) against
|
|
284
|
+
* a fully-populated resolved config, so a new `DeployConfig` field with no
|
|
285
|
+
* matching entry here fails CI.
|
|
286
|
+
*/
|
|
287
|
+
export const DEPLOY_CONFIG_HELP = [
|
|
288
|
+
{
|
|
289
|
+
key: 'app_name',
|
|
290
|
+
type: 'string (required)',
|
|
291
|
+
default: '(none — required)',
|
|
292
|
+
meaning: 'Logical app name. Also names the state file: ~/.hazo-deploy/<app_name>.json.',
|
|
293
|
+
example: 'app_name = gotimer',
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
key: 'dir_suffix',
|
|
297
|
+
type: 'string (required)',
|
|
298
|
+
default: '(none — required)',
|
|
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.',
|
|
300
|
+
example: 'dir_suffix = green',
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
key: 'prod_port',
|
|
304
|
+
type: 'integer',
|
|
305
|
+
default: '3000',
|
|
306
|
+
meaning: 'Production PM2 port.',
|
|
307
|
+
example: 'prod_port = 3000',
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
key: 'staging_port',
|
|
311
|
+
type: 'integer',
|
|
312
|
+
default: '3001',
|
|
313
|
+
meaning: 'Staging port used by `deploy build`/`deploy verify` before switching.',
|
|
314
|
+
example: 'staging_port = 3001',
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
key: 'health_url',
|
|
318
|
+
type: 'string',
|
|
319
|
+
default: '/api/health',
|
|
320
|
+
meaning: 'Path hit for health checks during build/verify/status.',
|
|
321
|
+
example: 'health_url = /healthz',
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
key: 'min_disk_mb',
|
|
325
|
+
type: 'integer',
|
|
326
|
+
default: '1024',
|
|
327
|
+
meaning: 'Minimum free disk (MB) required before a build proceeds.',
|
|
328
|
+
example: 'min_disk_mb = 2048',
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
key: 'min_memory_mb',
|
|
332
|
+
type: 'integer',
|
|
333
|
+
default: '512',
|
|
334
|
+
meaning: 'Minimum free memory (MB) required before a build proceeds (and the threshold `deploy clean`/`deploy status` compare against for swap/memory warnings).',
|
|
335
|
+
example: 'min_memory_mb = 1024',
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
key: 'branch',
|
|
339
|
+
type: 'string',
|
|
340
|
+
default: 'main',
|
|
341
|
+
meaning: 'Git branch pulled by `deploy build` (overridable with `--branch`).',
|
|
342
|
+
example: 'branch = release',
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
key: 'db_strategy',
|
|
346
|
+
type: '"auto" | "copy" | "shared"',
|
|
347
|
+
default: 'auto',
|
|
348
|
+
meaning: 'How the standby DB is provisioned: auto (infer from [db.*] driver), copy (sqlite file copy from the peer), or shared (both slots point at the same Postgres DB). An invalid value throws at config-resolve time.',
|
|
349
|
+
example: 'db_strategy = copy',
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
key: 'build_cmd',
|
|
353
|
+
type: 'string',
|
|
354
|
+
default: 'npm run build',
|
|
355
|
+
meaning: 'Shell command that builds the app.',
|
|
356
|
+
example: 'build_cmd = pnpm build',
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
key: 'install_cmd',
|
|
360
|
+
type: 'string',
|
|
361
|
+
default: 'npm ci',
|
|
362
|
+
meaning: 'Shell command that installs dependencies.',
|
|
363
|
+
example: 'install_cmd = pnpm install',
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
key: 'pre_build_cmd',
|
|
367
|
+
type: 'string',
|
|
368
|
+
default: 'rm -rf .next',
|
|
369
|
+
meaning: 'Shell command run before the build (cache busting, etc).',
|
|
370
|
+
example: 'pre_build_cmd = rm -rf dist',
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
key: 'migrate_cmd',
|
|
374
|
+
type: 'string',
|
|
375
|
+
default: '(empty — skipped)',
|
|
376
|
+
meaning: 'Optional shell command run after DB setup during `deploy build`. Empty (the default) means `deploy build` logs that it\'s assuming the app\'s own schema bootstrap runs automatically at startup and moves on.',
|
|
377
|
+
example: 'migrate_cmd = npm run db:migrate',
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
key: 'post_switch_cmd',
|
|
381
|
+
type: 'string, plus numbered post_switch_cmd_2, _3, ...',
|
|
382
|
+
default: '[] (none)',
|
|
383
|
+
meaning: 'Shell commands run after a successful `deploy switch` (indexnow submission, CDN purge, ...). Numbered suffixes run in order after the unsuffixed key; collection stops at the first missing/blank numbered key, so a gap silently truncates the list.',
|
|
384
|
+
example: 'post_switch_cmd = npm run indexnow\npost_switch_cmd_2 = bash scripts/cf-purge.sh',
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
key: 'sidecar_apps',
|
|
388
|
+
type: 'comma-separated list',
|
|
389
|
+
default: '[] (none)',
|
|
390
|
+
meaning: 'Other pm2 app names in the SAME ecosystem file that move with the live dir but are never blue-green-swapped themselves (a cron/scheduler/jobs worker, websocket server, PDF-render pool, ...).',
|
|
391
|
+
example: 'sidecar_apps = myapp-scheduler, myapp-pdf-pool',
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
key: 'env_files',
|
|
395
|
+
type: 'comma-separated list',
|
|
396
|
+
default: '.env.local',
|
|
397
|
+
meaning: 'Gitignored files (relative to app root) copied from the live dir to the peer during `deploy init`.',
|
|
398
|
+
example: 'env_files = .env.local, .env.production',
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
key: 'verify_tsc_cmd',
|
|
402
|
+
type: 'string',
|
|
403
|
+
default: 'npx tsc --noEmit',
|
|
404
|
+
meaning: 'Shell command used for the TypeScript check in `deploy verify`. Override to exclude test files, e.g. with a dedicated tsconfig.',
|
|
405
|
+
example: 'verify_tsc_cmd = npx tsc --noEmit -p tsconfig.verify.json',
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
key: 'shared_root',
|
|
409
|
+
type: 'absolute path (~ expanded)',
|
|
410
|
+
default: '~/<app_name>-shared',
|
|
411
|
+
meaning: 'Directory, outside BOTH slot dirs, that `shared_dirs` entries are symlinked from into each slot. Must resolve to an absolute path outside both the current and peer slot directories (validated at config-resolve time).',
|
|
412
|
+
example: 'shared_root = ~/gotimer-shared',
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
key: 'shared_dirs',
|
|
416
|
+
type: 'comma-separated list, slot-relative',
|
|
417
|
+
default: '[] (feature off)',
|
|
418
|
+
meaning: 'Folders (e.g. var/uploads) that must persist across blue-green slots instead of being duplicated per clone — see "Shared dirs" below. Validated: no absolute paths, no ".." traversal, no duplicates, no entry nested inside another, and (when the resolved db strategy is "copy") no entry containing the sqlite db path.',
|
|
419
|
+
example: 'shared_dirs = var/uploads, data/blog-images',
|
|
420
|
+
},
|
|
421
|
+
];
|
|
422
|
+
// ---------------------------------------------------------------------------
|
|
423
|
+
// Terminal renderers (plain text — no ANSI; cli.ts wraps the title line in
|
|
424
|
+
// its own pc.bold()). Shared by `deploy --help`, `deploy <cmd> --help`, and
|
|
425
|
+
// `deploy config --help`.
|
|
426
|
+
// ---------------------------------------------------------------------------
|
|
427
|
+
/** Body of `hazo-env deploy --help` — one line per subcommand plus its flags, exactly as before but generated. */
|
|
428
|
+
export function renderDeploySummaryList() {
|
|
429
|
+
const lines = ['Usage:'];
|
|
430
|
+
for (const name of DEPLOY_SUBCOMMAND_NAMES) {
|
|
431
|
+
const help = DEPLOY_SUBCOMMAND_HELP[name];
|
|
432
|
+
lines.push(` hazo-env deploy ${name.padEnd(10)} ${help.summary}`);
|
|
433
|
+
for (const f of help.flags) {
|
|
434
|
+
lines.push(` ${f.flag.padEnd(26)} ${f.description}`);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
lines.push(` hazo-env deploy config Show every [deploy] config key (default, meaning, example)`);
|
|
438
|
+
lines.push('');
|
|
439
|
+
lines.push(`Run "hazo-env deploy <subcommand> --help" for what it reads/writes and how it can fail.`);
|
|
440
|
+
return lines.join('\n');
|
|
441
|
+
}
|
|
442
|
+
/** Body of `hazo-env deploy <cmd> --help`. */
|
|
443
|
+
export function renderDeploySubcommandHelpText(name) {
|
|
444
|
+
const help = DEPLOY_SUBCOMMAND_HELP[name];
|
|
445
|
+
const lines = [`hazo-env deploy ${help.name} — ${help.summary}`, ''];
|
|
446
|
+
if (help.flags.length) {
|
|
447
|
+
lines.push('Flags:');
|
|
448
|
+
for (const f of help.flags)
|
|
449
|
+
lines.push(` ${f.flag.padEnd(18)} ${f.description}`);
|
|
450
|
+
lines.push('');
|
|
451
|
+
}
|
|
452
|
+
for (const para of help.description) {
|
|
453
|
+
lines.push(para, '');
|
|
454
|
+
}
|
|
455
|
+
lines.push('Reads:');
|
|
456
|
+
for (const r of help.reads)
|
|
457
|
+
lines.push(` - ${r}`);
|
|
458
|
+
lines.push('', 'Writes:');
|
|
459
|
+
for (const w of help.writes)
|
|
460
|
+
lines.push(` - ${w}`);
|
|
461
|
+
lines.push('', `Config keys used: ${help.configKeys.join(', ')}`, '', 'Failure modes:');
|
|
462
|
+
for (const f of help.failureModes)
|
|
463
|
+
lines.push(` - ${f}`);
|
|
464
|
+
lines.push('', 'Examples:');
|
|
465
|
+
for (const ex of help.examples)
|
|
466
|
+
lines.push(` ${ex}`);
|
|
467
|
+
return lines.join('\n');
|
|
468
|
+
}
|
|
469
|
+
/** Body of `hazo-env deploy config --help` (and `hazo-env deploy config`). */
|
|
470
|
+
export function renderDeployConfigHelpText() {
|
|
471
|
+
const lines = ['Every key hazo-env reads from the [deploy] section of hazo_env_config.ini:', ''];
|
|
472
|
+
for (const k of DEPLOY_CONFIG_HELP) {
|
|
473
|
+
lines.push(`${k.key} (${k.type})`);
|
|
474
|
+
lines.push(` default: ${k.default}`);
|
|
475
|
+
lines.push(` ${k.meaning}`);
|
|
476
|
+
for (const exLine of k.example.split('\n'))
|
|
477
|
+
lines.push(` example: ${exLine}`);
|
|
478
|
+
lines.push('');
|
|
479
|
+
}
|
|
480
|
+
return lines.join('\n').trimEnd();
|
|
481
|
+
}
|
|
482
|
+
// ---------------------------------------------------------------------------
|
|
483
|
+
// README generator. Same data as above, rendered as Markdown. Written in
|
|
484
|
+
// place between the DEPLOY_README markers by generate-readme-cli.ts
|
|
485
|
+
// (`npm run docs:deploy`) and checked byte-for-byte by
|
|
486
|
+
// __tests__/deploy-help.test.ts against what's committed in README.md.
|
|
487
|
+
// ---------------------------------------------------------------------------
|
|
488
|
+
export const DEPLOY_README_MARKER_START = '<!-- BEGIN GENERATED: deploy section (see src/deploy/help.ts) -->';
|
|
489
|
+
export const DEPLOY_README_MARKER_END = '<!-- END GENERATED: deploy section -->';
|
|
490
|
+
function mdList(items) {
|
|
491
|
+
return items.map((i) => `- ${i}`).join('\n');
|
|
492
|
+
}
|
|
493
|
+
const SHARED_DIRS_WALKTHROUGH = `### Shared dirs — first-time migration walkthrough
|
|
494
|
+
|
|
495
|
+
An app running blue-green loses every upload a user makes on each \`deploy switch\` unless the folder it's written to is declared as a shared dir. Migrating an EXISTING app (one that already has real, per-slot data in that folder) is a one-time, interactive step:
|
|
496
|
+
|
|
497
|
+
1. **Declare the folders.** Add \`shared_dirs\` (and, optionally, \`shared_root\`) to \`[deploy]\` in \`hazo_env_config.ini\` — in BOTH slots (the live one you edit now, and the standby, which \`deploy init\`/\`deploy build\` will keep in sync going forward). Example:
|
|
498
|
+
\`\`\`ini
|
|
499
|
+
[deploy]
|
|
500
|
+
shared_root = ~/gotimer-shared
|
|
501
|
+
shared_dirs = var/uploads, data/blog-images
|
|
502
|
+
\`\`\`
|
|
503
|
+
2. **Run the migration once**, from either slot:
|
|
504
|
+
\`\`\`
|
|
505
|
+
hazo-env deploy share --dry-run # preview: what would merge, what would conflict, what would link
|
|
506
|
+
hazo-env deploy share # apply it
|
|
507
|
+
\`\`\`
|
|
508
|
+
This merges whatever is already on disk in BOTH slots into \`shared_root\` (the live slot wins any same-path content conflict; the losing copy is parked under \`.conflicts/\`, never deleted), then replaces each slot's real folder with a symlink into \`shared_root\` — standby first, live last, so the running app sees the swap as late and as briefly as possible.
|
|
509
|
+
3. **Read the report.** Each shared dir prints how many files came from live, from standby, how many were identical (deduped), and how many conflicted. A non-zero conflict count means two slots had the SAME path with DIFFERENT content — go look at the parked copies under \`<shared_root>/.conflicts/<slot>/<dir>/...\` before deleting anything.
|
|
510
|
+
4. **Verify, then clean up.** \`deploy share\` never deletes your original data — it renames each slot's old real directory aside to \`<dir>.pre-share-<timestamp>\`. Once \`hazo-env deploy status\` shows every shared dir as \`linked\` in both slots and the app looks right, delete the \`.pre-share-*\` backup directories by hand.
|
|
511
|
+
5. **From then on it's automatic.** \`deploy init\` links a new peer's shared dirs on creation; \`deploy build\` self-heals a missing link or an empty leftover directory on the standby before it builds; \`deploy switch\`/\`deploy rollback\` refuse to promote a slot that isn't fully linked (bypass with \`--force\` only if you've verified it by hand); \`deploy status\` shows per-slot drift at a glance; \`deploy clean\` never deletes through a shared-dir symlink.
|
|
512
|
+
|
|
513
|
+
A BRAND NEW app that has never had real per-slot data in these folders doesn't need this walkthrough at all — just set \`shared_dirs\` before the first \`deploy init\`, and every slot starts out correctly linked.`;
|
|
514
|
+
/** The whole generated Markdown block, placed between DEPLOY_README_MARKER_START/_END in README.md. */
|
|
515
|
+
export function renderDeployReadmeSection() {
|
|
516
|
+
const parts = [];
|
|
517
|
+
parts.push('## Deploy (blue-green orchestration)');
|
|
518
|
+
parts.push('Drives `hazo-env deploy <subcommand>`. Two sibling directories differing only by a blue/green `dir_suffix` ' +
|
|
519
|
+
'(e.g. `gotimer-blue/`, `gotimer-green/`) — one live, one standby — swap roles on `deploy switch`. State lives ' +
|
|
520
|
+
'at `~/.hazo-deploy/<app_name>.json`, never inferred from the directory name alone. All subcommand and config ' +
|
|
521
|
+
'docs below are generated from `src/deploy/help.ts` — see `hazo-env deploy --help` / `hazo-env deploy <cmd> ' +
|
|
522
|
+
'--help` / `hazo-env deploy config --help` for the same content at the terminal.');
|
|
523
|
+
parts.push('### Subcommands');
|
|
524
|
+
const tableRows = DEPLOY_SUBCOMMAND_NAMES.map((name) => `| \`deploy ${name}\` | ${DEPLOY_SUBCOMMAND_HELP[name].summary} |`);
|
|
525
|
+
parts.push(['| Command | Purpose |', '|---|---|', ...tableRows, '| `deploy config` | Show every `[deploy]` config key (default, meaning, example) |'].join('\n'));
|
|
526
|
+
for (const name of DEPLOY_SUBCOMMAND_NAMES) {
|
|
527
|
+
const h = DEPLOY_SUBCOMMAND_HELP[name];
|
|
528
|
+
const sub = [`#### \`deploy ${name}\``];
|
|
529
|
+
if (h.flags.length) {
|
|
530
|
+
sub.push(h.flags.map((f) => `- \`${f.flag}\` — ${f.description}`).join('\n'));
|
|
531
|
+
}
|
|
532
|
+
sub.push(h.description.join('\n\n'));
|
|
533
|
+
sub.push(`**Reads:**\n${mdList(h.reads)}`);
|
|
534
|
+
sub.push(`**Writes:**\n${mdList(h.writes)}`);
|
|
535
|
+
sub.push(`**Config keys used:** ${h.configKeys.map((k) => `\`${k}\``).join(', ')}`);
|
|
536
|
+
sub.push(`**Failure modes:**\n${mdList(h.failureModes)}`);
|
|
537
|
+
sub.push(`**Examples:**\n\`\`\`\n${h.examples.join('\n')}\n\`\`\``);
|
|
538
|
+
parts.push(sub.join('\n\n'));
|
|
539
|
+
}
|
|
540
|
+
parts.push('### Config reference (`[deploy]`)');
|
|
541
|
+
const cfgRows = DEPLOY_CONFIG_HELP.map((k) => `| \`${k.key}\` | ${k.default} | ${k.meaning.replace(/\n/g, ' ')} |`);
|
|
542
|
+
parts.push(['| Key | Default | Meaning |', '|---|---|---|', ...cfgRows].join('\n'));
|
|
543
|
+
parts.push(SHARED_DIRS_WALKTHROUGH);
|
|
544
|
+
return parts.join('\n\n');
|
|
545
|
+
}
|