feat: add binary and docker install. still using mhutter role until fork

This commit is contained in:
Bertrand Lanson 2023-12-02 23:02:05 +01:00
parent 45754ea894
commit 9f42a1df42
18 changed files with 275 additions and 135 deletions

View File

@ -22,10 +22,10 @@ deploy_gitea_runner_config:
labels: [] labels: []
cache: cache:
enabled: true enabled: true
dir: "{{ deploy_gitea_runner_directory }}/cache" # this HAS TO BE /cache if deploy_gitea_runner_deploy_method is docker dir: "{{ deploy_gitea_runner_directory }}" # this HAS TO BE /cache if deploy_gitea_runner_deploy_method is docker
host: 127.0.0.1 host: 127.0.0.1
port: 4974 port: 4974
external_server: external_server: ""
container: container:
network: "" network: ""
privileged: false privileged: false
@ -34,4 +34,4 @@ deploy_gitea_runner_config:
valid_volumes: [] valid_volumes: []
docker_host: "-" docker_host: "-"
host: host:
workdir_parent: workdir_parent: ""

View File

@ -3,12 +3,14 @@
- name: "Reload systemd file" - name: "Reload systemd file"
ansible.builtin.systemd: ansible.builtin.systemd:
daemon_reload: true daemon_reload: true
become: true
listen: "systemctl-daemon-reload" listen: "systemctl-daemon-reload"
- name: "Enable gitea-runner service" - name: "Enable gitea-runner service"
ansible.builtin.service: ansible.builtin.service:
name: gitea-runner name: gitea-runner
enabled: true enabled: true
become: true
listen: "systemctl-enable-gitea-runner" listen: "systemctl-enable-gitea-runner"
- name: "Start gitea-runner service" - name: "Start gitea-runner service"
@ -18,3 +20,4 @@
listen: "systemctl-restart-gitea-runner" listen: "systemctl-restart-gitea-runner"
throttle: 1 throttle: 1
when: deploy_gitea_runner_start_service when: deploy_gitea_runner_start_service
become: true

View File

@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include ednxzu.deploy_gitea_runner"
ansible.builtin.include_role:
name: "ednxzu.deploy_gitea_runner"

View File

@ -0,0 +1,42 @@
---
# defaults file for deploy_gitea_runner
deploy_gitea_runner_version: latest
deploy_gitea_runner_deploy_method: docker # deployment method, either host or docker.
deploy_gitea_runner_directory: /opt/gitea-actions
deploy_gitea_runner_timezone: "Europe/Paris"
deploy_gitea_runner_register: true
deploy_gitea_runner_start_service: true
deploy_gitea_runner_server_url: https://git.example.com
deploy_gitea_runner_server_token: ""
deploy_gitea_runner_name: gitea-runner
deploy_gitea_runner_config:
log:
level: info
runner:
file: ".runner" # this HAS TO BE .runner if deploy_gitea_runner_deploy_method is docker
capacity: 1
timeout: 3h
insecure: false
fetch_timeout: 5s
fetch_interval: 15s
labels:
- alpine-latest:docker://node:16-alpine
- alpine-3.18:docker://node:16-alpine3.18
- alpine-3.17:docker://node:16-alpine3.17
- alpine-3.16:docker://node:16-alpine3.16
- ubuntu-latest:docker://ghcr.io/catthehacker/ubuntu:act-latest
- ubuntu-22.04:docker://ghcr.io/catthehacker/ubuntu:act-22.04
- ubuntu-20.04:docker://ghcr.io/catthehacker/ubuntu:act-20.04
cache:
enabled: true
dir: "/cache" # this HAS TO BE /cache if deploy_gitea_runner_deploy_method is docker
host: 127.0.0.1
port: 4974
container:
network: ""
privileged: false
options: ""
workdir_parent:
valid_volumes: []
docker_host: "-"
host: {}

View File

@ -0,0 +1,35 @@
---
dependency:
name: galaxy
options:
requirements-file: ./requirements.yml
driver:
name: vagrant
provider:
name: libvirt
platforms:
- name: instance
box: generic/${MOLECULE_TEST_OS}
cpus: 4
memory: 4096
provisioner:
name: ansible
config_options:
defaults:
remote_tmp: /tmp/.ansible
verifier:
name: ansible
scenario:
name: default_vagrant
test_sequence:
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
- idempotence
- verify
- cleanup
- destroy

View File

@ -0,0 +1,17 @@
---
- name: Prepare
hosts: all
tasks:
- name: "Include ednxzu.install_docker"
ansible.builtin.include_role:
name: ednxzu.install_docker
vars:
install_docker_edition: ce
install_docker_start_service: true
install_docker_compose: false
install_docker_compose_version: latest
install_docker_python_packages: true
install_docker_python_packages_version: latest
install_docker_users: []
install_docker_daemon_options:
live-restore: true

