Puppet Class: profile::gitlab::runner

Defined in:
modules/profile/manifests/gitlab/runner.pp

Overview

picks only jobs created on protected branches or protected tags, and ignores other jobs.

Parameters:

  • ensure (Wmflib::Ensure) (defaults to: lookup('profile::gitlab::runner::ensure'))

    Ensure of the resources that support it

  • access_level (Enum['not_protected', 'ref_protected']) (defaults to: lookup('profile::gitlab::runner::access_level'))

    Whether the runner is protected or not. Whenever a runner is protected, it

  • concurrent (Integer) (defaults to: lookup('profile::gitlab::runner::concurrent'))

    Number of concurrent jobs allowed by this runner.

  • docker_image (String) (defaults to: lookup('profile::gitlab::runner::docker_image'))

    Default Docker image to use for job execution

  • docker_volume (Boolean) (defaults to: lookup('profile::gitlab::runner::docker_volume'))

    Use a separate volume for docker data (for use on WMCS)

  • docker_volume_min (Integer) (defaults to: lookup('profile::gitlab::runner::docker_volume_min'))

    Minimum size (Gb) of attached volumes considered for the docker mount.

  • docker_volume_max (Integer) (defaults to: lookup('profile::gitlab::runner::docker_volume_max'))

    Maximum size (Gb) of attached volumes considered for the docker mount.

  • docker_settings (Hash) (defaults to: lookup('profile::gitlab::runner::docker_settings'))

    Docker daemon settings

  • docker_version (String) (defaults to: lookup('profile::gitlab::runner::docker_version'))

    Version of Docker to install

  • gitlab_url (Stdlib::HTTPSUrl) (defaults to: lookup('profile::gitlab::runner::gitlab_url'))

    URL of the GitLab instance on which to register

  • locked (Boolean) (defaults to: lookup('profile::gitlab::runner::locked'))

    Whether the runner is locked and can/cannot be enabled for projects

  • registration_token (String) (defaults to: lookup('profile::gitlab::runner::registration_token'))

    Token used to register the runner with the GitLab instance.

  • run_untagged (Boolean) (defaults to: lookup('profile::gitlab::runner::run_untagged'))

    Whether the runner should also run untagged jobs

  • tags (Array[String]) (defaults to: lookup('profile::gitlab::runner::tags'))

    Tags used to schedule matching jobs to this runner

  • docker_gc_interval (String) (defaults to: lookup('profile::gitlab::runner::docker_gc_interval'))
  • docker_gc_images_high_water_mark (String) (defaults to: lookup('profile::gitlab::runner::docker_gc_images_high_water_mark'))
  • docker_gc_images_low_water_mark (String) (defaults to: lookup('profile::gitlab::runner::docker_gc_images_low_water_mark'))
  • docker_gc_volumes_high_water_mark (String) (defaults to: lookup('profile::gitlab::runner::docker_gc_volumes_high_water_mark'))
  • docker_gc_volumes_low_water_mark (String) (defaults to: lookup('profile::gitlab::runner::docker_gc_volumes_low_water_mark'))
  • enable_exporter (Boolean) (defaults to: lookup('profile::gitlab::runner::enable_exporter', {default_value => false}))
  • prometheus_nodes (Array[Stdlib::Host]) (defaults to: lookup('prometheus_nodes', {default_value => []}))


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
122
123
124
# File 'modules/profile/manifests/gitlab/runner.pp', line 17

