Forgejo Actions administrator guide
Forgejo Actions
provides continuous integration driven from the files found in the .forgejo/workflows
directory of a repository.
Forgejo settings
Enabling
Forgejo Actions
is still in alpha and disabled by default. It can be activated by adding the following to app.ini
:
Note that Forgejo
does not run the jobs, it relies on the Forgejo runner
to do so. It needs
to be installed separately.
Default Actions URL
In a workflow, when uses:
does not specify an absolute URL, the
value of DEFAULT_ACTIONS_URL
is prepended to it.
The actions published at https://code.forgejo.org are:
- known to work with Forgejo Actions
- published under a Free Software license
They can be found in the following organizations:
When setting DEFAULT_ACTIONS_URL
to a Forgejo instance with an open
registration, care must be taken to avoid name conflicts. For
instance if an action has uses: foo/bar@main
it will clone and try
to run the action found at DEFAULT_ACTIONS_URL/foo/bar
if it exists,
even if it provides something different than what is expected.
Forgejo runner
The Forgejo runner
is a daemon that fetches workflows to run from a
Forgejo instance, executes them, sends back with the logs and
ultimately reports its success or failure.
Installation
Each Forgejo runner
release is published for all supported architectures as:
Installation of the binary
Download the latest binary release and verify its signature:
Installation of the OCI image
The OCI
images
are built from the Dockerfile which is found in the source
directory. It contains the forgejo-runner
binary.
It does not run as root:
A docker-compose example is provided to demonstrate how to install that OCI image to successfully run a workflow.
Execution of the workflows
The Forgejo runner
relies on application containers (Docker, Podman,
etc) or system containers (LXC) to execute a workflow in an isolated
environment. They need to be installed and configured independently.
-
Docker: See the Docker installation documentation for more information.
IPv6 support is not enabled by default in docker. The following snippet enables this.
-
Podman: While Podman is generally compatible with Docker, it does not create a socket for managing containers by default (because it doesn’t usually need one).
If the Forgejo runner complains about “daemon Docker Engine socket not found”, or “cannot ping the docker daemon”, you can use podman to provide a Docker compatible socket from an unprivileged user and pass that socket on to the runner, e.g. by executing:
-
LXC: For jobs to run in LXC containers, the
Forgejo runner
needs passwordless sudo access for alllxc-*
commands on a Debian GNU/Linuxbookworm
system where LXC is installed. The LXC helpers can be used as follows to create a suitable container:NOTE: Multiarch Go builds and binfmt need
bookworm
to produce and test binaries on a single machine for people who do not have access to dedicated hardware. If this is not needed, installing theForgejo runner
onbullseye
will also work.The
Forgejo runner
can then be installed and run within themyrunner
container.Warning: LXC containers do not provide a level of security that makes them safe for potentially malicious users to run jobs. They provide an excellent isolation for jobs that may accidentally damage the system they run on.
Registration
The Forgejo runner
needs to connect to a Forgejo
instance and must be registered before doing so. It will give it permission to read the repositories and send back information to Forgejo
such as the logs or its status.
-
Online registration A special kind of token is needed and can be obtained from the
Create new runner
button:- in
/admin/actions/runners
to accept workflows from all repositories. - in
/org/{org}/settings/actions/runners
to accept workflows from all repositories within the organization. - in
/user/settings/actions/runners
to accept workflows from all repositories of the logged in user - in
/{owner}/{repository}/settings/actions/runners
to accept workflows from a single repository.
For instance, using a token obtained for a test repository from
next.forgejo.org
:It will create a
.runner
file that looks like: - in
-
Offline registration When Infrastructure as Code (Ansible, kubernetes, etc.) is used to deploy and configure both Forgejo and the Forgejo runner, it may be more convenient for it to generate a secret and share it with both.
The
forgejo forgejo-cli actions register --secret <secret>
subcommand can be used to register the runner with the Forgejo instance and theforgejo-runner create-runner-file --secret <secret>
subcommand can be used to configure the Forgejo runner with the credentials that will allow it to start picking up tasks from the Forgejo instances as soon as it comes online.For instance, on the machine running Forgejo:
and on the machine on which the Forgejo runner is installed:
NOTE: the labels known to the runner are defined in the
config.yml
and MUST match the labels provided to theforgejo-cli actions register
command above. In this example,labels: ['docker:docker://node:16-bullseye']
will tell the Forgejo runner that when a job specifiesruns-on: docker
, it will run in a container created from thenode:16-bullseye
image by default.
Configuration
The default configuration for the runner can be
displayed with forgejo-runner generate-config
, stored in a
config.yml
file, modified and used instead of the default with the
--config
flag.
Cache configuration
Some actions such as https://code.forgejo.org/actions/cache or
https://code.forgejo.org/actions/setup-go can communicate with the
Forgejo runner
to save and restore commonly used files such as
compilation dependencies. They are stored as compressed tar archives,
fetched when a job starts and saved when it completes.
If the machine has a fast disk, uploading the cache when the job starts may significantly reduce the bandwidth required to download and rebuild dependencies.
If the machine on which the Forgejo runner
is running has a slow
disk and plenty of CPU and bandwidth, it may be better to not activate
the cache as it can slow down the execution time.
Running the daemon
Once the Forgejo runner
is successfully registered, it can be run from the directory in which the .runner
file is found with:
To verify it is actually available for the targeted repository, go to /{owner}/{repository}/settings/actions/runners
. It will show the runners:
- dedicated to the repository with the repo type
- available to all repositories within an organization or a user
- available to all repositories, with the Global type
Adding the .forgejo/workflows/demo.yaml
file to the test repository:
Will send a job request to the Forgejo runner
that will display logs such as:
It will also show a similar output in the Actions
tab of the repository.
If no Forgejo runner
is available, Forgejo
will wait for one to connect and submit the job as soon as it is available.
Labels and runs-on
The workflows / tasks defined in the files found in .forgejo/workflows
must specify the environment they need to run with runs-on
. Each Forgejo runner
declares with labels which one they support so Forgejo
sends them tasks accordingly. For instance if a job within a workflow has:
it will be submitted to a runner that registered with a docker
label (for instance with --labels docker:docker://node:16-bullseye
).
- Docker or Podman:
If
runs-on
is matched to a label that containsdocker://
, the rest of it is interpreted as the default container image to use if no other is specified. The runner will execute all the steps, as root, within a container created from that image. - LXC:
If
runs-on
isself-hosted
, the runner will execute all the steps, as root, within a Debian GNU/Linuxbullseye
LXC container.
Packaging
NixOS
The forgejo-actions-runner
recipe is released in NixOS.
Please note that the services.forgejo-actions-runner.instances.<name>.labels
key may be set to []
(an empty list) to use the packaged Forgejo instance list. One of virtualisation.docker.enable
or virtualisation.podman.enable
will need to be set. The default Forgejo image list is populated with docker images.
Other runners
It is possible to use other runners instead of Forgejo runner
. As long as they can connect to a Forgejo
instance using the same protocol, they will be given tasks to run.