2018-05-03 01:43:04 -04:00
pipeline {
options {
2018-07-29 05:09:40 -04:00
buildDiscarder(logRotator(numToKeepStr: '10'))
2018-05-03 01:43:04 -04:00
disableConcurrentBuilds()
}
agent any
environment {
2019-02-18 06:14:26 -05: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-19 23:35:10 -05:00
BRANCH_LOWER = "${BRANCH_NAME.toLowerCase()}"
2018-05-03 02:07:34 -04:00
}
2018-05-03 01:43:04 -04:00
stages {
2019-02-19 17:25:12 -05:00
stage('Build PR') {
when {
changeRequest()
}
2018-06-19 20:31:10 -04:00
steps {
2019-02-19 17:25:12 -05:00
ansiColor('xterm') {
// Codebase
2019-02-19 23:35:10 -05: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-19 17:25:12 -05:00
sh 'rm -rf node_modules'
2019-02-19 23:35:10 -05: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-19 17:25:12 -05:00
// Docker Build
2019-02-19 23:35:10 -05:00
sh 'docker build --pull --no-cache --squash --compress -t ${TEMP_IMAGE} .'
2019-02-19 17:25:12 -05:00
2019-02-19 17:25:12 -05: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-19 17:25:12 -05:00
}
2019-02-19 23:35:10 -05: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-19 17:25:12 -05:00
}
2018-05-03 01:43:04 -04:00
}
}
2018-11-12 06:48:12 -05:00
stage('Build Develop') {
when {
branch 'develop'
}
steps {
ansiColor('xterm') {
// Codebase
2019-02-19 23:35:10 -05: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 06:48:12 -05:00
sh 'rm -rf node_modules'
2019-02-19 23:35:10 -05: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 06:48:12 -05:00
// Docker Build
2019-02-19 23:35:10 -05:00
sh 'docker build --pull --no-cache --squash --compress -t ${TEMP_IMAGE} .'
2018-11-12 06:48:12 -05:00
// Dockerhub
2019-02-19 23:35:10 -05:00
sh 'docker tag ${TEMP_IMAGE} docker.io/jc21/${IMAGE}:develop'
2018-11-12 06:48:12 -05:00
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-19 23:35:10 -05:00
sh "docker login -u '${duser}' -p '${dpass}'"
sh 'docker push docker.io/jc21/${IMAGE}:develop'
2018-11-12 06:48:12 -05:00
}
2018-12-12 21:20:41 -05:00
// Private Registry
2019-02-19 23:35:10 -05:00
sh 'docker tag ${TEMP_IMAGE} ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:develop'
2018-12-12 21:20:41 -05:00
withCredentials([usernamePassword(credentialsId: 'jc21-private-registry', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-19 23:35:10 -05:00
sh "docker login -u '${duser}' -p '${dpass}' ${DOCKER_PRIVATE_REGISTRY}"
sh 'docker push ${DOCKER_PRIVATE_REGISTRY}/${IMAGE}:develop'
2018-12-12 21:20:41 -05:00
}
2019-02-19 23:35:10 -05:00
sh 'docker rmi ${TEMP_IMAGE}'
2018-11-12 06:48:12 -05:00
}
}
}
stage('Build Master') {
2019-03-01 05:12:49 -05:00
when {
branch 'master'
}
2018-07-29 05:09:40 -04:00
parallel {
stage('x86_64') {
steps {
2018-07-30 19:09:20 -04:00
ansiColor('xterm') {
// Codebase
2019-02-19 23:35:10 -05: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-30 19:09:20 -04:00
sh 'rm -rf node_modules'
2019-02-19 23:35:10 -05: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 05:09:40 -04:00
2018-07-30 19:09:20 -04:00
// Docker Build
2019-02-19 23:35:10 -05:00
sh 'docker build --pull --no-cache --squash --compress -t ${TEMP_IMAGE} .'
2018-07-29 05:09:40 -04:00
2018-07-30 19:09:20 -04:00
// Dockerhub
2019-02-19 23:35:10 -05: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 05:09:40 -04:00
2018-07-30 19:09:20 -04:00
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-19 23:35:10 -05: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-30 19:09:20 -04:00
}
2018-05-03 01:43:04 -04:00
2018-12-12 21:20:41 -05:00
// Private Registry
2019-02-19 23:35:10 -05: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-12 21:20:41 -05:00
withCredentials([usernamePassword(credentialsId: 'jc21-private-registry', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-19 23:35:10 -05: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-12 21:20:41 -05:00
}
2019-02-19 23:35:10 -05:00
sh 'docker rmi ${TEMP_IMAGE}'
2018-07-30 19:09:20 -04:00
}
2018-07-29 05:09:40 -04:00
}
}
stage('armhf') {
agent {
label 'armhf'
}
steps {
2018-07-30 19:09:20 -04:00
ansiColor('xterm') {
// Codebase
2019-02-19 23:35:10 -05: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 02:47:28 -04:00
sh 'rm -rf node_modules'
2019-02-19 23:35:10 -05:00
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE}:armhf yarn install --prod'
2018-07-29 05:09:40 -04:00
2018-07-30 19:09:20 -04:00
// Docker Build
2019-02-19 23:35:10 -05:00
sh 'docker build --pull --no-cache --squash --compress -t ${TEMP_IMAGE_ARM} -f Dockerfile.armhf .'
2018-07-29 05:09:40 -04:00
2018-07-30 19:09:20 -04:00
// Dockerhub
2019-02-19 23:35:10 -05: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 05:09:40 -04:00
2018-07-30 19:09:20 -04:00
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-19 23:35:10 -05: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-30 19:09:20 -04:00
}
2018-07-29 05:09:40 -04:00
2018-12-12 21:20:41 -05:00
// Private Registry
2019-02-19 23:35:10 -05: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-12 21:20:41 -05:00
withCredentials([usernamePassword(credentialsId: 'jc21-private-registry', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-19 23:35:10 -05: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-12 21:20:41 -05:00
}
2019-02-19 23:35:10 -05:00
sh 'docker rmi ${TEMP_IMAGE_ARM}'
2018-07-30 19:09:20 -04:00
}
2018-07-29 05:09:40 -04:00
}
2018-05-03 09:46:03 -04:00
}
2019-02-18 06:12:41 -05:00
stage('arm64') {
agent {
label 'arm64'
}
steps {
ansiColor('xterm') {
// Codebase
2019-02-19 23:35:10 -05: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 06:14:26 -05:00
sh 'sudo rm -rf node_modules'
2019-02-19 23:35:10 -05:00
sh 'docker run --rm -v $(pwd):/app -w /app ${BASE_IMAGE}:arm64 yarn install --prod'
2019-02-18 06:12:41 -05:00
// Docker Build
2019-02-19 23:35:10 -05:00
sh 'docker build --pull --no-cache --squash --compress -t ${TEMP_IMAGE_ARM64} -f Dockerfile.arm64 .'
2019-02-18 06:12:41 -05:00
// Dockerhub
2019-02-19 23:35:10 -05: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 06:12:41 -05:00
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-19 23:35:10 -05: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 06:12:41 -05:00
}
// Private Registry
2019-02-19 23:35:10 -05: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 06:12:41 -05:00
withCredentials([usernamePassword(credentialsId: 'jc21-private-registry', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
2019-02-19 23:35:10 -05: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 06:12:41 -05:00
}
2019-02-19 23:35:10 -05:00
sh 'docker rmi ${TEMP_IMAGE_ARM64}'
2019-02-18 06:14:26 -05:00
// Hack to clean up ec2 instance for next build
2019-03-04 17:25:12 -05:00
sh 'sudo chown -R ec2-user:ec2-user * || echo "Skipping ec2 ownership"'
2019-02-18 06:12:41 -05:00
}
}
}
2018-05-03 01:43:04 -04:00
}
}
}
post {
success {
2018-07-30 19:09:20 -04:00
juxtapose event: 'success'
2018-05-17 19:33:41 -04:00
sh 'figlet "SUCCESS"'
2018-05-03 01:43:04 -04:00
}
failure {
2018-07-30 19:09:20 -04:00
juxtapose event: 'failure'
2018-05-17 19:33:41 -04:00
sh 'figlet "FAILURE"'
2018-05-03 01:43:04 -04:00
}
}
}
2018-05-03 01:56:35 -04:00
def getPackageVersion() {
2019-02-19 23:35:10 -05: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 01:56:35 -04:00
return ver.trim()
}
2018-07-30 19:09:20 -04:00