Git at Home with Forgejo
Self-hosting git with Docker and Forgejo on a Raspberry Pi 4 turned out to be surprisingly easy. It is now the home of my private repositories, instead of using the increasingly bloated GitHub and GitLab services.
For the longest time, I have been hosting my git repositories on GitHub.com and GitLab.com, but the recent feature bloat and redesigns made me want to use these platforms less and less.
I was briefly evaluating EU-based git forges and their limits for hosting private repositories, but then I remembered an unused Raspberry Pi 4 Model B sitting around in a box.
Since I was already following the development of Codeberg and the open source git platform Forgejo, I decided to give it a try on the Pi 4 using Docker Compose. I never set up anything with Docker before, but the sandboxed, app-like installation and update process sounded appealing to me.
Setting Up The Pi
I prepared a Micro SD card with the official Raspberry Pi Imager and made sure to configure an account, SSH access and a network connection. The Pi is housed inside a case with additional heatsink from Amazon and sits right besides my router, where it is connected to an outlet with power surge protection. There, it silently runs ever since I set it up.
After powering up the Pi for the first time, I connected via ssh and started updating all system packages with sudo apt update, sudo apt upgrade, and sudo apt install docker-compose, sudo systemctl reboot to install docker compose. My router (a Fritz!Box) automatically assigns <hostname>.fritz.box domain names for network devices, but using the MDNS <hostname>.local domain from the avahi service would also work to address the machine in the local network.
Installing Forgejo with Docker Compose
The Forgejo documentation has a detailled guide for Docker. I chose the “rootless” variant of the compose file, replaced the database password and set up a /<your-preferred-path>/forgejo directory on the Pi, which contains the docker-compose.yaml file, a forgejo-data directory and a postgres-data directory with correct permissions. The documentation recommends using named volumes, so I updated the configuration according to the provided examples and made sure that the forgejo-data and postgres-data volumes were configured and used. That’s all you need to start the containers now.
Inside the directory with the docker-compose.yaml, I executed docker compose up -d to bring up the services in detached mode. Even if the Pi restarts, the containers will be relaunched, but they can be stopped with docker compose down as well. Occassionally, I update to the latest images with docker compose pull.
When everyhing is configured correctly, the Forgejo instance is accessible through the hostname and defined port. The initial setup process allows customization and user creation. I configured a dedicated admin user and a regular user account for myself.
Accessing Forgejo On The Go
I do not want to expose my Forgejo instance to the public internet, so I decided to use the native Wireguard VPN support of my Fritz!Box to connect remotely from Linux, macOS and iOS to my home network. This works extremely well on all these OSs and has the benefit that I don’t have to worry about reverse proxies and SSL, which are currently too advanced for me to set up securely.
Missing Pieces and Limitations
The Forgejo instance is usable now, but there are a few more things to consider before running this longterm: storage, encryption and backups.
Currently, repository data and the database are stored on the Micro SD card, which is not encrypted and might lead to data loss. I don’t store any super secret or important repositories on the Pi, so I’m not bothered by this at the moment. Also, the SSD pricing situation right now halted my efforts to resolve this issue. That’s why I’m relying on my automatic backup scripts, which I will describe in more detail in a follow-up post.
Overall, I’m happy with my setup and have been running it continuously for half a year now with the latest Forgejo releases. I like the simplicity of the UI and don’t have to worry about creating too many repos anymore. Even this website and all my drafts live in a git repo on my Raspberry Pi now.