From bf3da5e8062355fde11c0cca0ac11a5d6adefeee Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Mon, 11 Dec 2023 19:01:57 +0100 Subject: [PATCH] feat(test): some test refactoring --- molecule/default/converge.yml | 1 + molecule/default/prepare.yml | 9 +---- molecule/default/requirements.yml | 3 +- molecule/default/verify.yml | 3 +- molecule/default_vagrant/converge.yml | 1 + molecule/default_vagrant/group_vars/all.yml | 12 +++--- molecule/default_vagrant/prepare.yml | 9 +---- molecule/default_vagrant/requirements.yml | 3 +- molecule/default_vagrant/verify.yml | 1 + molecule/with_docker_host/converge.yml | 1 + molecule/with_docker_host/requirements.yml | 2 +- molecule/with_docker_host/verify.yml | 3 +- tasks/configure.yml | 5 +-- tasks/install_docker.yml | 41 ++++++++------------- 14 files changed, 39 insertions(+), 55 deletions(-) diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index ea9f7d8..2dab7e5 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -1,6 +1,7 @@ --- - name: Converge hosts: all + become: true tasks: - name: "Include ednxzu.deploy_gitea_runner" ansible.builtin.include_role: diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 60391d6..7f58328 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -1,17 +1,10 @@ --- - name: Prepare hosts: all + become: true 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 diff --git a/molecule/default/requirements.yml b/molecule/default/requirements.yml index e53b0f7..94c5a52 100644 --- a/molecule/default/requirements.yml +++ b/molecule/default/requirements.yml @@ -3,4 +3,5 @@ roles: - name: ednxzu.manage_repositories - name: ednxzu.manage_apt_packages - - name: mhutter.docker-systemd-service + - name: ednxzu.install_docker + - name: ednxzu.docker_systemd_service diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index bf52da2..a72e7ac 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -1,7 +1,8 @@ --- - name: Verify hosts: all - gather_facts: false + gather_facts: true + become: true tasks: - name: "Test: file /etc/hosts" block: diff --git a/molecule/default_vagrant/converge.yml b/molecule/default_vagrant/converge.yml index ea9f7d8..2dab7e5 100644 --- a/molecule/default_vagrant/converge.yml +++ b/molecule/default_vagrant/converge.yml @@ -1,6 +1,7 @@ --- - name: Converge hosts: all + become: true tasks: - name: "Include ednxzu.deploy_gitea_runner" ansible.builtin.include_role: diff --git a/molecule/default_vagrant/group_vars/all.yml b/molecule/default_vagrant/group_vars/all.yml index 6470cdf..45ca4fe 100644 --- a/molecule/default_vagrant/group_vars/all.yml +++ b/molecule/default_vagrant/group_vars/all.yml @@ -4,16 +4,16 @@ 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_register: false +deploy_gitea_runner_start_service: false +deploy_gitea_runner_server_url: https://git.ednz.fr deploy_gitea_runner_server_token: "" -deploy_gitea_runner_name: gitea-runner +deploy_gitea_runner_name: vagrant-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 + file: "{{ deploy_gitea_runner_directory }}/.runner" # this HAS TO BE .runner if deploy_gitea_runner_deploy_method is docker capacity: 1 timeout: 3h insecure: false @@ -22,7 +22,7 @@ deploy_gitea_runner_config: labels: [] cache: enabled: true - dir: "/cache" # this HAS TO BE /cache if deploy_gitea_runner_deploy_method is docker + dir: "{{ deploy_gitea_runner_directory }}/cache" # this HAS TO BE /cache if deploy_gitea_runner_deploy_method is docker host: 127.0.0.1 port: 4974 container: diff --git a/molecule/default_vagrant/prepare.yml b/molecule/default_vagrant/prepare.yml index 60391d6..7f58328 100644 --- a/molecule/default_vagrant/prepare.yml +++ b/molecule/default_vagrant/prepare.yml @@ -1,17 +1,10 @@ --- - name: Prepare hosts: all + become: true 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 diff --git a/molecule/default_vagrant/requirements.yml b/molecule/default_vagrant/requirements.yml index e53b0f7..94c5a52 100644 --- a/molecule/default_vagrant/requirements.yml +++ b/molecule/default_vagrant/requirements.yml @@ -3,4 +3,5 @@ roles: - name: ednxzu.manage_repositories - name: ednxzu.manage_apt_packages - - name: mhutter.docker-systemd-service + - name: ednxzu.install_docker + - name: ednxzu.docker_systemd_service diff --git a/molecule/default_vagrant/verify.yml b/molecule/default_vagrant/verify.yml index 60161b1..ec450ea 100644 --- a/molecule/default_vagrant/verify.yml +++ b/molecule/default_vagrant/verify.yml @@ -2,4 +2,5 @@ - name: Verify hosts: all gather_facts: true + become: true tasks: diff --git a/molecule/with_docker_host/converge.yml b/molecule/with_docker_host/converge.yml index ea9f7d8..2dab7e5 100644 --- a/molecule/with_docker_host/converge.yml +++ b/molecule/with_docker_host/converge.yml @@ -1,6 +1,7 @@ --- - name: Converge hosts: all + become: true tasks: - name: "Include ednxzu.deploy_gitea_runner" ansible.builtin.include_role: diff --git a/molecule/with_docker_host/requirements.yml b/molecule/with_docker_host/requirements.yml index e53b0f7..97a7046 100644 --- a/molecule/with_docker_host/requirements.yml +++ b/molecule/with_docker_host/requirements.yml @@ -3,4 +3,4 @@ roles: - name: ednxzu.manage_repositories - name: ednxzu.manage_apt_packages - - name: mhutter.docker-systemd-service + - name: ednxzu.docker_systemd_service diff --git a/molecule/with_docker_host/verify.yml b/molecule/with_docker_host/verify.yml index bf52da2..a72e7ac 100644 --- a/molecule/with_docker_host/verify.yml +++ b/molecule/with_docker_host/verify.yml @@ -1,7 +1,8 @@ --- - name: Verify hosts: all - gather_facts: false + gather_facts: true + become: true tasks: - name: "Test: file /etc/hosts" block: diff --git a/tasks/configure.yml b/tasks/configure.yml index 9988646..ab423cb 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -1,6 +1,6 @@ --- # task/configure file for deploy_adguard -- name: "configure host installation" +- name: "Configure host installation" when: deploy_gitea_runner_deploy_method == 'host' block: - name: "Copy gitea-runnner.service file" @@ -27,7 +27,7 @@ - systemctl-enable-gitea-runner - systemctl-restart-gitea-runner -- name: "configure docker installation" +- name: "Configure docker installation" when: deploy_gitea_runner_deploy_method == 'docker' block: - name: "Copy config.yaml" @@ -39,4 +39,3 @@ mode: '0600' when: deploy_gitea_runner_config != {} become: true - diff --git a/tasks/install_docker.yml b/tasks/install_docker.yml index a2f8687..46b3513 100644 --- a/tasks/install_docker.yml +++ b/tasks/install_docker.yml @@ -1,36 +1,27 @@ --- # task/install_docker file for deploy_gitea_runner -- name: "Include mhutter.docker-systemd-service" +- name: "Include ednxzu.docker_systemd_service" ansible.builtin.include_role: - name: mhutter.docker-systemd-service + name: ednxzu.docker_systemd_service apply: become: true vars: - container_image: "gitea/act_runner:{{ deploy_gitea_runner_version }}" - container_name: "{{ deploy_gitea_runner_name }}" - container_docker_pull: true - container_docker_pull_force_source: true - container_host_network: false - 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: + docker_systemd_service_container_name: "{{ deploy_gitea_runner_name }}" + docker_systemd_service_image: "gitea/act_runner:{{ deploy_gitea_runner_version }}" + docker_systemd_service_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 + docker_systemd_service_flags: + - network: bridge + - volume: + - "/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" + - publish: "{{ [deploy_gitea_runner_config.cache.port ~ ':' ~ deploy_gitea_runner_config.cache.port] if deploy_gitea_runner_config.cache.enabled else [] }}" + docker_systemd_service_name: "{{ docker_systemd_service_container_name }}_container" + docker_systemd_service_state: "{{ 'started' if deploy_gitea_runner_start_service else 'stopped'}}" + docker_systemd_service_restart: "{{ true if deploy_gitea_runner_start_service else false}}"