@@ -2,7 +2,11 @@ pipeline {
2
2
agent {
3
3
label ' X86-64-MULTI'
4
4
}
5
- // Configuration for the variables used for this specific repo
5
+ // Input to determine if this is a package check
6
+ parameters {
7
+ string(defaultValue : ' false' , description : ' package check run' , name : ' PACKAGE_CHECK' )
8
+ }
9
+ // Configuraiton for the variables used for this specific repo
6
10
environment {
7
11
EXT_GIT_BRANCH = ' master'
8
12
EXT_USER = ' bookstackapp'
@@ -17,28 +21,12 @@ pipeline {
17
21
BUILDS_DISCORD = credentials(' build_webhook_url' )
18
22
GITHUB_TOKEN = credentials(' 498b4638-2d02-4ce5-832d-8a57d01d97ab' )
19
23
DIST_IMAGE = ' alpine'
20
- DIST_TAG = ' 3.8'
21
- DIST_PACKAGES = ' curl \
22
- memcached \
23
- php7-openssl \
24
- php7-pdo_mysql \
25
- php7-mbstring \
26
- php7-memcached \
27
- php7-tidy \
28
- php7-phar \
29
- php7-dom \
30
- php7-tokenizer \
31
- php7-gd \
32
- php7-mysqlnd \
33
- php7-tidy \
34
- php7-simplexml \
35
- tar'
36
24
MULTIARCH = ' true'
37
25
CI = ' true'
38
26
CI_WEB = ' true'
39
27
CI_PORT = ' 80'
40
28
CI_SSL = ' false'
41
- CI_DELAY = ' 10 '
29
+ CI_DELAY = ' 120 '
42
30
TEST_MYSQL_HOST = credentials(' mysql_test_host' )
43
31
TEST_MYSQL_PASSWORD = credentials(' mysql_test_password' )
44
32
CI_AUTH = ' user:password'
@@ -49,6 +37,7 @@ pipeline {
49
37
stage(" Set ENV Variables base" ){
50
38
steps{
51
39
script{
40
+ env. EXIT_STATUS = ' '
52
41
env. LS_RELEASE = sh(
53
42
script : ''' curl -s https://api.github.com/repos/${LS_USER}/${LS_REPO}/releases/latest | jq -r '. | .tag_name' ''' ,
54
43
returnStdout : true ). trim()
@@ -88,14 +77,21 @@ pipeline {
88
77
/* #######################
89
78
Package Version Tagging
90
79
####################### */
91
- // If this is an alpine base image determine the base package tag to use
92
- stage(" Set Package tag Alpine " ){
80
+ // Grab the current package versions in Git to determine package tag
81
+ stage(" Set Package tag" ){
93
82
steps{
94
- sh ''' docker pull alpine:${DIST_TAG}'''
95
83
script{
96
84
env. PACKAGE_TAG = sh(
97
- script : ''' docker run --rm alpine:${DIST_TAG} sh -c 'apk update --quiet\
98
- && apk info '"${DIST_PACKAGES}"' | md5sum | cut -c1-8' ''' ,
85
+ script : ''' #!/bin/bash
86
+ http_code=$(curl --write-out %{http_code} -s -o /dev/null \
87
+ https://raw.githubusercontent.com/${LS_USER}/${LS_REPO}/master/package_versions.txt)
88
+ if [[ "${http_code}" -ne 200 ]] ; then
89
+ echo none
90
+ else
91
+ curl -s \
92
+ https://raw.githubusercontent.com/${LS_USER}/${LS_REPO}/master/package_versions.txt \
93
+ | md5sum | cut -c1-8
94
+ fi''' ,
99
95
returnStdout : true ). trim()
100
96
}
101
97
}
@@ -222,99 +218,173 @@ pipeline {
222
218
}
223
219
steps {
224
220
script{
225
- env. CI_URL = ' README_UPDATE'
226
- env. RELEASE_LINK = ' README_UPDATE'
227
- currentBuild. rawBuild. result = Result . ABORTED
228
- throw new hudson.AbortException (' ABORTED_README' )
221
+ env. EXIT_STATUS = ' ABORTED'
229
222
}
230
223
}
231
224
}
232
225
/* ###############
233
226
Build Container
234
227
############### */
235
- // Build Docker container for push to LS Repo
236
- stage(' Build-Single' ) {
237
- when {
238
- environment name : ' MULTIARCH' , value : ' false'
239
- }
240
- steps {
241
- sh " docker build --no-cache -t ${ IMAGE} :${ META_TAG} \
242
- --build-arg ${ BUILD_VERSION_ARG} =${ EXT_RELEASE} --build-arg VERSION=\" ${ META_TAG} \" --build-arg BUILD_DATE=${ GITHUB_DATE} ."
243
- }
244
- }
245
- // Build MultiArch Docker containers for push to LS Repo
246
- stage(' Build-Multi' ) {
247
- when {
248
- environment name : ' MULTIARCH' , value : ' true'
249
- }
250
- parallel {
251
- stage(' Build X86' ) {
252
- steps {
253
- sh " docker build --no-cache -t ${ IMAGE} :amd64-${ META_TAG} \
254
- --build-arg ${ BUILD_VERSION_ARG} =${ EXT_RELEASE} --build-arg VERSION=\" ${ META_TAG} \" --build-arg BUILD_DATE=${ GITHUB_DATE} ."
255
- }
256
- }
257
- stage(' Build ARMHF' ) {
258
- agent {
259
- label ' ARMHF'
260
- }
261
- steps {
262
- withCredentials([
263
- [
264
- $class : ' UsernamePasswordMultiBinding' ,
265
- credentialsId : ' 3f9ba4d5-100d-45b0-a3c4-633fd6061207' ,
266
- usernameVariable : ' DOCKERUSER' ,
267
- passwordVariable : ' DOCKERPASS'
268
- ]
269
- ]) {
270
- echo ' Logging into DockerHub'
271
- sh ''' #! /bin/bash
272
- echo $DOCKERPASS | docker login -u $DOCKERUSER --password-stdin
273
- '''
274
- sh " curl https://lsio-ci.ams3.digitaloceanspaces.com/qemu-arm-static -o qemu-arm-static"
275
- sh " chmod +x qemu-*"
276
- sh " docker build --no-cache -f Dockerfile.armhf -t ${ IMAGE} :arm32v6-${ META_TAG} \
277
- --build-arg ${ BUILD_VERSION_ARG} =${ EXT_RELEASE} --build-arg VERSION=\" ${ META_TAG} \" --build-arg BUILD_DATE=${ GITHUB_DATE} ."
278
- sh " docker tag ${ IMAGE} :arm32v6-${ META_TAG} lsiodev/buildcache:arm32v6-${ COMMIT_SHA} -${ BUILD_NUMBER} "
279
- sh " docker push lsiodev/buildcache:arm32v6-${ COMMIT_SHA} -${ BUILD_NUMBER} "
280
- }
281
- }
282
- }
283
- stage(' Build ARM64' ) {
284
- agent {
285
- label ' ARM64'
286
- }
287
- steps {
288
- withCredentials([
289
- [
290
- $class : ' UsernamePasswordMultiBinding' ,
291
- credentialsId : ' 3f9ba4d5-100d-45b0-a3c4-633fd6061207' ,
292
- usernameVariable : ' DOCKERUSER' ,
293
- passwordVariable : ' DOCKERPASS'
294
- ]
295
- ]) {
296
- echo ' Logging into DockerHub'
297
- sh ''' #! /bin/bash
298
- echo $DOCKERPASS | docker login -u $DOCKERUSER --password-stdin
299
- '''
300
- sh " curl https://lsio-ci.ams3.digitaloceanspaces.com/qemu-aarch64-static -o qemu-aarch64-static"
301
- sh " chmod +x qemu-*"
302
- sh " docker build --no-cache -f Dockerfile.aarch64 -t ${ IMAGE} :arm64v8-${ META_TAG} \
303
- --build-arg ${ BUILD_VERSION_ARG} =${ EXT_RELEASE} --build-arg VERSION=\" ${ META_TAG} \" --build-arg BUILD_DATE=${ GITHUB_DATE} ."
304
- sh " docker tag ${ IMAGE} :arm64v8-${ META_TAG} lsiodev/buildcache:arm64v8-${ COMMIT_SHA} -${ BUILD_NUMBER} "
305
- sh " docker push lsiodev/buildcache:arm64v8-${ COMMIT_SHA} -${ BUILD_NUMBER} "
306
- }
307
- }
308
- }
309
- }
310
- }
228
+ // Build Docker container for push to LS Repo
229
+ stage(' Build-Single' ) {
230
+ when {
231
+ environment name : ' MULTIARCH' , value : ' false'
232
+ environment name : ' EXIT_STATUS' , value : ' '
233
+ }
234
+ steps {
235
+ sh " docker build --no-cache -t ${ IMAGE} :${ META_TAG} \
236
+ --build-arg ${ BUILD_VERSION_ARG} =${ EXT_RELEASE} --build-arg VERSION=\" ${ META_TAG} \" --build-arg BUILD_DATE=${ GITHUB_DATE} ."
237
+ }
238
+ }
239
+ // Build MultiArch Docker containers for push to LS Repo
240
+ stage(' Build-Multi' ) {
241
+ when {
242
+ environment name : ' MULTIARCH' , value : ' true'
243
+ environment name : ' EXIT_STATUS' , value : ' '
244
+ }
245
+ parallel {
246
+ stage(' Build X86' ) {
247
+ steps {
248
+ sh " docker build --no-cache -t ${ IMAGE} :amd64-${ META_TAG} \
249
+ --build-arg ${ BUILD_VERSION_ARG} =${ EXT_RELEASE} --build-arg VERSION=\" ${ META_TAG} \" --build-arg BUILD_DATE=${ GITHUB_DATE} ."
250
+ }
251
+ }
252
+ stage(' Build ARMHF' ) {
253
+ agent {
254
+ label ' ARMHF'
255
+ }
256
+ steps {
257
+ withCredentials([
258
+ [
259
+ $class : ' UsernamePasswordMultiBinding' ,
260
+ credentialsId : ' 3f9ba4d5-100d-45b0-a3c4-633fd6061207' ,
261
+ usernameVariable : ' DOCKERUSER' ,
262
+ passwordVariable : ' DOCKERPASS'
263
+ ]
264
+ ]) {
265
+ echo ' Logging into DockerHub'
266
+ sh ''' #! /bin/bash
267
+ echo $DOCKERPASS | docker login -u $DOCKERUSER --password-stdin
268
+ '''
269
+ sh " curl https://lsio-ci.ams3.digitaloceanspaces.com/qemu-arm-static -o qemu-arm-static"
270
+ sh " chmod +x qemu-*"
271
+ sh " docker build --no-cache -f Dockerfile.armhf -t ${ IMAGE} :arm32v6-${ META_TAG} \
272
+ --build-arg ${ BUILD_VERSION_ARG} =${ EXT_RELEASE} --build-arg VERSION=\" ${ META_TAG} \" --build-arg BUILD_DATE=${ GITHUB_DATE} ."
273
+ sh " docker tag ${ IMAGE} :arm32v6-${ META_TAG} lsiodev/buildcache:arm32v6-${ COMMIT_SHA} -${ BUILD_NUMBER} "
274
+ sh " docker push lsiodev/buildcache:arm32v6-${ COMMIT_SHA} -${ BUILD_NUMBER} "
275
+ }
276
+ }
277
+ }
278
+ stage(' Build ARM64' ) {
279
+ agent {
280
+ label ' ARM64'
281
+ }
282
+ steps {
283
+ withCredentials([
284
+ [
285
+ $class : ' UsernamePasswordMultiBinding' ,
286
+ credentialsId : ' 3f9ba4d5-100d-45b0-a3c4-633fd6061207' ,
287
+ usernameVariable : ' DOCKERUSER' ,
288
+ passwordVariable : ' DOCKERPASS'
289
+ ]
290
+ ]) {
291
+ echo ' Logging into DockerHub'
292
+ sh ''' #! /bin/bash
293
+ echo $DOCKERPASS | docker login -u $DOCKERUSER --password-stdin
294
+ '''
295
+ sh " curl https://lsio-ci.ams3.digitaloceanspaces.com/qemu-aarch64-static -o qemu-aarch64-static"
296
+ sh " chmod +x qemu-*"
297
+ sh " docker build --no-cache -f Dockerfile.aarch64 -t ${ IMAGE} :arm64v8-${ META_TAG} \
298
+ --build-arg ${ BUILD_VERSION_ARG} =${ EXT_RELEASE} --build-arg VERSION=\" ${ META_TAG} \" --build-arg BUILD_DATE=${ GITHUB_DATE} ."
299
+ sh " docker tag ${ IMAGE} :arm64v8-${ META_TAG} lsiodev/buildcache:arm64v8-${ COMMIT_SHA} -${ BUILD_NUMBER} "
300
+ sh " docker push lsiodev/buildcache:arm64v8-${ COMMIT_SHA} -${ BUILD_NUMBER} "
301
+ }
302
+ }
303
+ }
304
+ }
305
+ }
306
+ // Take the image we just built and dump package versions for comparison
307
+ stage(' Update-packages' ) {
308
+ when {
309
+ branch " master"
310
+ environment name : ' CHANGE_ID' , value : ' '
311
+ environment name : ' EXIT_STATUS' , value : ' '
312
+ }
313
+ steps {
314
+ sh ''' #! /bin/bash
315
+ TEMPDIR=$(mktemp -d)
316
+ if [ "${MULTIARCH}" == "true" ]; then
317
+ LOCAL_CONTAINER=${IMAGE}:amd64-${META_TAG}
318
+ else
319
+ LOCAL_CONTAINER=${IMAGE}:${META_TAG}
320
+ fi
321
+ if [ "${DIST_IMAGE}" == "alpine" ]; then
322
+ docker run --rm -v ${TEMPDIR}:/tmp ${LOCAL_CONTAINER} sh -c '\
323
+ apk info > packages && \
324
+ apk info -v > versions && \
325
+ paste -d " " packages versions > /tmp/package_versions.txt'
326
+ elif [ "${DIST_IMAGE}" == "ubuntu" ]; then
327
+ docker run --rm -v ${TEMPDIR}:/tmp ${LOCAL_CONTAINER} sh -c '\
328
+ apt -qq list --installed | awk "{print \$ 1,\$ 2}" > /tmp/package_versions.txt'
329
+ fi
330
+ if [ "$(md5sum ${TEMPDIR}/package_versions.txt | cut -c1-8 )" != "${PACKAGE_TAG}" ]; then
331
+ git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/${LS_REPO}
332
+ cp ${TEMPDIR}/package_versions.txt ${TEMPDIR}/${LS_REPO}/
333
+ cd ${TEMPDIR}/${LS_REPO}/
334
+ git --git-dir ${TEMPDIR}/${LS_REPO}/.git add package_versions.txt
335
+ git --git-dir ${TEMPDIR}/${LS_REPO}/.git commit -m 'Bot Updating Package Versions'
336
+ git --git-dir ${TEMPDIR}/${LS_REPO}/.git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
337
+ echo "true" > /tmp/packages-${COMMIT_SHA}-${BUILD_NUMBER}
338
+ else
339
+ echo "false" > /tmp/packages-${COMMIT_SHA}-${BUILD_NUMBER}
340
+ fi
341
+ rm -Rf ${TEMPDIR}'''
342
+ script{
343
+ env. PACKAGE_UPDATED = sh(
344
+ script : ''' cat /tmp/packages-${COMMIT_SHA}-${BUILD_NUMBER}''' ,
345
+ returnStdout : true ). trim()
346
+ }
347
+ }
348
+ }
349
+ // Exit the build if the package file was just updated
350
+ stage(' PACKAGE-exit' ) {
351
+ when {
352
+ branch " master"
353
+ environment name : ' CHANGE_ID' , value : ' '
354
+ environment name : ' PACKAGE_UPDATED' , value : ' true'
355
+ environment name : ' EXIT_STATUS' , value : ' '
356
+ }
357
+ steps {
358
+ script{
359
+ env. EXIT_STATUS = ' ABORTED'
360
+ }
361
+ }
362
+ }
363
+ // Exit the build if this is just a package check and there are no changes to push
364
+ stage(' PACKAGECHECK-exit' ) {
365
+ when {
366
+ branch " master"
367
+ environment name : ' CHANGE_ID' , value : ' '
368
+ environment name : ' PACKAGE_UPDATED' , value : ' false'
369
+ environment name : ' EXIT_STATUS' , value : ' '
370
+ expression {
371
+ params. PACKAGE_CHECK == ' true'
372
+ }
373
+ }
374
+ steps {
375
+ script{
376
+ env. EXIT_STATUS = ' ABORTED'
377
+ }
378
+ }
379
+ }
311
380
/* #######
312
381
Testing
313
382
####### */
314
383
// Run Container tests
315
384
stage(' Test' ) {
316
385
when {
317
386
environment name : ' CI' , value : ' true'
387
+ environment name : ' EXIT_STATUS' , value : ' '
318
388
}
319
389
steps {
320
390
withCredentials([
@@ -361,6 +431,7 @@ pipeline {
361
431
stage(' Docker-Push-Single' ) {
362
432
when {
363
433
environment name : ' MULTIARCH' , value : ' false'
434
+ environment name : ' EXIT_STATUS' , value : ' '
364
435
}
365
436
steps {
366
437
withCredentials([
@@ -385,6 +456,7 @@ pipeline {
385
456
stage(' Docker-Push-Multi' ) {
386
457
when {
387
458
environment name : ' MULTIARCH' , value : ' true'
459
+ environment name : ' EXIT_STATUS' , value : ' '
388
460
}
389
461
steps {
390
462
withCredentials([
@@ -435,6 +507,7 @@ pipeline {
435
507
env. LS_RELEASE != env. EXT_RELEASE + ' -pkg-' + env. PACKAGE_TAG + ' -ls' + env. LS_TAG_NUMBER
436
508
}
437
509
environment name : ' CHANGE_ID' , value : ' '
510
+ environment name : ' EXIT_STATUS' , value : ' '
438
511
}
439
512
steps {
440
513
echo " Pushing New tag for current commit ${ EXT_RELEASE} -pkg-${ PACKAGE_TAG} -ls${ LS_TAG_NUMBER} "
@@ -460,6 +533,7 @@ pipeline {
460
533
stage(' Sync-README' ) {
461
534
when {
462
535
environment name : ' CHANGE_ID' , value : ' '
536
+ environment name : ' EXIT_STATUS' , value : ' '
463
537
}
464
538
steps {
465
539
withCredentials([
@@ -487,15 +561,22 @@ pipeline {
487
561
Send status to Discord
488
562
###################### */
489
563
post {
490
- success {
491
- sh ''' curl -X POST --data '{"avatar_url": "https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png","embeds": [{"color": 1681177,\
492
- "description": "**Build:** '${BUILD_NUMBER}'\\ n**CI Results:** '${CI_URL}'\\ n**Status:** Success\\ n**Job:** '${RUN_DISPLAY_URL}'\\ n**Change:** '${CODE_URL}'\\ n**External Release:**: '${RELEASE_LINK}'\\ n**DockerHub:** '${DOCKERHUB_LINK}'\\ n"}],\
493
- "username": "Jenkins"}' ${BUILDS_DISCORD} '''
494
- }
495
- failure {
496
- sh ''' curl -X POST --data '{"avatar_url": "https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png","embeds": [{"color": 16711680,\
497
- "description": "**Build:** '${BUILD_NUMBER}'\\ n**CI Results:** '${CI_URL}'\\ n**Status:** failure\\ n**Job:** '${RUN_DISPLAY_URL}'\\ n**Change:** '${CODE_URL}'\\ n**External Release:**: '${RELEASE_LINK}'\\ n**DockerHub:** '${DOCKERHUB_LINK}'\\ n"}],\
498
- "username": "Jenkins"}' ${BUILDS_DISCORD} '''
564
+ always {
565
+ script{
566
+ if (env. EXIT_STATUS == " ABORTED" ){
567
+ sh ' echo "build aborted"'
568
+ }
569
+ else if (currentBuild. currentResult == " SUCCESS" ){
570
+ sh ''' curl -X POST --data '{"avatar_url": "https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png","embeds": [{"color": 1681177,\
571
+ "description": "**Build:** '${BUILD_NUMBER}'\\ n**CI Results:** '${CI_URL}'\\ n**Status:** Success\\ n**Job:** '${RUN_DISPLAY_URL}'\\ n**Change:** '${CODE_URL}'\\ n**External Release:**: '${RELEASE_LINK}'\\ n**DockerHub:** '${DOCKERHUB_LINK}'\\ n"}],\
572
+ "username": "Jenkins"}' ${BUILDS_DISCORD} '''
573
+ }
574
+ else {
575
+ sh ''' curl -X POST --data '{"avatar_url": "https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png","embeds": [{"color": 16711680,\
576
+ "description": "**Build:** '${BUILD_NUMBER}'\\ n**CI Results:** '${CI_URL}'\\ n**Status:** failure\\ n**Job:** '${RUN_DISPLAY_URL}'\\ n**Change:** '${CODE_URL}'\\ n**External Release:**: '${RELEASE_LINK}'\\ n**DockerHub:** '${DOCKERHUB_LINK}'\\ n"}],\
577
+ "username": "Jenkins"}' ${BUILDS_DISCORD} '''
578
+ }
579
+ }
499
580
}
500
581
}
501
582
}
0 commit comments