diff --git a/manifests/cirunner.pp b/manifests/cirunner.pp index 756f6895..182c1151 100644 --- a/manifests/cirunner.pp +++ b/manifests/cirunner.pp @@ -13,7 +13,7 @@ # Default: gitlab_ci_runners_defaults # Name of hiera hash with default configs for CI Runners. # The config is the parameters for the /usr/bin/gitlab-ci-multi-runner register -# command. +# command (for version 10.x: /usr/bin/gitlab-runner). # # [*hiera_runners_key*] # Default: gitlab_ci_runners @@ -36,12 +36,16 @@ $manage_repo = true, $xz_package_name = 'xz-utils', $package_ensure = installed, + $package_name = 'gitlab-ci-multi-runner', ) { validate_string($hiera_default_config_key) validate_string($hiera_runners_key) validate_bool($manage_docker) validate_bool($manage_repo) + validate_string($xz_package_name) + validate_string($package_ensure) + validate_string($package_name) unless ($::osfamily == 'Debian' or $::osfamily == 'RedHat') { fail ("OS family ${::osfamily} is not supported. Only Debian and Redhat is suppported.") @@ -65,6 +69,8 @@ } if $manage_repo { + $repo_base_url = 'https://packages.gitlab.com' + case $::osfamily { 'Debian': { include apt @@ -74,7 +80,7 @@ ::apt::source { 'apt_gitlabci': comment => 'GitlabCI Runner Repo', - location => "https://packages.gitlab.com/runner/gitlab-ci-multi-runner/${distid}/", + location => "${repo_base_url}/runner/${package_name}/${distid}/", release => $::lsbdistcodename, repos => 'main', key => { @@ -86,29 +92,29 @@ 'deb' => true, } } - Apt::Source['apt_gitlabci'] -> Package['gitlab-ci-multi-runner'] - Exec['apt_update'] -> Package['gitlab-ci-multi-runner'] + Apt::Source['apt_gitlabci'] -> Package[$package_name] + Exec['apt_update'] -> Package[$package_name] } 'RedHat': { - yumrepo { 'runner_gitlab-ci-multi-runner': + yumrepo { "runner_${package_name}": ensure => 'present', - baseurl => "https://packages.gitlab.com/runner/gitlab-ci-multi-runner/el/${::operatingsystemmajrelease}/\$basearch", - descr => 'runner_gitlab-ci-multi-runner', + baseurl => "${repo_base_url}/runner/${package_name}/el/${::operatingsystemmajrelease}/\$basearch", + descr => "runner_${package_name}", enabled => '1', gpgcheck => '0', - gpgkey => 'https://packages.gitlab.com/gpg.key', + gpgkey => "${repo_base_url}/gpg.key", repo_gpgcheck => '1', sslcacert => '/etc/pki/tls/certs/ca-bundle.crt', sslverify => '1', } - yumrepo { 'runner_gitlab-ci-multi-runner-source': + yumrepo { "runner_${package_name}-source": ensure => 'present', - baseurl => "https://packages.gitlab.com/runner/gitlab-ci-multi-runner/el/${::operatingsystemmajrelease}/SRPMS", - descr => 'runner_gitlab-ci-multi-runner-source', + baseurl => "${repo_base_url}/runner/${package_name}/el/${::operatingsystemmajrelease}/SRPMS", + descr => "runner_${package_name}-source", enabled => '1', gpgcheck => '0', - gpgkey => 'https://packages.gitlab.com/gpg.key', + gpgkey => "${repo_base_url}/gpg.key", repo_gpgcheck => '1', sslcacert => '/etc/pki/tls/certs/ca-bundle.crt', sslverify => '1', @@ -120,7 +126,7 @@ } } - package { 'gitlab-ci-multi-runner': + package { $package_name: ensure => $package_ensure, } @@ -131,21 +137,22 @@ path => '/etc/gitlab-runner/config.toml', line => "concurrent = ${concurrent}", match => '^concurrent = \d+', - require => Package['gitlab-ci-multi-runner'], + require => Package[$package_name], notify => Exec['gitlab-runner-restart'], } } exec { 'gitlab-runner-restart': - command => '/usr/bin/gitlab-ci-multi-runner restart', + command => "/usr/bin/${package_name} restart", refreshonly => true, - require => Package['gitlab-ci-multi-runner'], + require => Package[$package_name], } $runners_hash = hiera_hash($hiera_runners_key, {}) $runners = keys($runners_hash) $default_config = hiera_hash($hiera_default_config_key, {}) gitlab::runner { $runners: + binary => $package_name, default_config => $default_config, runners_hash => $runners_hash, require => Exec['gitlab-runner-restart'], diff --git a/manifests/runner.pp b/manifests/runner.pp index 623f31cc..a09b423b 100644 --- a/manifests/runner.pp +++ b/manifests/runner.pp @@ -21,10 +21,12 @@ # Copyright 2015 Tobias Brunner, VSHN AG # define gitlab::runner ( + $binary, $runners_hash, $default_config = {}, ) { + validate_string($binary) validate_hash($runners_hash) validate_hash($default_config) @@ -48,7 +50,7 @@ # Execute gitlab ci multirunner register exec {"Register_runner_${title}": - command => "/usr/bin/gitlab-ci-multi-runner register -n ${parameters_string}", + command => "/usr/bin/${binary} register -n ${parameters_string}", unless => "/bin/grep ${runner_name} ${toml_file}", } diff --git a/spec/classes/cirunner_spec.rb b/spec/classes/cirunner_spec.rb index fa1a4d14..bf259cfb 100644 --- a/spec/classes/cirunner_spec.rb +++ b/spec/classes/cirunner_spec.rb @@ -2,6 +2,8 @@ describe 'gitlab::cirunner' do context 'supported operating systems' do + package_name = 'gitlab-ci-multi-runner' + describe "gitlab::cirunner class without any parameters on Ubuntu Trusty" do let(:params) {{ }} let(:facts) {{ @@ -19,7 +21,7 @@ it { is_expected.to contain_class('docker::images') } it { is_expected.to contain_apt__source('apt_gitlabci') } - it { is_expected.to contain_package('gitlab-ci-multi-runner').with_ensure('installed') } + it { is_expected.to contain_package(package_name).with_ensure('installed') } end describe "gitlab::cirunner class without any parameters on RedHat (CentOS)" do let(:params) {{ }} @@ -52,9 +54,9 @@ it { is_expected.to contain_class('docker') } it { is_expected.to contain_class('docker::images') } - it { is_expected.to contain_yumrepo('runner_gitlab-ci-multi-runner').with_baseurl('https://packages.gitlab.com/runner/gitlab-ci-multi-runner/el/6/$basearch') } + it { is_expected.to contain_yumrepo("runner_#{package_name}").with_baseurl("https://packages.gitlab.com/runner/#{package_name}/el/6/$basearch") } - it { is_expected.to contain_package('gitlab-ci-multi-runner').with_ensure('installed') } + it { is_expected.to contain_package(package_name).with_ensure('installed') } end describe "gitlab::cirunner class OS-independent behavior" do let(:facts) {{ @@ -83,10 +85,10 @@ }} context 'with default parameters' do - it { should contain_exec('gitlab-runner-restart').that_requires('Package[gitlab-ci-multi-runner]') } + it { should contain_exec('gitlab-runner-restart').that_requires("Package[#{package_name}]") } it do should contain_exec('gitlab-runner-restart').with({ - 'command' => '/usr/bin/gitlab-ci-multi-runner restart', + 'command' => "/usr/bin/#{package_name} restart", 'refreshonly' => true, }) end @@ -96,7 +98,7 @@ context 'with concurrent => 10' do let(:params) { { :concurrent => 10 } } - it { should contain_file_line('gitlab-runner-concurrent').that_requires('Package[gitlab-ci-multi-runner]') } + it { should contain_file_line('gitlab-runner-concurrent').that_requires("Package[#{package_name}]") } it { should contain_file_line('gitlab-runner-concurrent').that_notifies('Exec[gitlab-runner-restart]') } it do should contain_file_line('gitlab-runner-concurrent').with({