Keep server details out of the repo; deploy target comes from HOST or .deploy.env

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
neil 2026-11-02 01:19:28 -08:00
parent dc2b12a3c6
commit 21202c2ca3
6 changed files with 17 additions and 13 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
__pycache__/ __pycache__/
data/ data/
.venv/ .venv/
.deploy.env

View file

@ -21,8 +21,8 @@ See `README.md` for what this is and how it's deployed. This file is how to exte
3. **Server side, only if needed:** add `app/tools/<id>.py` exposing `router` (a FastAPI 3. **Server side, only if needed:** add `app/tools/<id>.py` exposing `router` (a FastAPI
`APIRouter`) with routes under `/api/<id>/…`, and optional `async startup()`/`shutdown()`. `APIRouter`) with routes under `/api/<id>/…`, and optional `async startup()`/`shutdown()`.
`main.py` mounts every module in `tools/` automatically. Persistent files go under `main.py` mounts every module in `tools/` automatically. Persistent files go under
`$DATA_DIR` (`/data`, bind-mounted from `/opt/tools/data`). Keep it light: this runs on the `$DATA_DIR` (`/data`, bind-mounted from `/opt/tools/data`). Keep it light: it shares a small
shared server (container capped at 192 MB / 0.5 CPU). server with other workloads (container capped at 192 MB / 0.5 CPU).
4. Prefer running in the browser. Vendor any library into `static/vendor/` (pinned version in 4. Prefer running in the browser. Vendor any library into `static/vendor/` (pinned version in
the filename comment or README); the CSP allows scripts from `'self'` only, no CDNs. the filename comment or README); the CSP allows scripts from `'self'` only, no CDNs.
@ -42,3 +42,6 @@ See `README.md` for what this is and how it's deployed. This file is how to exte
the initial page light (the server's upstream is slow). the initial page light (the server's upstream is slow).
- Run `node --test tests/` and check the page in a browser before deploying; `deploy.sh` refuses - Run `node --test tests/` and check the page in a browser before deploying; `deploy.sh` refuses
to deploy if the tests fail. to deploy if the tests fail.
- **This repo is public. Never commit anything about the machines it runs on**: no IPs, SSH
targets, hostnames, providers, network layout or tunnel setup. The deploy target lives in the
gitignored `.deploy.env`; operational notes belong in the private homelab docs.

View file

@ -70,13 +70,12 @@ docker run --rm --network host -e PORT=18090 -v "$PWD/data:/data" tools:dev
## Deploy ## Deploy
```sh ```sh
./deploy.sh # HOST=root@<server> HOST=root@<server> ./deploy.sh # or put HOST=… in .deploy.env (gitignored)
HOST=root@<other> ./deploy.sh
``` ```
On the server: `/opt/tools/{compose.yml,app/,data/}`, container `tools`, listening on On the server: `/opt/tools/{compose.yml,app/,data/}`, container `tools`, listening on
`127.0.0.1:8090` only. Put a reverse proxy or tunnel connector `127.0.0.1:8090` only, so put a reverse proxy or tunnel connector on the same host in front of it.
on the same host in front of it. It trusts `X-Forwarded-For` from loopback only, which is what makes the per-IP paste limit work.
## Pastebin limits ## Pastebin limits

View file

@ -90,8 +90,8 @@ async def shutdown():
def client_ip(request: Request) -> str: def client_ip(request: Request) -> str:
# uvicorn runs with --proxy-headers --forwarded-allow-ips 127.0.0.1, so behind # uvicorn runs with --proxy-headers --forwarded-allow-ips 127.0.0.1, so behind a
# a reverse proxy that connects over loopback this is already the visitor's address. # reverse proxy that connects over loopback this is already the visitor's address.
return request.client.host if request.client else "" return request.client.host if request.client else ""

View file

@ -1,5 +1,5 @@
# Host networking + loopback bind: only a proxy or tunnel on the same host can reach it. # Host networking + loopback bind: only a reverse proxy or tunnel connector on the
# It listens on 127.0.0.1:8090. # same host can reach it (127.0.0.1:8090); nothing is exposed directly.
name: tools name: tools
services: services:
tools: tools:
@ -13,7 +13,7 @@ services:
PORT: "8090" PORT: "8090"
volumes: volumes:
- ./data:/data - ./data:/data
# Small and capped: it shares a small server with other workloads. # Small and capped, so it can share a small server with other workloads.
mem_limit: 192m mem_limit: 192m
cpus: 0.5 cpus: 0.5
read_only: true read_only: true

View file

@ -1,12 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Deploy this checkout (including uncommitted changes) over SSH: # Deploy this checkout (including uncommitted changes) over SSH:
# HOST=root@<server> ./deploy.sh # HOST=root@<server> ./deploy.sh
# HOST=root@<server> ./deploy.sh # elsewhere # or put HOST=root@<server> in .deploy.env (gitignored; keep server details out of the repo).
# Copies app/ and compose.yml to /opt/tools, rebuilds and restarts the container, # Copies app/ and compose.yml to /opt/tools, rebuilds and restarts the container,
# then waits for it to report healthy. Paste data in /opt/tools/data is kept. # then waits for it to report healthy. Paste data in /opt/tools/data is kept.
set -euo pipefail set -euo pipefail
HOST=${HOST:?set HOST=root@<server>}
cd "$(dirname "$0")" cd "$(dirname "$0")"
[ -z "${HOST:-}" ] && [ -f .deploy.env ] && . ./.deploy.env
[ -n "${HOST:-}" ] || { echo "usage: HOST=root@<server> $0 (or set HOST in .deploy.env)" >&2; exit 1; }
node --test tests/ >/dev/null || { echo "tests failed; not deploying" >&2; exit 1; } node --test tests/ >/dev/null || { echo "tests failed; not deploying" >&2; exit 1; }
tar -czf - --exclude=__pycache__ --exclude=data app compose.yml | tar -czf - --exclude=__pycache__ --exclude=data app compose.yml |
ssh "$HOST" 'set -e; mkdir -p /opt/tools && rm -rf /opt/tools/app && tar --no-same-owner -xzf - -C /opt/tools' ssh "$HOST" 'set -e; mkdir -p /opt/tools && rm -rf /opt/tools/app && tar --no-same-owner -xzf - -C /opt/tools'