Puppet Class: profile::ci::docker

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

Overview

SPDX-License-Identifier: Apache-2.0

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'))
  • docker_version (Any) (defaults to: lookup('profile::ci::docker::docker_version'))


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
74
75
76
77
78
79
# File 'modules/profile/manifests/ci/docker.pp', line 6

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

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

    apt::repository { 'thirdparty-ci':
        uri        => 'http://apt.wikimedia.org/wikimedia',
        dist       => "${::lsbdistcodename}-wikimedia",
        components => 'thirdparty/ci',
    }

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

    profile::auto_restarts::service { 'docker':
        ensure => absent,
    }

    profile::auto_restarts::service { 'containerd':
        ensure => absent,
    }

    # Upstream package versions are always suffixed with "-codename"
    $full_docker_version = "${docker_version}-${::lsbdistcodename}"

    ensure_packages(
        'docker-ce',
        {
            'ensure'  => $full_docker_version,
            'require' => [
                Class['docker::configuration'],
                Apt::Repository['thirdparty-ci'],
            ],
        },
    )

    # Upstream docker debian package does not enable the service and it thus
    # does not start on reboot T313119
    service { 'docker':
        enable => true,
    }

    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-ce'],
            ],
        }
    }

    # 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',
    }
}