From c02dc6a20ac6f568419dc35b78dc1448a61f183e Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Mon, 16 Feb 2026 08:08:07 +0100 Subject: [PATCH] feat: Add labels to runners Fixes #2. Signed-off-by: Julien Riou --- README.md | 26 +++++++++++++++++-- defaults/main.yml | 2 +- handlers/main.yml | 7 +++++ meta/argument_specs.yml | 2 +- tasks/main.yml | 2 +- tasks/register-runner.yml | 17 ++++++------ .../runners/config.yml.j2 | 17 +++++------- 7 files changed, 49 insertions(+), 24 deletions(-) rename files/runners/config.yml => templates/runners/config.yml.j2 (59%) diff --git a/README.md b/README.md index 0e838bd..b15e690 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ The following variables can be configured for this role: | `forgejo_runners_version` | `str` | No | `"9.1.1"` | Version of the runners | | `forgejo_runners_config_dir` | `path` | No | `"/etc/forgejo-runners"` | Path to the configuration directory of the runners | | `forgejo_runners_instance` | `str` | No | N/A | URL of the Forgejo instance to register the runners | -| `forgejo_runners` | `dict` | No | N/A | List of runners to configure

The key is the name of the repository on the instance

The value is the token | +| `forgejo_runners` | `dict` | No | N/A | List of runners to configure

The key is the name of the repository on the instance

The value is a dict with a `token` key and optionally a dict of `labels` | ### `forgejo_server` @@ -283,7 +283,7 @@ List of runners to configure The key is the name of the repository on the instance -The value is the token +The value is a dict with a `token` key and optionally a dict of `labels` - **Type**: `dict` - **Required**: No @@ -309,6 +309,28 @@ Then run the playbook: ansible-playbook forgejo.yml ``` +## Runners + +Example of runners configuration: + +```yaml +- hosts: forgejo + roles: + - jriou.forgejo + vars: + forgejo_runners: + coller: + token: **redacted** + labels: + debian12: docker://data.forgejo.org/oci/debian:bookworm + debian13: docker://data.forgejo.org/oci/debian:trixie + ansible: + token: **redacted** + labels: + docker: docker://data.forgejo.org/oci/node:latest +``` + + ## Donate As we all love FOSS projects, you should consider [donating to diff --git a/defaults/main.yml b/defaults/main.yml index e99da24..1ba666e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -113,7 +113,7 @@ forgejo_runners_config_dir: /etc/forgejo-runners # # The key is the name of the repository on the instance # -# The value is the token +# The value is a dict with a `token` key and optionally a dict of `labels` # # - Type: dict # - Required: No diff --git a/handlers/main.yml b/handlers/main.yml index 330c1b2..e371990 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -8,3 +8,10 @@ project_src: "{{ forgejo_runners_config_dir }}" files: - docker-compose.yml + +- name: restart runners + community.docker.docker_compose_v2: + project_src: "{{ forgejo_runners_config_dir }}" + files: + - docker-compose.yml + state: restarted diff --git a/meta/argument_specs.yml b/meta/argument_specs.yml index b07a843..d3fe081 100644 --- a/meta/argument_specs.yml +++ b/meta/argument_specs.yml @@ -102,5 +102,5 @@ argument_specs: description: - List of runners to configure - The key is the name of the repository on the instance - - The value is the token + - The value is a dict with a `token` key and optionally a dict of `labels` type: dict diff --git a/tasks/main.yml b/tasks/main.yml index 72f051d..c845b1c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -18,4 +18,4 @@ - name: deploy runners ansible.builtin.include_tasks: deploy-runners.yml - when: forgejo_runners + when: forgejo_runners is defined diff --git a/tasks/register-runner.yml b/tasks/register-runner.yml index 6dbee47..f6fb137 100644 --- a/tasks/register-runner.yml +++ b/tasks/register-runner.yml @@ -2,11 +2,11 @@ - name: check variables ansible.builtin.assert: that: - - forgejo_runners_instance | mandatory - - forgejo_runners_version | mandatory - - forgejo_runners_config_dir | mandatory - - item.key | mandatory - - item.value | mandatory + - forgejo_runners_instance is defined + - forgejo_runners_version is defined + - forgejo_runners_config_dir is defined + - "'key' in item" + - "'value' in item" - name: create runner subdirectory ansible.builtin.file: @@ -33,8 +33,7 @@ notify: start runners - name: create runner configuration - ansible.builtin.copy: - src: runners/config.yml + ansible.builtin.template: + src: runners/config.yml.j2 dest: "{{ forgejo_runners_config_dir }}/{{ item.key }}/config.yml" - force: false - notify: start runners + notify: restart runners diff --git a/files/runners/config.yml b/templates/runners/config.yml.j2 similarity index 59% rename from files/runners/config.yml rename to templates/runners/config.yml.j2 index 297734e..39eb084 100644 --- a/files/runners/config.yml +++ b/templates/runners/config.yml.j2 @@ -1,8 +1,4 @@ -# Example configuration file, it's safe to copy this as the default config file without any modification. - -# You don't have to copy this file to your instance, -# just run `forgejo-runner generate-config > config.yaml` to generate a config file. - +{{ ansible_managed | comment }} log: level: info job_level: info @@ -10,17 +6,18 @@ log: 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 shutdown_timeout: 3h insecure: false fetch_timeout: 5s fetch_interval: 2s report_interval: 1s - labels: [] +{% if item.value.labels | default({}) %} + labels: +{% for label_name, label_value in item.value.labels.items() %} + - "{{ label_name }}:{{ label_value }}" +{% endfor %} +{% endif %} cache: enabled: true