Puppet Class: thumbor

Defined in:
puppet/modules/thumbor/manifests/init.pp

Overview

Class: Thumbor

This Puppet class installs and configures a Thumbor instance

Thumbor is installed as a Python package, and as part of that, pip compiles lxml.

Parameters

cfg_dir

Thumbor configuration directory. The directory will be generated by Puppet.

log_dir

Thumbor log directory. The directory will be generated by Puppet.

tmp_dir

Thumbor tmp directory. The directory will be generated by Puppet.

statsd_port

Port the statsd instance runs on.

Parameters:

  • cfg_dir (Any)
  • log_dir (Any)
  • tmp_dir (Any)
  • statsd_port (Any)


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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'puppet/modules/thumbor/manifests/init.pp', line 22

class thumbor (
    $cfg_dir,
    $log_dir,
    $tmp_dir,
    $statsd_port,
) {
    require_package('python-logstash')

    package { 'raven':
        provider => 'pip',
    }

    package { 'python-thumbor-wikimedia':
        ensure => 'present',
        notify => Exec['stop-and-disable-default-thumbor-service'],
    }

    exec { 'stop-and-disable-default-thumbor-service':
        command => '/bin/systemctl stop thumbor'
    }

    $statsd_host = 'localhost'
    $statsd_prefix = 'Thumbor'

    file { '/etc/firejail/thumbor.profile':
        ensure  => present,
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
        source  => 'puppet:///modules/thumbor/thumbor.profile',
        require => Package['firejail'],
    }

    file { '/etc/tinyrgb.icc':
        ensure  => present,
        source  => 'puppet:///modules/thumbor/tinyrgb.icc',
        require => Package['python-thumbor-wikimedia'],
    }

    file { $cfg_dir:
        ensure => directory,
    }

    file { $log_dir:
        ensure  => directory,
        group   => 'thumbor',
        mode    => '0775',
        require => Package['python-thumbor-wikimedia'],
    }

    file { $tmp_dir:
        ensure => directory,
    }

    file { "${cfg_dir}/10-thumbor.conf":
        ensure  => present,
        group   => 'thumbor',
        content => template('thumbor/10-thumbor.conf.erb'),
        mode    => '0640',
        require => [
            File[$cfg_dir],
            Package['python-thumbor-wikimedia'],
        ],
    }

    file { "${cfg_dir}/20-thumbor-logging.conf":
        ensure  => present,
        group   => 'thumbor',
        content => template('thumbor/20-thumbor-logging.conf.erb'),
        mode    => '0640',
        require => [
            File[$cfg_dir, $log_dir],
            Package['python-thumbor-wikimedia'],
        ],
    }

    file { "${cfg_dir}/60-thumbor-wikimedia.conf":
        ensure  => present,
        group   => 'thumbor',
        content => template('thumbor/20-thumbor-wikimedia.conf.erb'),
        mode    => '0640',
        require => [
            File[$cfg_dir],
            Package['python-thumbor-wikimedia'],
        ],
    }

    # This will generate a list of ports starting at 8889, with
    # as many ports as there are CPUs on the machine.
    $ports = sequence_array(8889, $::processorcount).map |$p| { String($p) }

    thumbor::service { $ports:
        tmp_dir   => $tmp_dir,
        cfg_files => File[
            "${cfg_dir}/10-thumbor.conf",
            "${cfg_dir}/20-thumbor-logging.conf",
            "${cfg_dir}/60-thumbor-wikimedia.conf"
        ],
    }

    varnish::backend { 'swift':
        host   => '127.0.0.1',
        port   => $::swift::port,
        onlyif => 'req.url ~ "^/images/.*"',
    }

    varnish::config { 'thumbor':
        content => template('thumbor/varnish.vcl.erb'),
        order   => 49, # Needs to be before default for vcl_recv override
    }

    $port = $::swift::port
    $project = $::swift::project
    $user = $::swift::user
    $key = $::swift::key

    # Since thumbor doesn't have the ability to create swift containers, we have to
    # create the sharded thumbnail containers ahead of time.
    exec { 'create-swift-thumbnail-containers':
        command   => '/usr/local/bin/mwscript extensions/WikimediaMaintenance/filebackend/setZoneAccess.php --wiki wiki --backend swift-backend',
        unless    => "swift -A http://127.0.0.1:${port}/auth/v1.0 -U ${project}:${user} -K ${key} stat wiki-dev-local-thumb.ff | grep -q wiki-dev-local-thumb.ff",
        require   => [
            Service[
                'swift-account-server',
                'swift-account-auditor',
                'swift-account-reaper',
                'swift-account-replicator',
                'swift-container-server',
                'swift-container-updater',
                'swift-container-replicator',
                'swift-container-sync',
                'swift-container-auditor',
                'swift-object-server',
                'swift-object-auditor',
                'swift-object-expirer',
                'swift-object-replicator',
                'swift-object-updater',
                'swift-proxy-server'
            ],
            Mediawiki::Settings['swift'],
        ],
        subscribe => Mediawiki::Settings['swift'],
    }

    cron { 'systemd-thumbor-tmpfiles-clean':
        minute   => '*',
        hour     => '*',
        monthday => '*',
        month    => '*',
        weekday  => '*',
        command  => "/bin/systemd-tmpfiles --clean --prefix=${tmp_dir}",
    }
}