Move Gitea to its own LXC; keep a forwarder on stpvm
Test and deploy / test (push) Successful in 17s
Test and deploy / deploy (push) Successful in 2s

Gitea (git, Actions, the registry) now runs from gitea/docker-compose.yml
on a separate Proxmox LXC with its own Postgres, deployed by hand. The
stack's gitea service becomes an haproxy TCP forwarder from stpvm's 3000
and 2222 to the LXC (GITEA_UPSTREAM), under the same container name, so
Caddy, the backend feed, usaco, the runner, Renovate and every repo's CI
keep their addresses. Webhooks from the LXC reach Caddy over the LAN.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 15:42:44 +00:00
co-authored by Claude Opus 5.5
parent aa4c3b1a67
commit 10606f4c77
13 changed files with 381 additions and 148 deletions
+93 -32
View File
@@ -14,7 +14,7 @@ network, behind one Caddy (nginx and certbot until 2026-11-17).
## 1. Service topology
Only three things are reachable from outside the host: Caddy on 80/443, Gitea on
3000/2222, and the liquidsoap harbor port. Everything else is internal. Web
3000/2222 (a forwarder to the Gitea LXC, below), and the liquidsoap harbor port. Everything else is internal. Web
traffic can also come in through the Cloudflare tunnel (`cloudflared`), which
dials out and publishes no port; see "Cloudflare Tunnel" in §3.
@@ -25,29 +25,54 @@ dials out and publishes no port; see "Cloudflare Tunnel" in §3.
v v v
+--------------+ +--------+ +-------------+
| caddy | | gitea | | liquidsoap |
| (TLS, SPA, | | (git + | | harbor |
| reverse | | CI) | | (live DJ) |
| proxy) | +--------+ +------+------+
+------+-------+ | |
| | |
--------------------------------------------- | (same container
| | | | | | | as icecast2)
v v v v v v | |
/api/ /radio/ /gitea/ /sb/ /notes/ /py/ | |
backend icecast2 gitea sb sb-pub python | |
| ^ | |
| | | |
| +---------------------------------------|---------------+
| |
+----------+--------------------------------------+
| (TLS, SPA, | | (fwd | | harbor |
| reverse | | to | | (live DJ) |
| proxy) | | LXC) | +------+------+
| | +--------+ |
+------+-------+ |
| |
--------------------------------------------- (same container
| | | | | | as icecast2)
v v v v v v |
/api/ /radio/ /gitea/ /sb/ /notes/ /py/ |
backend icecast2 gitea sb sb-pub python |
| ^ |
| | |
| +-------------------------------------------------------+
|
+----------+
v
+------+
| db | postgres:16
+------+ (app database + gitea database)
+------+ (app database + the trackers' databases)
vue one-shot build container -> writes vue_dist volume -> caddy serves it
```
### Gitea runs in its own LXC
Gitea (git, Actions, the image registry) is not in this stack. It runs on a
separate Proxmox LXC, from `gitea/docker-compose.yml`, with its own Postgres
(`gitea-db`); the runbook is "Gitea LXC" in §7. The `gitea` service here is
an haproxy TCP forwarder (`gitea/forwarder.cfg`) from this host's 3000 and
2222 to the LXC's LAN IP (`GITEA_UPSTREAM`), under the old container name, so
everything that reached Gitea on stpvm still does at the same address:
```
stpvm Gitea LXC (LAN IP)
caddy /gitea/, /v2/ --+ +------------------+
backend feed ----------+--> gitea:3000 (haproxy) ---> | gitea :3000 |
usaco pulls -----------+ :2222 ------------> | :2222 |
runner, Renovate localhost:3000 | gitea-db |
CI, obsidian localhost:2222 / DOMAIN:2222 +--------+---------+
usaco <-- caddy <-- https://www.DOMAIN/usaco/api/hooks/gitea --+ (webhook,
over the LAN)
```
The LXC is also on the tailnet, so a laptop can use its own name directly.
Deploys of this stack never restart Gitea; recreating the forwarder only
drops connections in flight.
### Who listens where
| Service | Container name | Internal port | Public route | Published to host |
@@ -62,7 +87,7 @@ backend icecast2 gitea sb sb-pub python | |
| jobs (job tracker, published image) | `jobs` | 8080 | `/jobs/` (admin-gated by Caddy `forward_auth`; capture API and userscript public, bearer-token) | no |
| activity-tracker (published image, adamf/ccp) | `activity-tracker` | 8080 | `/tracker/`, prefix stripped (pages admin-gated by Caddy `forward_auth`; `/api/v1/` bearer/app-checked) | no |
| icecast2 + liquidsoap | `${ICECAST_HOST}` | `${ICECAST_PORT}` | `/radio/` | **harbor port only** |
| gitea | `${GITEA_HOST}` | 3000, 2222 | `/gitea/` | **3000, 2222** |
| gitea (haproxy forwarder to the Gitea LXC) | `${GITEA_HOST}` | 3000, 2222 | `/gitea/`, and the registry at the apex `/v2/` | **3000, 2222** |
| vue | `vue` | 5173 (dev only) | `/` (dev only) | no |
| cloudflared | `cloudflared` | — (fixed IP `172.28.255.250`) | all of Caddy, via Cloudflare | no (outbound only) |
| dozzle (log viewer) | `dozzle` | 8080 | `/dozzle/` (admin-gated by Caddy `forward_auth`; reads the Docker socket) | no |
@@ -162,7 +187,8 @@ which has two jobs:
leaves the old containers running.
- **`deploy`** runs only on `main`, only after `test` passes, and only if the
tested commit is still the tip of `main` (so an older run cannot deploy a
newer, untested commit). It fetches over `ssh://git@localhost:2222`,
newer, untested commit). It fetches over `ssh://git@localhost:2222` (the
forwarder to the Gitea LXC),
hard-resets the deploy checkout, and runs
`docker compose up -d --build --remove-orphans` under the
`.compose.lock` flock, shared with the weekly maintenance workflow.
@@ -374,7 +400,7 @@ Setup, once:
| Volume | Holds | Losing it means |
| ---------- | ----------------------------------------------------- | -------------------------------------------------- |
| `dbdata` | Postgres: the app database **and** the Gitea database | All posts, users, messages, and all Gitea metadata |
| `dbdata` | Postgres: the app database and the trackers' databases | All posts, users and messages, and the trackers' data |
| `uploads` | Uploads from before Garage, private attachments, and any upload Garage refused | Those files |
| `garage_meta` | Garage's metadata: buckets, keys, object index, layout | Everything in the bucket (the bytes in `garage_data` are unreadable without it) |
| `garage_data` | The bucket's object bytes | Every upload stored in Garage |
@@ -390,12 +416,14 @@ of deleting the directory:
| `./certbot/conf` | The old certbot certificate and keys | Unused since 2026-11-17; kept as the rollback until it is cleaned up (§7). |
| `./backend/token/` | **Spotify OAuth refresh token** (`spotify_token.json`) | Gitignored. Without this mount, Spotify would need re-authorising after every rebuild. |
| `./jobs-data` | The job tracker's **capture token hash** and Graph OAuth session | Gitignored. Must be owned by uid 1000, the user the `jobs` image runs as. |
| `./gitea/data` | Git repositories, LFS objects, avatars, sessions | The actual git data |
| `./gitea/config` | Gitea's live `app.ini` | Gitignored; generated from the template on first boot and then owned by Gitea |
| `./logs` | Backend logs (`go.log`); Caddy's JSON request-body log in `logs/caddy/payloads.log` | Caddy rotates the payload log itself (50 MiB, five kept). `logs/nginx/` is nginx's, finished. |
| `./icecast2/fallback_music` | Radio fallback MP3s | Copied to the host by hand, not git |
| `${OBSIDIAN_DIR}` | The Obsidian vault (a git clone of the notes repo) | Read-write to backend and silverbullet, **read-only** to silverbullet-public |
Gitea's state (`gitea/data`, `gitea/config`, the `gitea_db` volume) is on
the Gitea LXC, not here; see "Gitea LXC" in §7. stpvm's own `gitea/data` and
`gitea/config` are the pre-move copy, kept as the rollback.
**Ephemeral:** anything else inside a container. Notably the Vue build, the
rendered icecast config, and the Gitea runner's downloaded binary
are all regenerated.
@@ -414,8 +442,9 @@ Two distinct mechanisms read it, and services use both:
- **`env_file: ./.env`** — injects the whole file into the container. Used by
backend, db and icecast2.
`gitea` instead receives explicit `GITEA__section__KEY` variables (Gitea's own
convention for overriding `app.ini` keys), and `python` receives an explicit
Gitea's own variables are in `gitea/.env` on the Gitea LXC (`gitea/.env.example`);
there it receives explicit `GITEA__section__KEY` variables (Gitea's own
convention for overriding `app.ini` keys). Here, `python` receives an explicit
allow-list (as do `jobs`, `caddy` and the rest), so it never sees the database password or any API key other than
the two it uses (`TFL_APP_KEY`, and `CLAUDE_API_KEY`, plus `CLAUDE_MODEL`,
which picks the model). The Python service
@@ -576,7 +605,8 @@ in `traffic` follows the rotation, so it needs no logrotate entry. The
`logs/nginx/*.log` stanza in `/etc/logrotate.d/web_server` is nginx's and
can go when `logs/nginx/` does.
**Reset the database** — destructive; wipes the app database **and Gitea's**:
**Reset the database** — destructive; wipes the app database (Gitea's is on
the Gitea LXC and is not affected):
```
docker compose down
@@ -585,13 +615,8 @@ docker compose up -d
```
The app schema is recreated by GORM auto-migration on backend start (there are no
migration files). **Gitea's database is not auto-created** — the Postgres image
only creates `POSTGRES_DB` on first init, so create `${POSTGRES_GITEA_DB}`
manually before Gitea will start:
```
docker compose exec db createdb -U "$POSTGRES_USER" "$POSTGRES_GITEA_DB"
```
migration files). The job and activity trackers' databases are not
auto-created; their READMEs have the commands.
**Garage (the `/uploads/` bucket).** Public uploads live in a Garage bucket,
with the `uploads` volume as a safety net. Nothing breaks while Garage is down
@@ -652,6 +677,42 @@ Back up `garage_meta` and `garage_data` together (meta without data, or the
reverse, is useless); Garage also snapshots its metadata every 6h inside
`garage_meta`.
**Gitea LXC.** Gitea runs in its own Proxmox LXC (§1), from
`gitea/docker-compose.yml` in a checkout of this repo, with its secrets in
`gitea/.env`. It is deployed by hand, never by CI:
```
cd ~/deploy/web_server/gitea && git pull && docker compose up -d
```
That includes a Renovate PR that bumps its image: merging deploys stpvm, not
the LXC, so pull and `up -d` here afterwards.
- *The container.* Debian, unprivileged, with `nesting=1,keyctl=1` (Docker
needs both), a static LAN IP on stpvm's bridge, Docker and Tailscale.
`GITEA_UPSTREAM` in stpvm's `.env` is that LAN IP; `GITEA_SSH_DOMAIN` in
`gitea/.env` is its tailnet name, which Gitea prints in SSH clone URLs.
- *Webhooks to the site* (usaco's push hook,
`https://www.<DOMAIN>/usaco/api/hooks/gitea`) go straight to stpvm's Caddy
over the LAN: `extra_hosts` pins `www.<DOMAIN>` to `EDGE_IP`, and
`ALLOWED_HOST_LIST` allows that name, since its address is private.
- *Backups.* A Proxmox `vzdump` of the whole LXC covers the git data and the
database together. `gitea/data` alone is not a backup: the issues, PRs,
users and registry index are in `gitea_db`.
- *If it is down,* `/gitea/` and the registry are 502, CI does not run, and
image pulls fail; the site itself keeps serving.
- *Moving it again* (or the first move, from stpvm): stop Gitea, `pg_dump -Fc`
its database and restore it with `pg_restore --no-owner --role=gitea` into
a fresh `gitea-db`, copy `gitea/data` and `gitea/config` with
`tar --numeric-owner` (owned by uid 1000), start it, then point
`GITEA_UPSTREAM` at the new address and `docker compose up -d gitea` on
stpvm. The SSH host key is in `gitea/data`, so clients' `known_hosts` still
match.
- *Rollback to running it on stpvm:* revert the commit that made `gitea` a
forwarder, restore its database into stpvm's `db`, and `docker compose up
-d gitea` with stpvm's own `gitea/data` (the pre-move copy, so anything
pushed since the move has to be copied back from the LXC first).
**Set up the CI runner on a fresh host:**
```