Files
stpweb/gitea/docker-compose.yml
T
adamfandClaude Opus 5.5 fc777ba8b2
Test and deploy / test (push) Successful in 21s
Test and deploy / deploy (push) Successful in 2s
Add a cloudflared connector for git.DOMAIN on the Gitea LXC
Gitea gets its own remotely managed Cloudflare tunnel, run beside it on the
LXC, so public HTTPS for git.DOMAIN no longer has to pass through stpvm. It is
a separate tunnel from the site's, since a tunnel's connectors share all its
hostnames. It sits behind the `tunnel` profile until git.DOMAIN is the
canonical address, so a routine `docker compose up -d` does not publish it
early.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 16:33:42 +00:00

153 lines
7.2 KiB
YAML

# =============================================================================
# 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
# Public HTTPS for git.DOMAIN through Gitea's OWN Cloudflare tunnel, so the
# public Gitea no longer passes through stpvm. Remotely managed: the
# hostname -> origin mapping (git.DOMAIN -> http://gitea:3000) lives in the
# Zero Trust dashboard and only the token is here. It must be a separate
# tunnel from the site's: connectors of one tunnel share all its hostnames,
# so a second connector here would be sent www traffic too.
#
# The tunnel carries HTTP only, with Cloudflare's 100 MB request-body cap, so
# SSH (2222), registry pushes and CI stay on the LAN/tailnet path above.
#
# Behind the `tunnel` profile until git.DOMAIN is the canonical address
# (ROOT_URL, the history-view protection), so a routine `docker compose up
# -d` does not publish it early: start it with
# docker compose --profile tunnel up -d
# and drop the profile once the cutover is done.
cloudflared:
image: cloudflare/cloudflared:2026.9.3
container_name: gitea-cloudflared
profiles: ["tunnel"]
restart: always
command: ["tunnel", "--no-autoupdate", "run"]
environment:
- TUNNEL_TOKEN=${GITEA_TUNNEL_TOKEN:-}
depends_on:
- gitea