From 45d29d1280aaa663ab18f36cb3375bdf23a0b3b8 Mon Sep 17 00:00:00 2001 From: polyfloyd Date: Sun, 2 Jun 2024 12:22:37 +0200 Subject: [PATCH] Add git-ci role --- git-ci.yaml | 10 ++++ hosts.yaml | 3 ++ roles/git-ci/defaults/main.yaml | 2 + roles/git-ci/handlers/main.yaml | 7 +++ roles/git-ci/tasks/main.yaml | 50 +++++++++++++++++++ roles/git-ci/templates/forgejo-runner.service | 14 ++++++ 6 files changed, 86 insertions(+) create mode 100644 git-ci.yaml create mode 100644 roles/git-ci/defaults/main.yaml create mode 100644 roles/git-ci/handlers/main.yaml create mode 100644 roles/git-ci/tasks/main.yaml create mode 100644 roles/git-ci/templates/forgejo-runner.service diff --git a/git-ci.yaml b/git-ci.yaml new file mode 100644 index 0000000..115ac6d --- /dev/null +++ b/git-ci.yaml @@ -0,0 +1,10 @@ +--- +- hosts: git-ci + roles: + - common + - common-bitlair + - git-ci + vars: + root_access: + - ak + - polyfloyd diff --git a/hosts.yaml b/hosts.yaml index dbd5690..14a3db2 100644 --- a/hosts.yaml +++ b/hosts.yaml @@ -17,6 +17,9 @@ all: git: hosts: git.bitlair.nl: + git-ci: + hosts: + 2a02:166b:92:1337:5054:ff:fee8:31cd: pad: hosts: pad.bitlair.nl: diff --git a/roles/git-ci/defaults/main.yaml b/roles/git-ci/defaults/main.yaml new file mode 100644 index 0000000..82807d7 --- /dev/null +++ b/roles/git-ci/defaults/main.yaml @@ -0,0 +1,2 @@ +runner_wd: /var/lib/forgejo-runner +runner_version: 3.4.1 diff --git a/roles/git-ci/handlers/main.yaml b/roles/git-ci/handlers/main.yaml new file mode 100644 index 0000000..99756ad --- /dev/null +++ b/roles/git-ci/handlers/main.yaml @@ -0,0 +1,7 @@ +--- +- import_tasks: ../../common/handlers/main.yaml + +- name: restart forgejo-runner + systemd: + name: forgejo-runner + state: restarted diff --git a/roles/git-ci/tasks/main.yaml b/roles/git-ci/tasks/main.yaml new file mode 100644 index 0000000..3565d0a --- /dev/null +++ b/roles/git-ci/tasks/main.yaml @@ -0,0 +1,50 @@ +--- +- tags: forgejo_runner + block: + - name: Install dependencies + apt: + name: docker.io + + - name: Download forgejo-runner + get_url: + url: "https://code.forgejo.org/forgejo/runner/releases/download/v{{ runner_version }}/forgejo-runner-{{ runner_version }}-linux-amd64" + dest: /usr/local/bin/forgejo-runner + mode: 0755 + notify: restart forgejo-runner + + - name: Create runner dir + file: + state: directory + path: "{{ runner_wd }}" + owner: root + group: root + mode: 0755 + + - name: Register runner + command: "forgejo-runner register --no-interactive --instance={{ forgejo_url }} --token={{ forgejo_runner_token }}" + args: + chdir: "{{ runner_wd }}" + creates: "{{ runner_wd }}/.runner" + + - name: Install service file + template: + src: forgejo-runner.service + dest: /etc/systemd/system/forgejo-runner.service + owner: root + group: root + mode: 0644 + notify: restart forgejo-runner + + - name: Enable service + systemd: + name: forgejo-runner + enabled: yes + daemon_reload: true + + - name: Start service + systemd: + name: forgejo-runner + state: started + daemon_reload: true + + - meta: flush_handlers diff --git a/roles/git-ci/templates/forgejo-runner.service b/roles/git-ci/templates/forgejo-runner.service new file mode 100644 index 0000000..c9550d2 --- /dev/null +++ b/roles/git-ci/templates/forgejo-runner.service @@ -0,0 +1,14 @@ +# {{ ansible_managed }} + +[Unit] +Description=Forgejo Runner +After=network.target + +[Service] +ExecStart=/usr/local/bin/forgejo-runner daemon +WorkingDirectory={{ runner_wd }} +Restart=on-failure +RestartSec=10s + +[Install] +WantedBy=multi-user.target