TGLMAN

Configure a Forgejo Runner

I've been using GitHub and then GitLab for a while, but recently a new git hosting service is online called Codeberg this is based on an open source Git Repo Hosting software called ForgeJo that implements the usual functionalities of a git hosting like: code browsing, issue tracking, continuous integration, and collaborative coding, with the aim to support in the long term federated collaboration, which give better long term prospective compared to the state of the art git hostings, anyway a smaller service like this one understandably have a limited support for free continues integration runners, but it gives an easy way to configure one on your machine.

Here are some steps I did to install run the forgejo runner on one of my debian machine.

First install (or make sure to have installed) some base software:

sudo apt install git golang docker.io

clone the repo:

git clone https://code.forgejo.org/forgejo/runner.git forgejo-runner

and then build it and install it


cd forgejo-runner
make build
sudo cp forgejo-runner /usr/local/bin/

After installing, we can setup the right environment to run it, in this case I just used a new machine user with its own home directory, also making sure is in the docker group, so it can run operations with it.


## Just follow the instructions of the command:
sudo adduser forgejo --disabled-login
sudo adduser forgejo docker

Now we can use that user to register the runner with Codeberg be aware that you need a runner token that you can get clicking "Create New Runner" from the Runner Settings Page


sudo su - forgejo
cd 
## Just follow the instructions of the command:
forgejo-runner register

Done this finally setup a systemd service, I got the example from here and modified it for my specific needs to the following:


[Unit]
Description=Forgejo Runner
Documentation=https://forgejo.org/docs/latest/admin/actions/
After=docker.service

[Service]
ExecStart=/usr/local/bin/forgejo-runner daemon
ExecReload=/bin/kill -s HUP $MAINPID

# This user and working directory must already exist
User=forgejo 
WorkingDirectory=/home/forgejo/
Restart=on-failure
TimeoutSec=0
RestartSec=10

[Install]
WantedBy=multi-user.target

Finally, make sure to enable and then start the services


sudo systemctl enable docker 
sudo systemctl enable forgejo-runner 

sudo systemctl start docker
sudo systemctl start forgejo-runner

Profit !