Hosting a Forgejo Runner on Scaleway
Some of my projects are hosted on Codeberg, and I wanted to setup a CI/CD flow a la Github Actions. Codeberg provides a few (very few) runners, but they rather encourage self-hosting your own and registering them, so I went ahead and did that.
I chose to use Scaleway because I’m already their customer and they have a very competitive instance type called STARDUST1-S (1 shared vCPU and 1 GB memory), priced at €0.00015 per hour: including 10GB of storage, the setup costs me ~€1 per month.
When setting up a Scaleway instance you can choose between OS Images or Instant Apps (e.g. Docker): in my case I needed a very simple runner, so I chose Debian. Create your instance and wait until it is ready.
In the meanwhile, find the Forgejo registration token in your Codeberg account settings (Create new runner button on the top-right) and copy it.
Once the instance is up and running, SSH into it (its IP address is visible in the Scaleway console) and create a script with the following content:
#!/bin/sh
set -e
RUNNER_VERSION="12.6.4"
RUNNER_DIR="/opt/forgejo-runner"
RUNNER_BIN="/usr/local/bin/forgejo-runner"
if [ -z "$1" ]; then
echo "Usage: $0 <forgejo-registration-token>"
exit 1
fi
# Install runner binary
wget -q "https://code.forgejo.org/forgejo/runner/releases/download/v${RUNNER_VERSION}/forgejo-runner-${RUNNER_VERSION}-linux-amd64" -O "$RUNNER_BIN"
chmod +x "$RUNNER_BIN"
# Register runner
mkdir -p "$RUNNER_DIR"
cd "$RUNNER_DIR"
forgejo-runner register \
--instance https://codeberg.org \
--token "$1" \
--name my-runner \
--labels debian:host \
--no-interactive
# Install systemd service
cat > /etc/systemd/system/forgejo-runner.service <<EOF
[Unit]
Description=Forgejo Runner
After=network.target
[Service]
ExecStart=${RUNNER_BIN} daemon
WorkingDirectory=${RUNNER_DIR}
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl enable --now forgejo-runner
echo "Runner installed and started."
Next steps:
- Make the script executable with
chmod +x <script_name>.sh - Run the script with
./<script_name>.sh <forgejo_registration_token>
This will register the runner with Codeberg and install it as a systemd service with automatic restart on the Scaleway instance.
Now your runner is ready to accept jobs from Codeberg!
Please note that it’s a barebone Debian instance, so you’ll need to install all the tooling necessary for your builds (e.g. nodejs, git, etc…).