Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install fleeting-plugin-openstack directly from GitHub #303

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions molecule/gitlab_runner/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,19 @@ provisioner:
gitlab_runner_registry_mirror: "https://registry-mirror.example"
gitlab_runner_listen_address: "127.0.0.1:9252"
gitlab_runner_set_default_network_opts: true
gitlab_runner_autoscaler_openstack_auth_url: "https://openstack.helmholtz.de:5000"
gitlab_runner_autoscaler_openstack_username: "openstackuser"
gitlab_runner_autoscaler_openstack_password: "123456"
gitlab_runner_autoscaler_openstack_project_id: "e5cc8263-be6c-45a7-a6ce-e852dac95395"
gitlab_runner_autoscaler_openstack_project_name: "openstack-project"
gitlab_runner_autoscaler_openstack_user_domain_name: "Default"
gitlab_runner_autoscaler_openstack_region_name: "Default"
gitlab_runner_list:
- name: "test01"
url: "https://gitlab.com"
description: "Molecule test runner"
authentication_token: "${AUTHENTICATION_TOKEN}"
executor: "docker+machine"
executor: "docker-autoscaler"
environment: ["CI_CPUS=8", "DOCKER_TLS_CERTDIR=/certs"]
docker_volumes: ["/cache", "/certs/client", "/opt/docker/daemon.json:/etc/docker/daemon.json:ro"]
docker_image: "python:3.8"
Expand All @@ -89,28 +96,21 @@ provisioner:
tags: ["docker", "hifis"]
locked: true
limit: 10
autoscaler_max_builds: 1
autoscaler_idle_count: 5
autoscaler_max_instances: 10
machine_idle_count: 5
machine_idle_time: 7200
machine_max_builds: 4
machine_max_growth_rate: 2
machine_driver: "openstack"
machine_name: "auto-scale-%s"
machine_options:
- "openstack-auth-url=https://openstack.example:5000/v3"
- "openstack-image-id=73f07dd3-fa8b-468f-b6bc-b0cd4510f5d0"
- "openstack-flavor-name=m1.small"
- "openstack-net-id=7834deeb-8bd5-4fc7-b35b-24035d8f47a7"
- "openstack-username=gitlab-runner"
- "openstack-password=secret"
- "openstack-tenant-id=123456"
- "openstack-domain-name=default"
- "openstack-ssh-user=core"
- "openstack-sec-groups=Internal"
- "openstack-keypair-name=runners-internal"
- "openstack-private-key-file=/etc/gitlab-runner/gitlab_runner_key"
- "openstack-user-data-file=/etc/gitlab-runner/ignition.json"
- "openstack-active-timeout=300"
- "engine-registry-mirror=https://registry-mirror.example"
autoscaler_group_name: "hifis"
autoscaler_cloud_name: "openstack"
autoscaler_clouds_config: "/etc/gitlab-runner/clouds.yaml"
autoscaler_use_ignition: true
autoscaler_flavor_ref: "a7779e0c-899a-4c73-b75d-757e7722dc9b"
autoscaler_image_ref: "67c1e69a-921d-4a5c-85cf-cf2a7d94a14d"
autoscaler_network_id: "183bd5c6-e720-4601-b471-f4135a32263d"
autoscaler_security_group: "8f291fca-006c-4576-a18e-f343d06af2c4"
autoscaler_scheduler_hint: "8357bc97-580a-429f-a71d-895a3ab4b645"
autoscaler_username: "core"
autoscaler_keyname: "runner-internal"
cache_type: "s3"
cache_server_address: "https://cache.example"
cache_access_key: "key"
Expand Down
11 changes: 11 additions & 0 deletions molecule/gitlab_runner/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
when: "gitlab_runner_list | selectattr('executor', 'equalto', 'docker+machine') | list | length > 0"
failed_when: "'0.16.2-gitlab.25' not in machine_version.stdout"

- name: "Identify installed fleeting plugins"
ansible.builtin.command: "gitlab-runner fleeting list"
register: "fleeting_cmd"
changed_when: false

- name: "Assert that fleeting-plugin-openstack is installed"
when: "gitlab_runner_list | selectattr('executor', 'equalto', 'docker-autoscaler') | list | length > 0"
ansible.builtin.assert:
that:
- "'fleeting-plugin-openstack' in fleeting_cmd.stdout"

- name: "Assert that Gitlab-Runner is installed"
ansible.builtin.assert:
that:
Expand Down
4 changes: 4 additions & 0 deletions roles/gitlab_runner/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ gitlab_runner_enable_session_server: false
gitlab_runner_session_server_listen_address: "0.0.0.0:8093"
gitlab_runner_session_server_advertise_address: "{{ gitlab_runner_session_server_listen_address }}"
gitlab_runner_session_server_timeout: 1800

