summaryrefslogtreecommitdiff
path: root/Jenkinsfile
blob: 9d10f3eef09189e6edd28ab85595acbb22f4b703 (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
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
#!groovy
/*
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
*/
pipeline {
  /* no top-level agent; agents must be declared for each stage */
  agent none

  environment {
    COUCHAUTH = credentials('couchdb_vm2_couchdb')
    recipient = 'notifications@couchdb.apache.org'
    COUCHDB_IO_LOG_DIR = '/tmp/couchjslogs'
  }

  stages {
    stage('Build') {
      agent {
        docker {
          label 'ubuntu'
          // This image has the oldest Erlang we support, 16B03
          image 'couchdbdev/ubuntu-14.04-erlang-default'
          // https://github.com/jenkins-infra/jenkins.io/blob/master/Jenkinsfile#64
          // We need the jenkins user mapped inside of the image
          args '-e npm_config_cache=npm-cache -e HOME=. -v=/etc/passwd:/etc/passwd -v /etc/group:/etc/group --user 0:0'
        }
      }
      steps {
        timeout(time: 15, unit: "MINUTES") {
          // npm config cache below is required because /home/jenkins doesn't
          // ACTUALLY exist in the image
          sh '''
            set
            rm -rf apache-couchdb-*.tar.gz
            #export npm_config_cache=$(mktemp -d)
            ./configure --with-curl
            make dist
            chmod -R a+w * || true
          '''
          stash includes: 'apache-couchdb-*.tar.gz', name: 'tarball'
          archiveArtifacts artifacts: 'apache-couchdb-*.tar.gz', fingerprint: true
          deleteDir()
        }
      }
    }

    // TODO rework this once JENKINS-41334 is released
    // https://issues.jenkins-ci.org/browse/JENKINS-41334

    // The builddir stuff is to prevent all 10 builds from live syncing
    // their build results to each other during the build. Moving the
    // build outside of the workdir should speed up the build process, too

    // we run all package builds as root inside the Docker container
    
    // Build packages on supported platforms using esl's erlang
    stage('Test') {
      steps {
        parallel(centos6erlang183: {
          node(label: 'ubuntu') {
            timeout(time: 60, unit: "MINUTES") {
              sh 'docker pull couchdbdev/centos-6-erlang-18.3'
              withDockerContainer(image: 'couchdbdev/centos-6-erlang-18.3', args: '-e LD_LIBRARY_PATH=/usr/local/bin -v=/etc/passwd:/etc/passwd -v /etc/group:/etc/group --user 0:0') {
                sh 'rm -f apache-couchdb-*.tar.gz'
                unstash 'tarball'
                sh '''
                  cwd=$(pwd)
                  umask 0
                  rm -rf /tmp/couchjslogs && mkdir -p /tmp/couchjslogs

                  # Build CouchDB from tarball
                  builddir=$(mktemp -d)
                  cd $builddir
                  tar -xf $cwd/apache-couchdb-*.tar.gz
                  cd apache-couchdb-*
                  ./configure --with-curl
                  make all
                  #make check || (build-aux/logfile-uploader.py && false)

                  # Build CouchDB packages
                  cd $builddir
                  git clone https://github.com/apache/couchdb-pkg
                  mkdir couchdb
                  cd couchdb
                  cp $cwd/apache-couchdb-*.tar.gz .
                  tar -xf apache-couchdb-*.tar.gz
                  cd ../couchdb-pkg
                  # centos only
                  platform=centos6
                  make $platform PLATFORM=$platform
                  rm -rf $cwd/pkgs/$platform && mkdir -p $cwd/pkgs/$platform
                  # CentOS variant
                  mv ~/rpmbuild/RPMS/x86_64/*rpm $cwd/pkgs/$platform || true

                  # Cleanup
                  cd $cwd && rm -rf $builddir
                  chown -R jenkins:jenkins *
                '''
              } // withDocker
            } // timeout
            archiveArtifacts artifacts: 'pkgs/**', fingerprint: true
            deleteDir()
          } // node
        },
        centos7erlangdefault: {
          node(label: 'ubuntu') {
            timeout(time: 45, unit: "MINUTES") {
              sh 'docker pull couchdbdev/centos-7-erlang-default'
              withDockerContainer(image: 'couchdbdev/centos-7-erlang-default', args: '-e LD_LIBRARY_PATH=/usr/local/bin -e npm_config_cache=npm-cache -e HOME=. -v=/etc/passwd:/etc/passwd -v /etc/group:/etc/group') {
                sh 'rm -f apache-couchdb-*.tar.gz'
                unstash 'tarball'
                sh '''
                  cwd=$(pwd)
                  rm -rf /tmp/couchjslogs
                  mkdir -p /tmp/couchjslogs
                  builddir=$(mktemp -d)
                  cd $builddir
                  tar -xf $cwd/apache-couchdb-*.tar.gz
                  cd apache-couchdb-*
                  ./configure --with-curl
                  make all
                  #make check || (build-aux/logfile-uploader.py && false)
                '''
              } // withDocker
            } // timeout
            deleteDir()
          } // node
        },
        centos7erlang183: {
          node(label: 'ubuntu') {
            timeout(time: 60, unit: "MINUTES") {
              sh 'docker pull couchdbdev/centos-7-erlang-18.3'
              withDockerContainer(image: 'couchdbdev/centos-7-erlang-18.3', args: '-e LD_LIBRARY_PATH=/usr/local/bin -v=/etc/passwd:/etc/passwd -v /etc/group:/etc/group --user 0:0') {
                sh 'rm -f apache-couchdb-*.tar.gz'
                unstash 'tarball'
                sh '''
                  cwd=$(pwd)
                  umask 0
                  rm -rf /tmp/couchjslogs && mkdir -p /tmp/couchjslogs

                  # Build CouchDB from tarball
                  builddir=$(mktemp -d)
                  cd $builddir
                  tar -xf $cwd/apache-couchdb-*.tar.gz
                  cd apache-couchdb-*
                  ./configure --with-curl
                  make all
                  #make check || (build-aux/logfile-uploader.py && false)

                  # Build CouchDB packages
                  cd $builddir
                  git clone https://github.com/apache/couchdb-pkg
                  mkdir couchdb
                  cd couchdb
                  cp $cwd/apache-couchdb-*.tar.gz .
                  tar -xf apache-couchdb-*.tar.gz
                  cd ../couchdb-pkg
                  # centos only
                  platform=centos7
                  make $platform PLATFORM=$platform
                  rm -rf $cwd/pkgs/$platform && mkdir -p $cwd/pkgs/$platform
                  # CentOS variant
                  mv ~/rpmbuild/RPMS/x86_64/*rpm $cwd/pkgs/$platform || true

                  # Cleanup
                  cd $cwd && rm -rf $builddir
                  chown -R jenkins:jenkins *
                '''
              } // withDocker
            } // timeout
            archiveArtifacts artifacts: 'pkgs/**', fingerprint: true
            deleteDir()
          } // node
        },
        ubuntu1204erlang183: {
          node(label: 'ubuntu') {
            timeout(time: 45, unit: "MINUTES") {
              sh 'docker pull couchdbdev/ubuntu-12.04-erlang-18.3'
              withDockerContainer(image: 'couchdbdev/ubuntu-12.04-erlang-18.3', args: '-e npm_config_cache=npm-cache -e HOME=. -v=/etc/passwd:/etc/passwd -v /etc/group:/etc/group') {
                sh 'rm -f apache-couchdb-*.tar.gz'
                unstash 'tarball'
                sh '''
                  cwd=$(pwd)
                  rm -rf /tmp/couchjslogs
                  mkdir -p /tmp/couchjslogs
                  builddir=$(mktemp -d)
                  cd $builddir
                  tar -xf $cwd/apache-couchdb-*.tar.gz
                  cd apache-couchdb-*
                  ./configure --with-curl
                  make all
                  #make check || (build-aux/logfile-uploader.py && false)
                '''
              } // withDocker
            } // timeout
            deleteDir()
          } // node
        },
        ubuntu1404erlangdefault: {
          node(label: 'ubuntu') {
            timeout(time: 45, unit: "MINUTES") {
              sh 'docker pull couchdbdev/ubuntu-14.04-erlang-default'
              withDockerContainer(image: 'couchdbdev/ubuntu-14.04-erlang-default', args: '-e npm_config_cache=npm-cache -e HOME=. -v=/etc/passwd:/etc/passwd -v /etc/group:/etc/group') {
                sh 'rm -f apache-couchdb-*.tar.gz'
                unstash 'tarball'
                sh '''
                  cwd=$(pwd)
                  rm -rf /tmp/couchjslogs
                  mkdir -p /tmp/couchjslogs
                  builddir=$(mktemp -d)
                  cd $builddir
                  tar -xf $cwd/apache-couchdb-*.tar.gz
                  cd apache-couchdb-*
                  ./configure --with-curl
                  make all
                  #make check || (build-aux/logfile-uploader.py && false)
                '''
              } // withDocker
            } // timeout
            deleteDir()
          } // node
        },
        ubuntu1404erlang183: {
          node(label: 'ubuntu') {
            timeout(time: 60, unit: "MINUTES") {
              sh 'docker pull couchdbdev/ubuntu-14.04-erlang-18.3'
              withDockerContainer(image: 'couchdbdev/ubuntu-14.04-erlang-18.3', args: '-v=/etc/passwd:/etc/passwd -v /etc/group:/etc/group --user 0:0') {
                sh 'rm -f apache-couchdb-*.tar.gz'
                unstash 'tarball'
                sh '''
                  cwd=$(pwd)
                  umask 0
                  rm -rf /tmp/couchjslogs && mkdir -p /tmp/couchjslogs

                  # Build CouchDB from tarball
                  builddir=$(mktemp -d)
                  cd $builddir
                  tar -xf $cwd/apache-couchdb-*.tar.gz
                  cd apache-couchdb-*
                  ./configure --with-curl
                  make all
                  #make check || (build-aux/logfile-uploader.py && false)

                  # Build CouchDB packages
                  cd $builddir
                  git clone https://github.com/apache/couchdb-pkg
                  mkdir couchdb
                  cd couchdb
                  cp $cwd/apache-couchdb-*.tar.gz .
                  tar -xf apache-couchdb-*.tar.gz
                  cd ../couchdb-pkg
                  # debian/ubuntu only
                  sudo apt-get install -y libmozjs185-dev
                  platform=$(lsb_release -cs)
                  make $platform PLATFORM=$platform
                  rm -rf $cwd/pkgs/$platform && mkdir -p $cwd/pkgs/$platform
                  # Ubuntu/Debian variant
                  mv ../couchdb/*deb $cwd/pkgs/$platform || true

                  # Cleanup
                  cd $cwd && rm -rf $builddir
                  chown -R jenkins:jenkins *
                '''
              } // withDocker
            } // timeout
            archiveArtifacts artifacts: 'pkgs/**', fingerprint: true
            deleteDir()
          } // node
        },
        ubuntu1604erlangdefault: {
          node(label: 'ubuntu') {
            timeout(time: 45, unit: "MINUTES") {
              sh 'docker pull couchdbdev/ubuntu-16.04-erlang-default'
              withDockerContainer(image: 'couchdbdev/ubuntu-16.04-erlang-default', args: '-e npm_config_cache=npm-cache -e HOME=. -v=/etc/passwd:/etc/passwd -v /etc/group:/etc/group') {
                sh 'rm -f apache-couchdb-*.tar.gz'
                unstash 'tarball'
                sh '''
                  cwd=$(pwd)
                  rm -rf /tmp/couchjslogs
                  mkdir -p /tmp/couchjslogs
                  builddir=$(mktemp -d)
                  cd $builddir
                  tar -xf $cwd/apache-couchdb-*.tar.gz
                  cd apache-couchdb-*
                  ./configure --with-curl
                  make all
                  #make check || (build-aux/logfile-uploader.py && false)
                '''
              } // withDocker
            } // timeout
            deleteDir()
          } // node
        },
        ubuntu1604erlang183: {
          node(label: 'ubuntu') {
            timeout(time: 60, unit: "MINUTES") {
              sh 'docker pull couchdbdev/ubuntu-16.04-erlang-18.3'
              withDockerContainer(image: 'couchdbdev/ubuntu-16.04-erlang-18.3', args: '-v=/etc/passwd:/etc/passwd -v /etc/group:/etc/group --user 0:0') {
                sh 'rm -f apache-couchdb-*.tar.gz'
                unstash 'tarball'
                sh '''
                  cwd=$(pwd)
                  umask 0
                  rm -rf /tmp/couchjslogs && mkdir -p /tmp/couchjslogs

                  # Build CouchDB from tarball
                  builddir=$(mktemp -d)
                  cd $builddir
                  tar -xf $cwd/apache-couchdb-*.tar.gz
                  cd apache-couchdb-*
                  ./configure --with-curl
                  make all
                  #make check || (build-aux/logfile-uploader.py && false)

                  # Build CouchDB packages
                  cd $builddir
                  git clone https://github.com/apache/couchdb-pkg
                  mkdir couchdb
                  cd couchdb
                  cp $cwd/apache-couchdb-*.tar.gz .
                  tar -xf apache-couchdb-*.tar.gz
                  cd ../couchdb-pkg
                  # debian/ubuntu only
                  sudo apt-get install -y libmozjs185-dev
                  platform=$(lsb_release -cs)
                  make $platform PLATFORM=$platform
                  rm -rf $cwd/pkgs/$platform && mkdir -p $cwd/pkgs/$platform
                  # Ubuntu/Debian variant
                  mv ../couchdb/*deb $cwd/pkgs/$platform || true

                  # Cleanup
                  cd $cwd && rm -rf $builddir
                  chown -R jenkins:jenkins *
                '''
              } // withDocker
            } // timeout
            archiveArtifacts artifacts: 'pkgs/**', fingerprint: true
            deleteDir()
          } // node
        },
        debian8erlangdefault: {
          node(label: 'ubuntu') {
            timeout(time: 45, unit: "MINUTES") {
              sh 'docker pull couchdbdev/debian-8-erlang-default'
              withDockerContainer(image: 'couchdbdev/debian-8-erlang-default', args: '-e npm_config_cache=npm-cache -e HOME=. -v=/etc/passwd:/etc/passwd -v /etc/group:/etc/group') {
                sh 'rm -f apache-couchdb-*.tar.gz'
                unstash 'tarball'
                sh '''
                  cwd=$(pwd)
                  rm -rf /tmp/couchjslogs
                  mkdir -p /tmp/couchjslogs
                  builddir=$(mktemp -d)
                  cd $builddir
                  tar -xf $cwd/apache-couchdb-*.tar.gz
                  cd apache-couchdb-*
                  ./configure --with-curl
                  make all
                  #make check || (build-aux/logfile-uploader.py && false)
                '''
              } // withDocker
            } // timeout
            deleteDir()
          } // node
        },
        debian8erlang183: {
          node(label: 'ubuntu') {
            timeout(time: 60, unit: "MINUTES") {
              sh 'docker pull couchdbdev/debian-8-erlang-18.3'
              // must run as root because of sudo step below
              withDockerContainer(image: 'couchdbdev/debian-8-erlang-18.3', args: '-v=/etc/passwd:/etc/passwd -v /etc/group:/etc/group --user 0:0') {
                sh 'rm -f apache-couchdb-*.tar.gz'
                unstash 'tarball'
                sh '''
                  cwd=$(pwd)
                  rm -rf /tmp/couchjslogs && mkdir -p /tmp/couchjslogs

                  # Build CouchDB from tarball
                  builddir=$(mktemp -d)
                  cd $builddir
                  tar -xf $cwd/apache-couchdb-*.tar.gz
                  cd apache-couchdb-*
                  ./configure --with-curl
                  make all
                  #make check || (build-aux/logfile-uploader.py && false)

                  # Build CouchDB packages
                  cd $builddir
                  git clone https://github.com/apache/couchdb-pkg
                  mkdir couchdb
                  cd couchdb
                  cp $cwd/apache-couchdb-*.tar.gz .
                  tar -xf apache-couchdb-*.tar.gz
                  cd ../couchdb-pkg
                  # debian/ubuntu only
                  sudo apt-get install -y libmozjs185-dev
                  platform=$(lsb_release -cs)
                  make $platform PLATFORM=$platform
                  rm -rf $cwd/pkgs/$platform && mkdir -p $cwd/pkgs/$platform
                  # Ubuntu/Debian variant
                  mv ../couchdb/*deb $cwd/pkgs/$platform || true

                  # Cleanup
                  cd $cwd && rm -rf $builddir
                  chown -R jenkins:jenkins *
                '''
              } // withDocker
            } // timeout
            archiveArtifacts artifacts: 'pkgs/**', fingerprint: true
            deleteDir()
          } // node
        }
        ) // parallel
      } // steps
    } // stage

    stage('Publish') {
      when {
        expression { return env.BRANCH_NAME ==~ /master|2.0.x|2.1.x|jenkins-.*/ }
      }
      agent {
        docker {
          // This image has the deb AND rpm repo tools installed in it
          image 'couchdbdev/debian-8-base'
          // We need the jenkins user mapped inside of the image
          // We must run as root because we have to create ~/.ssh for rsync
          args '-v /etc/passwd:/etc/passwd -v /etc/group:/etc/group --user 0:0'
          label 'ubuntu'
        }
      }
      steps {
        withCredentials([file(credentialsId: 'jenkins-key', variable: 'KEY')]) {
          sh 'umask 0 && rm -rf pkgs'
          unarchive mapping: ['pkgs/' : '.']
          echo 'Building Debian repo...'
          sh '''
            git clone https://github.com/apache/couchdb-pkg
            reprepro -b couchdb-pkg/repo includedeb jessie pkgs/jessie/*deb
            reprepro -b couchdb-pkg/repo includedeb trusty pkgs/trusty/*deb
            reprepro -b couchdb-pkg/repo includedeb xenial pkgs/xenial/*deb
          '''
          echo 'Building CentOS repos...'
          sh '''
            cd pkgs/centos6 && createrepo --database .
            cd ../centos7 && rm -f js* && createrepo --database .
          '''
          echo 'rsyncing repos to couchdb-vm2...'
          sh '''
            mkdir -p $BRANCH_NAME/debian $BRANCH_NAME/el6 $BRANCH_NAME/el7
            mv couchdb-pkg/repo/pool $BRANCH_NAME/debian
            mv couchdb-pkg/repo/dists $BRANCH_NAME/debian
            mv pkgs/centos6/* $BRANCH_NAME/el6
            mv pkgs/centos7/* $BRANCH_NAME/el7
            rsync -avz --delete -e "ssh -o StrictHostKeyChecking=no -i $KEY" $BRANCH_NAME username@couchdb-vm2.apache.org:/var/www/html
          '''
          // cronjob on couchdb-vm2 cleans up old tarballs (keeps latest 10)
          echo 'rsyncing source tarball to couchdb-vm2...'
          sh 'rm -rf *.tar.gz'
          unstash 'tarball'
          sh '''
            rm -rf $BRANCH_NAME
            mkdir -p $BRANCH_NAME/source
            mv apache-couchdb-*.tar.gz $BRANCH_NAME/source
            rsync -avz -e "ssh -o StrictHostKeyChecking=no -i $KEY" $BRANCH_NAME username@couchdb-vm2.apache.org:/var/www/html
            rm -rf $BRANCH_NAME couchdb-pkg *.tar.gz
            chmod -R a+w * .
          '''
          deleteDir()
        } // withCredentials
      } // steps
    } // stage
  } // stages

  post {
    success {
      mail to: "${env.recipient}",
        subject: "[Jenkins] SUCCESS: ${currentBuild.fullDisplayName}",
        replyTo: "${env.recipient}",
        body: "Yay, we passed. ${env.BUILD_URL}"
    }
    failure {
      mail to: "${env.recipient}",
        subject: "[Jenkins] FAILURE: ${currentBuild.fullDisplayName}",
        replyTo: "${env.recipient}",
        body: "Boo, we failed. ${env.BUILD_URL}"
    }
  }
}