View File

@ -0,0 +1,6 @@
---
# requirements file for molecule
roles:
- name: ednxzu.manage_repositories
- name: ednxzu.manage_apt_packages
- name: mhutter.docker-systemd-service

View File

@ -0,0 +1,5 @@
---
- name: Verify
hosts: all
gather_facts: true
tasks:

View File

@ -1,23 +1,42 @@
--- ---
# task/configure file for deploy_adguard # task/configure file for deploy_adguard
- name: "Copy gitea-runnner.service file" - name: "configure host installation"
ansible.builtin.template: when: deploy_gitea_runner_deploy_method == 'host'
src: "gitea-runner.service.j2" block:
dest: "/etc/systemd/system/gitea-runner.service" - name: "Copy gitea-runnner.service file"
owner: root ansible.builtin.template:
group: root src: "gitea-runner.service.j2"
mode: '0644' dest: "/etc/systemd/system/gitea-runner.service"
notify: owner: root
- systemctl-daemon-reload group: root
mode: '0644'
become: true
notify:
- systemctl-daemon-reload
- name: "Copy config.yaml"
ansible.builtin.template:
src: "config.yaml.j2"
dest: "{{ deploy_gitea_host_config_directory }}/config.yaml"
owner: act_runner
group: act_runner
mode: '0600'
when: deploy_gitea_runner_config != {}
become: true
notify:
- systemctl-enable-gitea-runner
- systemctl-restart-gitea-runner
- name: "configure docker installation"
when: deploy_gitea_runner_deploy_method == 'docker'
block:
- name: "Copy config.yaml"
ansible.builtin.template:
src: "config.yaml.j2"
dest: "{{ deploy_gitea_runner_directory }}/config.yaml"
owner: root
group: root
mode: '0600'
when: deploy_gitea_runner_config != {}
become: true
- name: "Copy config.yaml"
ansible.builtin.template:
src: "config.yaml.j2"
dest: "{{ deploy_gitea_runner_directory }}/config.yaml"
owner: root
group: root
mode: '0600'
when: deploy_gitea_runner_config != {}
notify:
- systemctl-enable-gitea-runner
- systemctl-restart-gitea-runner

View File

@ -1,14 +1,36 @@
--- ---
# task/install_docker file for deploy_gitea_runner # task/install_docker file for deploy_gitea_runner
- name: "Configure docker-compose deployment" - name: "Include mhutter.docker-systemd-service"
block: ansible.builtin.include_role:
- name: "Copy docker-compose.yml template" name: mhutter.docker-systemd-service
ansible.builtin.template: apply:
src: "docker-compose.yml.j2" become: true
dest: "{{ deploy_gitea_runner_directory }}/docker-compose.yml" vars:
owner: root container_image: "gitea/act_runner:{{ deploy_gitea_runner_version }}"
group: root container_name: "{{ deploy_gitea_runner_name }}"
mode: '0600' container_docker_pull: true
notify: container_docker_pull_force_source: true
- systemctl-enable-gitea-runner container_host_network: false
- systemctl-restart-gitea-runner container_network: "bridge"
container_ports: "{{ [deploy_gitea_runner_config.cache.port ~ ':' ~ deploy_gitea_runner_config.cache.port] if deploy_gitea_runner_config.cache.enabled else [] }}"
container_volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "{{ deploy_gitea_runner_directory }}/config.yaml:/config.yaml"
- "{{ deploy_gitea_runner_directory }}/data:/data"
- "{{ deploy_gitea_runner_directory }}/cache:/cache"
container_env:
TZ: "{{ deploy_gitea_runner_timezone }}"
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: "{{ deploy_gitea_runner_server_url }}"
GITEA_RUNNER_REGISTRATION_TOKEN: "{{ deploy_gitea_runner_server_token }}"
GITEA_RUNNER_NAME: "{{ deploy_gitea_runner_name }}"
service_name: "{{ deploy_gitea_runner_name }}_container"
service_systemd_options: []
service_systemd_unit_options:
After: docker.service
PartOf: docker.service
Requires: docker.service
service_enabled: true
service_masked: false
service_state: "{{ 'started' if deploy_gitea_runner_start_service else 'stopped'}}"
service_restart: false

View File

