← back to Auto Deploy Watcher
initial snapshot — gitify all builds (CLAUDE.md rule 2026-05-06)
92cb53391447ffe417d541db9177097dda48f5b6 · 2026-05-06 10:20:32 -0700 · Steve
Files touched
A .gitignoreA README.mdA ecosystem.config.cjsA package-lock.jsonA package.jsonA projects.jsonA server.js
Diff
commit 92cb53391447ffe417d541db9177097dda48f5b6
Author: Steve <steve@designerwallcoverings.com>
Date: Wed May 6 10:20:32 2026 -0700
initial snapshot — gitify all builds (CLAUDE.md rule 2026-05-06)
---
.gitignore | 25 ++
README.md | 61 ++++
ecosystem.config.cjs | 27 ++
package-lock.json | 845 +++++++++++++++++++++++++++++++++++++++++++++++++++
package.json | 16 +
projects.json | 11 +
server.js | 392 ++++++++++++++++++++++++
7 files changed, 1377 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9ae81e0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,25 @@
+node_modules/
+.env
+.env.*
+!.env.example
+tmp/
+*.log
+.DS_Store
+dist/
+build/
+.next/
+.cache/
+.parcel-cache/
+coverage/
+__pycache__/
+*.pyc
+*.pyo
+.venv/
+venv/
+.pytest_cache/
+.ruff_cache/
+.idea/
+.vscode/
+*.swp
+.qodo/
+out/
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a55756f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,61 @@
+# auto-deploy-watcher
+
+Watches each enabled project's git HEAD on `main` and runs that project's
+`scripts/deploy-*.sh` whenever the SHA changes.
+
+- HTTP: `http://127.0.0.1:9799`
+- Health: `GET /healthz` (public)
+- Dashboard: `GET /` (Basic Auth)
+- API: `GET /api/deploys` and `GET /api/deploys?service=<name>` (Basic Auth)
+- Auth: `process.env.BASIC_AUTH || 'admin:DWSecure2024!'`
+
+## Configure
+
+Edit `projects.json`:
+
+```json
+{
+ "watch": [
+ {
+ "name": "smb-builder",
+ "cwd": "/Users/stevestudio2/Projects/small-business-builder",
+ "deploy_script": "scripts/deploy-kamatera.sh",
+ "enabled": false
+ }
+ ]
+}
+```
+
+`enabled` defaults to **false**. Opt in per project after a non-prod
+validation run.
+
+## Safety rails
+
+- `enabled: false` is the default
+- `deploy_script` must match `scripts/deploy-*.sh`
+- Hard 10-minute timeout per deploy via `perl -e 'alarm shift; exec @ARGV' 600 ...`
+- Refuses to fire if the previous deploy is still running for the same service
+- Full stdout/stderr → `logs/<service>-<sha12>.log`
+- Last 20 deploys/service in memory + appended to `data/deploys.jsonl`
+
+## Watcher mechanics
+
+1. `fs.watch('<cwd>/.git/refs/heads/main')` triggers a 500 ms debounce.
+2. After debounce, `git log -1 --format=%H` confirms the SHA actually changed
+ (refs file can touch without a real change).
+3. On real change, spawns `perl -e 'alarm shift; exec @ARGV' 600 bash <script>`
+ with `cwd` set to the project, env vars `AUTO_DEPLOY_SHA` and
+ `AUTO_DEPLOY_SERVICE` exposed to the script.
+
+## Run
+
+```bash
+cd ~/Projects/auto-deploy-watcher
+npm install
+node server.js
+# or, after Steve reviews:
+pm2 start ecosystem.config.cjs && pm2 save
+```
+
+The watcher does NOT auto-add itself to pm2. The ecosystem config is for
+Steve to run manually after reviewing the scaffold.
diff --git a/ecosystem.config.cjs b/ecosystem.config.cjs
new file mode 100644
index 0000000..3648252
--- /dev/null
+++ b/ecosystem.config.cjs
@@ -0,0 +1,27 @@
+// pm2 ecosystem for auto-deploy-watcher.
+// Steve runs this manually after review:
+// pm2 start ecosystem.config.cjs && pm2 save
+module.exports = {
+ apps: [
+ {
+ name: 'auto-deploy-watcher',
+ script: 'server.js',
+ cwd: __dirname,
+ instances: 1,
+ exec_mode: 'fork',
+ autorestart: true,
+ max_restarts: 10,
+ max_memory_restart: '256M',
+ env: {
+ NODE_ENV: 'production',
+ PORT: 9799,
+ HOST: '127.0.0.1',
+ // BASIC_AUTH defaults to admin:DWSecure2024! — override here if needed.
+ },
+ out_file: './logs/pm2-out.log',
+ error_file: './logs/pm2-err.log',
+ merge_logs: true,
+ time: true,
+ },
+ ],
+};
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..8d8927d
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,845 @@
+{
+ "name": "auto-deploy-watcher",
+ "version": "0.1.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "auto-deploy-watcher",
+ "version": "0.1.0",
+ "dependencies": {
+ "express": "^4.19.2"
+ },
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/accepts": {
+ "version": "1.3.8",
+ "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
+ "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
+ "license": "MIT",
+ "dependencies": {
+ "mime-types": "~2.1.34",
+ "negotiator": "0.6.3"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/array-flatten": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+ "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
+ "license": "MIT"
+ },
+ "node_modules/body-parser": {
+ "version": "1.20.5",
+ "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.5.tgz",
+ "integrity": "sha512-3grm+/2tUOvu2cjJkvsIxrv/wVpfXQW4PsQHYm7yk4vfpu7Ekl6nEsYBoJUL6qDwZUx8wUhQ8tR2qz+ad9c9OA==",
+ "license": "MIT",
+ "dependencies": {
+ "bytes": "~3.1.2",
+ "content-type": "~1.0.5",
+ "debug": "2.6.9",
+ "depd": "2.0.0",
+ "destroy": "~1.2.0",
+ "http-errors": "~2.0.1",
+ "iconv-lite": "~0.4.24",
+ "on-finished": "~2.4.1",
+ "qs": "~6.15.1",
+ "raw-body": "~2.5.3",
+ "type-is": "~1.6.18",
+ "unpipe": "~1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.8",
+ "npm": "1.2.8000 || >= 1.4.16"
+ }
+ },
+ "node_modules/body-parser/node_modules/qs": {
+ "version": "6.15.1",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.1.tgz",
+ "integrity": "sha512-6YHEFRL9mfgcAvql/XhwTvf5jKcOiiupt2FiJxHkiX1z4j7WL8J/jRHYLluORvc1XxB5rV20KoeK00gVJamspg==",
+ "license": "BSD-3-Clause",
+ "dependencies": {
+ "side-channel": "^1.1.0"
+ },
+ "engines": {
+ "node": ">=0.6"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/bytes": {
+ "version": "3.1.2",
+ "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
+ "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/call-bind-apply-helpers": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
+ "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0",
+ "function-bind": "^1.1.2"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/call-bound": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
+ "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bind-apply-helpers": "^1.0.2",
+ "get-intrinsic": "^1.3.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/content-disposition": {
+ "version": "0.5.4",
+ "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
+ "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
+ "license": "MIT",
+ "dependencies": {
+ "safe-buffer": "5.2.1"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/content-type": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
+ "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/cookie": {
+ "version": "0.7.2",
+ "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
+ "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/cookie-signature": {
+ "version": "1.0.7",
+ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz",
+ "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==",
+ "license": "MIT"
+ },
+ "node_modules/debug": {
+ "version": "2.6.9",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
+ "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
+ "license": "MIT",
+ "dependencies": {
+ "ms": "2.0.0"
+ }
+ },
+ "node_modules/depd": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
+ "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/destroy": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
+ "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8",
+ "npm": "1.2.8000 || >= 1.4.16"
+ }
+ },
+ "node_modules/dunder-proto": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
+ "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bind-apply-helpers": "^1.0.1",
+ "es-errors": "^1.3.0",
+ "gopd": "^1.2.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/ee-first": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
+ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
+ "license": "MIT"
+ },
+ "node_modules/encodeurl": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
+ "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/es-define-property": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
+ "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/es-errors": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
+ "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/es-object-atoms": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
+ "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/escape-html": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
+ "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
+ "license": "MIT"
+ },
+ "node_modules/etag": {
+ "version": "1.8.1",
+ "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
+ "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/express": {
+ "version": "4.22.1",
+ "resolved": "https://registry.npmjs.org/express/-/express-4.22.1.tgz",
+ "integrity": "sha512-F2X8g9P1X7uCPZMA3MVf9wcTqlyNp7IhH5qPCI0izhaOIYXaW9L535tGA3qmjRzpH+bZczqq7hVKxTR4NWnu+g==",
+ "license": "MIT",
+ "dependencies": {
+ "accepts": "~1.3.8",
+ "array-flatten": "1.1.1",
+ "body-parser": "~1.20.3",
+ "content-disposition": "~0.5.4",
+ "content-type": "~1.0.4",
+ "cookie": "~0.7.1",
+ "cookie-signature": "~1.0.6",
+ "debug": "2.6.9",
+ "depd": "2.0.0",
+ "encodeurl": "~2.0.0",
+ "escape-html": "~1.0.3",
+ "etag": "~1.8.1",
+ "finalhandler": "~1.3.1",
+ "fresh": "~0.5.2",
+ "http-errors": "~2.0.0",
+ "merge-descriptors": "1.0.3",
+ "methods": "~1.1.2",
+ "on-finished": "~2.4.1",
+ "parseurl": "~1.3.3",
+ "path-to-regexp": "~0.1.12",
+ "proxy-addr": "~2.0.7",
+ "qs": "~6.14.0",
+ "range-parser": "~1.2.1",
+ "safe-buffer": "5.2.1",
+ "send": "~0.19.0",
+ "serve-static": "~1.16.2",
+ "setprototypeof": "1.2.0",
+ "statuses": "~2.0.1",
+ "type-is": "~1.6.18",
+ "utils-merge": "1.0.1",
+ "vary": "~1.1.2"
+ },
+ "engines": {
+ "node": ">= 0.10.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
+ "node_modules/finalhandler": {
+ "version": "1.3.2",
+ "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz",
+ "integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==",
+ "license": "MIT",
+ "dependencies": {
+ "debug": "2.6.9",
+ "encodeurl": "~2.0.0",
+ "escape-html": "~1.0.3",
+ "on-finished": "~2.4.1",
+ "parseurl": "~1.3.3",
+ "statuses": "~2.0.2",
+ "unpipe": "~1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/forwarded": {
+ "version": "0.2.0",
+ "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
+ "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/fresh": {
+ "version": "0.5.2",
+ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
+ "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/function-bind": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
+ "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/get-intrinsic": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
+ "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bind-apply-helpers": "^1.0.2",
+ "es-define-property": "^1.0.1",
+ "es-errors": "^1.3.0",
+ "es-object-atoms": "^1.1.1",
+ "function-bind": "^1.1.2",
+ "get-proto": "^1.0.1",
+ "gopd": "^1.2.0",
+ "has-symbols": "^1.1.0",
+ "hasown": "^2.0.2",
+ "math-intrinsics": "^1.1.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/get-proto": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
+ "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
+ "license": "MIT",
+ "dependencies": {
+ "dunder-proto": "^1.0.1",
+ "es-object-atoms": "^1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/gopd": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
+ "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/has-symbols": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
+ "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/hasown": {
+ "version": "2.0.3",
+ "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.3.tgz",
+ "integrity": "sha512-ej4AhfhfL2Q2zpMmLo7U1Uv9+PyhIZpgQLGT1F9miIGmiCJIoCgSmczFdrc97mWT4kVY72KA+WnnhJ5pghSvSg==",
+ "license": "MIT",
+ "dependencies": {
+ "function-bind": "^1.1.2"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/http-errors": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
+ "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
+ "license": "MIT",
+ "dependencies": {
+ "depd": "~2.0.0",
+ "inherits": "~2.0.4",
+ "setprototypeof": "~1.2.0",
+ "statuses": "~2.0.2",
+ "toidentifier": "~1.0.1"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
+ "node_modules/iconv-lite": {
+ "version": "0.4.24",
+ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
+ "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
+ "license": "MIT",
+ "dependencies": {
+ "safer-buffer": ">= 2.1.2 < 3"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/inherits": {
+ "version": "2.0.4",
+ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
+ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
+ "license": "ISC"
+ },
+ "node_modules/ipaddr.js": {
+ "version": "1.9.1",
+ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
+ "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.10"
+ }
+ },
+ "node_modules/math-intrinsics": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
+ "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/media-typer": {
+ "version": "0.3.0",
+ "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
+ "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/merge-descriptors": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
+ "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==",
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/sponsors/sindresorhus"
+ }
+ },
+ "node_modules/methods": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
+ "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/mime": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
+ "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
+ "license": "MIT",
+ "bin": {
+ "mime": "cli.js"
+ },
+ "engines": {
+ "node": ">=4"
+ }
+ },
+ "node_modules/mime-db": {
+ "version": "1.52.0",
+ "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
+ "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/mime-types": {
+ "version": "2.1.35",
+ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
+ "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
+ "license": "MIT",
+ "dependencies": {
+ "mime-db": "1.52.0"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/ms": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
+ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
+ "license": "MIT"
+ },
+ "node_modules/negotiator": {
+ "version": "0.6.3",
+ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
+ "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/object-inspect": {
+ "version": "1.13.4",
+ "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
+ "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/on-finished": {
+ "version": "2.4.1",
+ "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
+ "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
+ "license": "MIT",
+ "dependencies": {
+ "ee-first": "1.1.1"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/parseurl": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
+ "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/path-to-regexp": {
+ "version": "0.1.13",
+ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.13.tgz",
+ "integrity": "sha512-A/AGNMFN3c8bOlvV9RreMdrv7jsmF9XIfDeCd87+I8RNg6s78BhJxMu69NEMHBSJFxKidViTEdruRwEk/WIKqA==",
+ "license": "MIT"
+ },
+ "node_modules/proxy-addr": {
+ "version": "2.0.7",
+ "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
+ "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
+ "license": "MIT",
+ "dependencies": {
+ "forwarded": "0.2.0",
+ "ipaddr.js": "1.9.1"
+ },
+ "engines": {
+ "node": ">= 0.10"
+ }
+ },
+ "node_modules/qs": {
+ "version": "6.14.2",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.2.tgz",
+ "integrity": "sha512-V/yCWTTF7VJ9hIh18Ugr2zhJMP01MY7c5kh4J870L7imm6/DIzBsNLTXzMwUA3yZ5b/KBqLx8Kp3uRvd7xSe3Q==",
+ "license": "BSD-3-Clause",
+ "dependencies": {
+ "side-channel": "^1.1.0"
+ },
+ "engines": {
+ "node": ">=0.6"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/range-parser": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
+ "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/raw-body": {
+ "version": "2.5.3",
+ "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz",
+ "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==",
+ "license": "MIT",
+ "dependencies": {
+ "bytes": "~3.1.2",
+ "http-errors": "~2.0.1",
+ "iconv-lite": "~0.4.24",
+ "unpipe": "~1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/safe-buffer": {
+ "version": "5.2.1",
+ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
+ "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/feross"
+ },
+ {
+ "type": "patreon",
+ "url": "https://www.patreon.com/feross"
+ },
+ {
+ "type": "consulting",
+ "url": "https://feross.org/support"
+ }
+ ],
+ "license": "MIT"
+ },
+ "node_modules/safer-buffer": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
+ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
+ "license": "MIT"
+ },
+ "node_modules/send": {
+ "version": "0.19.2",
+ "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz",
+ "integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==",
+ "license": "MIT",
+ "dependencies": {
+ "debug": "2.6.9",
+ "depd": "2.0.0",
+ "destroy": "1.2.0",
+ "encodeurl": "~2.0.0",
+ "escape-html": "~1.0.3",
+ "etag": "~1.8.1",
+ "fresh": "~0.5.2",
+ "http-errors": "~2.0.1",
+ "mime": "1.6.0",
+ "ms": "2.1.3",
+ "on-finished": "~2.4.1",
+ "range-parser": "~1.2.1",
+ "statuses": "~2.0.2"
+ },
+ "engines": {
+ "node": ">= 0.8.0"
+ }
+ },
+ "node_modules/send/node_modules/ms": {
+ "version": "2.1.3",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
+ "license": "MIT"
+ },
+ "node_modules/serve-static": {
+ "version": "1.16.3",
+ "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz",
+ "integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==",
+ "license": "MIT",
+ "dependencies": {
+ "encodeurl": "~2.0.0",
+ "escape-html": "~1.0.3",
+ "parseurl": "~1.3.3",
+ "send": "~0.19.1"
+ },
+ "engines": {
+ "node": ">= 0.8.0"
+ }
+ },
+ "node_modules/setprototypeof": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
+ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
+ "license": "ISC"
+ },
+ "node_modules/side-channel": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz",
+ "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0",
+ "object-inspect": "^1.13.3",
+ "side-channel-list": "^1.0.0",
+ "side-channel-map": "^1.0.1",
+ "side-channel-weakmap": "^1.0.2"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/side-channel-list": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz",
+ "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0",
+ "object-inspect": "^1.13.4"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/side-channel-map": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
+ "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bound": "^1.0.2",
+ "es-errors": "^1.3.0",
+ "get-intrinsic": "^1.2.5",
+ "object-inspect": "^1.13.3"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/side-channel-weakmap": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
+ "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bound": "^1.0.2",
+ "es-errors": "^1.3.0",
+ "get-intrinsic": "^1.2.5",
+ "object-inspect": "^1.13.3",
+ "side-channel-map": "^1.0.1"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/statuses": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
+ "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/toidentifier": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
+ "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=0.6"
+ }
+ },
+ "node_modules/type-is": {
+ "version": "1.6.18",
+ "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
+ "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
+ "license": "MIT",
+ "dependencies": {
+ "media-typer": "0.3.0",
+ "mime-types": "~2.1.24"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/unpipe": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
+ "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/utils-merge": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
+ "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4.0"
+ }
+ },
+ "node_modules/vary": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
+ "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ }
+ }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..7ca1920
--- /dev/null
+++ b/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "auto-deploy-watcher",
+ "version": "0.1.0",
+ "description": "Watches project git HEADs on main and runs scripts/deploy-*.sh on change.",
+ "main": "server.js",
+ "type": "commonjs",
+ "scripts": {
+ "start": "node server.js"
+ },
+ "dependencies": {
+ "express": "^4.19.2"
+ },
+ "engines": {
+ "node": ">=18"
+ }
+}
diff --git a/projects.json b/projects.json
new file mode 100644
index 0000000..dba920c
--- /dev/null
+++ b/projects.json
@@ -0,0 +1,11 @@
+{
+ "watch": [
+ {
+ "name": "smb-builder",
+ "cwd": "/Users/stevestudio2/Projects/small-business-builder",
+ "deploy_script": "scripts/deploy-kamatera.sh",
+ "enabled": false,
+ "comment": "ENABLE ONLY AFTER VALIDATING THE WATCHER WORKS ON A NON-PROD PROJECT FIRST"
+ }
+ ]
+}
diff --git a/server.js b/server.js
new file mode 100644
index 0000000..8cc1e7e
--- /dev/null
+++ b/server.js
@@ -0,0 +1,392 @@
+/**
+ * auto-deploy-watcher
+ *
+ * Watches each enabled project's `.git/refs/heads/main` for changes and runs the
+ * project's `scripts/deploy-*.sh` when the SHA actually changes.
+ *
+ * Safety rails:
+ * - `enabled: false` is the default — opt-in per project.
+ * - Only deploy_script values matching `scripts/deploy-*.sh` are accepted.
+ * - Hard 10-minute timeout per deploy via `perl -e 'alarm shift; exec @ARGV' 600 ...`.
+ * - Refuses to fire if the previous deploy is still running for the same service.
+ * - Logs full stdout/stderr to logs/<service>-<sha>.log.
+ * - Persists last 20 deploys/service to data/deploys.jsonl.
+ *
+ * Endpoints:
+ * GET /healthz — public, no auth
+ * GET / — Basic Auth, status dashboard
+ * GET /api/deploys — Basic Auth, JSON. Optional ?service=<name>.
+ *
+ * Auth:
+ * process.env.BASIC_AUTH || 'admin:DWSecure2024!'
+ * /healthz is exempt.
+ */
+
+'use strict';
+
+const express = require('express');
+const fs = require('node:fs');
+const fsp = require('node:fs/promises');
+const path = require('node:path');
+const { spawn } = require('node:child_process');
+const { execFile } = require('node:child_process');
+
+// ---- config ---------------------------------------------------------------
+
+const ROOT = __dirname;
+const PORT = Number(process.env.PORT || 9799);
+const HOST = process.env.HOST || '127.0.0.1';
+const PROJECTS_FILE = path.join(ROOT, 'projects.json');
+const LOG_DIR = path.join(ROOT, 'logs');
+const DATA_DIR = path.join(ROOT, 'data');
+const DEPLOYS_FILE = path.join(DATA_DIR, 'deploys.jsonl');
+const DEPLOY_TIMEOUT_SECONDS = 600;
+const DEBOUNCE_MS = 500;
+const HISTORY_MAX = 20;
+const DEPLOY_SCRIPT_RE = /^scripts\/deploy-[A-Za-z0-9._-]+\.sh$/;
+
+const BASIC_AUTH = process.env.BASIC_AUTH || 'admin:DWSecure2024!';
+const EXPECTED_AUTH_HEADER =
+ 'Basic ' + Buffer.from(BASIC_AUTH, 'utf8').toString('base64');
+
+// ---- state ----------------------------------------------------------------
+
+/** name -> { entry, lastSha, lastDeployAt, running, debounceTimer, watcher, history[] } */
+const state = new Map();
+
+// ---- helpers --------------------------------------------------------------
+
+function log(...a) {
+ console.log('[' + new Date().toISOString() + ']', ...a);
+}
+
+function ensureDirs() {
+ for (const d of [LOG_DIR, DATA_DIR]) {
+ if (!fs.existsSync(d)) fs.mkdirSync(d, { recursive: true });
+ }
+}
+
+function readProjects() {
+ const raw = fs.readFileSync(PROJECTS_FILE, 'utf8');
+ const cfg = JSON.parse(raw);
+ if (!cfg || !Array.isArray(cfg.watch)) {
+ throw new Error('projects.json must contain { "watch": [...] }');
+ }
+ return cfg.watch;
+}
+
+function validateEntry(entry) {
+ const errs = [];
+ if (!entry.name || typeof entry.name !== 'string') errs.push('missing name');
+ if (!entry.cwd || typeof entry.cwd !== 'string') errs.push('missing cwd');
+ if (!entry.deploy_script || typeof entry.deploy_script !== 'string') {
+ errs.push('missing deploy_script');
+ } else if (!DEPLOY_SCRIPT_RE.test(entry.deploy_script)) {
+ errs.push('deploy_script must match scripts/deploy-*.sh');
+ }
+ if (entry.cwd && !fs.existsSync(entry.cwd)) errs.push('cwd does not exist: ' + entry.cwd);
+ return errs;
+}
+
+function gitHeadSha(cwd) {
+ return new Promise((resolve, reject) => {
+ execFile(
+ 'git',
+ ['log', '-1', '--format=%H'],
+ { cwd, timeout: 10_000 },
+ (err, stdout) => {
+ if (err) reject(err);
+ else resolve(stdout.trim());
+ }
+ );
+ });
+}
+
+async function appendDeploy(record) {
+ await fsp.appendFile(DEPLOYS_FILE, JSON.stringify(record) + '\n', 'utf8');
+}
+
+function pushHistory(name, record) {
+ const s = state.get(name);
+ if (!s) return;
+ s.history.unshift(record);
+ if (s.history.length > HISTORY_MAX) s.history.length = HISTORY_MAX;
+}
+
+// ---- deploy execution -----------------------------------------------------
+
+async function runDeploy(entry, sha) {
+ const s = state.get(entry.name);
+ if (!s) return;
+
+ if (s.running) {
+ log('SKIP', entry.name, '— previous deploy still running');
+ return;
+ }
+
+ const scriptAbs = path.join(entry.cwd, entry.deploy_script);
+ if (!fs.existsSync(scriptAbs)) {
+ log('SKIP', entry.name, '— deploy script not found:', scriptAbs);
+ pushHistory(entry.name, {
+ service: entry.name,
+ sha,
+ startedAt: new Date().toISOString(),
+ finishedAt: new Date().toISOString(),
+ exitCode: null,
+ error: 'deploy script not found',
+ logFile: null,
+ });
+ return;
+ }
+
+ s.running = true;
+ const startedAt = new Date();
+ const logFile = path.join(LOG_DIR, `${entry.name}-${sha.slice(0, 12)}.log`);
+ const logFd = fs.openSync(logFile, 'a');
+ fs.writeSync(
+ logFd,
+ `=== auto-deploy-watcher ${startedAt.toISOString()} service=${entry.name} sha=${sha} ===\n`
+ );
+
+ log('DEPLOY START', entry.name, sha.slice(0, 12), '->', logFile);
+
+ // perl-alarm hard timeout wrapper
+ const child = spawn(
+ 'perl',
+ [
+ '-e',
+ 'alarm shift; exec @ARGV',
+ String(DEPLOY_TIMEOUT_SECONDS),
+ 'bash',
+ scriptAbs,
+ ],
+ {
+ cwd: entry.cwd,
+ env: { ...process.env, AUTO_DEPLOY_SHA: sha, AUTO_DEPLOY_SERVICE: entry.name },
+ stdio: ['ignore', 'pipe', 'pipe'],
+ }
+ );
+
+ child.stdout.on('data', (d) => fs.writeSync(logFd, d));
+ child.stderr.on('data', (d) => fs.writeSync(logFd, d));
+
+ child.on('close', async (code, signal) => {
+ const finishedAt = new Date();
+ fs.writeSync(
+ logFd,
+ `\n=== exit code=${code} signal=${signal} duration_ms=${finishedAt - startedAt} ===\n`
+ );
+ fs.closeSync(logFd);
+ s.running = false;
+ s.lastDeployAt = finishedAt.toISOString();
+
+ const record = {
+ service: entry.name,
+ sha,
+ startedAt: startedAt.toISOString(),
+ finishedAt: finishedAt.toISOString(),
+ durationMs: finishedAt - startedAt,
+ exitCode: code,
+ signal,
+ logFile,
+ };
+ pushHistory(entry.name, record);
+ try {
+ await appendDeploy(record);
+ } catch (e) {
+ log('appendDeploy error', e.message);
+ }
+ log(
+ 'DEPLOY END ',
+ entry.name,
+ sha.slice(0, 12),
+ 'code=' + code,
+ 'signal=' + signal,
+ 'dur=' + (finishedAt - startedAt) + 'ms'
+ );
+ });
+
+ child.on('error', (err) => {
+ fs.writeSync(logFd, '\n=== spawn error: ' + err.message + ' ===\n');
+ log('DEPLOY ERROR', entry.name, err.message);
+ });
+}
+
+// ---- watcher --------------------------------------------------------------
+
+async function setupWatcher(entry) {
+ const errs = validateEntry(entry);
+ if (errs.length) {
+ log('SKIP', entry.name || '<unnamed>', '— invalid entry:', errs.join('; '));
+ return;
+ }
+ if (entry.enabled !== true) {
+ log('disabled', entry.name);
+ state.set(entry.name, {
+ entry,
+ lastSha: null,
+ lastDeployAt: null,
+ running: false,
+ debounceTimer: null,
+ watcher: null,
+ history: [],
+ });
+ return;
+ }
+
+ const refPath = path.join(entry.cwd, '.git', 'refs', 'heads', 'main');
+ let initialSha = null;
+ try {
+ initialSha = await gitHeadSha(entry.cwd);
+ } catch (e) {
+ log('SKIP', entry.name, '— git log failed:', e.message);
+ return;
+ }
+
+ const slot = {
+ entry,
+ lastSha: initialSha,
+ lastDeployAt: null,
+ running: false,
+ debounceTimer: null,
+ watcher: null,
+ history: [],
+ };
+ state.set(entry.name, slot);
+
+ if (!fs.existsSync(refPath)) {
+ log('WARN ', entry.name, '— refs/heads/main does not exist yet at', refPath);
+ }
+
+ const onChange = () => {
+ if (slot.debounceTimer) clearTimeout(slot.debounceTimer);
+ slot.debounceTimer = setTimeout(async () => {
+ slot.debounceTimer = null;
+ let sha;
+ try {
+ sha = await gitHeadSha(entry.cwd);
+ } catch (e) {
+ log('git log failed for', entry.name, e.message);
+ return;
+ }
+ if (sha === slot.lastSha) return; // no real change
+ log('SHA changed', entry.name, slot.lastSha?.slice(0, 12), '->', sha.slice(0, 12));
+ slot.lastSha = sha;
+ runDeploy(entry, sha).catch((e) => log('runDeploy error', entry.name, e.message));
+ }, DEBOUNCE_MS);
+ };
+
+ try {
+ slot.watcher = fs.watch(refPath, { persistent: true }, onChange);
+ slot.watcher.on('error', (err) => log('watch error', entry.name, err.message));
+ log('watching', entry.name, refPath, 'sha=' + initialSha.slice(0, 12));
+ } catch (e) {
+ log('SKIP', entry.name, '— fs.watch failed:', e.message);
+ }
+}
+
+// ---- HTTP -----------------------------------------------------------------
+
+const app = express();
+app.disable('x-powered-by');
+
+app.get('/healthz', (_req, res) => {
+ res.json({
+ ok: true,
+ service: 'auto-deploy-watcher',
+ port: PORT,
+ watching: Array.from(state.values()).filter((s) => s.entry.enabled).length,
+ total: state.size,
+ uptimeSec: Math.round(process.uptime()),
+ });
+});
+
+// Basic Auth gate for everything else
+app.use((req, res, next) => {
+ if (req.path === '/healthz') return next();
+ const got = req.headers.authorization || '';
+ if (got === EXPECTED_AUTH_HEADER) return next();
+ res.set('WWW-Authenticate', 'Basic realm="auto-deploy-watcher"');
+ res.status(401).send('auth required');
+});
+
+app.get('/api/deploys', (req, res) => {
+ const service = typeof req.query.service === 'string' ? req.query.service : null;
+ if (service) {
+ const s = state.get(service);
+ if (!s) return res.status(404).json({ error: 'unknown service', service });
+ return res.json({ service, history: s.history });
+ }
+ const out = {};
+ for (const [name, s] of state) out[name] = s.history;
+ res.json(out);
+});
+
+app.get('/', (_req, res) => {
+ const rows = Array.from(state.values()).map((s) => {
+ const e = s.entry;
+ const last = s.history[0];
+ return `<tr>
+ <td>${e.name}</td>
+ <td>${e.enabled ? 'yes' : 'no'}</td>
+ <td><code>${e.cwd}</code></td>
+ <td><code>${e.deploy_script}</code></td>
+ <td>${s.lastSha ? s.lastSha.slice(0, 12) : '—'}</td>
+ <td>${s.running ? 'RUNNING' : 'idle'}</td>
+ <td>${last ? `${last.finishedAt} exit=${last.exitCode}` : '—'}</td>
+ </tr>`;
+ }).join('\n');
+
+ res.set('content-type', 'text/html; charset=utf-8').send(`<!doctype html>
+<html><head><meta charset="utf-8"><title>auto-deploy-watcher</title>
+<style>
+body{font:14px -apple-system,BlinkMacSystemFont,sans-serif;margin:24px;color:#111;}
+h1{margin:0 0 4px 0;}
+small{color:#666;}
+table{border-collapse:collapse;margin-top:16px;width:100%;}
+th,td{border:1px solid #ddd;padding:6px 10px;text-align:left;font-size:13px;vertical-align:top;}
+th{background:#f3f3f3;}
+code{background:#f7f7f7;padding:1px 4px;border-radius:3px;}
+</style></head>
+<body>
+<h1>auto-deploy-watcher</h1>
+<small>port ${PORT} · uptime ${Math.round(process.uptime())}s · ${state.size} project(s) configured</small>
+<p><a href="/api/deploys">/api/deploys</a> · <a href="/healthz">/healthz</a></p>
+<table>
+<tr><th>service</th><th>enabled</th><th>cwd</th><th>deploy_script</th><th>last sha</th><th>status</th><th>last deploy</th></tr>
+${rows || '<tr><td colspan="7"><em>no projects configured</em></td></tr>'}
+</table>
+</body></html>`);
+});
+
+// ---- boot -----------------------------------------------------------------
+
+async function main() {
+ ensureDirs();
+ let entries = [];
+ try {
+ entries = readProjects();
+ } catch (e) {
+ log('FATAL: cannot read projects.json —', e.message);
+ process.exit(1);
+ }
+ log('loaded', entries.length, 'project(s) from projects.json');
+ for (const entry of entries) {
+ await setupWatcher(entry);
+ }
+
+ app.listen(PORT, HOST, () => {
+ log(`listening on http://${HOST}:${PORT}`);
+ });
+}
+
+process.on('SIGTERM', () => {
+ log('SIGTERM — shutting down');
+ for (const s of state.values()) s.watcher?.close();
+ process.exit(0);
+});
+
+main().catch((e) => {
+ log('FATAL', e.stack || e.message);
+ process.exit(1);
+});
(oldest)
·
back to Auto Deploy Watcher
·
gitignore: cover snapshot/backup file patterns b22f241 →