Move Gitea to its own LXC; keep a forwarder on stpvm
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:
@@ -0,0 +1,30 @@
|
||||
# =============================================================================
|
||||
# gitea/.env.example — variables for gitea/docker-compose.yml (the Gitea LXC).
|
||||
#
|
||||
# Copy to gitea/.env on the LXC and fill in. Separate from the site's .env on
|
||||
# purpose: the LXC holds Gitea's secrets and nothing of the site's.
|
||||
# NOTHING IN THIS FILE HAS A REAL VALUE.
|
||||
# =============================================================================
|
||||
|
||||
# Gitea's own Postgres (the gitea-db service). Created on first init.
|
||||
GITEA_DB_NAME=gitea
|
||||
GITEA_DB_USER=gitea
|
||||
GITEA_DB_PASSWORD=
|
||||
|
||||
# Passed as GITEA__section__KEY overrides so the committed app.ini.template
|
||||
# can keep those fields blank. Moving from stpvm, copy the existing values
|
||||
# from the site's .env (they had the same names there); a fresh install
|
||||
# generates each as a long random string.
|
||||
GITEA_INTERNAL_TOKEN=
|
||||
GITEA_LFS_JWT_SECRET=
|
||||
GITEA_OAUTH2_JWT_SECRET=
|
||||
|
||||
# This LXC's Tailscale MagicDNS name (e.g. stpgit.tailf20278.ts.net), shown in
|
||||
# Gitea's SSH clone URLs. Becomes Gitea's SSH_DOMAIN and DOMAIN.
|
||||
GITEA_SSH_DOMAIN=
|
||||
|
||||
# The site's public domain (no www), and stpvm's LAN IP, where Caddy listens.
|
||||
# Webhooks to https://www.DOMAIN/... are sent there directly (see the compose
|
||||
# file's extra_hosts).
|
||||
DOMAIN=
|
||||
EDGE_IP=
|
||||
@@ -9,8 +9,8 @@
|
||||
; SECRET FIELDS ARE DELIBERATELY BLANK HERE
|
||||
; LFS_JWT_SECRET, PASSWD, SECRET_KEY and JWT_SECRET are empty on purpose so
|
||||
; nothing sensitive is committed. Real values arrive at runtime as
|
||||
; GITEA__section__KEY environment variables from ./.env (see
|
||||
; docker-compose.yml), which override app.ini. SECRET_KEY is the exception —
|
||||
; GITEA__section__KEY environment variables from gitea/.env (see
|
||||
; gitea/docker-compose.yml), which override app.ini. SECRET_KEY is the exception —
|
||||
; Gitea generates one itself on first run and writes it into the live app.ini.
|
||||
;
|
||||
; SETTINGS WORTH KNOWING
|
||||
@@ -18,23 +18,27 @@
|
||||
; every link, clone URL and OAuth redirect Gitea emits will be wrong.
|
||||
; START_SSH_SERVER = true with SSH_PORT 2222: the rootless image cannot bind
|
||||
; 22 and cannot use the host's sshd, so Gitea runs its own Go SSH server.
|
||||
; 2222 is published in docker-compose.yml; the deploy workflow clones over
|
||||
; 2222 is published in gitea/docker-compose.yml (on the Gitea LXC) and
|
||||
; forwarded on stpvm, so the deploy workflow still clones over
|
||||
; ssh://git@localhost:2222.
|
||||
; SSH_DOMAIN and DOMAIN are not set here: they come from GITEA_SSH_DOMAIN in
|
||||
; ./.env (see docker-compose.yml). The value is the host's Tailscale
|
||||
; gitea/.env (see gitea/docker-compose.yml). The value is the Gitea LXC's Tailscale
|
||||
; MagicDNS name, not the public domain: SSH
|
||||
; (22 and 2222) is not forwarded by the router, so the SSH clone URL Gitea
|
||||
; shows only works from a device on the tailnet. HTTPS clones go through
|
||||
; Caddy at ROOT_URL and stay public.
|
||||
; REVERSE_PROXY_LIMIT = 1 / TRUSTED_PROXIES = * : trust exactly one hop of
|
||||
; X-Forwarded-For, i.e. our Caddy, so Gitea logs real client IPs. Caddy
|
||||
; sends a single entry, the visitor (its `proxy` snippet). This is only
|
||||
; safe because Caddy is the sole edge.
|
||||
; sends a single entry, the visitor (its `proxy` snippet). stpvm's
|
||||
; forwarder is TCP-level and adds no hop. This is only safe because Caddy
|
||||
; is the sole edge (3000 on the LXC is reachable from the LAN and the
|
||||
; tailnet, never from the internet).
|
||||
; INSTALL_LOCK = true skips the first-run web installer.
|
||||
; DISABLE_REGISTRATION = true — single-user instance; nobody can sign up.
|
||||
; OFFLINE_MODE = true — no calls out to gravatar/CDNs.
|
||||
; DB_TYPE postgres pointing at the shared `db` container, in its own database
|
||||
; alongside the app's. WORK_PATH/APP_DATA_PATH are /var/lib/gitea, the
|
||||
; DB_TYPE postgres; the host, name and credentials come from gitea/.env
|
||||
; (gitea/docker-compose.yml), pointing at its own `gitea-db` container.
|
||||
; The HOST below is only the seed value. WORK_PATH/APP_DATA_PATH are /var/lib/gitea, the
|
||||
; rootless image's layout (the root image uses /data instead).
|
||||
; =============================================================================
|
||||
APP_NAME = Gitea: Git with a cup of tea
|
||||
@@ -68,9 +72,9 @@ OFFLINE_MODE = true
|
||||
[database]
|
||||
PATH = /var/lib/gitea/data/gitea.db
|
||||
DB_TYPE = postgres
|
||||
HOST = db
|
||||
HOST = gitea-db:5432
|
||||
NAME = gitea
|
||||
USER = postgres
|
||||
USER = gitea
|
||||
PASSWD =
|
||||
SCHEMA =
|
||||
SSL_MODE = disable
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
# =============================================================================
|
||||
# gitea/docker-compose.yml — Gitea and its database, on the Gitea LXC.
|
||||
#
|
||||
# WHAT IT DOES
|
||||
# Runs the self-hosted git server (also the Actions server and the image
|
||||
# registry) and a Postgres that holds nothing but Gitea's database. It does
|
||||
# NOT run on stpvm: it runs in its own Proxmox LXC, so a bad deploy of the
|
||||
# site stack, a site Postgres problem or load on stpvm cannot take down the
|
||||
# git server and CI you would use to fix them. DEPLOYMENT.md §7, "Gitea
|
||||
# LXC", is the runbook (setup, upgrade, backup, rollback).
|
||||
#
|
||||
# WHEN IT RUNS
|
||||
# By hand, on the LXC, from this directory:
|
||||
# cd ~/deploy/web_server/gitea && git pull && docker compose up -d
|
||||
# Deliberately NOT by CI. The runner that would deploy it lives on stpvm and
|
||||
# deploys stpvm; letting CI redeploy the server CI itself runs on is the
|
||||
# coupling this split exists to remove. A Renovate PR that bumps the image
|
||||
# below is therefore deployed by hand here after it merges.
|
||||
#
|
||||
# HOW THE SITE REACHES IT
|
||||
# stpvm's stack keeps a `gitea` service, but it is a TCP forwarder
|
||||
# (haproxy, gitea/forwarder.cfg) pointed at this host's LAN IP. So the Caddy
|
||||
# routes, the registry at /v2/, the backend's activity feed, usaco's pulls,
|
||||
# and everything on stpvm that says localhost:3000 or localhost:2222 (the
|
||||
# runner, every repo's CI, Renovate, the obsidian checkout) still work
|
||||
# unchanged. Clients on the tailnet can also use this host's own name.
|
||||
#
|
||||
# ENV VARS
|
||||
# Read from ./.env in THIS directory (gitea/.env, gitignored), not the
|
||||
# site's .env. gitea/.env.example lists them.
|
||||
# =============================================================================
|
||||
|
||||
volumes:
|
||||
# PERSISTENT: Gitea's relational data (users, issues, PRs, Actions runs,
|
||||
# registry metadata). The git objects themselves are in ./data. Back the two
|
||||
# up together: Proxmox's vzdump of the whole LXC does that.
|
||||
gitea_db:
|
||||
|
||||
services:
|
||||
# Postgres 16, the same major as the site's `db`, so the pg_dump taken
|
||||
# there restores here with no surprises. Owned by its own `gitea` role, and
|
||||
# POSTGRES_DB means the image creates the database on first init (it had to
|
||||
# be created by hand in the shared instance).
|
||||
gitea-db:
|
||||
image: postgres:16
|
||||
container_name: gitea-db
|
||||
restart: always
|
||||
environment:
|
||||
- POSTGRES_USER=${GITEA_DB_USER:-gitea}
|
||||
- POSTGRES_PASSWORD=${GITEA_DB_PASSWORD}
|
||||
- POSTGRES_DB=${GITEA_DB_NAME:-gitea}
|
||||
volumes:
|
||||
- gitea_db:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
start_period: 30s
|
||||
|
||||
# ROOTLESS image: runs as an unprivileged user, so config lives in /etc/gitea
|
||||
# and data in /var/lib/gitea (not /data as in the root image) — that is why
|
||||
# the bind mounts look unlike most Gitea compose examples.
|
||||
#
|
||||
# The GITEA__section__KEY environment convention is Gitea's own: each maps to
|
||||
# an app.ini key and overrides the file at runtime, which is how the secrets
|
||||
# stay in .env instead of in the committed app.ini.template.
|
||||
#
|
||||
# entrypoint is overridden to run our wrapper (which materialises app.ini
|
||||
# from the template on first boot) before handing off to Gitea's real
|
||||
# docker-entrypoint.sh. dumb-init is kept as PID 1 for correct signal/zombie
|
||||
# handling, exactly as the stock image does it.
|
||||
gitea:
|
||||
image: docker.gitea.com/gitea:1.25.4-rootless
|
||||
container_name: gitea
|
||||
entrypoint: ["/usr/bin/dumb-init", "--", "/etc/gitea/entrypoint.sh"]
|
||||
environment:
|
||||
- GITEA__database__DB_TYPE=postgres
|
||||
- GITEA__database__HOST=gitea-db:5432
|
||||
- GITEA__database__NAME=${GITEA_DB_NAME:-gitea}
|
||||
- GITEA__database__USER=${GITEA_DB_USER:-gitea}
|
||||
- GITEA__database__PASSWD=${GITEA_DB_PASSWORD}
|
||||
- GITEA__server__LFS_JWT_SECRET=${GITEA_LFS_JWT_SECRET}
|
||||
- GITEA__security__INTERNAL_TOKEN=${GITEA_INTERNAL_TOKEN}
|
||||
- GITEA__oauth2__JWT_SECRET=${GITEA_OAUTH2_JWT_SECRET}
|
||||
# The name Gitea prints in SSH clone URLs: a tailnet MagicDNS name, since
|
||||
# 2222 is not reachable from the internet. Blank means localhost.
|
||||
- GITEA__server__SSH_DOMAIN=${GITEA_SSH_DOMAIN:-localhost}
|
||||
- GITEA__server__DOMAIN=${GITEA_SSH_DOMAIN:-localhost}
|
||||
# Webhooks are refused to private addresses by default ("external").
|
||||
# The usaco site's push hook goes to https://www.DOMAIN/usaco/..., which
|
||||
# extra_hosts below sends to stpvm's Caddy on the LAN, a private address,
|
||||
# so that one name is allowed explicitly.
|
||||
- GITEA__webhook__ALLOWED_HOST_LIST=external,www.${DOMAIN}
|
||||
- USER_UID=1000
|
||||
- USER_GID=1000
|
||||
# Webhooks to the site go straight to Caddy on stpvm over the LAN rather
|
||||
# than out through Cloudflare and back down the tunnel. Caddy still
|
||||
# terminates TLS with the real certificate, so the name has to be the
|
||||
# public one. The container does not read the LXC's /etc/hosts, hence here.
|
||||
extra_hosts:
|
||||
- "www.${DOMAIN}:${EDGE_IP}"
|
||||
restart: always
|
||||
volumes:
|
||||
# PERSISTENT: repositories, LFS objects, avatars, sessions, the SSH host
|
||||
# key, registry blobs. The git data itself.
|
||||
- ./data:/var/lib/gitea
|
||||
# PERSISTENT: app.ini is generated into this host directory on first boot
|
||||
# and then edited by Gitea itself, so it is gitignored — only the
|
||||
# template is committed.
|
||||
- ./config:/etc/gitea
|
||||
# Mounted over the config dir so the wrapper script is available at the
|
||||
# path the overridden entrypoint points at.
|
||||
- ./entrypoint.sh:/etc/gitea/entrypoint.sh:ro
|
||||
# Match the host's clock/zone so commit and CI timestamps are local time.
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
ports:
|
||||
# 2222 = Gitea's *built-in* SSH server (the rootless image cannot use 22).
|
||||
# 3000 = HTTP. Both are reached by stpvm's forwarder over the LAN and by
|
||||
# tailnet clients directly; neither is forwarded by the router.
|
||||
- "2222:2222"
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
gitea-db:
|
||||
condition: service_healthy
|
||||
+3
-3
@@ -17,15 +17,15 @@
|
||||
# it to re-seed, which loses any UI-made settings).
|
||||
#
|
||||
# WHEN IT RUNS
|
||||
# Container start. docker-compose.yml overrides gitea's entrypoint to
|
||||
# Container start. gitea/docker-compose.yml overrides gitea's entrypoint to
|
||||
# ["/usr/bin/dumb-init", "--", "/etc/gitea/entrypoint.sh"], keeping dumb-init
|
||||
# as PID 1 for signal handling exactly as the stock image does, and inserting
|
||||
# this script ahead of Gitea's own docker-entrypoint.sh.
|
||||
#
|
||||
# WHERE THE SECRETS ACTUALLY COME FROM
|
||||
# Not from the template. docker-compose.yml passes GITEA__section__KEY
|
||||
# Not from the template. gitea/docker-compose.yml passes GITEA__section__KEY
|
||||
# environment variables (database credentials, LFS_JWT_SECRET,
|
||||
# INTERNAL_TOKEN, OAUTH2 JWT_SECRET) sourced from ./.env; Gitea applies those
|
||||
# INTERNAL_TOKEN, OAUTH2 JWT_SECRET) sourced from gitea/.env; Gitea applies those
|
||||
# over whatever app.ini says. That is why the template can safely ship with
|
||||
# those fields empty.
|
||||
#
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# =============================================================================
|
||||
# gitea/forwarder.cfg — haproxy config for the `gitea` service on stpvm.
|
||||
#
|
||||
# Gitea itself runs in its own LXC (gitea/docker-compose.yml). This forwards
|
||||
# stpvm's Gitea ports to it, unchanged, at the TCP level:
|
||||
# :3000 HTTP — Caddy's /gitea/ and /v2/ routes, the backend's activity
|
||||
# feed and usaco's pulls reach it as gitea:3000 on
|
||||
# app-network; the runner and Renovate as localhost:3000.
|
||||
# :2222 SSH — every repo's CI (ssh://git@localhost:2222), the obsidian
|
||||
# checkout and silverbullet-git (DOMAIN:2222, pinned to this
|
||||
# host), and laptops using stpvm's tailnet name.
|
||||
# So nothing that talked to Gitea on stpvm had to change address.
|
||||
#
|
||||
# TCP mode, not HTTP: the bytes are passed through untouched, so Caddy's
|
||||
# X-Forwarded-For still reaches Gitea (which trusts one hop of it), SSH just
|
||||
# works, and there is no second body-size limit on registry uploads.
|
||||
#
|
||||
# GITEA_UPSTREAM is the LXC's LAN IP, set in the site's .env. An IP and not a
|
||||
# name: Docker's DNS cannot see tailnet or LAN names.
|
||||
# =============================================================================
|
||||
global
|
||||
log stdout format raw local0 notice
|
||||
|
||||
defaults
|
||||
mode tcp
|
||||
log global
|
||||
option tcplog
|
||||
timeout connect 5s
|
||||
# Inactivity timeouts, not total ones. A large clone or image layer upload
|
||||
# keeps bytes moving; an idle `git` waiting on a slow server-side pack
|
||||
# should not be cut off at a minute, so these are generous.
|
||||
timeout client 1h
|
||||
timeout server 1h
|
||||
# Start even if the upstream does not resolve yet (dev has no Gitea at
|
||||
# all); connections then fail rather than the container.
|
||||
default-server init-addr last,libc,none
|
||||
|
||||
frontend http
|
||||
bind :3000
|
||||
default_backend gitea_http
|
||||
|
||||
frontend ssh
|
||||
bind :2222
|
||||
default_backend gitea_ssh
|
||||
|
||||
backend gitea_http
|
||||
server gitea "${GITEA_UPSTREAM}:3000"
|
||||
|
||||
backend gitea_ssh
|
||||
server gitea "${GITEA_UPSTREAM}:2222"
|
||||
Reference in New Issue
Block a user