download binary if deploy_mode is host

This commit is contained in:
Bertrand Lanson 2023-08-11 20:06:15 +02:00
parent 2f76958c89
commit 313c1212a5
7 changed files with 65 additions and 48 deletions

View File

@ -1,7 +1,7 @@
deploy_gitea_runner
=========
A brief description of the role goes here.
This role installs and configure a gitea act runner on **debian-based** distributions.
Requirements
------------
@ -20,7 +20,7 @@ A quick description of the variable, what it does, and how to use it.
Dependencies
------------
None.
Example Playbook
----------------

View File

@ -5,16 +5,16 @@
daemon_reload: true
listen: "systemctl-daemon-reload"
- name: "Enable gitea-actions-runnner service"
- name: "Enable gitea-runnner service"
ansible.builtin.service:
name: gitea-actions-runnner
name: gitea-runnner
enabled: true
listen: "systemctl-enable-gitea-actions-runnner"
listen: "systemctl-enable-gitea-runnner"
- name: "Start gitea-actions-runnner service"
- name: "Start gitea-runnner service"
ansible.builtin.service:
name: gitea-actions-runnner
name: gitea-runnner
state: restarted
listen: "systemctl-restart-gitea-actions-runnner"
listen: "systemctl-restart-gitea-runnner"
throttle: 1
when: deploy_gitea_runner_start_service

View File

@ -4,7 +4,7 @@ galaxy_info:
namespace: 'ednxzu'
role_name: 'deploy_gitea_runner'
author: 'Bertrand Lanson'
description: 'Deploy gitea-actions CICD runners using docker-compose on Debian based distributions'
description: 'Deploy gitea-actions CICD runners on Debian based distributions'
license: 'license (BSD, MIT)'
min_ansible_version: '2.10'
platforms:

View File

@ -1,9 +1,9 @@
---
# task/configure file for deploy_adguard
- name: "Copy gitea-actions-runnner.service file"
- name: "Copy gitea-runnner.service file"
ansible.builtin.template:
src: "gitea-actions-runnner.service.j2"
dest: "/etc/systemd/system/gitea-actions-runnner.service"
src: "gitea-runnner.service.j2"
dest: "/etc/systemd/system/gitea-runnner.service"
owner: root
group: root
mode: '0644'
@ -20,8 +20,8 @@
group: root
mode: '0600'
notify:
- systemctl-enable-gitea-actions-runnner
- systemctl-restart-gitea-actions-runnner
- systemctl-enable-gitea-runnner
- systemctl-restart-gitea-runnner
- name: "Copy config.yaml"
ansible.builtin.template:
@ -32,4 +32,4 @@
mode: '0600'
when: deploy_gitea_runner_config != {}
notify:
- systemctl-restart-gitea-actions-runnner
- systemctl-restart-gitea-runnner

View File

@ -1,46 +1,54 @@
---
# task/install_compose file for install_docker
- name: "Get release for compose:{{ install_docker_compose_version }}"
# task/install_host file for deploy_gitea_runner
- name: "Get release for gitea_runner:{{ deploy_gitea_runner_version }}"
vars:
_docker_compose_url_ext: "{% if install_docker_compose_version == 'latest'%}releases{% else %}releases/tags{% endif %}"
_gitea_actions_url_ext: "{% if deploy_gitea_runner_version == 'latest'%}releases{% else %}releases/tags{% endif %}"
ansible.builtin.uri:
url: "{{ install_docker_compose_github_api }}/{{ _docker_compose_url_ext }}/{{ install_docker_compose_version }}"
url: "{{ deploy_gitea_runner_gitea_api }}/{{ _docker_compose_url_ext }}/{{ install_docker_compose_version }}"
return_content: true
register: _docker_compose_new_release
register: _gitea_runner_new_release
- name: "Check current compose version"
ansible.builtin.command: "{{ install_docker_compose_path }} --version --short"
register: _docker_compose_old_release
- name: "Check if gitea_runner is already installed"
ansible.builtin.stat:
path: "{{ deploy_gitea_runner_directory }}/.version"
changed_when: false
check_mode: false
register: _gitea_runner_is_installed
- name: "Check current gitea_runner version"
ansible.builtin.command: "cat {{ deploy_gitea_runner_directory }}/.version"
register: _gitea_runner_old_release
check_mode: false
changed_when: false
failed_when: false
when: _gitea_runner_is_installed.stat.exists
- name: "Set facts for wanted compose release"
- name: "Set facts for wanted gitea_runner release"
ansible.builtin.set_fact:
install_docker_compose_wanted_version: "{{ _docker_compose_new_release.json['tag_name']|regex_replace('v', '') }}"
when: _docker_compose_new_release.json is defined
and (_docker_compose_new_release.json | length > 0)
deploy_gitea_runner_wanted_version: "{{ _gitea_runner_new_release.json['tag_name']|regex_replace('v', '') }}"
when: _gitea_runner_new_release.json is defined
and (_gitea_runner_new_release.json | length > 0)
- name: "Set facts for current compose release"
- name: "Set facts for current gitea_runner release"
ansible.builtin.set_fact:
install_docker_compose_current_version: "{{ _docker_compose_old_release.stdout | regex_replace('v', '') }}"
when: _docker_compose_old_release.stdout is defined
and (_docker_compose_old_release.stdout | length > 0)
deploy_gitea_runner_current_version: "{{ _gitea_runner_old_release.stdout | regex_replace('v', '') }}"
when: _gitea_runner_old_release.stdout is defined
and (_gitea_runner_old_release.stdout | length > 0)
- name: "Remove old compose binary if different"
ansible.builtin.file:
path: "{{ install_docker_compose_path }}"
state: absent
register: _docker_compose_binary_removed
when: install_docker_compose_current_version is defined
and install_docker_compose_wanted_version not in install_docker_compose_current_version
- name: "Download and install compose:{{ install_docker_compose_version }}"
- name: "Install gitea_runner"
when: deploy_gitea_runner_current_version is not defined
or deploy_gitea_runner_wanted_version not in deploy_gitea_runner_current_version
block:
- name: "Download and install gitea_runner version:{{ hashi_consul_envoy_version }}"
ansible.builtin.get_url:
url: "{{ install_docker_compose_github_url }}/releases/download/v{{ install_docker_compose_wanted_version }}/docker-compose-linux-{{ ansible_architecture }}"
dest: "{{ install_docker_compose_path }}"
url: "{{ deploy_gitea_runner_gitea_url }}/releases/download/v{{ deploy_gitea_runner_wanted_version }}/act_runner-{{ deploy_gitea_runner_wanted_version }}-linux-{{ deploy_gitea_runner_arch_map[ansible_distribution] }}"
dest: "{{ hashi_consul_envoy_path }}"
force: true
owner: root
group: root
mode: '0755'
when: (install_docker_compose_current_version is not defined)
or (_docker_compose_binary_removed.changed)
- name: "Update version file"
ansible.builtin.copy:
content: "{{ deploy_gitea_runner_wanted_version }}"
dest: "{{ deploy_gitea_runner_directory }}/.version"
mode: "0600"

View File

@ -1,2 +1,11 @@
---
# vars file for deploy_gitea_runner
deploy_gitea_runner_path: "/usr/local/bin/act-runner"
deploy_gitea_runner_gitea_api: https://gitea.com/api/v1/repos/gitea/act_runner
deploy_gitea_runner_gitea_url: https://gitea.com/gitea/act_runner
deploy_gitea_runner_arch_map:
x86_64: 'amd64'
aarch64: 'arm64'
armv7l: 'arm-7'
armv5tel: 'arm-5'
armv6l: 'arm-6'