OpenTofu + Ansible that provision and maintain a self-hosted Forgejo on the Pit homelab. https://forgejo.thepit.space
  • Shell 54.1%
  • Makefile 17.7%
  • Python 13.3%
  • HCL 10.5%
  • Jinja 4.4%
Find a file
Pedro Paredes 624e2cb9f9
All checks were successful
deploy (play) the deploy play
deploy / deploy (push) Successful in 4m5s
The apt cache refresh is preparation, not a change (THE-125) (!117)
Reviewed-on: #117
Reviewed-by: Minos <noreply+minos@thepit.space>
2026-12-03 06:38:05 +00:00
.forgejo/workflows The update flow opens the pull requests that move a pinned version (THE-40) (!110) 2026-12-02 15:01:53 +00:00
.mise/locks/pypi-ansible-core/2.21.5 predeploy snapshots on both Guests, and preflight goes (FO-59) (!89) 2026-11-11 11:41:48 +00:00
.out-of-scope docs(out-of-scope): a rejected request keeps its reason (FO-36) (!74) 2026-10-20 07:58:50 +00:00
bao/recipients The forge's env map gains the actor axis, and every row names its actors (FO-62) (!90) 2026-11-11 17:42:19 +00:00
docs The page says which claim each of the two roles binds (THE-40) (!115) 2026-12-03 06:32:38 +00:00
forgejo The apt cache refresh is preparation, not a change (THE-125) (!117) 2026-12-03 06:38:05 +00:00
npm/edge npm: the edge's plan refuses a certificate the managing account does not own (paperclip:THE-94) (!103) 2026-11-13 08:59:35 +00:00
runner The apt cache refreshes report no change, so the drift check reads zero (THE-126) (!116) 2026-12-03 06:35:59 +00:00
scripts The page says which claim each of the two roles binds (THE-40) (!115) 2026-12-03 06:32:38 +00:00
.env.example The update flow opens the pull requests that move a pinned version (THE-40) (!110) 2026-12-02 15:01:53 +00:00
.gitignore The forge's env map gains the actor axis, and every row names its actors (FO-62) (!90) 2026-11-11 17:42:19 +00:00
AGENTS.md The environment is fetched from the store, and the vaults go (FO-43) (!79) 2026-10-28 13:44:32 +00:00
env.map The update flow opens the pull requests that move a pinned version (THE-40) (!110) 2026-12-02 15:01:53 +00:00
GLOSSARY.md The forge's deploy script, and the play's status when the runner restarts (FO-64) (!102) 2026-11-12 16:08:41 +00:00
LICENSE docs: add the docs tree — entry point, architecture, runbooks, ADRs, glossary, license (#13) 2026-10-06 11:03:37 +00:00
Makefile The update flow opens the pull requests that move a pinned version (THE-40) (!110) 2026-12-02 15:01:53 +00:00
mise.lock predeploy snapshots on both Guests, and preflight goes (FO-59) (!89) 2026-11-11 11:41:48 +00:00
mise.toml predeploy snapshots on both Guests, and preflight goes (FO-59) (!89) 2026-11-11 11:41:48 +00:00
README.md The update flow opens the pull requests that move a pinned version (THE-40) (!110) 2026-12-02 15:01:53 +00:00
renovate.json The update flow opens the pull requests that move a pinned version (THE-40) (!110) 2026-12-02 15:01:53 +00:00

infra-forge

OpenTofu + Ansible that provision and maintain a self-hosted Forgejo on the Pit homelab.

OpenTofu creates the LXC Guest on the Proxmox Node, Ansible installs Forgejo on it natively, and NPM publishes it from the Edge. It exists so the lab can host its own git service — repositories, issues, pull requests and CI — instead of depending on a public one, and doubles as the worked example of the three-layer pattern (Guest, Edge, service) that the other sites copy.

Requirements

  • A Proxmox VE Node reachable from the machine that runs OpenTofu, and an API token for it.
  • The repo's toolchain, installed once with make deps. mise is the dependency manager: mise.toml declares the tools the Targets call — OpenTofu, ansible-core, Python and jq, with uv to resolve the Python ones — mise.lock pins what those requests resolved to, and the Ansible collections come from forgejo/service/requirements.yml.
  • An admin account on the Edge (NPM), with sshd disabled in its LXC and the router forwarding WAN 22/TCP to it.

Environment variables

No secret is committed and none is kept in the tree: make env writes the repo-root .env whole, at 0600, from the store and the age class, and .env.example declares the names it can carry. The interface — the stamp line, the print, the refusal rules, the map — is documented once, in infra-secrets' docs/env-fetch.md.

From Variables
the store, secret/services/forgejo/* FORGEJO_DB_PASSWORD, FORGEJO_SECRET_KEY, FORGEJO_INTERNAL_TOKEN, FORGEJO_JWT_SECRET, FORGEJO_RUNNER_SECRET, FORGEJO_PIT_PASSWORD, FORGEJO_SMTP_USERNAME, FORGEJO_SMTP_PASSWORD (the service layer's secrets; the deploy reads them too)
the store, secret/homelab/npm/forge/manage NGINXPROXYMANAGER_USERNAME, NGINXPROXYMANAGER_PASSWORD (the Edge's managing account for this repository)
the store, two paths per Stack FORGE_GUEST_STATE_ACCESS_KEY_ID, FORGE_GUEST_STATE_SECRET_ACCESS_KEY (the forge Guest Stack's), FORGE_RUNNER_STATE_ACCESS_KEY_ID, FORGE_RUNNER_STATE_SECRET_ACCESS_KEY (the runner's) and FORGE_EDGE_STATE_ACCESS_KEY_ID, FORGE_EDGE_STATE_SECRET_ACCESS_KEY (the Edge Stack's) — from each record's apply key for the Operator and the Admin agent, from its deploy key for the Semaphore runner
the store, secret/homelab/proxmox/runner-token PROXMOX_VE_API_TOKEN for the Semaphore runner — its own infra-runner@pve!deploy, in place on the Guests it deploys; the endpoint comes from the job's environment, not the store
the store, the deploy's own tokens FORGEJO_STATUS_TOKEN (Semaphore's Forgejo token, for the merge commit's status) and SEMAPHORE_API_TOKEN (this repository's Semaphore project, for deploy.yml)
the store, secret/services/semaphore/deploy-ssh SEMAPHORE_SSH_KEY for the Semaphore runner — root on 141 and 146, loaded into an agent the service Targets start and kill; the Operator's hand run uses their own agent
the age class, ~/.secrets/proxmox/prod.age PROXMOX_VE_ENDPOINT, PROXMOX_VE_API_TOKEN (what applies to the Node — never the store)
the repo, a refused non-secret NGINXPROXYMANAGER_URL, which the Edge reads from npm/edge/providers.tf

env.map is what pairs each store path with the names it fills, and make env-check compares it against .env.example in both directions — so the map and the declared set are one set, and a name in neither is a failed check. Every row names the actors it is for — the Operator, the Admin agent, the Semaphore runner or the CI login — and a row is read only by those, because an unscoped one would hand each actor a 403 that was never its to walk into. One record's apply and deploy keys therefore carry the same two names on two rows with no actor in common. make pre is the one thing that opens a second sealed file: it decrypts ~/.secrets/proxmox/pre.age in process and exports the PRE pair over .env's, which is why the rehearsal's token never lands in the file.

Both Guest Stacks and the Edge keep their state in the store — one object per Stack, read over the LAN with a key of its own — so nothing is kept in a checkout and nothing is copied between them. .env carries a pair per Stack, each fetched from the store path that holds it. make env refuses the whole run on a path the store does not hold, so a Stack's env.map row lands in the change that mints its key. A checkout that has never applied anything still runs make validate with no credential at all. Where the state lives, and what a clone needs to read it, is §7 of the deploy runbook under docs/.

Running

A merge to main is the deploy: .forgejo/workflows/deploy.yml starts it on Semaphore, whose runner runs make prod NONINTERACTIVE=1 and then make verify. The deploy is packaged as Make Targets at the repo root, and the Operator runs them by hand for the PRE rehearsal and for resolving a change the deploy may not make, a destroy or a replace (workshop ADR-0011), which is not a deploy (workshop ADR-0009). Targets are run through the dependency manager, mise exec -- make <target>, which makes the declared tools available to make and to everything make runs; the commands below are written make <target> for short.

make deps                      # the one install step: the manager, the pinned tools, the collections
mise exec -- make              # list the Targets (deploys nothing)
mise exec -- make prod         # the whole deploy: the eight steps, in order, stopping on the first failure

make deps is the one Target that runs bare: it is what brings the manager in when the machine lacks it.

make prod is the eight steps in the order a deploy requires — snapshot, the forge's Guest, the identity check, the runner's Guest, the runner's service, the forge's service, Edge, verify — one after the other, stopping on the first failure, with each apply gated exactly as its own Target gates it. The order is the restore points first, then each Guest, then the identity check, then the two service layers, then the Edge: the check compares the literals the layers behind it read, and the service sits ahead of the Edge in the order CP-39 fixes for every repository. The runbook's make prod section is where that order, and its one cost, are written down. Each step is also a Target of its own, and the read-only and utility Targets round out the surface:

# one step at a time
make snapshot     # predeploy-<date>-<time> on both PROD Guests, the newest three kept per Guest
make guest        # Guest Stack: the LXC, with the committed key set injected
make runner-guest # the runner Guest Stack (146): the LXC, with its keys injected
make service      # service layer: Forgejo installed and configured on the Guest
make edge         # Edge Stack: the proxy host, TLS lookup and git SSH stream
make verify       # the external checks, from the WAN

# the runner's own service layer
make runner-service   # the runner's daemon and Docker on that Guest

# read-only — these mutate nothing
make service-check     # the service layer's --check --diff run
make verify            # the external checks, from the WAN
make identity-check    # the Guest's identity, checked where it is stated

# the credential-free floor, and the environment
make check        # env-check, snapshot-test, renovate-token-test, renovate-workflow-test, plan-workflow-test, deploy-test, fmt-check and docs-check: no store, no key, no credential
make env          # write this checkout's .env from the store and the age class
make env-check    # the vendored fetch against its pin, env.map against .env.example

# utilities
make ssh          # a shell on the PROD Guest
make fmt          # tofu fmt across every Stack
make validate     # tofu validate every Stack (forgejo/guest, runner/guest, npm/edge)
make worktree     # a worktree + fresh branch off origin/main; fetch its environment there

The plan checks are CI's now, not a checkout's: plan.yml plans each of the three Stacks in its own job — with main's workflow against the pull request's head — against PROD's own state record with that record's plan key, and judges what the plan would lose, so a pull request that would destroy something says so before the merge.

The three OpenTofu/Ansible layers the Targets wrap, the raw commands for a machine without make, and the plan-review and environment-word gates each apply carries, are in the deploy runbook under docs/.

Repository overview

A folder per service: forgejo/guest/ the forge Guest Stack, forgejo/service/ its service layer, runner/guest/ the runner Guest Stack, runner/service/ the runner's service layer, npm/edge/ the Edge Stack; docs/ the detailed documentation.

For agents

Read AGENTS.md: the working context for this repository.

Contributing

Work on a branch and open a pull request for a human to review — nothing goes directly to main. A merge needs an approval from someone other than the author.

License

MIT — see LICENSE.