Self Host Wizard Docs

Git hosting (forgejo)

Git hosting on a Self Host Wizard box: the forgejo piece, served at git.<apps domain>, oidc sign-in, memory limit 280 MB.

At a glance

FieldValue
Addresshttps://git.<apps domain>
Sign-inoidc: OpenID Connect through Authelia: the office sign-in carries over
Memory limit280 MB (ram_mb: measured peak × 1.3)
Databasenone shared: it keeps its own data in THX_DATA
Needslldap, authelia, stalwart
Needed bynothing
Containersforgejo
Image: forgejocodeberg.org/forgejo/forgejo:15.0.12-rootless@sha256:b670d7724274e1d5c7801b76017b7267e6e5432aa4fe8bed49f781d09476b9dd
Public ports2222/tcp
Set-up script after startscripts/post-up.sh, daily
Licence (from the README)GPL-3.0-or-later
Upstream (from the README)https://forgejo.org

Turn it on

thx enable adds forgejo and everything it needs to the box's state; thx apply then installs it. Apps are applied only once site_domain is set.

sudo thx enable forgejo
sudo thx apply

Engineering notes (pieces/forgejo/README.md)

Upstream: Forgejo 15.0.12 (LTS line), GPL-3.0-or-later, image codeberg.org/forgejo/forgejo:15.0.12-rootless, pinned by multi-arch index digest (docker buildx imagetools inspect lists linux/amd64 and linux/arm64). We ship compose and config only. 15 is the long-term-support line (17.0.2 is the newest; 15 gets fixes for longer and has everything used here).

Served at https://git.<apps_domain>; git over ssh on public port 2222.

