Fly.io is a “serverless” hosting platform usually used to host web services. It can be used for more than just web services; it can also be used to run long-running tasks. I wanted to try a new way to run the Gitea Actions runner, and Fly.io would be interesting way to try out.
Treat this as a proof of concept, I’m unsure if this is a good idea, but it’s fun to try out.
To simplify things, I will run the runner in “host” mode, meaning that each job won’t be containerized but will run directly on the host. This was a decision made before getting started to limit the amount of debugging sorting out Docker in Docker.
To get started I creted a new Fly.io app with the following configuration:
# fly.toml
app = "actions-on-fly"
primary_region = "ams"
[[mounts]]
destination = "/data"
source = "data"
I mounted a persistent volume to /data
so that the runner can be registered and persist the registration token across restarts.
Since there are no prebuilt Docker images (as of the time of publishing) I created one and installed the runner in it. The Dockerfile is as follows:
# Dockerfile
FROM ghcr.io/catthehacker/ubuntu:act-latest
# the FROM image is based on ubuntu and has appropriate tools installed to run Gitea Actions
# install act_runner
RUN curl https://dl.gitea.com/act_runner/nightly/act_runner-nightly-linux-amd64 > /usr/local/bin/act_runner && \
chmod +x /usr/local/bin/act_runner
# add start script
ADD start.sh /start.sh
RUN chmod +x /start.sh && mkdir -p /data
ENTRYPOINT ["/start.sh"]
When running the container, the startup logic will check if the runner is already registered, and if not it will register it. The registration token is passed in as an environment variable. The runner will then be started.
#!/bin/bash
# start.sh
# $ACTIONS_REGISTER_TOKEN is the registration token for the runner that is given by the Gitea runner settings page.
# set /data as the working dir
cd /data
# check if runner is already registered, and if not register it
if [ ! -f .runner ]; then
# register runner on gitea.com, and set label as fly-runner so it runs as "host" mode
act_runner register --no-interactive --instance "https://gitea.com" --labels "fly-runner" --token $ACTIONS_REGISTER_TOKEN
fi
# start runner
act_runner daemon
It really was a handful of lines to get a runner up and running. The runner is now running on Fly.io and can be used to run Gitea Actions. The only issue I ran into when setting this up, was that Fly.io will terminate apps if they run out of memory. This is a problem because what I was testing used a lot of memory. I ended up increasing the memory limit. Maybe a different hosting would handle OOMs differently, but I was pretty satisfied with the result. The blog you are reading right now is built using this runner.