Runner not respecting provided labels #174
Labels
No labels
Kind/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: forgejo/runner#174
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
As discuss in #153 (comment), runner is not respecting provided labels.
you can see it here: https://code.forgejo.org/forgejo/runner/actions/runs/870#jobstep-4-277
Where the actions use
node:16-bullseye
instead ofalpine
as specified inside the compose file heresed -i -e "s|labels: \[\]|labels: \[\"docker:docker://alpine:3.18\"\]|" config.yml ;
This issue is tied to this existing issue : #149 but the problem is larger than just kubernetes as I faced it using the docker-compose examples.
I try to investigate and it seems that the
sed
command ineb89a98c6a/examples/docker-compose/compose-forgejo-and-runner.yml
are all good.It seems that for offline registration, specifying labels in the
config.yml
don't work.The only way I achieved to make it work is by putting label in the
.runner
file after it's generation and before starting the runner:Starting the runner (using
forgejo-runner --config config.yml daemon
) with labels in theconfig.yml
and without labels in the.runner
seems to populate the.runner
but the labels are not taken into account (maybe a restart of the runner would work ?).Btw using online registration, it work like a charm using this (without having to specify the labels elsewhere):
⚠️ Actually, using
alpine:3.18
in the example will make the CI fail because this image do not have node inside and it is needed for the actions. It would be better usingnode:16-bullseye
. It were not failling until now because the labels were not taken into accout by the runner ...Here some working example in my work for the #153:
sed -i -e "s|\"labels\": null|\"labels\": [\"docker:docker://node:16-bullseye\", \"ubuntu-22.04:docker://catthehacker/ubuntu:act-22.04\"]|" .runner ;
Thanks for the samples! I was able to reproduce it.
It does in fact fix it.
rundown
Runner loads registration labels and then checks the config ones, claiming to use all of them. Issue is that the declared labels aren't the same as the ones passes to
NewRunner
.NewRunner gets config and registration but only uses labels from registration.
Possible quick fix
After runner loads all labels replace original ones with the declared ones:
abc9bf653a
This doubles labels parsing, but at least runner still stop "lying" to the instance about it's labels.
I ran the example and confirm the problem. Although the config.yml has the proper label set, the runner is not registered with a label when looking at http://0.0.0.0:8080/root/test/settings/actions/runners
log:
level: info
runner:
file: .runner
capacity: 1
envs:
A_TEST_ENV_NAME_1: a_test_env_value_1
A_TEST_ENV_NAME_2: a_test_env_value_2
env_file: .env
timeout: 3h
insecure: false
fetch_timeout: 5s
fetch_interval: 2s
labels: ["docker:docker://alpine:3.18"]
cache:
enabled: true
dir: ""
host: ""
port: 0
external_server: ""
container:
network: host
enable_ipv6: false
privileged: false
options:
workdir_parent:
valid_volumes: []
docker_host: ""
force_pull: false
host:
workdir_parent:
The problem seems to be rooted in the first invocation of the runner daemon. When it is restarted, the "docker" label is correctly associated to the image specified in the configuration file.
Since Forgejo knows nothing about how the labels are mapped to images by default, the bug has to be in the runner.
The bug is that when the labels in .runner & config.yml are different, the .runner labels take precedence and then the labels found in config.yml are written to .runner. In the docker compose example the .runner file has no labels the first time around, hence defaults to bullseye. So the second time around the labels from config.yml will be used. I'll file a bug with a reproducer and add a workaround in the example in the meantime to avoid confusing until a release fixing this bug is published.
On top of that there is also a race in the order of operations in the docker compose file. I think it is wrong to rely on
depends_on
to ensure the order in which forgejo & registration & daemon start as I've observed it does not behave the way it should in some cases. Making assertions on the existence of a file in the shell script is more straightforward to understand and reliable.Steps to reproduce:
labels: ["docker:docker://node:20-bookworm"]
labels: null
runner --config config.yml daemon
runs-on: docker
node:16-bullseye
(the default associated with the docker label when no labels are set) instead ofnode:20-bookworm
"labels": ["docker:docker://node:20-bookworm"]
runner --config config.yml daemon
runs-on: docker
node:20-bookworm
Fixed by #176