summaryrefslogtreecommitdiffstats
path: root/puppet/modules/ci_server/manifests/debian.pp
blob: e945cf6b92f51a20939595d85efd86206803a260 (plain)
1
2
3
4
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
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
 class ci_server::debian inherits ci_server
{
 # ============================== qtqa setup in jenkins homedir ======================

    file { "/var/lib/jenkins/.profile":
        ensure => present,
        source => "puppet:///modules/ci_server/dot.profile",
        require => Package["jenkins", "liblocal-lib-perl"],
        owner => "jenkins",
        group => "nogroup",
    }

    # all packages needed for qtqa repo setup.
    # most of these are to support a working homedir CPAN setup
    # (able to compile and install XS modules)
    $qtqa_packages = [
        "git",
        "libwww-perl",
        "liblocal-lib-perl",
        "libc6-dev",
        "libexpat1-dev",
        "make"
    ]

    package { $qtqa_packages: ensure => installed; }

    exec { "clone qtqa into jenkins homedir":
        command => "/bin/su -c \"   \
            \
            rm -rf qtqa.cloning && \
            git clone git://code.qt.io/qt/qtqa qtqa.cloning && \
            mv -v qtqa.cloning qtqa && \
            eval \$(perl -Mlocal::lib) && \
            qtqa/scripts/setup.pl --install \
            \
            \" - jenkins",
        require => Package[
            $qtqa_packages,
            "jenkins"       # jenkins package creates jenkins user
        ],
        timeout => 360,     # allow 1 hour for installation (can be slow)
        creates => "/var/lib/jenkins/qtqa/scripts/setup.pl",
        logoutput => true,
    }

    cron { "update qtqa":
        command =>
            "( \
                source \$HOME/.profile && \
                cd qtqa && \
                git fetch --quiet origin && \
                git reset --quiet --hard origin/master && \
                git clean -dqffx . \
            ) 2>&1 | logger -t jenkins-qtqa-update",
        user => "jenkins",
        hour => "*/2",
        minute => "20",
        require => Exec["clone qtqa into jenkins homedir"],
    }

    # ======================== 'reliable' versions of git, scp =========================
    $reliable = "/var/lib/jenkins/qtqa/scripts/generic/reliable.pl"
    $reliable_bin = "/var/lib/jenkins/reliable-bin"

    file {
        $reliable_bin:
            ensure => directory,
            mode => 0755,
            owner => "jenkins",
            group => "nogroup",
        ;

        # currently we don't deploy a reliable ssh because we'll want to run some ssh
        # commands which read from STDIN and we don't have a decent way to automatically
        # retry those
        ["$reliable_bin/git", "$reliable_bin/scp"]:
            ensure => link,
            target => $reliable,
            owner => "jenkins",
            group => "nogroup",
            require => [
                File[$reliable_bin],
                Exec["clone qtqa into jenkins homedir"],
            ],
        ;
    }


    # ======================= ssh setup ================================================

    Sshkey { type => "ssh-rsa" }

    sshkey { "[codereview.qt-project.org]:29418":
        key => "AAAAB3NzaC1yc2EAAAADAQABAAAAgQCvXdApmCFiAyXDiYU5+z6762Qv8+vrmM3+9YrxDKByyphaxblLJC9txPv3D/w7rzSyiMMHL/5ssCemwz+6QBqnemFl4B+FNv81fpZFsqCg5afrTi62WFllGWIQAiYb2JZmkmSAbxm+sAxLE1ritp+Syxz8Gb8WR27G/3TSHerdBQ==",
    }
    sshkey { "[dev-codereview.qt-project.org]:29418":
        key => "AAAAB3NzaC1yc2EAAAADAQABAAAAgQDSl0SfLVrmQf5lxz8/Xo5IYa8DSymJkc8lNDQx0ZHySzveR5RxLtAqhxKN8HXYyz22xImOkr9Lu8tt4OKx7+SsN/LXV9zARdK9enJk7pEatmD/9GhwhhgKLtCKGuGrSxiTvDyesg6TVL59pdyXom+E8lU/fOhf2Qv6+8+Ow7EGow==",
    }
    sshkey { "testresults.qt.io":
        key => "AAAAB3NzaC1yc2EAAAADAQABAAABAQDE6+70RZyZdK4nUwXb5O/IYZjNpHC8OKp7+3NCMqKYIFxzyDrb8BgPu5utqcolJ6rPYppE+PD4ZBKkA4+sebGyJD54kszj9emhpNDB7say1kd7Xdwy2hEjUawdcTkKxVkGXDQQQULCL0tvBPthmj8doWbFarmpxfnpTvwQdaj2aRK1Get2g2CTnmoNGnH4KoSVoa7/Ge+nkCN+Ub8Qfk/UboBRGdSAqSYAuPz/x+bfpNz0spKL2VY2f/Yg3IxjQBTB/Z4Jpj3Hi+ckj4DUiYj7lDnYEw/IsMyU5p0VZzy22ZV7cIkfkeOuYOyvSLLoyXHJrZKte5wuddMtBvnyFqGx",
    }

