railyard/apps/gitea/docker-compose.yml
2026-11-18 03:49:00 +03:00

265 lines
15 KiB
YAML

# apps/gitea — Railyard's code-hosting service: the official go-gitea/gitea
# image (MIT) + Postgres. Replaces the from-scratch "Rithub + Rit" build
# (apps/rit, apps/rithub — Rust, preserved, not deleted) per
# plans/OSS-ADOPTION-2026-10-15.md.
#
# app.ini is generated entirely from GITEA__<SECTION>__<KEY> environment
# variables (Gitea's "environment-to-ini" mechanism) — no app.ini file is
# committed. Branding overrides (logo, footer, locale strings) live in
# ./custom and are bind-mounted over the persistent /data volume's
# gitea/custom subdirectory, Gitea's documented customization path.
#
# Local proof (this machine): HTTP on 3300, SSH on 2222 (both non-default to
# avoid clashing with other local services / the eventual Oracle box's :22).
# Production (Oracle ARM box): see deploy/RUNBOOK.md — same compose file,
# Cloudflare Tunnel in front of HTTP, SSH opened on a non-22 port in the
# box's security list.
#
# Usage:
# cd apps/gitea
# cp .env.example .env # fill in secrets (or export them)
# docker compose up -d
# docker compose exec gitea gitea admin user create --admin \
# --username <name> --password <pass> --email <email>
services:
gitea-postgres:
image: postgres:17
restart: unless-stopped
environment:
POSTGRES_USER: gitea
POSTGRES_PASSWORD: ${GITEA_DB_PASSWORD:-gitea}
POSTGRES_DB: gitea
volumes:
- gitea-pgdata:/var/lib/postgresql/data
ports:
- "${GITEA_DB_HOST_PORT:-5433}:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U gitea -d gitea"]
interval: 5s
timeout: 5s
retries: 10
gitea:
image: gitea/gitea:${GITEA_IMAGE_TAG:-1.23}
restart: unless-stopped
depends_on:
gitea-postgres:
condition: service_healthy
environment:
USER_UID: 1000
USER_GID: 1000
# --- identity / branding -------------------------------------------------
# APP_NAME has no [section] in app.ini (it's a top-of-file root key), so
# the environment-to-ini mapping uses an empty section segment:
# GITEA + "__" + "" + "__" + APP_NAME.
# 2026-11-17: dropped "(by Railyard)" per owner's Apple-design pass —
# one short product name only, no parenthetical attribution in the
# UI itself (it's still visible everywhere it belongs: OG tags,
# footer, SEO pages).
GITEA____APP_NAME: "Rithub"
# 2026-11-17 (PH launch day -1): stock Gitea boilerplate ("Gitea (Git
# with a cup of tea) is a painless self-hosted Git service written in
# Go") was still rendering in <meta name="description">, og:description
# and twitter:description on every non-repo page (home, explore,
# register, etc.) -- exactly what Product Hunt/Google/X/LinkedIn link
# previews show. Root cause: setting.UI.Meta.{Author,Description,
# Keywords} (modules/setting/ui.go) default to the stock Gitea strings
# and are only overridable via app.ini's [ui.meta] section -- there is
# no template-level override point (templates/base/head.tmpl and
# head_opengraph.tmpl both read {{MetaAuthor}}/{{MetaDescription}}/
# {{MetaKeywords}}, which call straight into this setting). A dotted
# section name must be hex-escaped in the GITEA__ env-var form: "." ->
# "_0x2E_" (confirmed against Gitea's own config_env_test.go, e.g.
# LOG_0x2E_CONSOLE__STDERR -> section "log.console"), so "ui.meta"
# becomes "ui_0x2E_meta" below. This is the officially-supported
# app.ini key, not a template hack -- it also fixes og:description/
# twitter:description for free since head_opengraph.tmpl's non-repo
# branch already reads the same {{MetaDescription}} value (see this
# repo's own templates/base/head_opengraph.tmpl, non-repo branch).
GITEA__ui_0x2E_meta__AUTHOR: "Rithub"
GITEA__ui_0x2E_meta__DESCRIPTION: "Rithub — your own code host. Move from GitHub in 5 minutes."
GITEA__ui_0x2E_meta__KEYWORDS: "git hosting,self-hosted git,github alternative,code host,rithub,move from github"
# Drop the stock "Powered by Gitea" / "Page: Xms Template: Xms"
# footer line (noisy, unbranded, not part of the Apple design pass) —
# our own custom/templates/custom/footer.tmpl already credits Gitea
# by name with a real MIT link, so this isn't losing the license
# credit, just the debug-grade timing line and the duplicate credit.
GITEA__other__SHOW_FOOTER_TEMPLATE_LOAD_TIME: "false"
GITEA__other__SHOW_FOOTER_POWERED_BY: "false"
GITEA__other__SHOW_FOOTER_VERSION: "false"
GITEA__server__DOMAIN: ${GITEA_DOMAIN:-git.ereboslab.com}
GITEA__server__ROOT_URL: ${GITEA_ROOT_URL:-https://git.ereboslab.com/}
# SSH_DOMAIN is deliberately a SEPARATE var from DOMAIN/ROOT_URL above:
# DOMAIN is the Cloudflare-proxied (orange-cloud) public hostname, and
# Cloudflare's proxy only forwards HTTP(S) (80/443) -- it does not
# forward arbitrary TCP ports like 2222, so a clone URL built from
# DOMAIN (ssh://git@git.ereboslab.com:2222/...) times out for every
# end user even once the OCI security list + UFW allow 2222 inbound.
# Point this at a DNS-only (grey-cloud) A/AAAA record for the same box
# instead (e.g. git-ssh.ereboslab.com) -- confirmed 2026-10-25 by a
# real SSH push: hostname-through-Cloudflare timed out, the box's raw
# IP and a grey-cloud hostname both worked.
GITEA__server__SSH_DOMAIN: ${GITEA_SSH_DOMAIN:-git-ssh.ereboslab.com}
# SSH_PORT is the port advertised in clone URLs / the UI; the container
# itself always listens on :22 via the base image's passthrough OpenSSH
# (the default — do NOT also set START_SSH_SERVER=true, Gitea's own
# built-in SSH server, or the two fight over :22 and crash-loop).
GITEA__server__SSH_PORT: ${GITEA_SSH_PUBLIC_PORT:-2222}
GITEA__server__HTTP_PORT: "3000"
GITEA__server__DISABLE_SSH: "false"
GITEA__server__LFS_START_SERVER: "true"
# --- database -------------------------------------------------------------
GITEA__database__DB_TYPE: postgres
GITEA__database__HOST: gitea-postgres:5432
GITEA__database__NAME: gitea
GITEA__database__USER: gitea
GITEA__database__PASSWD: ${GITEA_DB_PASSWORD:-gitea}
# --- secrets (required in production; generate with
# `docker compose run --rm gitea gitea generate secret SECRET_KEY` /
# `... INTERNAL_TOKEN`) -----------------------------------------------
GITEA__security__SECRET_KEY: ${GITEA_SECRET_KEY:-dev-only-secret-key-change-me}
GITEA__security__INTERNAL_TOKEN: ${GITEA_INTERNAL_TOKEN:-dev-only-internal-token-change-me}
# DB/branding are fully supplied above; skip the interactive install
# wizard and boot straight into normal run mode.
GITEA__security__INSTALL_LOCK: "true"
# --- packages / LFS / wiki / actions (the Dec 21/28 roadmap scope) --------
GITEA__packages__ENABLED: "true"
GITEA__packages__LIMIT_TOTAL_OWNER_COUNT: "-1"
GITEA__repository__DISABLE_DOWNLOAD_SOURCE_ARCHIVES: "false"
GITEA__repository__DEFAULT_PRIVATE: "private"
GITEA__actions__ENABLED: "true"
GITEA__actions__DEFAULT_ACTIONS_URL: github
# --- migrations: one-click "Import from GitHub" (/repo/migrate) ----------
# 2026-11-17 (wave7): this section was ABSENT entirely, which per
# Gitea's own docs means ALLOWED_DOMAINS defaults to blank == every
# domain allowed, not just github.com -- the live migrate form could
# already hit any http(s) URL the signed-in user typed, a real SSRF
# surface (internal railyard-box services, cloud metadata endpoints,
# etc.) that nobody had scoped down yet. First attempt used literal
# "github.com" only -- a real live test caught that Gitea's GitHub
# migrator actually dials api.github.com (metadata/issues/PRs) and
# codeload.github.com (archive downloads) as separate hostnames, so
# an exact match alone 500'd every real import ("migration can only
# call allowed HTTP servers ... deny 'api.github.com'"). Glob
# wildcards fixed it. Confirmed live end-to-end after this change: a
# real github.com/octocat/Hello-World migration succeeds (3 commits,
# 3 branches); the same flow against gitlab.com now fails fast with
# Gitea's own "You can not import from disallowed hosts" 422 instead
# of ever issuing the fetch.
GITEA__migrations__ALLOWED_DOMAINS: "github.com,*.github.com,*.githubusercontent.com"
GITEA__migrations__ALLOW_LOCALNETWORKS: "false"
# --- accounts: native Gitea auth, or Railyard SSO once registered --------
# CLOSED (backlog item 5, was TODO(railyard-sso)): apps/console now
# exposes a real OIDC discovery endpoint (lib/oidc.ts, /oidc/{authorize,
# token,userinfo,jwks}). Register it once RAILYARD_OIDC_SIGNING_KEY and
# RAILYARD_OIDC_CLIENTS (client_id "railyard-id" below) are set on
# console:
# docker compose exec gitea gitea admin auth add-oauth \
# --name railyard-id --provider openidConnect \
# --key railyard-id --secret <the RAILYARD_OIDC_CLIENTS secret> \
# --auto-discover-url https://railyard.ereboslab.com/.well-known/openid-configuration \
# --group-claim-name groups --admin-group railyard-admins
# The redirect_uri Gitea will present is
# <GITEA_ROOT_URL>user/oauth2/railyard-id/callback -- it must exactly
# match the redirect_uri configured for "railyard-id" in console's
# RAILYARD_OIDC_CLIENTS. Native accounts stay available alongside this;
# the webhook-bridge billing hook (integrations/railyard/) is unaffected
# either way.
# 2026-11-17: default flipped to open (was accidentally left "true" in
# the box's .env, silently blocking every "Move from GitHub" signup —
# nobody but the admin could ever get a Rithub account). No mailer is
# configured (ENABLED false below), so REGISTER_EMAIL_CONFIRM must stay
# false too (turning it on with no mailer would just brick signup the
# same way). Built-in image captcha substitutes for email verification
# as the anti-spam gate -- no external API key, no SMTP needed.
GITEA__service__DISABLE_REGISTRATION: ${GITEA_DISABLE_REGISTRATION:-false}
GITEA__service__REGISTER_EMAIL_CONFIRM: "false"
GITEA__service__ENABLE_CAPTCHA: "true"
GITEA__service__CAPTCHA_TYPE: ${GITEA_CAPTCHA_TYPE:-cfturnstile}
GITEA__service__CF_TURNSTILE_SITEKEY: ${GITEA_CF_TURNSTILE_SITEKEY:-}
GITEA__service__CF_TURNSTILE_SECRET: ${GITEA_CF_TURNSTILE_SECRET:-}
GITEA__service__REQUIRE_CAPTCHA_FOR_LOGIN: "false"
GITEA__openid__ENABLE_OPENID_SIGNIN: "false"
GITEA__mailer__ENABLED: "false"
# --- Sign in with GitHub/Google/Apple (2026-11-18) ------------------
# Sources themselves are added via `gitea admin auth add-oauth`, not
# app.ini (Gitea has no app.ini key to declare an OAuth2 source) --
# see apps/gitea/scripts/add-rithub-oauth-sources.sh, run on
# railyard-box reading /etc/products/rithub-oauth.env (owner-filled,
# root-only). These two keys are the app.ini side: a first OAuth
# login creates the Rithub account directly (no separate sign-up
# form), and auto-links to an existing native account on matching
# verified email instead of erroring with "email already used".
GITEA__oauth2_client__ENABLE_AUTO_REGISTRATION: "true"
GITEA__oauth2_client__ACCOUNT_LINKING: auto
volumes:
- gitea-data:/data
# The official Docker image collapses Gitea's normal "custom/" override
# dir straight into /data/gitea (CustomPath == WorkPath in this image,
# NOT /data/gitea/custom) — bind-mount only the public/templates/options
# subpaths, never the whole /data/gitea, or this would shadow conf/,
# the sqlite/log dirs and ssh host keys that live there too.
- ./custom/public:/data/gitea/public:ro
- ./custom/templates:/data/gitea/templates:ro
# 2026-11-18: locale override (custom/options/locale/locale_en-US.ini)
# to kill visible "Gitea" text on /repo/migrate and the repo Signing
# Verification Settings page — see plans/railyard.md PH-visitor QA
# finding #1 (HIGH). Gitea's locale loader does a full-file swap, not
# a per-key merge, when a custom locale file exists for a language
# (confirmed in modules/translation/translation.go + options/base.go
# for 1.23.8) — this file is a full copy of the stock en-US locale
# with only the "Gitea"-literal strings edited, not a short snippet,
# or every other English string on the site would go blank.
- ./custom/options:/data/gitea/options:ro
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "${GITEA_HTTP_HOST_PORT:-3300}:3000"
- "${GITEA_SSH_HOST_PORT:-2222}:22"
# Gitea Actions CI runner (closes the "forge CI runners" gap from
# plans/OSS-ADOPTION-2026-10-15.md — Gitea's built-in Actions covers the
# pipeline definition/UI, this is what actually *executes* a pushed
# `.gitea/workflows/*.yml` job; without it the Actions tab is cosmetic).
# `profiles: [actions]` keeps this out of a bare `docker compose up -d`
# (it must be started by name: `docker compose up -d act_runner`) — a
# fresh clone/box must never fail to bring up gitea+postgres just because
# a runner token doesn't exist yet. Requires a one-time registration token:
# docker compose exec -u git gitea gitea actions generate-runner-token
# then put it in .env as GITEA_RUNNER_TOKEN before the up -d above. Token
# is consumed on first boot: act_runner persists its signed credentials in
# the gitea-runner-data volume (`.runner` file) and reconnects with those
# on every restart, so the token env var is only read once per fresh
# volume. Starting this with GITEA_RUNNER_TOKEN still unset/blank is safe
# (no required-var interpolation failure that could block the rest of the
# stack) — act_runner just exits/restarts with a clear "no token" error
# until a real one is set.
act_runner:
image: gitea/act_runner:${ACT_RUNNER_IMAGE_TAG:-0.6.1}
profiles: ["actions"]
restart: unless-stopped
depends_on: [gitea]
environment:
# Internal compose-network hostname, not the public HTTPS URL — the
# runner calls Gitea's gRPC/HTTP registration+task API directly inside
# the shared docker network, so it doesn't depend on the public DNS
# name, TLS termination, or Cloudflare being reachable from the box's
# own loopback. Override only if act_runner runs on a different host
# than the gitea container (e.g. a dedicated runner box).
GITEA_INSTANCE_URL: ${ACT_RUNNER_INSTANCE_URL:-http://gitea:3000}
GITEA_RUNNER_REGISTRATION_TOKEN: ${GITEA_RUNNER_TOKEN:-}
GITEA_RUNNER_NAME: ${GITEA_RUNNER_NAME:-railyard-box}
# No CONFIG_FILE: act_runner runs fine on its built-in defaults from
# just the env vars above (DooD via the mounted socket, default
# `ubuntu-latest`-style labels) — a mounted config.yaml is only
# needed to override those defaults, which nothing here requires yet.
volumes:
- gitea-runner-data:/data
- /var/run/docker.sock:/var/run/docker.sock
volumes:
gitea-pgdata:
gitea-data:
gitea-runner-data: