Skip to content

Commit

Permalink
Add 'package_name' param
Browse files Browse the repository at this point in the history
  • Loading branch information
dandunckelman committed Sep 27, 2017
1 parent a0cd33d commit c7f9bd5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
38 changes: 22 additions & 16 deletions manifests/cirunner.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.")
Expand All @@ -65,6 +69,8 @@
}

if $manage_repo {
$repo_base_url = 'https://packages.gitlab.com'

case $::osfamily {
'Debian': {
include apt
Expand All @@ -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 => {
Expand All @@ -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',
Expand All @@ -120,7 +126,7 @@
}
}

package { 'gitlab-ci-multi-runner':
package { $package_name:
ensure => $package_ensure,
}

Expand All @@ -131,15 +137,15 @@
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, {})
Expand Down
14 changes: 8 additions & 6 deletions spec/classes/cirunner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) {{
Expand All @@ -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) {{ }}
Expand Down Expand Up @@ -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) {{
Expand Down Expand Up @@ -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
Expand All @@ -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({
Expand Down

0 comments on commit c7f9bd5

Please sign in to comment.