From b7b340c93357668eb9a780d9f532f5838a57ee0f Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Thu, 27 Jul 2023 19:12:18 +0200 Subject: [PATCH] added another bunch of things --- defaults/main.yml | 17 ++++------- handlers/main.yml | 20 ++++++++++++- meta/main.yml | 7 +++-- tasks/configure.yml | 35 ++++++++++++++++++++++ tasks/main.yml | 5 ++++ tasks/prerequisites.yml | 27 +++++++++++++++++ templates/config.yaml.j2 | 2 +- templates/docker-compose.yml.j2 | 22 +++++++++----- templates/gitea-actions-runner.service.j2 | 13 -------- templates/gitea-actions-runnner.service.j2 | 13 ++++++++ 10 files changed, 123 insertions(+), 38 deletions(-) create mode 100644 tasks/configure.yml create mode 100644 tasks/prerequisites.yml delete mode 100644 templates/gitea-actions-runner.service.j2 create mode 100644 templates/gitea-actions-runnner.service.j2 diff --git a/defaults/main.yml b/defaults/main.yml index 3d41c58..e91746d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,30 +1,23 @@ --- # defaults file for deploy_adguard -deploy_gitea_runner_directory: /opt/adguard +deploy_gitea_runner_directory: /opt/gitea-actions deploy_gitea_runner_timezone: "Europe/Paris" deploy_gitea_runner_start_service: false +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: debug runner: file: .runner capacity: 1 - envs: - env_file: .env 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: false + enabled: true container: network: "gitea-actions_internal" privileged: true diff --git a/handlers/main.yml b/handlers/main.yml index 9856457..d295f45 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,20 @@ --- -# handlers file for deploy_gitea_runner +# handlers file for deploy_adguard +- name: "Reload systemd file" + ansible.builtin.systemd: + daemon_reload: true + listen: "systemctl-daemon-reload" + +- name: "Enable gitea-actions-runnner service" + ansible.builtin.service: + name: gitea-actions-runnner + enabled: true + listen: "systemctl-enable-gitea-actions-runnner" + +- name: "Start gitea-actions-runnner service" + ansible.builtin.service: + name: gitea-actions-runnner + state: restarted + listen: "systemctl-restart-gitea-actions-runnner" + throttle: 1 + when: deploy_gitea_runner_start_service diff --git a/meta/main.yml b/meta/main.yml index 28e0f94..fcd7147 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -4,7 +4,7 @@ galaxy_info: namespace: 'ednxzu' role_name: 'deploy_gitea_runner' author: 'Bertrand Lanson' - description: '' + description: 'Deploy gitea-actions CICD runners using docker-compose on Debian based distributions' license: 'license (BSD, MIT)' min_ansible_version: '2.10' platforms: @@ -15,11 +15,12 @@ galaxy_info: - name: Debian versions: - bullseye + - bookworm galaxy_tags: - 'ubuntu' - 'debian' - - 'adguard' - - 'adblock' + - 'gitea' + - 'cicd' - 'docker' dependencies: [] diff --git a/tasks/configure.yml b/tasks/configure.yml new file mode 100644 index 0000000..737d7a3 --- /dev/null +++ b/tasks/configure.yml @@ -0,0 +1,35 @@ +--- +# task/configure file for deploy_adguard +- name: "Copy gitea-actions-runnner.service file" + ansible.builtin.template: + src: "gitea-actions-runnner.service.j2" + dest: "/etc/systemd/system/gitea-actions-runnner.service" + owner: root + group: root + mode: '0644' + notify: + - systemctl-daemon-reload + +- name: "Configure docker-compose deployment" + block: + - name: "Copy docker-compose.yml template" + ansible.builtin.template: + src: "docker-compose.yml.j2" + dest: "{{ deploy_gitea_runner_directory }}/docker-compose.yml" + owner: root + group: root + mode: '0600' + notify: + - systemctl-enable-gitea-actions-runnner + - systemctl-restart-gitea-actions-runnner + +- 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-restart-gitea-actions-runnner diff --git a/tasks/main.yml b/tasks/main.yml index 7aa1552..66ce02a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,7 @@ --- # task/main file for deploy_gitea_runner +- name: "Import prerequisites.yml" + ansible.builtin.include_tasks: prerequisites.yml + +- name: "Import configure.yml" + ansible.builtin.include_tasks: configure.yml diff --git a/tasks/prerequisites.yml b/tasks/prerequisites.yml new file mode 100644 index 0000000..6488383 --- /dev/null +++ b/tasks/prerequisites.yml @@ -0,0 +1,27 @@ +--- +# task/prerequisites file for deploy_gitea_runner +- name: "Create gitea_actions directory" + ansible.builtin.file: + path: "{{ deploy_gitea_runner_directory }}" + state: directory + owner: root + group: root + mode: '0755' + +- name: "Create gitea_actions/data directory" + ansible.builtin.file: + path: "{{ deploy_gitea_runner_directory }}/data" + state: directory + owner: root + group: root + mode: '0755' + +- name: "Create gitea_actions/cache directory" + ansible.builtin.file: + path: "{{ deploy_gitea_runner_directory }}/cache" + state: directory + owner: root + group: root + mode: '0755' + when: deploy_gitea_runner_config['cache']['enabled'] is defined + and deploy_gitea_runner_config['cache']['enabled'] diff --git a/templates/config.yaml.j2 b/templates/config.yaml.j2 index ec64ae3..b388546 100644 --- a/templates/config.yaml.j2 +++ b/templates/config.yaml.j2 @@ -1,2 +1,2 @@ # {{ ansible_managed }} -{{ deploy_adguard_config | to_yaml }} \ No newline at end of file +{{ deploy_gitea_runner_config | to_nice_yaml }} \ No newline at end of file diff --git a/templates/docker-compose.yml.j2 b/templates/docker-compose.yml.j2 index df92a92..4123b52 100644 --- a/templates/docker-compose.yml.j2 +++ b/templates/docker-compose.yml.j2 @@ -9,18 +9,22 @@ services: target: /config.yaml environment: CONFIG_FILE: /config.yaml - GITEA_INSTANCE_URL: "https://git.ednz.fr" - GITEA_RUNNER_REGISTRATION_TOKEN: "cWetxKkQT0EpdEkh5K9E7Cq5a7t0RWv5BCUnmuxP" - GITEA_RUNNER_NAME: "hs1-actions-runner" + 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: 1234 - published: 1234 + - target: {{ deploy_gitea_runner_config['cache']['port'] }} + published: {{ deploy_gitea_runner_config['cache']['port'] }} protocol: tcp mode: ingress +{%- endif %} networks: - internal @@ -32,14 +36,16 @@ volumes: data: driver_opts: o: bind - device: /opt/gitea-actions/data + 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: /opt/gitea-actions/cache + device: {{ deploy_gitea_runner_directory }}/cache type: none +{%- endif %} configs: config_yaml: - file: /opt/gitea-actions/config.yaml \ No newline at end of file + file: {{ deploy_gitea_runner_directory }}/config.yaml diff --git a/templates/gitea-actions-runner.service.j2 b/templates/gitea-actions-runner.service.j2 deleted file mode 100644 index 9994c39..0000000 --- a/templates/gitea-actions-runner.service.j2 +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Free and open source, powerful network-wide ads & trackers blocking DNS server. -After=docker.service -Requires=docker.service - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/bin/bash -c "docker-compose -f {{ deploy_adguard_directory }}/docker-compose.yml up --detach" -ExecStop=/bin/bash -c "docker-compose -f {{ deploy_adguard_directory }}/docker-compose.yml down" - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/templates/gitea-actions-runnner.service.j2 b/templates/gitea-actions-runnner.service.j2 new file mode 100644 index 0000000..82546b0 --- /dev/null +++ b/templates/gitea-actions-runnner.service.j2 @@ -0,0 +1,13 @@ +[Unit] +Description=Act runner is a runner for Gitea based on Gitea fork of act. +After=docker.service +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 \ No newline at end of file