A spare-machine Gitea forge, hardened, backed up and with CI, as a template. Personal values are placeholders listed in the README.
136 lines
6.8 KiB
Markdown
136 lines
6.8 KiB
Markdown
# Mithlond
|
||
|
||
A template for running your own Gitea git forge on a spare machine, public on
|
||
your own domain, with per-repository public/private control, hardened, backed
|
||
up every night, and with CI. Every step is written down so you can repeat it.
|
||
|
||
<img src="assets/y530-still-alive.jpeg" alt="A 2008 Lenovo IdeaPad Y530 running as the server: lid open, screen barely alive, Ethernet plugged in, a shell prompt on the screen" width="375">
|
||
|
||
*The reference server: a 2008 Lenovo IdeaPad Y530 with 3 GB of RAM, still alive.
|
||
If it runs on this, it runs on whatever you have in a drawer.*
|
||
|
||
## What you get
|
||
|
||
```
|
||
Internet → Router → Caddy (TLS) → Gitea (SQLite) git.example.com
|
||
└→ optional apex site example.com
|
||
→ Gitea SSH (port 2222)
|
||
→ Admin SSH (port 2234, LAN only; WireGuard from outside)
|
||
|
||
DNS: Cloudflare, kept on your home IP by ddclient
|
||
Backups: nightly restic to a USB drive, mail on failure, weekly report
|
||
CI: Gitea Actions runner on the same box
|
||
```
|
||
|
||
| Component | Role |
|
||
|---|---|
|
||
| Arch Linux (headless) | Host OS |
|
||
| Docker Compose | Runs Gitea, Caddy and the Actions runner |
|
||
| Gitea + SQLite | Git forge |
|
||
| Caddy | Reverse proxy, automatic Let's Encrypt TLS |
|
||
| ddclient + Cloudflare | Dynamic DNS |
|
||
| nftables + fail2ban | Host firewall, brute-force bans |
|
||
| restic + msmtp (Gmail SMTP) | Nightly backups and failure mail |
|
||
|
||
The guides document this one path. **Adapt if yours differs**: another
|
||
distribution, DNS provider, router or mail server works, but the commands and
|
||
menu names will change.
|
||
|
||
## Before you start: replace the placeholders
|
||
|
||
| Placeholder | Meaning | Where |
|
||
|---|---|---|
|
||
| `example.com`, `git.example.com`, `www.example.com` | your domain and the forge's hostname | `Caddyfile`, `compose.yml`, guides |
|
||
| `you@example.com`, `you@gmail.com` | Let's Encrypt contact; mail sender and recipient | `Caddyfile`, `systemd/msmtprc.example`, `systemd/gitea-backup.env.example` |
|
||
| `admin` | your login on the server | guides, `scripts/gitea-backup` (`STACK=`) |
|
||
| `yourname` | your Gitea username | `profile/`, guide 12 |
|
||
| `192.168.1.50`, `192.168.1.1` | the server's reserved LAN IP; the router | guides |
|
||
| `BACKUP` | filesystem label of the USB backup drive | `scripts/`, `systemd/gitea-backup.env.example` |
|
||
| `portfolio:8000` | the optional apex site's container and port | `Caddyfile` (delete the block if you host only Gitea) |
|
||
| `DRIVE_USB=0000:0000` | the backup drive's USB ID, for NTFS repair | `scripts/chkdsk-vm.sh` |
|
||
|
||
Find any you missed with `grep -rnE 'example\.com|yourname|192\.168\.1\.|you@' .`
|
||
|
||
## Setup, step by step
|
||
|
||
Do them in order and tick each guide's checklist before moving on. The router
|
||
port-forwards come only after step 9, so the server stays LAN-only until it is
|
||
hardened.
|
||
|
||
1. **Install Arch Linux** headless from a live USB: partitions, packages,
|
||
bootloader, user. → [01-arch-install](OKF/guides/01-arch-install.md)
|
||
2. **Make it a server**: closing the lid never suspends it, first boot, DHCP
|
||
reservation at the router. → [02-server-first-boot](OKF/guides/02-server-first-boot.md)
|
||
3. **Harden admin SSH**: keys only, port 2234, LAN-only, WireGuard for remote
|
||
access. → [03-ssh-hardening](OKF/guides/03-ssh-hardening.md)
|
||
4. **Create DNS records**: rule out CGNAT, add Cloudflare A records, create an
|
||
API token. → [04-dns-records](OKF/guides/04-dns-records.md)
|
||
5. **Keep DNS current** with ddclient as your home IP changes.
|
||
→ [05-ddns](OKF/guides/05-ddns.md)
|
||
6. **Deploy the stack**: copy `compose.yml` and `Caddyfile`, prove TLS on
|
||
Let's Encrypt staging, then go live. → [06-docker-deploy](OKF/guides/06-docker-deploy.md)
|
||
7. **Set up Gitea**: install wizard, 2FA, SSH keys, access tokens.
|
||
→ [07-gitea-setup](OKF/guides/07-gitea-setup.md)
|
||
8. **Turn on the firewall**: nftables without breaking Docker, survives
|
||
reboot. → [08-firewall](OKF/guides/08-firewall.md)
|
||
9. **Ban brute force and harden Gitea**: fail2ban for SSH and Gitea logins,
|
||
then create the router port-forwards. → [09-fail2ban](OKF/guides/09-fail2ban.md)
|
||
10. **Back up by hand** to a USB drive and prove the archive restores.
|
||
→ [10-backup-manual](OKF/guides/10-backup-manual.md)
|
||
11. **Automate backups**: nightly restic, failure mail, weekly report.
|
||
→ [11-backup-automated](OKF/guides/11-backup-automated.md)
|
||
12. **Add CI**: a Gitea Actions runner, with a profile-page snake as the first
|
||
job. → [12-gitea-actions](OKF/guides/12-gitea-actions.md)
|
||
|
||
When something needs doing later:
|
||
[maintenance](OKF/guides/maintenance.md) (updates, reboots, server quirks),
|
||
[backup-operations](OKF/guides/backup-operations.md) (remote operation, restore,
|
||
troubleshooting), [ntfs-repair](OKF/guides/ntfs-repair.md) (a dirty or damaged
|
||
NTFS backup drive).
|
||
|
||
## Ports
|
||
|
||
| Port | Protocol | Purpose | Forwarded by the router |
|
||
|---|---|---|---|
|
||
| 80 | TCP | HTTP (ACME challenge only, redirects to 443) | yes |
|
||
| 443 | TCP | HTTPS: Gitea web UI and git over HTTPS | yes |
|
||
| 2222 | TCP | Git over SSH | yes |
|
||
| 2234 | TCP | Admin SSH to the host | **no** |
|
||
|
||
## Repository layout
|
||
|
||
```
|
||
.
|
||
├── README.md
|
||
├── LICENSE
|
||
├── AGENTS.md # contract for AI coding agents; CLAUDE.md points here
|
||
├── assets/ # images for this README
|
||
├── compose.yml # Docker Compose stack: gitea, caddy, runner
|
||
├── Caddyfile # Caddy reverse proxy config
|
||
├── OKF/ # project wiki — start at OKF/index.md
|
||
│ ├── guides/ # setup guides 01–12 + operations (index.md)
|
||
│ ├── decisions/ # why the stack is what it is
|
||
│ ├── CONTEXT.md, ROADMAP.md, SUMMARY.md, ARCHITECTURE.md
|
||
│ └── modules/
|
||
├── scripts/
|
||
│ ├── backup.sh # manual backup + restore test (guide 10)
|
||
│ ├── chkdsk-vm.sh # Windows Setup VM for chkdsk on the backup drive — runs on a separate PC
|
||
│ └── gitea-backup # nightly restic backup, installed to /usr/local/sbin (guide 11)
|
||
├── systemd/ # gitea-backup units + config examples (guide 11)
|
||
├── runner/config.yaml # Gitea Actions runner config (guide 12)
|
||
├── profile/ # content for your <user>/.profile repo — snake workflow (guide 12)
|
||
├── vm/ # created on the repair PC — Windows ISO + UEFI vars (not committed)
|
||
├── gitea-data/ # created at runtime — Gitea volume (not committed)
|
||
├── caddy-data/ # created at runtime — TLS certs (not committed)
|
||
├── caddy-config/ # created at runtime — Caddy state (not committed)
|
||
└── runner-data/ # created at runtime — runner registration (not committed)
|
||
```
|
||
|
||
Vocabulary: [OKF/CONTEXT.md](OKF/CONTEXT.md). Plan and verify steps:
|
||
[OKF/ROADMAP.md](OKF/ROADMAP.md). Why each piece was chosen:
|
||
[OKF/decisions/index.md](OKF/decisions/index.md).
|
||
|
||
## License
|
||
|
||
[MIT](LICENSE).
|