Puppet Class: phabricator

Defined in:
modules/phabricator/manifests/init.pp

Overview

Parameters:

  • phabdir (Stdlib::Unixpath) (defaults to: '/srv/phab')
  • confdir (Stdlib::Unixpath) (defaults to: '/srv/phab/phabricator/conf')
  • timezone (String) (defaults to: 'UTC')
  • trusted_proxies (Array) (defaults to: [])
  • libraries (Array) (defaults to: [])
  • settings (Hash) (defaults to: {})
  • conf_files (Hash) (defaults to: {})
  • mysql_admin_user (String) (defaults to: '')
  • mysql_admin_pass (String) (defaults to: '')
  • serveradmin (String) (defaults to: '')
  • serveraliases (Array) (defaults to: [])
  • deploy_user (String) (defaults to: undef)
  • deploy_target (String) (defaults to: 'phabricator/deployment')
  • opcache_validate (Integer) (defaults to: 0)
  • phd_service_ensure (Stdlib::Ensure::Service) (defaults to: running)
  • manage_scap_user (Boolean) (defaults to: undef)


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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'modules/phabricator/manifests/init.pp', line 57

class phabricator (
    Stdlib::Unixpath $phabdir = '/srv/phab',
    Stdlib::Unixpath $confdir = '/srv/phab/phabricator/conf',
    String $timezone          = 'UTC',
    Array $trusted_proxies    = [],
    Array $libraries          = [],
    Hash $settings            = {},
    Hash $conf_files          = {},
    String $mysql_admin_user  = '',
    String $mysql_admin_pass  = '',
    String $serveradmin       = '',
    Array $serveraliases      = [],
    String $deploy_user       = undef,
    String $deploy_target     = 'phabricator/deployment',
    Integer $opcache_validate = 0,
    Stdlib::Ensure::Service $phd_service_ensure = running,
    Boolean $manage_scap_user = undef,
) {
    $deploy_root = "/srv/deployment/${deploy_target}"

    # base dependencies to ensure the phabricator deployment root exists
    # save as a var since this will be required by many resources in this class
    $base_requirements = [Package[$deploy_target]]

    #A combination of static and dynamic conf parameters must be merged
    $module_path = get_module_path($module_name)
    $fixed_settings = loadyaml("${module_path}/data/fixed_settings.yaml")

    if ($libraries) {
        phabricator::libext { $libraries:
            rootdir => $phabdir,
            require => $base_requirements,
        }
        $library_settings = { 'load-libraries' => $libraries }
    }

    #per stdlib merge the dynamic settings will take precendence for conflicts
    $phab_settings = merge($fixed_settings, $library_settings, $settings)

    if empty($mysql_admin_user) {
        $storage_user = $phab_settings['mysql.user']
    } else {
        $storage_user = $mysql_admin_user
    }

    if empty($mysql_admin_pass) {
        $storage_pass = $phab_settings['mysql.pass']
    } else {
        $storage_pass = $mysql_admin_pass
    }


    # First installs can trip without this
    exec {'apt_update_php':
        command     => '/usr/bin/apt-get update',
        refreshonly => true,
        logoutput   => true,
    }

    package { [
        'python3-pygments',
        'python-phabricator',
        'apachetop',
        'subversion',
        's-nail']:
            ensure => present;
    }

    $docroot = "${phabdir}/phabricator/webroot"

    $phab_servername = hiera('phabricator_servername', $phab_settings['phabricator.base-uri'])

    httpd::site { 'phabricator':
        content => template('phabricator/phabricator-default.conf.erb'),
        require => $base_requirements,
    }

    # git.wikimedia.org hosts rewrite rules to redirect old gitblit urls to
    # equivilent diffusion urls.

    $gitblit_servername = $phab_settings['gitblit.hostname']

    file { '/srv/git.wikimedia.org':
        ensure => 'directory',
        owner  => 'root',
        group  => 'root',
    }

    httpd::site { 'git.wikimedia.org':
        content => template('phabricator/gitblit_vhost.conf.erb'),
        require => File['/srv/git.wikimedia.org'],
    }

    # Robots.txt disallowing to crawl the alias domain
    if $serveraliases {
        file {"${phabdir}/robots.txt":
            ensure  => present,
            owner   => 'root',
            group   => 'root',
            mode    => '0444',
            content => "User-agent: *\nDisallow: /\n",
        }
    }

    scap::target { $deploy_target:
        deploy_user => $deploy_user,
        key_name    => 'phabricator',
        manage_user => $manage_scap_user,
        require     => File['/usr/local/sbin/phab_deploy_finalize'],
        sudo_rules  => [
            'ALL=(root) NOPASSWD: /usr/local/sbin/phab_deploy_promote',
            'ALL=(root) NOPASSWD: /usr/local/sbin/phab_deploy_rollback',
            'ALL=(root) NOPASSWD: /usr/local/sbin/phab_deploy_finalize',
        ],
    }

    file { $phabdir:
        ensure  => 'link',
        target  => $deploy_root,
        require => Package[$deploy_target],
    }

    file { "${phabdir}/phabricator/scripts/":
        mode    => '0754',
        recurse => true,
        before  => File["${phabdir}/phabricator/scripts/mail/"],
        require => $base_requirements,
    }

    file { "${phabdir}/phabricator/scripts/mail/":
        mode    => '0755',
        recurse => true,
        require => $base_requirements,
    }

    file { '/etc/apache2/phabbanlist.conf':
        source  => 'puppet:///modules/phabricator/apache/phabbanlist.conf',
        notify  => Service['apache2'],
        require => Package['apache2'],
    }

    file { $confdir:
        ensure => 'directory',
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
    }

    file { "${confdir}/local":
        ensure => 'directory',
        owner  => 'root',
        group  => 'root',
        mode   => '0755',
    }

    file { "${confdir}/local/local.json":
        content => template('phabricator/local.json.erb'),
        require => $base_requirements,
        owner   => 'root',
        group   => 'www-data',
        mode    => '0644',
    }

    file { '/usr/local/sbin/phab_deploy_promote':
        content => file('phabricator/phab_deploy_promote.sh'),
        owner   => 'root',
        group   => 'root',
        mode    => '0700',
    }

    file { '/usr/local/sbin/phab_deploy_finalize':
        content => template('phabricator/deployment/phab_deploy_finalize.erb'),
        owner   => 'root',
        group   => 'root',
        mode    => '0700',
    }

    file { '/usr/local/sbin/phab_deploy_rollback':
        content => file('phabricator/phab_deploy_rollback.sh'),
        owner   => 'root',
        group   => 'root',
        mode    => '0700',
    }


    if !empty($conf_files) {
        create_resources(phabricator::conf_env, $conf_files)
    }

    #default location for phabricator tracked repositories
    if ($phab_settings['repository.default-local-path']) {
        $repo_root = $phab_settings['repository.default-local-path']
        file { $repo_root:
            ensure => directory,
            mode   => '0755',
            owner  => 'phd',
            group  => 'www-data',
        }
        file { "${deploy_root}/repos":
            ensure  => 'link',
            target  => $repo_root,
            require => $base_requirements,
        }
    }

    file { '/usr/local/bin/arc':
        ensure  => 'link',
        owner   => 'root',
        group   => 'root',
        mode    => '0755',
        target  => '/srv/phab/arcanist/bin/arc',
        require => $base_requirements,
    }

    class { '::phabricator::vcs':
        basedir  => $phabdir,
        settings => $phab_settings,
        require  => $base_requirements,
    }

    class { '::phabricator::phd':
        basedir  => $phabdir,
        settings => $phab_settings,
        require  => $base_requirements,
    }

    systemd::service { 'phd':
        ensure         => 'present',
        content        => systemd_template('phd'),
        require        => Class['::phabricator::phd'],
        service_params => {
            ensure     => $phd_service_ensure,
            hasrestart => true,
        },
    }

    # mysql read access for phab admins, in production (T238425)
    if $::realm == 'production' {
        $::admin::data['groups']['phabricator-admin']['members'].each |String $user| {
            file { "/home/${user}/.my.cnf":
                content => template('phabricator/my.cnf.erb'),
                owner   => $user,
                group   => 'root',
                mode    => '0440',
            }
        }
    }
}