What it does on the box

  • One container, SQLite (WAL) in THX_DATA, built-in ssh server (the rootless image has no OpenSSH). The image runs as uid 1000, so THX_DATA must be owned by 1000:1000 (data_owner in piece.toml).
  • Login only through Authelia (OpenID Connect, source name authelia). First login creates the account (username = preferred_username = LLDAP uid, email from LLDAP). No local sign-up, no password form (ENABLE_INTERNAL_SIGNIN=false). Anonymous visitors see nothing (REQUIRE_SIGNIN_VIEW), new repositories are private.
  • Login is automatic. Forgejo has no setting to skip its login page, so piece.toml's [oidc] login_page/login_start has Caddy send a person who arrives at /user/login from outside Forgejo (a link, a bookmark, Forgejo's own redirect from /) straight on to /user/oauth2/authelia, keeping redirect_to. Someone already signed in to the office lands inside without a click; anyone else signs in at Authelia once and comes back. After signing out of Forgejo the login page stays (the request comes from Forgejo itself), and a failed sign-in shows Forgejo's error instead of looping (one automatic try a minute).
  • Companies → organizations. post_up creates one organization per org in THX_ORGS, each with a members team (write on all repos, may create repos). The login source maps groups on every login, and removes memberships when the group goes away:

    LLDAP groupForgejo
    adminssite administrator
    org-<org>team members of organization <org>
    team-<org>-adminsteam Owners of organization <org> (org settings, runners, secrets)

    Organizations are never deleted by thx; an org removed from state just stops being mapped. Other team-<org>-<team> groups are not mapped yet (one line each in the map if wanted).

  • A local service account thx-admin (password = THX_SECRET_ADMIN_PASSWORD, only on the box) exists for post_up's API calls and owns every organization it created. It is also the break-glass path while Authelia is down: the API (basic auth) and forgejo admin in the container, not the web UI.
  • Packages and the container registry are on (git.<apps_domain>/v2/, /api/packages/<org>/…).
  • Mail through THX_SMTP_HOST:THX_SMTP_PORT from THX_MAIL_FROM (certificate not checked on the private piece network: stalwart's certificate is not for the name stalwart).
  • Actions are on, but no runner runs on the box. The box has 2 cores shared with mail; a CI job would starve it. Each company runs its runner on its own machine (below).

Using it

  • https: git clone https://git.<apps_domain>/<org>/<repo>.git. Accounts have no password (they log in through Authelia), so git over https uses a personal access token as the password: Settings → Applications → Generate new token, scope repository: read and write.
  • ssh: add a key in Settings → SSH / GPG keys, then git clone ssh://git@git.<apps_domain>:2222/<org>/<repo>.git.

Registering a CI runner on another machine

Forgejo Runner 13 no longer uses register; the runner is created in Forgejo and the runner machine gets its UUID and token. This is the exact path the test runs.

  1. In Forgejo, an org owner (LLDAP group team-<org>-admins) opens Organization → Settings → Actions → Runners and creates a runner, or calls the API: curl -X POST -H "Authorization: token <PAT>" -H 'Content-Type: application/json' -d '{"name":"office-pc"}' https://git.<apps_domain>/api/v1/orgs/<org>/actions/runners → {"uuid": "…", "token": "…"}. Keep the token secret.
  2. On the runner machine (any Linux PC or VM with Docker), write config.yml:

    runner:
      file: /data/.runner
      capacity: 1
      labels: ["docker:docker://node:22-bookworm"]
    server:
      connections:
        office:
          url: https://git.<apps_domain>/
          uuid: <uuid>
          token: <token>
  3. Run it (image pinned like everything else; check the digest with docker buildx imagetools inspect data.forgejo.org/forgejo/runner:13.2.2):

    docker run -d --name forgejo-runner --restart unless-stopped \
      -v "$PWD/config.yml:/config.yml:ro" -v runner-data:/data \
      -v /var/run/docker.sock:/var/run/docker.sock --group-add "$(stat -c %g /var/run/docker.sock)" \
      data.forgejo.org/forgejo/runner:13.2.2 forgejo-runner daemon -c /config.yml

    Jobs with runs-on: docker then run in throwaway containers on that machine. Mounting the Docker socket gives jobs root on that machine: use a machine dedicated to CI.

  4. Workflows live in .forgejo/workflows/*.yml (GitHub Actions syntax).

The test proves steps 1–2 and a job run end to end, with a self-hosted:host label (job steps run inside the runner container, no Docker needed). The docker:// label variant above is the upstream-documented way and was not run here (it needs Docker inside the test).

Mirroring to GitHub

Per repository: Settings → Repository → Mirror settings → Push mirror. Remote URL https://github.com/<owner>/<repo>.git, username = GitHub user, password = a GitHub fine-grained token with Contents: read and write on that repo; tick Sync when commits are pushed. Forgejo then pushes every branch and tag to GitHub. To bring a GitHub repo in, use New migration → GitHub (one-off copy, or a pull mirror that re-fetches on an interval).

Measured (dev PC, amd64, test.sh)

RAM: three runs peaked at 187, 214 and 134 MiB (docker stats, which includes page cache) over the whole test (login, token, repo, https + ssh push, package upload, Actions job, mail). ram_mb = 280 (214 × 1.3 = 278). Large pushes, git gc on big repos and the code/issue indexers can exceed this; raise it from a measurement if it OOMs.

Test

HEAVY_CLASS=check ~/.cache/run-heavy.sh 4G pieces/forgejo/test.sh — throwaway LLDAP, Authelia, Caddy (self-signed CA), a mail catcher answering as stalwart. Proves: post_up converges and a second run changes nothing; alice (LLDAP, org-acme) logs in via OIDC and is auto-registered; she makes a token in the web UI, is in org acme only, creates acme/hello (and cannot create in beta), pushes over https through Caddy/TLS and over ssh; generic package upload; /v2/ answers; boss (admins) is a site admin and, as team-acme-admins, creates an org runner; a runner container connects and runs a pushed workflow to success; a mail reaches the catcher. Prints PASS forgejo ram_peak_mb=<n>.

testkit/thxtest.py is the shared throwaway-SSO harness for every piece test of this lane.

Known gaps

  • OIDC users have no password, so https git needs a token (as on GitHub). LDAP basic auth for git would need a second login source per user; not done.
  • team-<org>-<team> groups other than -admins are not mapped to Forgejo teams.
  • No runner on the box by design.

Facts on this page come from these files in the selfhostwizard repository:

  • pieces/forgejo/piece.toml
  • pieces/forgejo/compose.yaml
  • pieces/forgejo/README.md
  • internal/piece/piece.go

This page is generated from the code at build time, so it changes when the code does.