diff --git a/README.md b/README.md index 6938835b..66f1ae09 100644 --- a/README.md +++ b/README.md @@ -230,49 +230,6 @@ gitlab::gitlab_rails: user_filter: '' ``` -### Gitlab CI Runner Config - -Here is an example how to configure Gitlab CI runners using Hiera: - -To use the Gitlab CI runners it is required to have the [puppetlabs/docker](https://forge.puppetlabs.com/puppetlabs/docker) module. - -`$manage_docker` can be set to false if docker is managed externally. - -```yaml -classes: - - gitlab::cirunner - -gitlab::cirunner::concurrent: 4 - -gitlab::cirunner::metrics_server: "localhost:8888" - -gitlab_ci_runners: - test_runner1:{} - test_runner2:{} - test_runner3: - url: "https://git.alternative.org/ci" - registration-token: "abcdef1234567890" - -gitlab_ci_runners_defaults: - url: "https://git.example.com/ci" - registration-token: "1234567890abcdef" - executor: "docker" - docker-image: "ubuntu:trusty" -``` - -To unregister a specific runner you may use `ensure` param: - -```yaml -gitlab_ci_runners: - test_runner1:{} - test_runner2:{} - test_runner3: - url: "https://git.alternative.org/ci" - registration-token: "abcdef1234567890" - ensure: absent -``` - - ### NGINX Configuration Configuration of the embedded NGINX instance is handled by the `/etc/gitlab/gitlab.rb` file. Details on available configuration options are available at http://doc.gitlab.com/omnibus/settings/nginx.html. Options listed here can be passed in to the `nginx` parameter as a hash. For example, to enable ssh redirection: @@ -406,10 +363,6 @@ class {'gitlab': } ``` -### Gitlab CI Runner Limitations - -The Gitlab CI runner installation is at the moment only tested on Ubuntu 14.04. - ## Tasks The Gitlab module has a task that allows a user to upgrade the pgsql database Gitlab uses if upgrading from version 9.2.18, which is required to upgrade Gitlab past 10. When running the tasks on the command line, you will need to use the `--sudo`, `--run-as-root`, and `--tty` flags to execute the commands as needed for your environment. diff --git a/manifests/cirunner.pp b/manifests/cirunner.pp deleted file mode 100644 index 614eb64b..00000000 --- a/manifests/cirunner.pp +++ /dev/null @@ -1,163 +0,0 @@ -# == Class: gitlab::cirunner -# -# This module installs and configures Gitlab CI Runners. -# -# === Parameters -# -# [*concurrent*] -# Default: `undef` -# The limit on the number of jobs that can run concurrently among -# all runners, or `undef` to leave unmanaged. -# -# [*metrics_server*] -# Default: `undef` -# [host]: to enable metrics server as described in -# https://docs.gitlab.com/runner/monitoring/README.html#configuration-of-the-metrics-http-server -# -# [*hiera_default_config_key*] -# 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 (for version 10.x: /usr/bin/gitlab-runner). -# -# [*hiera_runners_key*] -# Default: gitlab_ci_runners -# Name of hiera hash with individual runners to be installed. -# -# === Authors -# -# Tobias Brunner -# Matthias Indermuehle -# -# === Copyright -# -# Copyright 2015 Tobias Brunner, VSHN AG -# -class gitlab::cirunner ( - Optional[Integer] $concurrent = undef, - Optional[Pattern[/.*:.+/]] $metrics_server = undef, - String $hiera_default_config_key = 'gitlab_ci_runners_defaults', - String $hiera_runners_key = 'gitlab_ci_runners', - Boolean $manage_docker = true, - Boolean $manage_repo = true, - String $xz_package_name = 'xz-utils', - String $package_ensure = installed, - String $package_name = 'gitlab-runner', -) { - - unless ($::osfamily == 'Debian' or $::osfamily == 'RedHat') { - fail ("OS family ${::osfamily} is not supported. Only Debian and Redhat is supported.") - } - - if $manage_docker { - include ::docker - # workaround for cirunner issue #1617 - # https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/1617 - ensure_packages($xz_package_name) - - $docker_images = { - ubuntu_trusty => { - image => 'ubuntu', - image_tag => 'trusty', - }, - } - class { '::docker::images': - images => $docker_images, - } - } - - if $manage_repo { - $repo_base_url = 'https://packages.gitlab.com' - - case $::osfamily { - 'Debian': { - include apt - - apt::source { 'apt_gitlabci': - comment => 'GitlabCI Runner Repo', - location => "${repo_base_url}/runner/${package_name}/${::lsbdistid.downcase}/", - repos => 'main', - key => { - 'id' => '1A4C919DB987D435939638B914219A96E15E78F4', - 'server' => 'keys.gnupg.net', - }, - include => { - 'src' => false, - 'deb' => true, - }, - } - Apt::Source['apt_gitlabci'] -> Package[$package_name] - Exec['apt_update'] -> Package[$package_name] - } - 'RedHat': { - yumrepo { "runner_${package_name}": - ensure => 'present', - baseurl => "${repo_base_url}/runner/${package_name}/el/\$releasever/\$basearch", - descr => "runner_${package_name}", - enabled => '1', - gpgcheck => '0', - gpgkey => "${repo_base_url}/gpg.key", - repo_gpgcheck => '1', - sslcacert => '/etc/pki/tls/certs/ca-bundle.crt', - sslverify => '1', - } - - yumrepo { "runner_${package_name}-source": - ensure => 'present', - baseurl => "${repo_base_url}/runner/${package_name}/el/\$releasever/SRPMS", - descr => "runner_${package_name}-source", - enabled => '1', - gpgcheck => '0', - gpgkey => "${repo_base_url}/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.") - } - } - } - - package { $package_name: - ensure => $package_ensure, - } - - if $concurrent != undef { - file_line { 'gitlab-runner-concurrent': - path => '/etc/gitlab-runner/config.toml', - line => "concurrent = ${concurrent}", - match => '^concurrent = \d+', - require => Package[$package_name], - notify => Exec['gitlab-runner-restart'], - } - } - - if $metrics_server { - file_line { 'gitlab-runner-metrics-server': - path => '/etc/gitlab-runner/config.toml', - line => "metrics_server = \"${metrics_server}\"", - match => '^metrics_server = .+', - require => Package[$package_name], - notify => Exec['gitlab-runner-restart'], - } - } - - exec { 'gitlab-runner-restart': - command => "/usr/bin/${package_name} restart", - refreshonly => true, - require => Package[$package_name], - } - - $runners_hash = lookup({'name' => $hiera_runners_key, 'value_type' => Hash, 'default_value' => {}}) - $runners = $runners_hash.keys - $default_config = lookup({'name' => $hiera_default_config_key, 'value_type' => Hash, 'default_value' => {}}) - - 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 deleted file mode 100644 index c8abc824..00000000 --- a/manifests/runner.pp +++ /dev/null @@ -1,60 +0,0 @@ -# == Define: gitlab::runner -# -# This module installs and configures Gitlab CI Runners. -# -# === Parameters -# -# [*runners_hash*] -# Hash with configuration for runners -# -# [*default_config*] -# Hash with default configration for runners. This will -# be merged with the runners_hash config -# -# === Authors -# -# Tobias Brunner -# Matthias Indermuehle -# -# === Copyright -# -# Copyright 2015 Tobias Brunner, VSHN AG -# -define gitlab::runner ( - String $binary, - Hash $runners_hash, - Hash $default_config = {}, -) { - # Set resource name as name for the runner - $name_config = { - name => $title, - } - $_default_config = merge($default_config, $name_config) - $config = $runners_hash[$title] - - # Merge default config with actual config - $_config = merge($_default_config, $config) - - # Convert configuration into a string - $parameters_array = join_keys_to_values($_config, ' ') - $parameters_array_dashes = prefix($parameters_array, '--') - $parameters_string = join($parameters_array_dashes, ' ') - - $runner_name = $_config['name'] - $toml_file = '/etc/gitlab-runner/config.toml' - - if $_config['ensure'] == 'absent' { - # Execute gitlab ci multirunner unregister - exec {"Unregister_runner_${title}": - command => "/usr/bin/${binary} unregister -n ${title}", - onlyif => "/bin/grep ${runner_name} ${toml_file}", - } - } else { - # Execute gitlab ci multirunner register - exec {"Register_runner_${title}": - command => "/usr/bin/${binary} register -n ${parameters_string}", - unless => "/bin/grep ${runner_name} ${toml_file}", - } - } - -} diff --git a/spec/acceptance/gitlabci_spec.rb b/spec/acceptance/gitlabci_spec.rb deleted file mode 100644 index 4c778abd..00000000 --- a/spec/acceptance/gitlabci_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'gitlab:;cirunner class' do - context 'default parameters' do - # Using puppet_apply as a helper - it '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-runner') do - it { is_expected.to be_installed } - end - end -end diff --git a/spec/classes/cirunner_spec.rb b/spec/classes/cirunner_spec.rb deleted file mode 100644 index 19c61a76..00000000 --- a/spec/classes/cirunner_spec.rb +++ /dev/null @@ -1,84 +0,0 @@ -require 'spec_helper' - -describe 'gitlab::cirunner' do - package_name = 'gitlab-runner' - - on_supported_os.each do |os, facts| - context "on #{os}" do - let(:facts) do - facts - end - - 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_package(package_name).with_ensure('installed') } - - case facts[:osfamily] - when 'RedHat' - it { is_expected.to contain_yumrepo("runner_#{package_name}").with_baseurl("https://packages.gitlab.com/runner/#{package_name}/el/$releasever/$basearch") } - when 'Debian' - it { is_expected.to contain_apt__source('apt_gitlabci') } - end - - it { is_expected.to contain_exec('gitlab-runner-restart').that_requires("Package[#{package_name}]") } - it do - is_expected.to contain_exec('gitlab-runner-restart').with('command' => "/usr/bin/#{package_name} restart", - 'refreshonly' => true) - end - it { is_expected.to contain_gitlab__runner('test_runner').that_requires('Exec[gitlab-runner-restart]') } - it { is_expected.not_to contain_file_line('gitlab-runner-concurrent') } - it { is_expected.not_to contain_file_line('gitlab-runner-metrics-server') } - end - - context "on #{os} with concurrent => 10" do - let(:facts) do - facts - end - - let(:params) { { concurrent: 10 } } - - it { is_expected.to contain_file_line('gitlab-runner-concurrent').that_requires("Package[#{package_name}]") } - it { is_expected.to contain_file_line('gitlab-runner-concurrent').that_notifies('Exec[gitlab-runner-restart]') } - it do - is_expected.to contain_file_line('gitlab-runner-concurrent').with('path' => '/etc/gitlab-runner/config.toml', - 'line' => 'concurrent = 10', - 'match' => '^concurrent = \d+') - end - end - - context "on #{os} with metrics_server => localhost:9252" do - let(:facts) do - facts - end - - let(:params) { { metrics_server: 'localhost:9252' } } - - it { is_expected.to contain_file_line('gitlab-runner-metrics-server').that_requires("Package[#{package_name}]") } - it { is_expected.to contain_file_line('gitlab-runner-metrics-server').that_notifies('Exec[gitlab-runner-restart]') } - it do - is_expected.to contain_file_line('gitlab-runner-metrics-server').with('path' => '/etc/gitlab-runner/config.toml', - 'line' => 'metrics_server = "localhost:9252"', - 'match' => '^metrics_server = .+') - end - end - end - - context 'unsupported operating systems' do - describe 'gitlab::cirunner class without any parameters on unsupported OS' do - let(:params) { {} } - let(:facts) do - { - osfamily: 'unsupported_os_family' - } - end - - it 'fails' do - expect do - catalogue - end.to raise_error(Puppet::Error, %r{OS family unsupported_os_family is not supported. Only Debian and Redhat is supported.}) - end - end - end -end