When self-hosting forgejo-runner
using docker
in order to run your Actions, you need to specify what images should be available.
I think one of the most common ones are whatever the latest stable version of node
is. The reason for this, is that the actions that we usually invoke when using these kind of runners, those actions are themselves most often written in Node.JS.
However, if you don't want to do that, but you want to run on some other image, you will still probably need to install a few things in your image.
One way to do this, is to start with, for example debian:bookworm
, and then install a bunch of stuff as the first step of your action.
on:
jobs:
build:
runs-on: docker
container:
image: debian:bookworm
steps:
- run: apt update && apt -y install nodejs git
- uses: actions/checkout@v4
# The rest of your action below here...
The reason for installing nodejs
and git
before doing uses: actions/checkout
, is of course to make sure that we can run the Node.JS code in the actions/checkout
action, which in turn uses git
in order to clone whatever repo it is you are running this CI job in.
Installing packages can be a bit tedious, and take up some time, and if your repo needs something more, then you'll have to install that as well.
I wanted to build this site, so I needed zola
. Of course, there already exist images for that, but I wanted to figure out how to build my own.
As it turns out, that's not very hard at all. I'll just choose a starting image, install the system packages nedeed, and then run a command to fetch a release tarball from zola's github releases, and put that in the right place.
FROM debian:bookworm
RUN apt update && apt -y install git nodejs jq curl
RUN zola_tag=$(curl -L -H "Accept: application/json" https://github.com/getzola/zola/releases/latest | jq -r .tag_name) && \
package_name="zola-$zola_tag-amd64-unknown-linux-gnu.tar.gz" && \
curl -L "https://github.com/getzola/zola/releases/download/$zola_tag/$package_name" 2>/dev/null | tar zx -C /usr/local/bin
I could build and host this image anywhere I wanted, but I only ever want to run it on my server, so I just put the above Dockerfile on the server, and built the image there. The only important part here is to build the image as the same user as the one that's running the forgejo-runner
instance.
Once that's done, you can add a zola:docker://localhost/zola-bookworm
label to your .runner
config, and then you can skip some lines from the above yaml action specification:
on:
jobs:
build:
runs-on: zola
steps:
- uses: actions/checkout@v4
# The rest of your action below here...
It also runs faster. In my case, I saved about 30 seconds, which is around 75% of the previous build time for this site. Not very necessary, but nice anyway.