@ -14,6 +14,7 @@
changed_when: false changed_when: false
check_mode: false check_mode: false
register: _gitea_runner_is_installed register: _gitea_runner_is_installed
become: true
- name: "Check current gitea_runner version" - name: "Check current gitea_runner version"
ansible.builtin.command: "cat {{ deploy_gitea_runner_directory }}/.version" ansible.builtin.command: "cat {{ deploy_gitea_runner_directory }}/.version"
@ -21,6 +22,7 @@
check_mode: false check_mode: false
changed_when: false changed_when: false
when: _gitea_runner_is_installed.stat.exists when: _gitea_runner_is_installed.stat.exists
become: true
- name: "Set facts for wanted gitea_runner release" - name: "Set facts for wanted gitea_runner release"
ansible.builtin.set_fact: ansible.builtin.set_fact:
@ -35,6 +37,7 @@
and (_gitea_runner_old_release.stdout | length > 0) and (_gitea_runner_old_release.stdout | length > 0)
- name: "Install gitea_runner" - name: "Install gitea_runner"
become: true
when: deploy_gitea_runner_current_version is not defined when: deploy_gitea_runner_current_version is not defined
or deploy_gitea_runner_wanted_version not in deploy_gitea_runner_current_version or deploy_gitea_runner_wanted_version not in deploy_gitea_runner_current_version
block: block:

View File

@ -3,12 +3,12 @@
- name: "Import prerequisites.yml" - name: "Import prerequisites.yml"
ansible.builtin.include_tasks: prerequisites.yml ansible.builtin.include_tasks: prerequisites.yml
- name: "Import install.yml"
ansible.builtin.include_tasks: "install_{{ deploy_gitea_runner_deploy_method }}.yml"
- name: "Import configure.yml" - name: "Import configure.yml"
ansible.builtin.include_tasks: configure.yml ansible.builtin.include_tasks: configure.yml
- name: "Import install.yml"
ansible.builtin.include_tasks: "install_{{ deploy_gitea_runner_deploy_method }}.yml"
- name: "Import register.yml" - name: "Import register.yml"
ansible.builtin.include_tasks: register.yml ansible.builtin.include_tasks: register.yml
when: deploy_gitea_runner_register when: deploy_gitea_runner_register

View File

@ -1,28 +1,69 @@
--- ---
# task/prerequisites file for deploy_gitea_runner # task/prerequisites file for deploy_gitea_runner
- name: "Create gitea_actions directory" - name: "Prerequisites for host installation"
ansible.builtin.file: when: deploy_gitea_runner_deploy_method == 'host'
path: "{{ deploy_gitea_runner_directory }}" block:
state: directory - name: "Create group act_runner"
owner: root ansible.builtin.group:
group: root name: "{{ deploy_gitea_runner_host_user }}"
mode: '0755' state: present
become: true
- name: "Create gitea_actions/data directory" - name: "Create user act_runner"
ansible.builtin.file: ansible.builtin.user:
path: "{{ deploy_gitea_runner_directory }}/data" name: "{{ deploy_gitea_runner_host_user }}"
state: directory group: "{{ deploy_gitea_runner_host_user }}"
owner: root home: "{{ deploy_gitea_runner_directory }}"
group: root shell: /bin/false
mode: '0755' state: present
when: deploy_gitea_runner_deploy_method == "docker" become: true
- name: "Create gitea_actions/cache directory" - name: "Add act_runner user to docker group"
ansible.builtin.file: ansible.builtin.user:
path: "{{ deploy_gitea_runner_config['cache']['dir'] if deploy_gitea_runner_deploy_method == 'host' else deploy_gitea_runner_directory + '/data' }}" name: "{{ deploy_gitea_runner_host_user }}"
state: directory groups: "{{ deploy_gitea_runner_docker_group }}"
owner: root append: true
group: root become: true
mode: '0755'
when: deploy_gitea_runner_config['cache']['enabled'] is defined - name: "Create runner configuration directory"
and deploy_gitea_runner_config['cache']['enabled'] ansible.builtin.file:
path: "{{ deploy_gitea_host_config_directory }}"
state: directory
owner: act_runner
group: act_runner
mode: '0755'
become: true
- name: "Prerequisites for docker installation"
when: deploy_gitea_runner_deploy_method == 'docker'
block:
- name: "Create gitea_actions directory"
ansible.builtin.file:
path: "{{ deploy_gitea_runner_directory }}"
state: directory
owner: root
group: root
mode: '0755'
become: true
- name: "Create gitea_actions/data directory"
ansible.builtin.file:
path: "{{ deploy_gitea_runner_directory }}/data"
state: directory
owner: root
group: root
mode: '0755'
when: deploy_gitea_runner_deploy_method == "docker"
become: true
- name: "Create gitea_actions/cache directory"
ansible.builtin.file:
path: "{{ deploy_gitea_runner_directory }}/cache"
state: directory
owner: root
group: root
mode: '0755'
become: true
when: deploy_gitea_runner_config['cache']['enabled'] is defined
and deploy_gitea_runner_config['cache']['enabled']

View File

