← back to Auto Deploy Watcher
README.md
62 lines
# 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.