Skip to content

Commit

Permalink
Add registration configuration and logic (#3)
Browse files Browse the repository at this point in the history
Rewrite the configuration template to make modifying defaults easier

Co-authored-by: Benjamin Cook <[email protected]>
  • Loading branch information
bcook254 and Benjamin Cook authored May 12, 2024
1 parent ad5b86c commit 05ac83b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 33 deletions.
59 changes: 28 additions & 31 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,33 @@ actrunner_config_dir: /etc/actrunner
actrunner_config_file: "{{ actrunner_config_dir }}/config.yaml"
actrunner_url: "https://dl.gitea.com/act_runner/{{ actrunner_version }}/act_runner-{{ actrunner_version }}-linux-{{ __architecture_map[ansible_architecture] }}"

actrunner_register: false
actrunner_name: "{{ ansible_hostname }}-runner"

actrunner_manage_config: true

actrunner_config:
log:
level: info
runner:
file: .runner
capacity: 1
envs:
env_file: .env
timeout: 3h
insecure: false
fetch_timeout: 5s
fetch_interval: 2s
labels:
- "ubuntu-latest:docker://gitea/runner-images:ubuntu-latest"
cache:
enabled: true
dir: ""
host: ""
port: 0
external_server: ""
container:
network: ""
privileged: false
options:
workdir_parent:
valid_volumes: []
docker_host: ""
force_pull: true
force_rebuild: false
host:
workdir_parent:
actrunner_log_level: info
actrunner_runner_file: .runner
actrunner_runner_capacity: 1
actrunner_runner_envs:
actrunner_runner_env_file: .env
actrunner_runner_timeout: 3h
actrunner_runner_insecure: false
actrunner_runner_fetch_timeout: 5s
actrunner_runner_fetch_interval: 2s
actrunner_runner_labels:
- ubuntu-latest:docker://gitea/runner-images:ubuntu-latest
actrunner_cache_enabled: true
actrunner_cache_dir: ""
actrunner_cache_host: ""
actrunner_cache_port: 0
actrunner_cache_external_server: ""
actrunner_container_network: ""
actrunner_container_privileged: false
actrunner_container_options:
actrunner_container_workdir_parent:
actrunner_container_valid_volumes: []
actrunner_container_docker_host: ""
actrunner_container_force_pull: true
actrunner_container_force_rebuild: false
actrunner_host_workdir_parent:
24 changes: 24 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,27 @@
owner: "{{ actrunner_user }}"
group: "{{ actrunner_group }}"
mode: 0644

- name: Check if Act Runner is registered.
ansible.builtin.slurp:
src: "{{ (actrunner_data_dir, actrunner_runner_file) | path_join }}"
ignore_errors: true
register: __actrunner_registration_result
when: actrunner_register

- name: Register Act Runner.
# runner file must be created by the same user that actrunner runs as
become: true
become_user: "{{ actrunner_user }}"
ansible.builtin.command:
chdir: "{{ actrunner_data_dir }}"
cmd: >-
{{ actrunner_bin_file }}
register
--config {{ actrunner_config_file }}
--no-interactive
--name {{ actrunner_name }}
--labels {{ actrunner_runner_labels | join(',') }}
--instance {{ actrunner_instance }}
--token {{ actrunner_token }}
when: __actrunner_registration_result is failed
2 changes: 1 addition & 1 deletion tasks/install.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Ensure actrunner {{ actrunner_group }} exists.
- name: Ensure {{ actrunner_group }} group exists.
ansible.builtin.group:
name: "{{ actrunner_group }}"
state: present
Expand Down
30 changes: 29 additions & 1 deletion templates/config.yaml.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
{{ ansible_managed | comment }}

{{ actrunner_config | to_yaml }}
log:
level: {{ actrunner_log_level }}
runner:
file: {{ actrunner_runner_file }}
capacity: {{ actrunner_runner_capacity }}
envs: {{ actrunner_runner_envs }}
env_file: {{ actrunner_runner_env_file }}
timeout: {{ actrunner_runner_timeout }}
insecure: {{ actrunner_runner_insecure | bool | to_json }}
fetch_timeout: {{ actrunner_runner_fetch_timeout }}
fetch_interval: {{ actrunner_runner_fetch_interval }}
labels: {{ actrunner_runner_labels | to_yaml }}
cache:
enabled: {{ actrunner_cache_enabled | bool | to_yaml }}
dir: {{ actrunner_cache_dir }}
host: {{ actrunner_cache_host }}
port: {{ actrunner_cache_port }}
external_server: {{ actrunner_cache_external_server }}
container:
network: {{ actrunner_container_network }}
privileged: {{ actrunner_container_privileged | bool | to_json }}
options: {{ actrunner_container_options }}
workdir_parent: {{ actrunner_container_workdir_parent }}
valid_volumes: {{ actrunner_container_valid_volumes }}
docker_host: {{ actrunner_container_docker_host }}
force_pull: {{ actrunner_container_force_pull | bool | to_json }}
force_rebuild: {{ actrunner_container_force_rebuild | bool | to_json }}
host:
workdir_parent: {{ actrunner_host_workdir_parent }}

0 comments on commit 05ac83b

Please sign in to comment.