From 09441fecfe54eb88b64d10e6a4ef2f6af697f390 Mon Sep 17 00:00:00 2001 From: rodrigo diaz Date: Mon, 20 Mar 2017 13:03:15 -0300 Subject: [PATCH 1/2] first try --- .gitignore | 9 ++++++ BINSCRIPTS.md | 41 ++++++++++++++++++++++++ Dockerfile | 4 +-- Jenkinsfile | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ common.bash | 6 ++++ 5 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 BINSCRIPTS.md create mode 100644 Jenkinsfile create mode 100644 common.bash diff --git a/.gitignore b/.gitignore index b0cd0f3..bcd1af1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,11 @@ *.rpm *.zip +bin/destroy.sh +bin/build.sh +bin/run.sh +bin/test.sh +bin/rebuild.sh +bin/install.sh +bin/start.sh +bin/rerun.sh +bin/stop.sh diff --git a/BINSCRIPTS.md b/BINSCRIPTS.md new file mode 100644 index 0000000..7818108 --- /dev/null +++ b/BINSCRIPTS.md @@ -0,0 +1,41 @@ +# util + +This repository is intended to be downloaded into a container repository during development for convenience purposes. Since the major mechanisms of developing to the Docker container construction lifecycle are identical across container images, this repository allows for consistency and additional ease of use across all container images. + +## Install + +If you are reading this file in BINSCRIPTS.md, your container project is likely to be util-enabled. + +To use these scripts yourself, issue this command: + +``` +curl "https://github.internet2.edu/raw/docker/util/master/bin/install.sh?token=AAAAE4VRBLPB8VExPHSR5nCe791IAYqaks5Xzug5wA%3D%3D" | bash +``` + +### common.bash + +The installation process will create a common.bash file. This file should be the central, canonical authority for management of environment variables. While a subprocess may override them, the files in common.bash should be treated as authoritative defaults. Processes (e.g. `docker build`, `bats`, inside `Jenkinsfile`) can read this file and process the results therein. + +You should edit this file to change the image name, and add any other helpful environment variables. + +### Jenkinsfile + +This will also install a Jenkinsfile to your repository, if it doesn't have one. This will ensure that your Jenkins pipeline can leverage these scripts in the way intended. Ensuring the commands that you issue on your laptop match the commands issued by the build pipeline is critical to ensure predictable, reliable results. + +## Use + + +### Building + +#### build.sh +`bin/build.sh ` +#### destroy.sh +#### rebuild.sh + +### Running +### rerun.sh +### run.sh + + +### Testing +#### test.sh diff --git a/Dockerfile b/Dockerfile index 2d48193..86f4177 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM tier/centos7base ARG maintainer=my -ARG imagename=shibboleth_idp +ARG imagename=shibboleth_idp_standalone ARG version=3.3.0 ENV VERSION=$version ENV IMAGENAME=$imagename @@ -9,7 +9,7 @@ ENV MAINTAINER=$maintainer ARG registry=docker.io ARG maintainer=tier -ARG imagename=shibboleth_idp +ARG imagename=shibboleth_idp_standalone ARG version=3.3.0 ARG tierversion=17020 ARG tierbuild=$tierbuild diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..c4b3931 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,88 @@ +node { + + stage 'Checkout' + + checkout scm + + stage 'Acquire util' + + sh 'mkdir -p tmp && mkdir -p bin' + dir('tmp'){ + git([ url: "https://github.internet2.edu/docker/util.git", + credentialsId: "jenkins-github-access-token" ]) + sh 'mv ./bin/* ../bin/.' + } + sh 'rm -rf tmp' + + stage 'Setting build context' + + def maintainer = maintainer() + def imagename = imagename() + def tag + + // Tag images created on master branch with 'latest' + if(env.BRANCH_NAME == "master"){ + tag = "latest" + }else{ + tag = env.BRANCH_NAME + } + + if(!imagename){ + echo "You must define an imagename in common.bash" + currentBuild.result = 'FAILURE' + } + if(maintainer){ + echo "Building ${imagename}:${tag} for ${maintainer}" + } + + stage 'Build' + try{ + sh 'bin/build.sh &> debug' + } catch(error) { + def error_details = readFile('./debug'); + def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}" + sh "rm -f ./debug" + handleError(message) + } + + stage 'Tests' + + try{ + sh 'bin/test.sh &> debug' + } catch(error) { + def error_details = readFile('./debug'); + def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}" + sh "rm -f ./debug" + handleError(message) + } + + stage 'Push' + + docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") { + def baseImg = docker.build("$maintainer/$imagename") + baseImg.push("$tag") + } + + stage 'Notify' + + slackSend color: 'good', message: "$maintainer/$imagename:$tag pushed to DockerHub" + +} + +def maintainer() { + def matcher = readFile('common.bash') =~ 'maintainer="(.+)"' + matcher ? matcher[0][1] : 'tier' +} + +def imagename() { + def matcher = readFile('common.bash') =~ 'imagename="(.+)"' + matcher ? matcher[0][1] : null +} + +def handleError(String message){ + echo "${message}" + currentBuild.setResult("FAILED") + slackSend color: 'danger', message: "${message}" + //step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'chris.bynum@levvel.io', sendToIndividuals: true]) + sh 'exit 1' +} \ No newline at end of file diff --git a/common.bash b/common.bash new file mode 100644 index 0000000..caa2ef7 --- /dev/null +++ b/common.bash @@ -0,0 +1,6 @@ +registry="docker.io" +maintainer="bigfleet" +basename="shibboleth_idp_standalone" +imagename="shibboleth_idp_standalone" +version="3.3.0" + From b8e15712ed6657edd8e6b1c6a42195693485be02 Mon Sep 17 00:00:00 2001 From: rodrigo diaz Date: Mon, 20 Mar 2017 15:16:09 -0300 Subject: [PATCH 2/2] removing test phase --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c4b3931..63eb3f9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -45,7 +45,7 @@ node { handleError(message) } - stage 'Tests' +/* stage 'Tests' try{ sh 'bin/test.sh &> debug' @@ -54,7 +54,7 @@ node { def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}" sh "rm -f ./debug" handleError(message) - } + }*/ stage 'Push'