From c87ad99de5115d87009fa2faf4eb3b4749f6947e Mon Sep 17 00:00:00 2001 From: Martin Alfke Date: Tue, 28 May 2024 15:06:28 +0200 Subject: [PATCH 1/8] Add basic SuSE support --- .fixtures.yml | 1 + README.md | 24 ++++++++++++++---- REFERENCE.md | 27 +++++++++++++++++++++ data/family/Suse.yaml | 3 +++ manifests/init.pp | 9 +++++++ manifests/install.pp | 20 +++++++++++++-- metadata.json | 7 ++++++ spec/classes/gitlab_ci_runner_spec.rb | 35 +++++++++++++++------------ 8 files changed, 104 insertions(+), 22 deletions(-) create mode 100644 data/family/Suse.yaml diff --git a/.fixtures.yml b/.fixtures.yml index 3020aba..d57507d 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -8,3 +8,4 @@ fixtures: ruby_task_helper: "https://github.com/puppetlabs/puppetlabs-ruby_task_helper.git" translate: "https://github.com/puppetlabs/puppetlabs-translate.git" yumrepo_core: "https://github.com/puppetlabs/puppetlabs-yumrepo_core.git" + archive: "https://github.com/voxpupuli/puppet-archive.git" diff --git a/README.md b/README.md index ffa30c1..98c4633 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,14 @@ #### Table of Contents -1. [Overview](#overview) -1. [Usage - Configuration options and additional functionality](#usage) -1. [Limitations - OS compatibility, etc.](#limitations) -1. [Upgrading from version 3](#upgrading-from-version-3) -1. [License](#license) +- [Gitlab-CI runner module for Puppet](#gitlab-ci-runner-module-for-puppet) + - [Table of Contents](#table-of-contents) + - [Overview](#overview) + - [Usage](#usage) + - [SLES](#sles) + - [Upgrading from version 3](#upgrading-from-version-3) + - [Limitations](#limitations) + - [License](#license) ## Overview @@ -69,6 +72,17 @@ gitlab_ci_runner::runners: ensure: absent ``` +## SLES + +There are no gitlab_ci_runner repositories for SLES/zypper available! +Please set the following data to be able to use this module on SLES: + +```yaml +gitlab_ci_runner::install_method: 'binary' # required for SLES +gitlab_ci_runner::binary_source: 'https://s3.dualstack.us-east-1.amazonaws.com/gitlab-runner-downloads/latest/binaries/gitlab-runner-linux-amd64' # default value +gitlab_ci_runner::binary_path: '/usr/local/bin/gitlab-runner' # default value +``` + ## Upgrading from version 3 Version 4 of this module introduces some big changes. diff --git a/REFERENCE.md b/REFERENCE.md index 5f85a5e..afeae11 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -81,6 +81,9 @@ The following parameters are available in the `gitlab_ci_runner` class: * [`listen_address`](#-gitlab_ci_runner--listen_address) * [`session_server`](#-gitlab_ci_runner--session_server) * [`manage_docker`](#-gitlab_ci_runner--manage_docker) +* [`install_method`](#-gitlab_ci_runner--install_method) +* [`binary_source`](#-gitlab_ci_runner--binary_source) +* [`binary_path`](#-gitlab_ci_runner--binary_path) * [`manage_repo`](#-gitlab_ci_runner--manage_repo) * [`package_ensure`](#-gitlab_ci_runner--package_ensure) * [`package_name`](#-gitlab_ci_runner--package_name) @@ -190,6 +193,30 @@ If docker should be installs (uses the puppetlabs-docker). Default value: `false` +##### `install_method` + +Data type: `Enum['repo', 'binary']` + +If repo or binary should be installed + +Default value: `'repo'` + +##### `binary_source` + +Data type: `Stdlib::HTTPUrl` + +URL to the binary file + +Default value: `'https://s3.dualstack.us-east-1.amazonaws.com/gitlab-runner-downloads/latest/binaries/gitlab-runner-linux-amd64'` + +##### `binary_path` + +Data type: `Stdlib::Absolutepath` + +Absolute path where to install gitlab_runner binary + +Default value: `'/usr/local/bin/gitlab-runner'` + ##### `manage_repo` Data type: `Boolean` diff --git a/data/family/Suse.yaml b/data/family/Suse.yaml new file mode 100644 index 0000000..07d89f1 --- /dev/null +++ b/data/family/Suse.yaml @@ -0,0 +1,3 @@ +--- +gitlab_ci_runner::install_method: 'binary' +gitlab_ci_runner::manage_repo: false diff --git a/manifests/init.pp b/manifests/init.pp index dc58275..9867a25 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -35,6 +35,12 @@ # Session server lets users interact with jobs, for example, in the interactive web terminal. # @param manage_docker # If docker should be installs (uses the puppetlabs-docker). +# @param install_method +# If repo or binary should be installed +# @param binary_source +# URL to the binary file +# @param binary_path +# Absolute path where to install gitlab_runner binary # @param manage_repo # If the repository should be managed. # @param package_ensure @@ -89,6 +95,9 @@ Optional[String] $sentry_dsn = undef, Optional[Pattern[/.*:.+/]] $listen_address = undef, Optional[Gitlab_ci_runner::Session_server] $session_server = undef, + Enum['repo', 'binary'] $install_method = 'repo', + Stdlib::HTTPUrl $binary_source = 'https://s3.dualstack.us-east-1.amazonaws.com/gitlab-runner-downloads/latest/binaries/gitlab-runner-linux-amd64', + Stdlib::Absolutepath $binary_path = '/usr/local/bin/gitlab-runner', Boolean $manage_docker = false, Boolean $manage_repo = true, String $package_ensure = installed, diff --git a/manifests/install.pp b/manifests/install.pp index d32eebb..3ae12bb 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -8,7 +8,23 @@ ) { assert_private() - package { $package_name: - ensure => $package_ensure, + case $gitlab_ci_runner::install_method { + 'repo': { + package { $package_name: + ensure => $package_ensure, + } + } + 'binary': { + $_package_ensure = $package_ensure ? { + 'installed' => 'present', + default => $package_ensure, + } + archive { $gitlab_ci_runner::binary_path: + ensure => $_package_ensure, + source => $gitlab_ci_runner::binary_source, + extract => false, + creates => $gitlab_ci_runner::binary_path, + } + } } } diff --git a/metadata.json b/metadata.json index 612be94..031050f 100644 --- a/metadata.json +++ b/metadata.json @@ -82,6 +82,13 @@ "20.04", "22.04" ] + }, + { + "operatingsystem": "SLES", + "operatingsystemrelease": [ + "12", + "15" + ] } ], "requirements": [ diff --git a/spec/classes/gitlab_ci_runner_spec.rb b/spec/classes/gitlab_ci_runner_spec.rb index 6be5b81..d1e8cbe 100644 --- a/spec/classes/gitlab_ci_runner_spec.rb +++ b/spec/classes/gitlab_ci_runner_spec.rb @@ -38,7 +38,9 @@ it { is_expected.not_to contain_class('docker') } it { is_expected.not_to contain_class('docker::images') } - it { is_expected.to contain_package('gitlab-runner') } + + it { is_expected.to contain_package('gitlab-runner') } unless facts[:os]['family'] == 'Suse' + it { is_expected.to contain_service('gitlab-runner') } it { is_expected.to contain_class('gitlab_ci_runner::install') } @@ -337,20 +339,22 @@ } end - it { is_expected.to compile } + unless facts[:os]['family'] == 'Suse' + it { is_expected.to compile } - it { is_expected.to contain_class('docker') } + it { is_expected.to contain_class('docker') } - it do - is_expected.to contain_class('docker::images'). - with( - images: { - 'ubuntu_focal' => { - 'image' => 'ubuntu', - 'image_tag' => 'focal' + it do + is_expected.to contain_class('docker::images'). + with( + images: { + 'ubuntu_focal' => { + 'image' => 'ubuntu', + 'image_tag' => 'focal' + } } - } - ) + ) + end end end @@ -361,9 +365,10 @@ ) end - it { is_expected.to compile } - it { is_expected.to contain_class('gitlab_ci_runner::repo') } - + unless facts[:os]['family'] == 'Suse' + it { is_expected.to compile } + it { is_expected.to contain_class('gitlab_ci_runner::repo') } + end case facts[:os]['family'] when 'Debian' it do From 2df4e5631d0fe1ed2ba1762b4b28a7d59f317cff Mon Sep 17 00:00:00 2001 From: Martin Alfke Date: Tue, 28 May 2024 15:10:15 +0200 Subject: [PATCH 2/8] add case default --- manifests/install.pp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/manifests/install.pp b/manifests/install.pp index 3ae12bb..ed0ceb8 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -26,5 +26,8 @@ creates => $gitlab_ci_runner::binary_path, } } + default: { + fail("Unsupported install method: ${gitlab_ci_runner::install_method}") + } } } From 27d3ca98db7d3bee0c4af4a2e03410fbb7f0e21e Mon Sep 17 00:00:00 2001 From: Martin Alfke Date: Tue, 28 May 2024 15:52:52 +0200 Subject: [PATCH 3/8] on sles we must ensure the config dir is in place --- data/family/Suse.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/data/family/Suse.yaml b/data/family/Suse.yaml index 07d89f1..fbc51f0 100644 --- a/data/family/Suse.yaml +++ b/data/family/Suse.yaml @@ -1,3 +1,4 @@ --- gitlab_ci_runner::install_method: 'binary' gitlab_ci_runner::manage_repo: false +gitlab_ci_runner::manage_config_dir: true From 95ee68f41053494c8ea0e7561d25a3fe59e3755c Mon Sep 17 00:00:00 2001 From: Martin Alfke Date: Tue, 28 May 2024 15:56:36 +0200 Subject: [PATCH 4/8] make downloaded file executable --- manifests/install.pp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/manifests/install.pp b/manifests/install.pp index ed0ceb8..abe9c9a 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -25,6 +25,10 @@ extract => false, creates => $gitlab_ci_runner::binary_path, } + file { $gitlab_ci_runner::binary_path: + ensure => file, + mode => '0755', + } } default: { fail("Unsupported install method: ${gitlab_ci_runner::install_method}") From cac68720c41da0ca440985977fbd8793c9c6ec67 Mon Sep 17 00:00:00 2001 From: Martin Alfke Date: Tue, 28 May 2024 16:02:06 +0200 Subject: [PATCH 5/8] on sles we must manage gitlab runner group and user --- data/family/Suse.yaml | 1 + manifests/init.pp | 9 +++++++++ manifests/install.pp | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/data/family/Suse.yaml b/data/family/Suse.yaml index fbc51f0..4aa725a 100644 --- a/data/family/Suse.yaml +++ b/data/family/Suse.yaml @@ -2,3 +2,4 @@ gitlab_ci_runner::install_method: 'binary' gitlab_ci_runner::manage_repo: false gitlab_ci_runner::manage_config_dir: true +gitlab_ci_runner::manage_user: true diff --git a/manifests/init.pp b/manifests/init.pp index 9867a25..d76dbc7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -41,6 +41,12 @@ # URL to the binary file # @param binary_path # Absolute path where to install gitlab_runner binary +# @param manage_user +# If the user should be managed. +# @param user +# The user to manage. +# @param group +# The group to manage. # @param manage_repo # If the repository should be managed. # @param package_ensure @@ -98,6 +104,9 @@ Enum['repo', 'binary'] $install_method = 'repo', Stdlib::HTTPUrl $binary_source = 'https://s3.dualstack.us-east-1.amazonaws.com/gitlab-runner-downloads/latest/binaries/gitlab-runner-linux-amd64', Stdlib::Absolutepath $binary_path = '/usr/local/bin/gitlab-runner', + Boolean $manage_user = false, + String[1] $user = 'gitlab-runner', + String[1] $group = $user, Boolean $manage_docker = false, Boolean $manage_repo = true, String $package_ensure = installed, diff --git a/manifests/install.pp b/manifests/install.pp index abe9c9a..af501c1 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -29,6 +29,15 @@ ensure => file, mode => '0755', } + if $gitlab_ci_runner::manage_user { + group { $gitlab_ci_runner::group: + ensure => present, + } + user { $gitlab_ci_runner::user: + ensure => present, + gid => $gitlab_ci_runner::group, + } + } } default: { fail("Unsupported install method: ${gitlab_ci_runner::install_method}") From 9e35a109701327243696ac142944f257f8da12bf Mon Sep 17 00:00:00 2001 From: Martin Alfke Date: Tue, 28 May 2024 16:07:29 +0200 Subject: [PATCH 6/8] use gitlab runner to create systemd unit file --- manifests/service.pp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/manifests/service.pp b/manifests/service.pp index d1d08bf..5f73cf7 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -7,6 +7,11 @@ ) { assert_private() + if $facts['os']['family'] == 'Suse' { + exec { "${gitlab_ci_runner::binary_path} install -u ${gitlab_ci_runner::user}": + creates => '/etc/systemd/system/gitlab-runner.service', + } + } service { $package_name: ensure => running, enable => true, From a2a4f6b0dd5aa2c25637e58a9c09d3affad242de Mon Sep 17 00:00:00 2001 From: Martin Alfke Date: Tue, 28 May 2024 16:08:46 +0200 Subject: [PATCH 7/8] update REFERENCE --- REFERENCE.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/REFERENCE.md b/REFERENCE.md index afeae11..f679268 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -84,6 +84,9 @@ The following parameters are available in the `gitlab_ci_runner` class: * [`install_method`](#-gitlab_ci_runner--install_method) * [`binary_source`](#-gitlab_ci_runner--binary_source) * [`binary_path`](#-gitlab_ci_runner--binary_path) +* [`manage_user`](#-gitlab_ci_runner--manage_user) +* [`user`](#-gitlab_ci_runner--user) +* [`group`](#-gitlab_ci_runner--group) * [`manage_repo`](#-gitlab_ci_runner--manage_repo) * [`package_ensure`](#-gitlab_ci_runner--package_ensure) * [`package_name`](#-gitlab_ci_runner--package_name) @@ -217,6 +220,30 @@ Absolute path where to install gitlab_runner binary Default value: `'/usr/local/bin/gitlab-runner'` +##### `manage_user` + +Data type: `Boolean` + +If the user should be managed. + +Default value: `false` + +##### `user` + +Data type: `String[1]` + +The user to manage. + +Default value: `'gitlab-runner'` + +##### `group` + +Data type: `String[1]` + +The group to manage. + +Default value: `$user` + ##### `manage_repo` Data type: `Boolean` From f3e99dc02001910a3c82b170995dc3b83274bdb0 Mon Sep 17 00:00:00 2001 From: Martin Alfke Date: Mon, 17 Jun 2024 10:41:49 +0200 Subject: [PATCH 8/8] update documentation and the need for puppet-archive --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 98c4633..546deb1 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,9 @@ gitlab_ci_runner::runners: ## SLES There are no gitlab_ci_runner repositories for SLES/zypper available! +Instead one can use the go binary. +This setup requires the [puppet-archive](https://github.com/voxpupuli/puppet-archive) module. + Please set the following data to be able to use this module on SLES: ```yaml