When DEPLOY_REVISION/GIT_REVISION are unset, ecosystem.config.cjs runs git rev-parse --short HEAD at pm2 start so /health deploy_revision matches the checkout. Documented in README and .env.example. Made-with: Cursor
This commit is contained in:
1 parent
20b94eadf9
commit
7f941e3cf7
3 files changed
+29
-1
No files matched your search
@@ -40,6 +40,7 @@ SCRAPER_RETRY_BASE_MS=500
|
|||||||
HOST=0.0.0.0
|
HOST=0.0.0.0
|
||||||
PORT=3200
|
PORT=3200
|
||||||
# Optional: set at deploy (CI webhook) — surfaced in GET /health as deploy_revision
|
# Optional: set at deploy (CI webhook) — surfaced in GET /health as deploy_revision
|
||||||
|
# PM2 ecosystem.config.cjs also injects DEPLOY_REVISION from `git rev-parse --short HEAD` when unset.
|
||||||
# DEPLOY_REVISION=
|
# DEPLOY_REVISION=
|
||||||
# GIT_REVISION=
|
# GIT_REVISION=
|
||||||
# Inbound socket timeouts (ms). headers must stay above request (enforced in code if misconfigured).
|
# Inbound socket timeouts (ms). headers must stay above request (enforced in code if misconfigured).
|
||||||
|
|||||||
@@ -179,9 +179,11 @@ pm2 start ecosystem.config.cjs
|
|||||||
pm2 save && pm2 startup
|
pm2 save && pm2 startup
|
||||||
```
|
```
|
||||||
|
|
||||||
|
When you start from a **git checkout**, `ecosystem.config.cjs` sets **`DEPLOY_REVISION`** to `git rev-parse --short HEAD` if `DEPLOY_REVISION` / `GIT_REVISION` are not already in the environment — the app exposes this on **`GET /health`** as `deploy_revision`.
|
||||||
|
|
||||||
*(Alternative, easier to mistype: `pm2 start src/index.js --name ai-news-writer --cwd /srv/ai-news-writer --time -- listen` — the `--` before `listen` is required.)*
|
*(Alternative, easier to mistype: `pm2 start src/index.js --name ai-news-writer --cwd /srv/ai-news-writer --time -- listen` — the `--` before `listen` is required.)*
|
||||||
|
|
||||||
**NPM (CT 102):** Proxy Host `ainews.bitreport.pt` → `http://<lxc-ip>:3200` (forward scheme **http** unless you terminate TLS only at NPM). Quick check from another machine: `curl -sS http://<lxc-ip>:3200/health` — JSON includes `version`, `mode: "listen"`, and **non-secret flags**: `rss_feed_count`, `rss_listener_active` (false if the cron listener failed to start), **`rss_listener_last_tick_at` / `rss_listener_last_tick_ok` / `rss_listener_last_tick_error`** (cron liveness after the first tick), `x_listening` (bearer + `social.json` queries), `wp_credentials_configured`, `openai_api_key_configured`, `ai_model`.
|
**NPM (CT 102):** Proxy Host `ainews.bitreport.pt` → `http://<lxc-ip>:3200` (forward scheme **http** unless you terminate TLS only at NPM). Quick check from another machine: `curl -sS http://<lxc-ip>:3200/health` — JSON includes `version`, `mode: "listen"`, optional **`deploy_revision`** (git SHA / deploy tag when configured), and **non-secret flags**: `rss_feed_count`, `rss_listener_active` (false if the cron listener failed to start), **`rss_listener_last_tick_at` / `rss_listener_last_tick_ok` / `rss_listener_last_tick_error`** (cron liveness after the first tick), `x_listening` (bearer + `social.json` queries), `wp_credentials_configured`, `openai_api_key_configured`, `ai_model`.
|
||||||
|
|
||||||
**Structured check (exit code 0/1):** from a machine with `curl` + `node` (e.g. the CT or your laptop):
|
**Structured check (exit code 0/1):** from a machine with `curl` + `node` (e.g. the CT or your laptop):
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,29 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For GET /health `deploy_revision`: honour existing env, else short git SHA when `.git` exists.
|
||||||
|
*/
|
||||||
|
function resolveDeployRevisionForPm2() {
|
||||||
|
const fromEnv = (process.env.DEPLOY_REVISION || process.env.GIT_REVISION || '').trim();
|
||||||
|
if (fromEnv) {
|
||||||
|
return fromEnv;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return execSync('git rev-parse --short HEAD', {
|
||||||
|
cwd: __dirname,
|
||||||
|
encoding: 'utf8',
|
||||||
|
stdio: ['ignore', 'pipe', 'ignore'],
|
||||||
|
maxBuffer: 64,
|
||||||
|
}).trim();
|
||||||
|
} catch (_err) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const _deploy_revision = resolveDeployRevisionForPm2();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PM2 process definition — always runs `listen` (HTTP + RSS cron).
|
* PM2 process definition — always runs `listen` (HTTP + RSS cron).
|
||||||
* Prefer this over `pm2 start src/index.js ... -- listen` to avoid footguns.
|
* Prefer this over `pm2 start src/index.js ... -- listen` to avoid footguns.
|
||||||
@@ -26,6 +50,7 @@ module.exports = {
|
|||||||
NODE_ENV: 'production',
|
NODE_ENV: 'production',
|
||||||
HOST: '0.0.0.0',
|
HOST: '0.0.0.0',
|
||||||
PORT: '3200',
|
PORT: '3200',
|
||||||
|
...(_deploy_revision ? { DEPLOY_REVISION: _deploy_revision } : {}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in new issue
Block a user