Puppet Class: puppet_compiler::uploader

Defined in:
modules/puppet_compiler/manifests/uploader.pp

Summary

class to install the puppet uploader

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • ensure (Wmflib::Ensure) (defaults to: 'present')

    ensurable parameter

  • port (Stdlib::Port) (defaults to: 8001)

    the port the service listens on

  • app_dir (Stdlib::Unixpath) (defaults to: '/usr/local/share/pcc_uploader')

    location to install the flask app

  • upload_dir (Stdlib::Unixpath) (defaults to: '/srv/pcc_uploader')

    location to store uploaded files

  • webroot (Stdlib::Unixpath) (defaults to: '/srv/www')

    the docuemtn root of the website

  • jenkins_user (String[1]) (defaults to: 'jenkins-deploy')

    user jenkis process uses

  • jenkins_group (String[1]) (defaults to: 'wikidev')

    group jenkis process uses

  • web_user (String[1]) (defaults to: 'www-data')

    user web process uses

  • web_group (String[1]) (defaults to: 'www-data')

    group web process uses

  • max_content_length (Integer) (defaults to: 16000000)

    The maximum upload size

  • realms (Hash[String[1], Hash[Stdlib::Host, String[1]]]) (defaults to: {})

    a hash of realms and the ip addresses that are allowed to make submissions



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
# File 'modules/puppet_compiler/manifests/uploader.pp', line 14

class puppet_compiler::uploader (
    Wmflib::Ensure   $ensure             = 'present',
    Stdlib::Port     $port               = 8001,
    Stdlib::Unixpath $app_dir            = '/usr/local/share/pcc_uploader',
    Stdlib::Unixpath $upload_dir         = '/srv/pcc_uploader',
    Stdlib::Unixpath $webroot            = '/srv/www',
    String[1]        $jenkins_user       = 'jenkins-deploy',
    String[1]        $jenkins_group      = 'wikidev',
    String[1]        $web_user           = 'www-data',
    String[1]        $web_group          = 'www-data',
    Integer          $max_content_length = 16000000,  # 16MB
    Hash[String[1], Hash[Stdlib::Host, String[1]]] $realms = {}
) {
    $wsgi_file = "${app_dir}/wsgi.py"
    $config_file = "${app_dir}/pcc_uploader.json"
    $config = {
        'UPLOAD_FOLDER'      => $upload_dir,
        'MAX_CONTENT_LENGTH' => $max_content_length,
        'REALMS'             => $realms,
    }

    ensure_packages(['python3-flask', 'python3-magic', 'python3-pypuppetdb'])
    wmflib::dir::mkdir_p([$app_dir, $upload_dir, $webroot])
    file { "${webroot}/facts":
        ensure => stdlib::ensure($ensure, 'directory'),
        mode   => '0660',
        owner  => $web_user,
        group  => $jenkins_group,
    }
    $realms.keys.each |$realm| {
        file { "${upload_dir}/${realm}":
            ensure => stdlib::ensure($ensure, 'directory'),
            owner  => $web_user,
            mode   => '0660',
            group  => $jenkins_group,
        }
    }
    file { $config_file:
        ensure  => stdlib::ensure($ensure, 'file'),
        content => $config.to_json,
        notify  => Uwsgi::App['pcc-uploader'],
    }
    file { $wsgi_file:
        ensure => stdlib::ensure($ensure, 'file'),
        source => 'puppet:///modules/puppet_compiler/pcc_uploader.py',
        notify => Uwsgi::App['pcc-uploader'],
    }
    uwsgi::app{'pcc-uploader':
        settings => {
            uwsgi => {
                'plugins'     => 'python3',
                'master'      => true,
                'socket'      => "127.0.0.1:${port}",
                'wsgi-file'   => $wsgi_file,
                'die-on-term' => true,
            },
        },
    }
    file {'/usr/local/sbin/pcc_facts_processor':
        ensure => stdlib::ensure($ensure, 'file'),
        source => 'puppet:///modules/puppet_compiler/pcc_facts_processor.py',
        owner  => 'root',
        group  => $jenkins_group,
        mode   => '0550',
    }
    systemd::timer::job { 'pcc_facts_processor':
        ensure      => $ensure,
        user        => $jenkins_user,
        description => 'Process uploaded facts',
        command     => '/usr/local/sbin/pcc_facts_processor',
        interval    => {'start' => 'OnUnitInactiveSec', 'interval' => '24h'},
    }
}