    # make sure ssh_known_hosts is world-readable
    file { "/etc/ssh/ssh_known_hosts":
        mode => 0644,
    }

    file {
        "/var/lib/jenkins/.ssh":
            ensure => directory,
            mode => 0755,
            owner => "jenkins",
            group => "nogroup",
            require => Package["jenkins"],
        ;
        "/var/lib/jenkins/.ssh/config":
            ensure => present,
            source => "puppet:///modules/ci_server/ssh_config",
            mode => 0644,
            owner => "jenkins",
            group => "nogroup",
            require => File["/var/lib/jenkins/.ssh"],
        ;
    }

    # generate a warning each time we are run until this key is set up.
    $pubkey = 'AAAAB3NzaC1yc2EAAAADAQABAAABAQCx2Xb8YE0AMFF/BEODFQgxVZmJdR5rTukX5PwDweJLik3YUCl9Ja6DMgBCSjuJWSPNlFnJoAUQXE2J/zOcp0RK9n1m1nVcraw5kuHDrnocuL6e+e9OHyBaYMoBFo7VYZgg/pBEuwL1Spn+KYFP60gbZm5aQw81t/jcwrVn60YtbGypsNzLd97knY7eamBEhId9B4CVF79/deUa+SoNiZ46hO7mNtXmTiJBPc4ilsm3Fy99sO5VSY/wJTsiltRWaWxnJrS2Ww29VfPzJksAo4c5S6gBnOLPIs/TLMwYSCEbUnwn/NPE3WGG/psvhy0X1Y/Acjtl/inxhoOVIF1yt+2J'

    exec { "warn about jenkins ssh key":
        command => "/bin/echo 'WARNING: manual installation of Jenkins ssh key is required, matching public key: $pubkey'",
        logoutput => true,
        require => File["/var/lib/jenkins/.ssh"],
        unless => "/bin/grep -q -F '$pubkey' /var/lib/jenkins/.ssh/id_rsa.pub",
    }

    # ================================= git setup ======================================

    Git::Config {
        require => Package["git","jenkins"],
        file => "/var/lib/jenkins/.gitconfig",
    }

    git::config { "jenkins user.name":
        key => "user.name",
        content => "Qt Project Jenkins",
        user => "jenkins",
    }

    git::config { "jenkins user.email":
        key => "user.email",
        content => "jenkins@qt-project.org",
        user => "jenkins",
    }

    git::object_cache { "jenkins git object cache":
        cache_path => "/var/lib/jenkins/git-objects",
        git_path => [
            # default workspace path
            "/var/lib/jenkins/jobs/*/workspace",

            # custom shorter workspace path used by some jobs
            "/var/lib/jenkins/ci/*",
            "/var/lib/jenkins/ci/*/*",

            # other repos, not created by jenkins
            "/var/lib/jenkins/qtqa",
        ],
        require => Package["jenkins"],  # jenkins package creates jenkins user
        owner => "jenkins",
        group => "nogroup",
    }

    # ================================= gerrit -> jenkins integrator ============
    # environment; warnings and worse go to syslog
    $env = "/usr/bin/env PERL_ANYEVENT_VERBOSE=5 PERL_ANYEVENT_LOG=log=syslog"

    # start-stop-daemon base cmd (for /usr/bin/perl)
    $start_stop_daemon_perl = "start-stop-daemon --chuid jenkins:nogroup --background --user jenkins --exec /usr/bin/perl --make-pidfile --startas /bin/sh"

    # script cmd
    $sh_args = "exec perl /var/lib/jenkins/qtqa/scripts/jenkins/qt-jenkins-integrator.pl --config /var/lib/jenkins/ci.cfg"

    # pid file base
    $pidfile = "/var/run/qt-jenkins-integrator.pid"

    exec { "qt-jenkins-integrator":
        command => "$env $start_stop_daemon_perl --pidfile $pidfile --start -- -l -c '$sh_args'",
        onlyif => "$env $start_stop_daemon_perl --pidfile $pidfile --test --start",
        require => Cron["update qtqa"],
    }

    # ============================= port forward for remote API ========================
    # start-stop-daemon base cmd (for /usr/bin/ssh)
    $start_stop_daemon_ssh = "start-stop-daemon --chuid jenkins:nogroup --background --user jenkins --exec /usr/bin/ssh --make-pidfile --startas /bin/sh"

    # ssh base cmd (user@hostname omitted)
    $sh_args_ssh = "exec ssh -oServerAliveInterval=30 -R 7181:127.0.0.1:7181 -N"

    # pid file base
    $pidfile_base_ssh = "/var/run/ssh-qt-ci-remote-api"

    exec { "ssh fwd for testresults remote API":
        command => "$env $start_stop_daemon_ssh --pidfile $pidfile_base_ssh-testresults.pid --start -- -l -c '$sh_args_ssh qtintegration@testresults.qt.io'",
        onlyif => "$env $start_stop_daemon_ssh --pidfile $pidfile_base_ssh-testresults.pid --test --start",
    }

}