class profile::gitlab::runner (
    Wmflib::Ensure                         $ensure             = lookup('profile::gitlab::runner::ensure'),
    Enum['not_protected', 'ref_protected'] $access_level       = lookup('profile::gitlab::runner::access_level'),
    Integer                                $concurrent         = lookup('profile::gitlab::runner::concurrent'),
    String                                 $docker_image       = lookup('profile::gitlab::runner::docker_image'),
    Boolean                                $docker_volume      = lookup('profile::gitlab::runner::docker_volume'),
    Integer                                $docker_volume_min  = lookup('profile::gitlab::runner::docker_volume_min'),
    Integer                                $docker_volume_max  = lookup('profile::gitlab::runner::docker_volume_max'),
    Hash                                   $docker_settings    = lookup('profile::gitlab::runner::docker_settings'),
    String                                 $docker_version     = lookup('profile::gitlab::runner::docker_version'),
    String                                 $docker_gc_interval = lookup('profile::gitlab::runner::docker_gc_interval'),
    String                                 $docker_gc_images_high_water_mark  = lookup('profile::gitlab::runner::docker_gc_images_high_water_mark'),
    String                                 $docker_gc_images_low_water_mark   = lookup('profile::gitlab::runner::docker_gc_images_low_water_mark'),
    String                                 $docker_gc_volumes_high_water_mark = lookup('profile::gitlab::runner::docker_gc_volumes_high_water_mark'),
    String                                 $docker_gc_volumes_low_water_mark  = lookup('profile::gitlab::runner::docker_gc_volumes_low_water_mark'),
    Stdlib::HTTPSUrl                       $gitlab_url         = lookup('profile::gitlab::runner::gitlab_url'),
    Boolean                                $locked             = lookup('profile::gitlab::runner::locked'),
    String                                 $registration_token = lookup('profile::gitlab::runner::registration_token'),
    Boolean                                $run_untagged       = lookup('profile::gitlab::runner::run_untagged'),
    Array[String]                          $tags               = lookup('profile::gitlab::runner::tags'),
    Boolean                                $enable_exporter    = lookup('profile::gitlab::runner::enable_exporter', {default_value => false}),
    Array[Stdlib::Host]                    $prometheus_nodes   = lookup('prometheus_nodes', {default_value => []}),
) {
    class { 'docker::configuration':
        settings => $docker_settings,
    }

    class { 'docker':
        package_name => 'docker.io',
        version      => $docker_version,
    }

    if $docker_volume {
        cinderutils::ensure { '/var/lib/docker':
            min_gb        => $docker_volume_min,
            max_gb        => $docker_volume_max,
            mount_point   => '/var/lib/docker',
            mount_mode    => '711',
            mount_options => 'discard,defaults',
            before        => Class['docker'],
        }
    }

    ferm::conf { 'docker-ferm':
        ensure => $ensure,
        prio   => 20,
        source => 'puppet:///modules/profile/ci/docker-ferm',
    }

    apt::package_from_component{ 'gitlab-runner':
        component => 'thirdparty/gitlab-runner',
        require   =>  Class['docker'],
    }

    class { 'docker::gc':
        ensure                  => $ensure,
        interval                => $docker_gc_interval,
        images_high_water_mark  => $docker_gc_images_high_water_mark,
        images_low_water_mark   => $docker_gc_images_low_water_mark,
        volumes_high_water_mark => $docker_gc_volumes_high_water_mark,
        volumes_low_water_mark  => $docker_gc_volumes_low_water_mark,
    }

    $runner_name = "${::hostname}.${::domain}"

    class { 'gitlab_runner::config':
        concurrent              => $concurrent,
        docker_image            => $docker_image,
        gitlab_url              => $gitlab_url,
        runner_name             => $runner_name,
        exporter_listen_address => $facts['ipaddress'],
        enable_exporter         => $enable_exporter,
        prometheus_nodes        => $prometheus_nodes,
    }

    if $ensure == 'present' {
        $tag_list = join($tags, ',')

        exec { 'gitlab-register-runner':
            user    => 'root',
            command => @("CMD"/L$)
                /usr/bin/gitlab-runner register \
                --template-config /etc/gitlab-runner/config-template.toml \
                --non-interactive \
                --name "${runner_name}" \
                --url "${gitlab_url}" \
                --registration-token "${registration_token}" \
                --executor "docker" \
                --docker-image "${docker_image}" \
                --tag-list "${tag_list}" \
                --run-untagged="${run_untagged}" \
                --locked="${locked}" \
                --access-level="${access_level}"
                |- CMD
            ,
            unless  => "/usr/bin/gitlab-runner list 2>&1 | /bin/grep -q '^${runner_name} '",
            require => Apt::Package_from_component['gitlab-runner'],
        }

    } else {
        exec { 'gitlab-unregister-runner':
            user    => 'root',
            command => "/usr/bin/gitlab-runner unregister --name '${runner_name}'",
            onlyif  => "/usr/bin/gitlab-runner list 2>&1 | /bin/grep -q '^${runner_name} '",
            before  =>  Package['gitlab-runner'],
        }
    }
}