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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# 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'),
) {
    # Let us elevate permissions to the user running a containerized process
    ensure_packages('acl')

    if debian::codename::lt('buster') {
        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 stretch is gone
    $docker_version = $::lsbdistcodename ? {
        'stretch'  => '5:19.03.5~3-0~debian-stretch',
        # Docker version is ignored starting with Buster
        default    => '',
    }

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

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

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

        # Purge images on a weekly basis to avoid partition filling up
        systemd::timer::job { 'docker-system-prune-all':
            ensure      => present,
            description => 'Prune all Docker images and volumes',
            user        => 'root',
            command     => '/usr/bin/docker system prune --all --volumes --force',

            splay       => 3600,  # seconds
            interval    => {
                'start'    => 'OnCalendar',
                'interval' => 'Sunday 3:00 UTC',
            },
        }

        systemd::timer::job { 'docker-system-prune-dangling':
            ensure      => present,
            description => 'Prune dangling Docker images',
            user        => 'root',
            command     => '/usr/bin/docker system prune --force',

            splay       => 3600,  # seconds
            interval    => {
                'start'    => 'OnCalendar',
                'interval' => 'Mon-Sat 3:00 UTC',
            },
        }
    }

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