From 48ff2f633479d8c7258e5e1c28fb63846004e59f Mon Sep 17 00:00:00 2001
From: Peter Souter
Date: Fri, 12 Feb 2016 10:31:28 +0000
Subject: [PATCH 1/2] Allow installing cirunner on RedHat based systems
---
.fixtures.yml | 3 ++
manifests/cirunner.pp | 69 ++++++++++++++++++++++++++---------
spec/classes/cirunner_spec.rb | 14 ++++++-
3 files changed, 68 insertions(+), 18 deletions(-)
diff --git a/.fixtures.yml b/.fixtures.yml
index f9f371a4..2f45d984 100644
--- a/.fixtures.yml
+++ b/.fixtures.yml
@@ -7,5 +7,8 @@ fixtures:
docker:
repo: "https://github.com/garethr/garethr-docker.git"
ref: "v4.1.1"
+ epel:
+ repo: "https://github.com/stahnma/puppet-module-epel"
+ ref: "1.2.2"
symlinks:
gitlab: "#{source_dir}"
diff --git a/manifests/cirunner.pp b/manifests/cirunner.pp
index af97f0ce..0c6fe9b5 100644
--- a/manifests/cirunner.pp
+++ b/manifests/cirunner.pp
@@ -5,7 +5,7 @@
# === Parameters
#
# [*hiera_default_config_key*]
-# Default: gitlab_ci_runners_defaults
+# 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.
@@ -34,7 +34,8 @@
validate_string($hiera_runners_key)
validate_bool($manage_docker)
validate_bool($manage_repo)
- unless ($::osfamily == 'Debian') {
+
+ unless ($::osfamily == 'Debian' or $::osfamily == 'RedHat') {
fail ("OS family ${::osfamily} is not supported. Only Debian is suppported.")
}
@@ -52,25 +53,59 @@
}
}
- $distid = downcase($::lsbdistid)
if $manage_repo {
- ::apt::source { 'apt_gitlabci':
- comment => 'GitlabCI Runner Repo',
- location => "https://packages.gitlab.com/runner/gitlab-ci-multi-runner/${distid}/",
- release => $::lsbdistcodename,
- repos => 'main',
- key => {
- 'id' => '1A4C919DB987D435939638B914219A96E15E78F4',
- 'server' => 'keys.gnupg.net',
- },
- include => {
- 'src' => false,
- 'deb' => true,
+ case $::osfamily {
+ 'Debian': {
+ $distid = downcase($::lsbdistid)
+
+ ::apt::source { 'apt_gitlabci':
+ comment => 'GitlabCI Runner Repo',
+ location => "https://packages.gitlab.com/runner/gitlab-ci-multi-runner/${distid}/",
+ release => $::lsbdistcodename,
+ repos => 'main',
+ key => {
+ 'id' => '1A4C919DB987D435939638B914219A96E15E78F4',
+ 'server' => 'keys.gnupg.net',
+ },
+ include => {
+ 'src' => false,
+ 'deb' => true,
+ }
+ }
+ Apt::Source['apt_gitlabci'] -> Package['gitlab-ci-multi-runner']
+ Exec['apt_update'] -> Package['gitlab-ci-multi-runner']
+ }
+ 'RedHat': {
+ yumrepo { 'runner_gitlab-ci-multi-runner':
+ ensure => 'present',
+ baseurl => "https://packages.gitlab.com/runner/gitlab-ci-multi-runner/el/${::operatingsystemmajrelease}/\$basearch",
+ descr => 'runner_gitlab-ci-multi-runner',
+ enabled => '1',
+ gpgcheck => '0',
+ gpgkey => 'https://packages.gitlab.com/gpg.key',
+ repo_gpgcheck => '1',
+ sslcacert => '/etc/pki/tls/certs/ca-bundle.crt',
+ sslverify => '1',
+ }
+
+ yumrepo { 'runner_gitlab-ci-multi-runner-source':
+ ensure => 'present',
+ baseurl => "https://packages.gitlab.com/runner/gitlab-ci-multi-runner/el/${::operatingsystemmajrelease}/SRPMS",
+ descr => 'runner_gitlab-ci-multi-runner-source',
+ enabled => '1',
+ gpgcheck => '0',
+ gpgkey => 'https://packages.gitlab.com/gpg.key',
+ repo_gpgcheck => '1',
+ sslcacert => '/etc/pki/tls/certs/ca-bundle.crt',
+ sslverify => '1',
+ }
+ }
+ default: {
+ fail ("gitlab::cirunner::manage_repo parameter for ${::osfamily} is not supported.")
}
}
- Apt::Source['apt_gitlabci'] -> Package['gitlab-ci-multi-runner']
- Exec['apt_update'] -> Package['gitlab-ci-multi-runner']
}
+
package { 'gitlab-ci-multi-runner':
ensure => 'present',
}
diff --git a/spec/classes/cirunner_spec.rb b/spec/classes/cirunner_spec.rb
index 5e62593a..81ae3251 100644
--- a/spec/classes/cirunner_spec.rb
+++ b/spec/classes/cirunner_spec.rb
@@ -41,9 +41,21 @@
:enabled => false
}
},
+ :osfamily => 'RedHat',
+ :operatingsystemmajrelease => '6',
+ :operatingsystemrelease => '6.5',
+ :kernelversion => '2.6.32',
+ :kernelrelease => '2.6.32-573.8.1.el6.x86_64'
}}
- it { expect { is_expected.to contain_package('gitlab') }.to raise_error(Puppet::Error, /OS family redhat is not supported. Only Debian is suppported./) }
+ it { is_expected.to compile.with_all_deps }
+
+ 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_package('gitlab-ci-multi-runner').with_ensure('present') }
+
end
end
From b6dbe16f381b60ed2e90cac34bb1f826b2ad4584 Mon Sep 17 00:00:00 2001
From: Peter Souter
Date: Fri, 12 Feb 2016 10:35:22 +0000
Subject: [PATCH 2/2] Adds acceptance test for cirunner class
---
spec/acceptance/gitlabci_spec.rb | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 spec/acceptance/gitlabci_spec.rb
diff --git a/spec/acceptance/gitlabci_spec.rb b/spec/acceptance/gitlabci_spec.rb
new file mode 100644
index 00000000..99f92f3f
--- /dev/null
+++ b/spec/acceptance/gitlabci_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper_acceptance'
+
+describe 'gitlab:;cirunner class' do
+
+ context 'default parameters' do
+ # Using puppet_apply as a helper
+ it 'should work idempotently with no errors' do
+ pp = <<-EOS
+ class { 'gitlab::cirunner': }
+ EOS
+
+ # Run it twice and test for idempotency
+ apply_manifest(pp, :catch_failures => true)
+ apply_manifest(pp, :catch_changes => true)
+ end
+
+ describe package('gitlab-ci-multi-runner') do
+ it { is_expected.to be_installed }
+ end
+ end
+end