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:
parent
dc2b12a3c6
commit
21202c2ca3
6 changed files with 17 additions and 13 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
__pycache__/
|
||||
data/
|
||||
.venv/
|
||||
.deploy.env
|
||||
|
|
|
|||
|
|
@ -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
|
||||
`APIRouter`) with routes under `/api/<id>/…`, and optional `async startup()`/`shutdown()`.
|
||||
`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
|
||||
shared server (container capped at 192 MB / 0.5 CPU).
|
||||
`$DATA_DIR` (`/data`, bind-mounted from `/opt/tools/data`). Keep it light: it shares a small
|
||||
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
|
||||
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).
|
||||
- Run `node --test tests/` and check the page in a browser before deploying; `deploy.sh` refuses
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -70,13 +70,12 @@ docker run --rm --network host -e PORT=18090 -v "$PWD/data:/data" tools:dev
|
|||
## Deploy
|
||||
|
||||
```sh
|
||||
./deploy.sh # HOST=root@<server>
|
||||
HOST=root@<other> ./deploy.sh
|
||||
HOST=root@<server> ./deploy.sh # or put HOST=… in .deploy.env (gitignored)
|
||||
```
|
||||
|
||||
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
|
||||
on the same host in front of it.
|
||||
`127.0.0.1:8090` only, so put a reverse proxy or tunnel connector 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
|
||||
|
||||
|
|
|
|||
|
|
@ -90,8 +90,8 @@ async def shutdown():
|
|||
|
||||
|
||||
def client_ip(request: Request) -> str:
|
||||
# uvicorn runs with --proxy-headers --forwarded-allow-ips 127.0.0.1, so behind
|
||||
# a reverse proxy that connects over loopback this is already the visitor's address.
|
||||
# uvicorn runs with --proxy-headers --forwarded-allow-ips 127.0.0.1, so behind a
|
||||
# reverse proxy that connects over loopback this is already the visitor's address.
|
||||
return request.client.host if request.client else ""
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Host networking + loopback bind: only a proxy or tunnel on the same host can reach it.
|
||||
# It listens on 127.0.0.1:8090.
|
||||
# Host networking + loopback bind: only a reverse proxy or tunnel connector on the
|
||||
# same host can reach it (127.0.0.1:8090); nothing is exposed directly.
|
||||
name: tools
|
||||
services:
|
||||
tools:
|
||||
|
|
@ -13,7 +13,7 @@ services:
|
|||
PORT: "8090"
|
||||
volumes:
|
||||
- ./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
|
||||
cpus: 0.5
|
||||
read_only: true
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
# Deploy this checkout (including uncommitted changes) over SSH:
|
||||
# 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,
|
||||
# then waits for it to report healthy. Paste data in /opt/tools/data is kept.
|
||||
set -euo pipefail
|
||||
HOST=${HOST:?set HOST=root@<server>}
|
||||
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; }
|
||||
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'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue