Description
Background
Act runner will ask for labels when you register it to a Gitea instance. For example, one of the default labels is ubuntu-latest:docker://node:16-bullseye
. It could be split into two parts.:
ubuntu-latest
: This means it can run jobs withruns-on: ubuntu-latest
docker://node:16-bullseye
: This means that the jobs will run in Docker containers with the specified image.
The runner will report ubuntu-latest
to the Gitea instance, so the instance will know what kind of jobs can be assigned to this runner. However, the instance doesn't know the second part of the label because Gitea doesn't care how a runner runs jobs.
For some reason, it was designed to allow modifying labels on the Gitea side, in a special way:
- Gitea cannot modify the labels reported by runners, which are called "Agent Labels".
- Gitea can append more labels to runners, which are called "Custom Labels".
So it will be convenient for users when they have a job with runs-on: centos
, but there are no runners with the label. They can add centos
as a custom label to let the runner pick up the jobs.
Unfortunately, when the runner receives the job, it doesn't understand how to run it. To avoid failure, the act runner will use the default image to run jobs with unrecognized labels. This may surprise users.
IMO, the point is that we shouldn't let Gitea define runners. It should be the runners who decide what kind of jobs they can run, not the Gitea instance. However, we also need to provide an elegant way to modify labels on the runner side, instead of re-registration.
Solution
Forbid modifying runner labels on the Gitea side
Combine “agent labels” and “custom labels” to “labels”.Drop “custom labels” and use “agent labels” only.- Users cannot modify the labels on settings pages of Gitea.
Provide a new RPC method for runners to declare their labels
- A new method like
Declare
(or a better name). - Act runner will call
Declare
to pass its current labels to Gitea once it has started. - Gitea will update the labels of the runner in database.
Support specifying labels in the config file of the runner
- Users can specify labels in the config file; it's optional. An empty value means "none" instead of "empty”.
- When registering a runner:
- Ignore the step/flag for labels if a config file with labels has been specified.
- Otherwise, ask for labels.
- When running a runner:
- Overwrite the labels to state file (.runner) if a config file with labels has been specified, and declare with new labels to Gitea.
- Otherwise, use the labels stored in the state file.
Benefits
- Provide convenience. Users can add/remove/change the labels of a runner by simply updating the config file and restarting the runner.
- Reduce confusion. The only way to the labels of a runner is modifying the config file.
- Clear boundaries. Users cannot modify the labels if they cannot touch the runner, even if they are the admin of the Gitea instance.