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 {
2019-02-18 21:14:26 +10:00
IMAGE = "nginx-proxy-manager"
BASE_IMAGE = "jc21/nginx-proxy-manager-base"
TEMP_IMAGE = "nginx-proxy-manager-build_${BUILD_NUMBER}"
TEMP_IMAGE_ARM = "nginx-proxy-manager-arm-build_${BUILD_NUMBER}"
TEMP_IMAGE_ARM64 = "nginx-proxy-manager-arm64-build_${BUILD_NUMBER}"
TAG_VERSION = getPackageVersion()
MAJOR_VERSION = "2"
2019-02-20 14:35:10 +10:00
BRANCH_LOWER = "${BRANCH_NAME.toLowerCase()}"
2018-05-03 16:07:34 +10:00
}
2018-05-03 15:43:04 +10:00
stages {
2019-02-20 08:25:12 +10:00
stage('Build PR') {
when {
changeRequest()
}
2018-06-20 10:31:10 +10:00
steps {
2019-02-20 08:25:12 +10:00
ansiColor('xterm') {
// Codebase
2019-02-20 14:35:10 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE} yarn install'
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE} npm run-script build'
2019-02-20 08:25:12 +10:00
sh 'rm -rf node_modules'
2019-02-20 14:35:10 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE} yarn install --prod'
sh 'docker run --rm -v $(pwd):/data ${DOCKER_CI_TOOLS} node-prune'
2019-02-20 08:25:12 +10:00
// Docker Build
2019-02-20 14:35:10 +10:00
sh 'docker build --pull --no-cache --squash --compress -t ${TEMP_IMAGE} .'
2019-02-20 08:25:12 +10:00
2019-02-20 08:25:12 +10:00
// Dockerhub
sh 'docker tag ${TEMP_IMAGE} docker.io/jc21/${IMAGE}:github-${BRANCH_LOWER}'
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
sh "docker login -u '${duser}' -p '${dpass}'"
sh 'docker push docker.io/jc21/${IMAGE}:github-${BRANCH_LOWER}'
2019-02-20 08:25:12 +10:00
}
2019-02-20 14:35:10 +10:00
sh 'docker rmi ${TEMP_IMAGE}'
script {
def comment = pullRequest.comment("Docker Image for build ${BUILD_NUMBER} is available on [DockerHub](https://cloud.docker.com/repository/docker/jc21/${IMAGE}) as `jc21/${IMAGE}:github-${BRANCH_LOWER}`")
}
2019-02-20 08:25:12 +10:00
}
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
2019-02-20 14:35:10 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE} yarn install'
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE} npm run-script build'
2018-11-12 21:48:12 +10:00
sh 'rm -rf node_modules'
2019-02-20 14:35:10 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE} yarn install --prod'
sh 'docker run --rm -v $(pwd):/data ${DOCKER_CI_TOOLS} node-prune'
2018-11-12 21:48:12 +10:00
// Docker Build
2019-02-20 14:35:10 +10:00
sh 'docker build --pull --no-cache --squash --compress -t ${TEMP_IMAGE} .'
2018-11-12 21:48:12 +10:00
// Dockerhub
2019-02-20 14:35:10 +10:00
sh 'docker tag ${TEMP_IMAGE} docker.io/jc21/${IMAGE}:develop'
2018-11-12 21:48:12 +10:00
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-20 14:35:10 +10:00
sh "docker login -u '${duser}' -p '${dpass}'"
sh 'docker push docker.io/jc21/${IMAGE}:develop'
2018-11-12 21:48:12 +10:00
}
2018-12-13 12:20:41 +10:00
// Private Registry
2019-02-20 14:35:10 +10:00
sh 'docker tag ${TEMP_IMAGE} ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:develop'
2018-12-13 12:20:41 +10:00
withCredentials([usernamePassword(credentialsId: 'jc21-private-registry', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-20 14:35:10 +10:00
sh "docker login -u '${duser}' -p '${dpass}' ${DOCKER_PRIVATE_REGISTRY}"
sh 'docker push ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:develop'
2018-12-13 12:20:41 +10:00
}
2019-02-20 14:35:10 +10:00
sh 'docker rmi ${TEMP_IMAGE}'
2018-11-12 21:48:12 +10:00
}
}
}
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
2019-02-20 14:35:10 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE} yarn install'
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE} npm run-script build'
2018-07-31 09:09:20 +10:00
sh 'rm -rf node_modules'
2019-02-20 14:35:10 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE} yarn install --prod'
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
2019-02-20 14:35:10 +10:00
sh 'docker build --pull --no-cache --squash --compress -t ${TEMP_IMAGE} .'
2018-07-29 19:09:40 +10:00
2018-07-31 09:09:20 +10:00
// Dockerhub
2019-02-20 14:35:10 +10:00
sh 'docker tag ${TEMP_IMAGE} docker.io/jc21/${IMAGE}:${TAG_VERSION}'
sh 'docker tag ${TEMP_IMAGE} docker.io/jc21/${IMAGE}:${MAJOR_VERSION}'
sh 'docker tag ${TEMP_IMAGE} docker.io/jc21/${IMAGE}: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')]) {
2019-02-20 14:35:10 +10:00
sh "docker login -u '${duser}' -p '${dpass}'"
sh 'docker push docker.io/jc21/${IMAGE}:${TAG_VERSION}'
sh 'docker push docker.io/jc21/${IMAGE}:${MAJOR_VERSION}'
sh 'docker push docker.io/jc21/${IMAGE}:latest'
2018-07-31 09:09:20 +10:00
}
2018-05-03 15:43:04 +10:00
2018-12-13 12:20:41 +10:00
// Private Registry
2019-02-20 14:35:10 +10:00
sh 'docker tag ${TEMP_IMAGE} ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:${TAG_VERSION}'
sh 'docker tag ${TEMP_IMAGE} ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:${MAJOR_VERSION}'
sh 'docker tag ${TEMP_IMAGE} ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:latest'
2018-12-13 12:20:41 +10:00
withCredentials([usernamePassword(credentialsId: 'jc21-private-registry', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-20 14:35:10 +10:00
sh "docker login -u '${duser}' -p '${dpass}' ${DOCKER_PRIVATE_REGISTRY}"
sh 'docker push ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:${TAG_VERSION}'
sh 'docker push ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:${MAJOR_VERSION}'
sh 'docker push ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:latest'
2018-12-13 12:20:41 +10:00
}
2019-02-20 14:35:10 +10:00
sh 'docker rmi ${TEMP_IMAGE}'
2018-07-31 09:09:20 +10:00
}
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
2019-02-20 14:35:10 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE}:armhf yarn install'
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE}:armhf npm run-script build'
2018-07-30 16:47:28 +10:00
sh 'rm -rf node_modules'
2019-02-20 14:35:10 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE}:armhf yarn install --prod'
2018-07-29 19:09:40 +10:00
2018-07-31 09:09:20 +10:00
// Docker Build
2019-02-20 14:35:10 +10:00
sh 'docker build --pull --no-cache --squash --compress -t ${TEMP_IMAGE_ARM} -f Dockerfile.armhf .'
2018-07-29 19:09:40 +10:00
2018-07-31 09:09:20 +10:00
// Dockerhub
2019-02-20 14:35:10 +10:00
sh 'docker tag ${TEMP_IMAGE_ARM} docker.io/jc21/${IMAGE}:${TAG_VERSION}-armhf'
sh 'docker tag ${TEMP_IMAGE_ARM} docker.io/jc21/${IMAGE}:${MAJOR_VERSION}-armhf'
sh 'docker tag ${TEMP_IMAGE_ARM} docker.io/jc21/${IMAGE}: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')]) {
2019-02-20 14:35:10 +10:00
sh "docker login -u '${duser}' -p '${dpass}'"
sh 'docker push docker.io/jc21/${IMAGE}:${TAG_VERSION}-armhf'
sh 'docker push docker.io/jc21/${IMAGE}:${MAJOR_VERSION}-armhf'
sh 'docker push docker.io/jc21/${IMAGE}:latest-armhf'
2018-07-31 09:09:20 +10:00
}
2018-07-29 19:09:40 +10:00
2018-12-13 12:20:41 +10:00
// Private Registry
2019-02-20 14:35:10 +10:00
sh 'docker tag ${TEMP_IMAGE_ARM} ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:${TAG_VERSION}-armhf'
sh 'docker tag ${TEMP_IMAGE_ARM} ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:${MAJOR_VERSION}-armhf'
sh 'docker tag ${TEMP_IMAGE_ARM} ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:latest-armhf'
2018-12-13 12:20:41 +10:00
withCredentials([usernamePassword(credentialsId: 'jc21-private-registry', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-20 14:35:10 +10:00
sh "docker login -u '${duser}' -p '${dpass}' ${DOCKER_PRIVATE_REGISTRY}"
sh 'docker push ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:${TAG_VERSION}-armhf'
sh 'docker push ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:${MAJOR_VERSION}-armhf'
sh 'docker push ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:latest-armhf'
2018-12-13 12:20:41 +10:00
}
2019-02-20 14:35:10 +10:00
sh 'docker rmi ${TEMP_IMAGE_ARM}'
2018-07-31 09:09:20 +10:00
}
2018-07-29 19:09:40 +10:00
}
2018-05-03 23:46:03 +10:00
}
2019-02-18 21:12:41 +10:00
stage('arm64') {
when {
branch 'master'
}
agent {
label 'arm64'
}
steps {
ansiColor('xterm') {
// Codebase
2019-02-20 14:35:10 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE}:arm64 yarn install'
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE}:arm64 npm run-script build'
2019-02-18 21:14:26 +10:00
sh 'sudo rm -rf node_modules'
2019-02-20 14:35:10 +10:00
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE}:arm64 yarn install --prod'
2019-02-18 21:12:41 +10:00
// Docker Build
2019-02-20 14:35:10 +10:00
sh 'docker build --pull --no-cache --squash --compress -t ${TEMP_IMAGE_ARM64} -f Dockerfile.arm64 .'
2019-02-18 21:12:41 +10:00
// Dockerhub
2019-02-20 14:35:10 +10:00
sh 'docker tag ${TEMP_IMAGE_ARM64} docker.io/jc21/${IMAGE}:${TAG_VERSION}-arm64'
sh 'docker tag ${TEMP_IMAGE_ARM64} docker.io/jc21/${IMAGE}:${MAJOR_VERSION}-arm64'
sh 'docker tag ${TEMP_IMAGE_ARM64} docker.io/jc21/${IMAGE}:latest-arm64'
2019-02-18 21:12:41 +10:00
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-20 14:35:10 +10:00
sh "docker login -u '${duser}' -p '${dpass}'"
sh 'docker push docker.io/jc21/${IMAGE}:${TAG_VERSION}-arm64'
sh 'docker push docker.io/jc21/${IMAGE}:${MAJOR_VERSION}-arm64'
sh 'docker push docker.io/jc21/${IMAGE}:latest-arm64'
2019-02-18 21:12:41 +10:00
}
// Private Registry
2019-02-20 14:35:10 +10:00
sh 'docker tag ${TEMP_IMAGE_ARM64} ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:${TAG_VERSION}-arm64'
sh 'docker tag ${TEMP_IMAGE_ARM64} ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:${MAJOR_VERSION}-arm64'
sh 'docker tag ${TEMP_IMAGE_ARM64} ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:latest-arm64'
2019-02-18 21:12:41 +10:00
withCredentials([usernamePassword(credentialsId: 'jc21-private-registry', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-20 14:35:10 +10:00
sh "docker login -u '${duser}' -p '${dpass}' ${DOCKER_PRIVATE_REGISTRY}"
sh 'docker push ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:${TAG_VERSION}-arm64'
sh 'docker push ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:${MAJOR_VERSION}-arm64'
sh 'docker push ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:latest-arm64'
2019-02-18 21:12:41 +10:00
}
2019-02-20 14:35:10 +10:00
sh 'docker rmi ${TEMP_IMAGE_ARM64}'
2019-02-18 21:14:26 +10:00
// Hack to clean up ec2 instance for next build
sh 'sudo chown -R ec2-user:ec2-user *'
2019-02-18 21:12:41 +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() {
2019-02-20 14:35:10 +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