Puppet Class: codesearch

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

Overview

Class: codesearch

This class sets up the basics needed for MediaWiki code search hosted at codesearch.wmflabs.org

Parameters:

  • base_dir (Optional[Stdlib::Unixpath]) (defaults to: undefined)
  • ports (Hash[String, Integer]) (defaults to: undefined)


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
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
# File 'modules/codesearch/manifests/init.pp', line 6

class codesearch(
    Optional[Stdlib::Unixpath] $base_dir = undefined,
    Hash[String, Integer] $ports = undefined,
){
    $hound_dir  = "${base_dir}/hound"
    $clone_dir  = "${base_dir}/codesearch"
    $puppet_dir = "${base_dir}/puppet"

    apt::package_from_component { 'thirdparty-kubeadm-k8s':
        component => 'thirdparty/kubeadm-k8s-1-15',
        packages  => ['docker-ce'],
    }

    require_package([
        'gunicorn3',
        'python3-flask',
        'python3-requests',
        'python3-yaml',
    ])

    if os_version('debian == buster') {
        # We need iptables 1.8.3+ for compatibility with docker
        # (see comments on <https://gerrit.wikimedia.org/r/565752>)
        apt::pin { 'iptables':
            pin      => 'release a=buster-backports',
            package  => 'iptables',
            priority => '1001',
            before   => Package['docker-ce'],
        }
    }

    file { $hound_dir:
        ensure => directory,
        owner  => 'codesearch',
        group  => 'codesearch',
        mode   => '0755',
    }

    group { 'codesearch':
        ensure => present,
        name   => 'codesearch',
        system => true,
    }

    user { 'codesearch':
        ensure  => present,
        system  => true,
        groups  => 'docker',
        require => Package['docker-ce'],
    }

    git::clone {'labs/codesearch':
        ensure    => latest,
        directory => $clone_dir,
        branch    => 'master',
        require   => User['codesearch'],
        owner     => 'codesearch',
        group     => 'codesearch',
    }

    git::clone {'operations/puppet':
        ensure    => latest,
        directory => $puppet_dir,
        branch    => 'production',
        require   => User['codesearch'],
        owner     => 'codesearch',
        group     => 'codesearch',
    }

    # Alias production to master for puppet
    exec { 'puppet alias origin/master':
        command => '/usr/bin/git symbolic-ref refs/remotes/origin/master refs/remotes/origin/production',
        cwd     => $puppet_dir,
        user    => 'codesearch',
        creates => "${puppet_dir}/.git/refs/remotes/origin/master",
        require => Git::Clone['operations/puppet'],
    }

    exec { 'puppet alias master':
        command => '/usr/bin/git symbolic-ref refs/heads/master refs/heads/production',
        cwd     => $puppet_dir,
        user    => 'codesearch',
        creates => "${puppet_dir}/.git/refs/heads/master",
        require => Git::Clone['operations/puppet'],
    }

    systemd::timer::job { 'codesearch-write-config':
        description => 'Generate hound configuration files',
        command     => "${clone_dir}/write_config.py",
        user        => 'codesearch',
        interval    => {
            'start'    => 'OnCalendar',
            'interval' => '*-*-* 00:00:00',  # Every day at midnight
        },
        require     => [
            Git::Clone['labs/codesearch'],
            User['codesearch'],
        ],
    }

    systemd::service { 'hound_proxy':
        ensure    => present,
        content   => template('codesearch/initscripts/hound_proxy.service.erb'),
        restart   => true,
        subscribe => File['/etc/codesearch_ports.json'],
        require   => [
            Git::Clone['labs/codesearch'],
            Package['gunicorn3'],
            File['/etc/codesearch_ports.json'],
        ]
    }

    file { '/etc/codesearch_ports.json':
        ensure  => present,
        content => ordered_json($ports),
        owner   => 'codesearch',
        require => User['codesearch'],
    }

    $ports.each |String $name, Integer $port| {
        systemd::service { "hound-${name}":
            ensure  => present,
            content => template('codesearch/initscripts/hound.service.erb'),
            restart => true,
            require => [
                Package['docker-ce'],
                Git::Clone['operations/puppet'],
                Systemd::Service['hound_proxy'],
                Systemd::Timer::Job['codesearch-write-config'],
            ]
        }
    }
}