summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorTyler Hoang <tyler@tylerhoang.xyz>2026-05-30 00:26:08 -0700
committerTyler Hoang <tyler@tylerhoang.xyz>2026-05-30 00:26:08 -0700
commitc0724a62c5e5742469339ec7aef4d0f509e10559 (patch)
treeb9e646b400f49a8759b5f0d5ecbab3b80e8a3387 /README.md
parent5fbc175e540803d919863f3d90dffc3c0645a90b (diff)
fix: align deploy flow with post-receive checkout (no .git in /var/www)
The working tree at /var/www/prism-v2 is populated by a post-receive hook that does `git --work-tree=... checkout -f`, so it has no .git directory. Drop git operations from deploy.sh and add scripts/post-receive.sample plus README setup for the bare repo + hook + sudoers wiring. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Diffstat (limited to 'README.md')
-rw-r--r--README.md55
1 files changed, 41 insertions, 14 deletions
diff --git a/README.md b/README.md
index 9f6b77d..cf2eecb 100644
--- a/README.md
+++ b/README.md
@@ -51,36 +51,63 @@ SQLite lives at `backend/data/prism.db`. Backend seeds a `default` profile on st
## Production Deployment
-Target topology: backend on `127.0.0.1:8001`, frontend on `127.0.0.1:3001`, nginx terminates TLS and reverse-proxies. Code lives at `/var/www/prism-v2/` owned by `www-data`.
+Target topology:
-Use `scripts/deploy.sh` on the server — it is idempotent and handles both initial install and redeploys.
+- Bare repo at `/srv/git/prism-v2.git` (push target)
+- Working tree at `/var/www/prism-v2/` owned by `www-data` (no `.git/` — populated by post-receive hook via `git --work-tree=... checkout -f`)
+- Backend on `127.0.0.1:8001`, frontend on `127.0.0.1:3001`
+- nginx terminates TLS and reverse-proxies `/api/` → backend, `/` → frontend
-### First-time setup on a fresh server
+Workflow: `git push prod master` on your laptop → post-receive hook checks out the tree into `/var/www/prism-v2/` and runs `scripts/deploy.sh`, which builds + restarts.
+
+### First-time setup
```bash
-# As root / via sudo
-mkdir -p /var/www && chown www-data:www-data /var/www
-sudo -u www-data git clone <repo-url> /var/www/prism-v2
-cd /var/www/prism-v2
+# 1. Create bare repo
+sudo mkdir -p /srv/git && sudo git init --bare /srv/git/prism-v2.git
+
+# 2. Create working tree dir
+sudo install -d -o www-data -g www-data /var/www/prism-v2
-# Install systemd units + nginx site + build + start
+# 3. Push from your laptop so the working tree gets populated
+# (add the remote on your laptop: git remote add prod user@host:/srv/git/prism-v2.git)
+# git push prod master
+
+# 4. On the server: install systemd units + nginx site + build + start
+cd /var/www/prism-v2
sudo ./scripts/deploy.sh --install
-# First-time TLS (Certbot edits the nginx server block in-place)
+# 5. First-time TLS (Certbot edits the nginx server block in-place)
sudo certbot --nginx -d prism.tylerhoang.xyz
sudo systemctl reload nginx
+
+# 6. Install the post-receive hook so future pushes auto-deploy
+sudo cp /var/www/prism-v2/scripts/post-receive.sample /srv/git/prism-v2.git/hooks/post-receive
+sudo chmod +x /srv/git/prism-v2.git/hooks/post-receive
+
+# 7. Sudoers entry so the git-push user can run deploy.sh without a password
+# (replace GIT_USER with the account that owns /srv/git or receives the push)
+echo 'GIT_USER ALL=(root) NOPASSWD: /var/www/prism-v2/scripts/deploy.sh' | sudo tee /etc/sudoers.d/prism-v2-deploy
+sudo chmod 0440 /etc/sudoers.d/prism-v2-deploy
+```
+
+### Subsequent deploys
+
+From your laptop:
+
+```bash
+git push prod master # post-receive hook checks out + runs deploy.sh
```
-### Redeploy
+Manual deploy on the server (e.g. retry after a failed build, or to refresh systemd/nginx):
```bash
cd /var/www/prism-v2
-sudo ./scripts/deploy.sh # pull + build + restart + smoke check
-sudo ./scripts/deploy.sh --no-pull # rebuild + restart without git pull
-sudo ./scripts/deploy.sh --install # also refresh systemd units / nginx site
+sudo ./scripts/deploy.sh # build + restart + smoke check
+sudo ./scripts/deploy.sh --install # also refresh systemd units / nginx site
```
-The script runs all build steps as `www-data` (with `HOME` + `NPM_CONFIG_CACHE` set), restarts both services, and curls `/health` on the backend and `/` on the frontend before exiting.
+`deploy.sh` is idempotent: ensures ownership, builds the backend venv and `npm ci && npm run build` as `www-data` (with `HOME` + `NPM_CONFIG_CACHE` set), restarts both services, and curls `/health` and `/` before exiting. It does NOT touch git — the post-receive hook owns checkout.
### Ops