Puppet Class: profile::ci::docker

Defined in:
modules/profile/manifests/ci/docker.pp

Overview

Class profile::ci::docker

Configures a host to be a docker-backed Jenkins agent

Parameters:

  • jenkins_agent_username (Any) (defaults to: lookup('jenkins_agent_username'))
  • settings (Any) (defaults to: lookup('profile::ci::docker::settings'))


5
6
7
8
9
10
11
12
13
14
15
16
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
# File 'modules/profile/manifests/ci/docker.pp', line 5

class profile::ci::docker(
    $jenkins_agent_username = lookup('jenkins_agent_username'),
    $settings = lookup('profile::ci::docker::settings'),
) {
    include profile::docker::prune

    # Let us elevate permissions to the user running a containerized process
    ensure_packages('acl')

    if debian::codename::lt('bullseye') {
        apt::repository { 'thirdparty-ci':
            uri        => 'http://apt.wikimedia.org/wikimedia',
            dist       => "${::lsbdistcodename}-wikimedia",
            components => 'thirdparty/ci',
        }
    }

    class { 'docker::configuration':
        settings => $settings,
    }

    # TODO: Drop the entire version-specific pinning once buster is gone
    $docker_version = $::lsbdistcodename ? {
        'stretch' => '5:19.03.5~3-0~debian-stretch',
        'buster'  => '5:20.10.12~3-0~debian-buster',
        # Docker version is ignored starting with Bullseye
        default   => 'present',
    }

    $docker_package = $::lsbdistcodename ? {
        'stretch'  => 'docker-ce',
        'buster'   => 'docker-ce',
        'bullseye' => 'docker.io',
    }

    ensure_packages(
        $docker_package,
        {
            'ensure'  => $docker_version,
            'require' => Class['docker::configuration'],
        },
    )

    file { '/usr/local/bin/docker-credential-environment':
        source => 'puppet:///modules/docker/docker-credential-environment.py',
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
    }

    if $::realm == 'labs' {
        # ensure jenkins-deploy membership in the docker group
        exec { 'jenkins user docker membership':
            unless  => "/usr/bin/id -Gn '${jenkins_agent_username}' | /bin/grep -qw 'docker'",
            command => "/usr/sbin/usermod -aG docker '${jenkins_agent_username}'",
            require => [
                Package[ $docker_package ],
            ],
        }
    }

    # Ship the entire docker iptables configuration via ferm
    # This is here to make sure docker and ferm play nice together.
    ferm::conf { 'docker-ferm':
        ensure => present,
        prio   => 20,
        source => 'puppet:///modules/profile/ci/docker-ferm',
    }
}