gitlab_runner_autoscaler_plugin_version: "0.21.1"
gitlab_runner_autoscaler_plugin_url: "https://github.com/sardinasystems/fleeting-plugin-openstack/releases/download/{{ gitlab_runner_autoscaler_plugin_version }}/fleeting-plugin-openstack_{{ gitlab_runner_autoscaler_plugin_version }}_linux_amd64.tar.gz"
gitlab_runner_autoscaler_plugin_checksumfile: "https://github.com/sardinasystems/fleeting-plugin-openstack/releases/download/{{ gitlab_runner_autoscaler_plugin_version }}/fleeting-plugin-openstack_{{ gitlab_runner_autoscaler_plugin_version }}_sha512-checksums.txt"
64 changes: 56 additions & 8 deletions roles/gitlab_runner/tasks/install.autoscaler-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,62 @@
# SPDX-License-Identifier: Apache-2.0

---
- name: "Download and install autoscaler plugin"
ansible.builtin.get_url:
url: "{{ gitlab_runner_autoscaler_plugin_url }}"
dest: "/usr/local/bin/fleeting-plugin-openstack"
checksum: "{{ gitlab_runner_autoscaler_plugin_checksum }}"
mode: '0755'
owner: "root"
group: "root"

- name: "Check if fleeting-plugin-openstack is installed"
ansible.builtin.stat:
path: "/usr/local/bin/fleeting-plugin-openstack"
register: "_fleeting_plugin_openstack_stat"

- name: "Check version of installed fleeting plugin"
when: "_fleeting_plugin_openstack_stat.stat.exists"
ansible.builtin.shell:
cmd: |
set -o pipefail
strings /usr/local/bin/fleeting-plugin-openstack | grep -oP "(?<=fleeting-plugin-openstack.Version=)(\d+\.\d+\.\d+)" | head -n 1
executable: "/bin/bash"
register: "_fleeting_plugin_version_installed"
changed_when: false
check_mode: false

- name: "Download and install fleeting plugin"
when: "not _fleeting_plugin_openstack_stat.stat.exists or _fleeting_plugin_version_installed.stdout != gitlab_runner_autoscaler_plugin_version"
block:
- name: "Create temporary directory"
ansible.builtin.tempfile:
state: "directory"
register: "tempdir_fleeting_plugin"
check_mode: false
changed_when: false

- name: "Download fleeting-plugin-openstack"
ansible.builtin.get_url:
url: "{{ gitlab_runner_autoscaler_plugin_url }}"
dest: "{{ (tempdir_fleeting_plugin.path, 'fleeting-plugin-openstack.tar.gz') | path_join }}"
checksum: "sha512:{{ gitlab_runner_autoscaler_plugin_checksumfile }}"
owner: "root"
group: "root"
mode: "0600"
check_mode: false

- name: "Extract fleeting-plugin-openstack binary"
ansible.builtin.unarchive:
src: "{{ (tempdir_fleeting_plugin.path, 'fleeting-plugin-openstack.tar.gz') | path_join }}"
dest: "/usr/local/bin/"
include:
- "bin/fleeting-plugin-openstack"
owner: "root"
group: "root"
mode: "0755"
remote_src: true
extra_opts: ['--strip-components=1']

always:
- name: "Remove temporary directory"
ansible.builtin.file:
path: "{{ tempdir_fleeting_plugin.path }}"
state: "absent"
check_mode: false
changed_when: false

- name: "Place clouds.yaml template"
ansible.builtin.template:
Expand Down
1 change: 1 addition & 0 deletions roles/gitlab_runner/tasks/install.debianlike.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- "debian-archive-keyring"
- "apt-transport-https"
- "gnupg"
- "binutils"
state: "present"
update_cache: true

Expand Down
5 changes: 4 additions & 1 deletion roles/gitlab_runner/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
ansible.builtin.slurp:
src: "/etc/gitlab-runner/ignition.json"
register: "ignition_json"
when: "gitlab_runner_install_autoscaler"
when:
- "gitlab_runner_install_autoscaler"
- "not gitlab_runner_is_initial_dryrun"

- name: "Template config file"
ansible.builtin.template:
Expand All @@ -64,6 +66,7 @@
no_log: true
vars:
ignition_content: "{{ ignition_json['content'] | b64decode }}"
when: "not gitlab_runner_is_initial_dryrun"

- name: "Start GitLab-Runner"
ansible.builtin.service:
Expand Down