@ -16,9 +16,10 @@
GITEA_URL: "{{ deploy_gitea_runner_server_url }}" GITEA_URL: "{{ deploy_gitea_runner_server_url }}"
GITEA_TOKEN: "{{ deploy_gitea_runner_server_token }}" GITEA_TOKEN: "{{ deploy_gitea_runner_server_token }}"
GITEA_RUNNER_NAME: "{{ deploy_gitea_runner_name }}" GITEA_RUNNER_NAME: "{{ deploy_gitea_runner_name }}"
CONFIG_FILE: "{{ deploy_gitea_runner_directory }}/config.yaml" CONFIG_FILE: "{{ deploy_gitea_host_config_directory }}/config.yaml"
changed_when: false changed_when: false
register: register_gitea_runner register: register_gitea_runner
become: true
- name: "Ensure registration is successful" - name: "Ensure registration is successful"
ansible.builtin.assert: ansible.builtin.assert:

View File

@ -1,51 +0,0 @@
---
version: '3.9'
services:
runner:
image: gitea/act_runner:{{ deploy_gitea_runner_version }}
configs:
- source: config_yaml
target: /config.yaml
environment:
CONFIG_FILE: /config.yaml
GITEA_INSTANCE_URL: "{{ deploy_gitea_runner_server_url }}"
GITEA_RUNNER_REGISTRATION_TOKEN: "{{ deploy_gitea_runner_server_token }}"
GITEA_RUNNER_NAME: "{{ deploy_gitea_runner_name }}"
volumes:
- data:/data
{% if deploy_gitea_runner_config['cache']['enabled'] is defined and deploy_gitea_runner_config['cache']['enabled'] %}
- cache:/cache
{% endif %}
- /var/run/docker.sock:/var/run/docker.sock
{% if deploy_gitea_runner_config['cache']['port'] is defined %}
ports:
- target: {{ deploy_gitea_runner_config['cache']['port'] }}
published: {{ deploy_gitea_runner_config['cache']['port'] }}
protocol: tcp
mode: ingress
{% endif %}
networks:
- internal
networks:
internal:
driver: bridge
volumes:
data:
driver_opts:
o: bind
device: {{ deploy_gitea_runner_directory }}/data
type: none
{% if deploy_gitea_runner_config['cache']['enabled'] is defined and deploy_gitea_runner_config['cache']['enabled'] %}
cache:
driver_opts:
o: bind
device: {{ deploy_gitea_runner_directory }}/cache
type: none
{%- endif %}
configs:
config_yaml:
file: {{ deploy_gitea_runner_directory }}/config.yaml

View File

@ -1,29 +1,16 @@
{% if deploy_gitea_runner_deploy_method == 'docker' %}
[Unit] [Unit]
Description=Act runner is a runner for Gitea based on Gitea fork of act. Description=Gitea Actions runner
After=docker.service Documentation=https://gitea.com/gitea/act_runner
Requires=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/bash -c "docker-compose -f {{ deploy_gitea_runner_directory }}/docker-compose.yml up --detach"
ExecStop=/bin/bash -c "docker-compose -f {{ deploy_gitea_runner_directory }}/docker-compose.yml down"
[Install]
WantedBy=multi-user.target WantedBy=multi-user.target
{% elif deploy_gitea_runner_deploy_method == 'host' %}
[Unit]
Description=Act runner is a runner for Gitea based on Gitea fork of act.
After=network.target
Requires=network.target
[Service] [Service]
Type=simple ExecStart={{ deploy_gitea_runner_path }} daemon --config /etc/act_runner/config.yaml
EnvironmentFile=-{{ deploy_gitea_runner_directory }}/gitea-runner.env ExecReload=/bin/kill -s HUP $MAINPID
WorkingDirectory={{ deploy_gitea_runner_directory }} WorkingDirectory={{ deploy_gitea_runner_directory }}
ExecStart={{ deploy_gitea_runner_path }} daemon TimeoutSec=0
RestartSec=10
Restart=always
User=act_runner
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
{% endif %}

View File

@ -1,8 +1,11 @@
--- ---
# vars file for deploy_gitea_runner # vars file for deploy_gitea_runner
deploy_gitea_host_config_directory: "/etc/act_runner"
deploy_gitea_runner_path: "/usr/local/bin/act-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_api: https://gitea.com/api/v1/repos/gitea/act_runner
deploy_gitea_runner_gitea_url: https://gitea.com/gitea/act_runner deploy_gitea_runner_gitea_url: https://gitea.com/gitea/act_runner
deploy_gitea_runner_host_user: act_runner
deploy_gitea_runner_docker_group: docker
deploy_gitea_runner_arch_map: deploy_gitea_runner_arch_map:
x86_64: 'amd64' x86_64: 'amd64'
aarch64: 'arm64' aarch64: 'arm64'