Puppet Class: gitlab_ci_runner

Defined in:
manifests/init.pp

Summary

This module installs and configures Gitlab CI Runners.

Overview

Examples:

Simple runner registration

class { 'gitlab_ci_runner':
  runners => {
 	 example_runner => {
 		 'registration-token' => 'gitlab-token',
 		 'url'                => 'https://gitlab.com',
 		 'tag-list'           => 'docker,aws',
 	 },
  },
}

Parameters:

  • runners (Hash) (defaults to: {})

    Hashkeys are used as $title in runners.pp. The subkeys have to be named as the parameter names from ´gitlab-runner register´ command cause they’re later joined to one entire string using 2 hyphen to look like shell command parameters. See ´docs.gitlab.com/runner/register/#one-line-registration-command´ for details.

  • runner_defaults (Hash) (defaults to: {})

    A hash with defaults which will be later merged with $runners.

  • xz_package_name (String)

    The name of the ‘xz’ package. Needed for local docker installations.

  • concurrent (Optional[Integer]) (defaults to: undef)

    Limits how many jobs globally can be run concurrently. The most upper limit of jobs using all defined runners. 0 does not mean unlimited!

  • log_level (Optional[Gitlab_ci_runner::Log_level]) (defaults to: undef)

    Log level (options: debug, info, warn, error, fatal, panic). Note that this setting has lower priority than level set by command line argument –debug, -l or –log-level

  • log_format (Optional[Gitlab_ci_runner::Log_format]) (defaults to: undef)

    Log format (options: runner, text, json). Note that this setting has lower priority than format set by command line argument –log-format

  • check_interval (Optional[Integer]) (defaults to: undef)

    defines the interval length, in seconds, between new jobs check. The default value is 3; if set to 0 or lower, the default value will be used.

  • sentry_dsn (Optional[String]) (defaults to: undef)

    Enable tracking of all system level errors to sentry.

  • listen_address (Optional[Pattern[/.*:.+/]]) (defaults to: undef)

    Address (<host>:<port>) on which the Prometheus metrics HTTP server should be listening.

  • session_server (Optional[Gitlab_ci_runner::Session_server]) (defaults to: undef)

    Session server lets users interact with jobs, for example, in the interactive web terminal.

  • manage_docker (Boolean) (defaults to: false)

    If docker should be installs (uses the puppetlabs-docker).

  • manage_repo (Boolean) (defaults to: true)

    If the repository should be managed.

  • package_ensure (String) (defaults to: installed)

    The package ‘ensure’ state.

  • package_name (String) (defaults to: 'gitlab-runner')

    The name of the package.

  • repo_base_url (Stdlib::HTTPUrl) (defaults to: 'https://packages.gitlab.com')

    The base repository url.

  • repo_keyserver (Optional[Gitlab_ci_runner::Keyserver]) (defaults to: undef)

    The keyserver which should be used to get the repository key.

  • config_path (String) (defaults to: '/etc/gitlab-runner/config.toml')

    The path to the config file of Gitlab runner.

  • http_proxy (Optional[Stdlib::HTTPUrl]) (defaults to: undef)

    An HTTP proxy to use whilst registering runners. This setting is only used when registering or unregistering runners and will be used for all runners in the ‘runners` parameter. If you have some runners that need to use a proxy and others that don’t, leave ‘runners` and `http_proxy` unset and declare `gitlab_ci_runnner::runner` resources separately. If you do need to use an http proxy, you’ll probably also want to configure other aspects of your runners to use it, (eg. setting ‘http_proxy` environment variables, `pre-clone-script`, `pre-build-script` etc.) Exactly how you might need to configure your runners varies between runner executors and specific use-cases. This module makes no attempt to automatically alter your runner configurations based on the value of this parameter. More information on what you might need to configure can be found [here](docs.gitlab.com/runner/configuration/proxy.html)



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'manifests/init.pp', line 56

class gitlab_ci_runner (
  String                                     $xz_package_name, # Defaults in module hieradata
  Hash                                       $runners         = {},
  Hash                                       $runner_defaults = {},
  Optional[Integer]                          $concurrent      = undef,
  Optional[Gitlab_ci_runner::Log_level]      $log_level       = undef,
  Optional[Gitlab_ci_runner::Log_format]     $log_format      = undef,
  Optional[Integer]                          $check_interval  = undef,
  Optional[String]                           $sentry_dsn      = undef,
  Optional[Pattern[/.*:.+/]]                 $listen_address  = undef,
  Optional[Gitlab_ci_runner::Session_server] $session_server  = undef,
  Boolean                                    $manage_docker   = false,
  Boolean                                    $manage_repo     = true,
  String                                     $package_ensure  = installed,
  String                                     $package_name    = 'gitlab-runner',
  Stdlib::HTTPUrl                            $repo_base_url   = 'https://packages.gitlab.com',
  Optional[Gitlab_ci_runner::Keyserver]      $repo_keyserver   = undef,
  String                                     $config_path     = '/etc/gitlab-runner/config.toml',
  Optional[Stdlib::HTTPUrl]                  $http_proxy      = undef,
) {
  if $manage_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_focal => {
        image     => 'ubuntu',
        image_tag => 'focal',
      },
    }

    include docker
    class { 'docker::images':
      images => $docker_images,
    }
  }

  if $manage_repo {
    contain gitlab_ci_runner::repo
  }

  contain gitlab_ci_runner::install
  contain gitlab_ci_runner::config
  contain gitlab_ci_runner::service

  Class['gitlab_ci_runner::install']
  -> Class['gitlab_ci_runner::config']
  ~> Class['gitlab_ci_runner::service']

  $runners.each |$runner_name,$config| {
    $_config = merge($runner_defaults, $config)
    $title   = $_config['name'] ? {
      undef   => $runner_name,
      default => $_config['name'],
    }

    gitlab_ci_runner::runner { $title:
      ensure     => $_config['ensure'],
      config     => $_config - ['ensure', 'name'],
      http_proxy => $http_proxy,
      require    => Class['gitlab_ci_runner::config'],
      notify     => Class['gitlab_ci_runner::service'],
    }
  }
}