nginx-proxy-manager/Jenkinsfile

156 lines
6.3 KiB
Plaintext
Raw Permalink Normal View History

2018-05-03 15:43:04 +10:00
pipeline {
options {
2018-07-29 19:09:40 +10:00
buildDiscarder(logRotator(numToKeepStr: '10'))
2018-05-03 15:43:04 +10:00
disableConcurrentBuilds()
}
agent any
environment {
2018-07-29 19:09:40 +10:00
IMAGE_NAME = "nginx-proxy-manager"
BASE_IMAGE_NAME = "jc21/nginx-proxy-manager-base:v2"
2018-07-29 19:09:40 +10:00
TEMP_IMAGE_NAME = "nginx-proxy-manager-build_${BUILD_NUMBER}"
TEMP_IMAGE_NAME_ARM = "nginx-proxy-manager-arm-build_${BUILD_NUMBER}"
2018-07-29 19:09:40 +10:00
TAG_VERSION = getPackageVersion()
2018-08-24 16:59:03 +10:00
MAJOR_VERSION = "2"
2018-05-03 16:07:34 +10:00
}
2018-05-03 15:43:04 +10:00
stages {
stage('Prepare') {
2018-06-20 10:31:10 +10:00
steps {
sh 'docker pull $DOCKER_CI_TOOLS'
2018-05-03 15:43:04 +10:00
}
}
2018-11-12 21:48:12 +10:00
stage('Build Develop') {
when {
branch 'develop'
}
steps {
ansiColor('xterm') {
// Codebase
sh 'docker run --rm -v $(pwd):/app -w /app $BASE_IMAGE_NAME yarn install'
sh 'docker run --rm -v $(pwd):/app -w /app $BASE_IMAGE_NAME npm run-script build'
sh 'rm -rf node_modules'
sh 'docker run --rm -v $(pwd):/app -w /app $BASE_IMAGE_NAME yarn install --prod'
sh 'docker run --rm -v $(pwd):/data $DOCKER_CI_TOOLS node-prune'
// Docker Build
sh 'docker build --pull --no-cache --squash --compress -t $TEMP_IMAGE_NAME .'
// Private Registry
sh 'docker tag $TEMP_IMAGE_NAME $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:develop'
sh 'docker push $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:develop'
// Dockerhub
sh 'docker tag $TEMP_IMAGE_NAME docker.io/jc21/$IMAGE_NAME:develop'
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
sh "docker login -u '${duser}' -p '$dpass'"
sh 'docker push docker.io/jc21/$IMAGE_NAME:develop'
}
sh 'docker rmi $TEMP_IMAGE_NAME'
}
}
}
stage('Build Master') {
2018-07-29 19:09:40 +10:00
parallel {
stage('x86_64') {
when {
branch 'master'
}
steps {
2018-07-31 09:09:20 +10:00
ansiColor('xterm') {
// Codebase
2018-10-25 10:53:45 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app $BASE_IMAGE_NAME yarn install'
sh 'docker run --rm -v $(pwd):/app -w /app $BASE_IMAGE_NAME npm run-script build'
2018-07-31 09:09:20 +10:00
sh 'rm -rf node_modules'
2018-10-25 10:53:45 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app $BASE_IMAGE_NAME yarn install --prod'
2018-07-30 16:47:28 +10:00
sh 'docker run --rm -v $(pwd):/data $DOCKER_CI_TOOLS node-prune'
2018-07-29 19:09:40 +10:00
2018-07-31 09:09:20 +10:00
// Docker Build
sh 'docker build --pull --no-cache --squash --compress -t $TEMP_IMAGE_NAME .'
2018-07-29 19:09:40 +10:00
2018-07-31 09:09:20 +10:00
// Private Registry
2018-07-30 16:47:28 +10:00
sh 'docker tag $TEMP_IMAGE_NAME $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:$TAG_VERSION'
sh 'docker push $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:$TAG_VERSION'
2018-08-24 16:59:03 +10:00
sh 'docker tag $TEMP_IMAGE_NAME $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:$MAJOR_VERSION'
sh 'docker push $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:$MAJOR_VERSION'
2018-07-31 09:09:20 +10:00
sh 'docker tag $TEMP_IMAGE_NAME $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:latest'
sh 'docker push $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:latest'
2018-07-29 19:09:40 +10:00
2018-07-31 09:09:20 +10:00
// Dockerhub
sh 'docker tag $TEMP_IMAGE_NAME docker.io/jc21/$IMAGE_NAME:$TAG_VERSION'
2018-08-24 21:29:31 +10:00
sh 'docker tag $TEMP_IMAGE_NAME docker.io/jc21/$IMAGE_NAME:$MAJOR_VERSION'
sh 'docker tag $TEMP_IMAGE_NAME docker.io/jc21/$IMAGE_NAME:latest'
2018-07-29 19:09:40 +10:00
2018-07-31 09:09:20 +10:00
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
sh "docker login -u '${duser}' -p '$dpass'"
sh 'docker push docker.io/jc21/$IMAGE_NAME:$TAG_VERSION'
2018-08-24 21:29:31 +10:00
sh 'docker push docker.io/jc21/$IMAGE_NAME:$MAJOR_VERSION'
sh 'docker push docker.io/jc21/$IMAGE_NAME:latest'
2018-07-31 09:09:20 +10:00
}
2018-05-03 15:43:04 +10:00
2018-07-31 09:09:20 +10:00
sh 'docker rmi $TEMP_IMAGE_NAME'
}
2018-07-29 19:09:40 +10:00
}
}
stage('armhf') {
when {
branch 'master'
}
agent {
label 'armhf'
}
steps {
2018-07-31 09:09:20 +10:00
ansiColor('xterm') {
// Codebase
2018-10-25 10:53:45 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app $BASE_IMAGE_NAME-armhf yarn install'
sh 'docker run --rm -v $(pwd):/app -w /app $BASE_IMAGE_NAME-armhf npm run-script build'
2018-07-30 16:47:28 +10:00
sh 'rm -rf node_modules'
2018-10-25 10:53:45 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app $BASE_IMAGE_NAME-armhf yarn install --prod'
2018-07-29 19:09:40 +10:00
2018-07-31 09:09:20 +10:00
// Docker Build
sh 'docker build --pull --no-cache --squash --compress -t $TEMP_IMAGE_NAME_ARM -f Dockerfile.armhf .'
2018-07-29 19:09:40 +10:00
2018-07-31 09:09:20 +10:00
// Private Registry
2018-07-31 14:34:31 +10:00
sh 'docker tag $TEMP_IMAGE_NAME_ARM $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:$TAG_VERSION-armhf'
2018-07-30 16:47:28 +10:00
sh 'docker push $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:$TAG_VERSION-armhf'
2018-08-24 16:59:03 +10:00
sh 'docker tag $TEMP_IMAGE_NAME_ARM $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:$MAJOR_VERSION-armhf'
sh 'docker push $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:$MAJOR_VERSION-armhf'
2018-07-31 09:09:20 +10:00
sh 'docker tag $TEMP_IMAGE_NAME_ARM $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:latest-armhf'
sh 'docker push $DOCKER_PRIVATE_REGISTRY/$IMAGE_NAME:latest-armhf'
2018-07-29 19:09:40 +10:00
2018-07-31 09:09:20 +10:00
// Dockerhub
sh 'docker tag $TEMP_IMAGE_NAME_ARM docker.io/jc21/$IMAGE_NAME:$TAG_VERSION-armhf'
2018-08-24 21:29:31 +10:00
sh 'docker tag $TEMP_IMAGE_NAME_ARM docker.io/jc21/$IMAGE_NAME:$MAJOR_VERSION-armhf'
sh 'docker tag $TEMP_IMAGE_NAME_ARM docker.io/jc21/$IMAGE_NAME:latest-armhf'
2018-07-29 19:09:40 +10:00
2018-07-31 09:09:20 +10:00
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
sh "docker login -u '${duser}' -p '$dpass'"
sh 'docker push docker.io/jc21/$IMAGE_NAME:$TAG_VERSION-armhf'
2018-08-24 21:29:31 +10:00
sh 'docker push docker.io/jc21/$IMAGE_NAME:$MAJOR_VERSION-armhf'
sh 'docker push docker.io/jc21/$IMAGE_NAME:latest-armhf'
2018-07-31 09:09:20 +10:00
}
2018-07-29 19:09:40 +10:00
2018-07-31 09:09:20 +10:00
sh 'docker rmi $TEMP_IMAGE_NAME_ARM'
}
2018-07-29 19:09:40 +10:00
}
2018-05-03 23:46:03 +10:00
}
2018-05-03 15:43:04 +10:00
}
}
}
post {
success {
2018-07-31 09:09:20 +10:00
juxtapose event: 'success'
2018-05-18 09:33:41 +10:00
sh 'figlet "SUCCESS"'
2018-05-03 15:43:04 +10:00
}
failure {
2018-07-31 09:09:20 +10:00
juxtapose event: 'failure'
2018-05-18 09:33:41 +10:00
sh 'figlet "FAILURE"'
2018-05-03 15:43:04 +10:00
}
}
}
2018-05-03 15:56:35 +10:00
def getPackageVersion() {
2018-06-20 09:53:18 +10:00
ver = sh(script: 'docker run --rm -v $(pwd):/data $DOCKER_CI_TOOLS bash -c "cat /data/package.json|jq -r \'.version\'"', returnStdout: true)
2018-05-03 15:56:35 +10:00
return ver.trim()
}
2018-07-31 09:09:20 +10:00