From 0d1ee26ed51cd75d259fc5727e6f0426e99871e5 Mon Sep 17 00:00:00 2001 From: Jim Van Fleet Date: Wed, 14 Sep 2016 10:11:49 -0400 Subject: [PATCH 1/6] One of the autoexec tests is passing --- Dockerfile | 5 +++-- container_files/autoexec/firstrun/touch.sh | 3 +++ container_files/autoexec/onbuild/touch.sh | 3 +++ tests/image.bats | 8 ++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100755 container_files/autoexec/firstrun/touch.sh create mode 100755 container_files/autoexec/onbuild/touch.sh diff --git a/Dockerfile b/Dockerfile index 079a4b1..98811cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM bigfleet/grouper +FROM tier/grouper ARG maintainer=my ARG imagename=grouper @@ -16,7 +16,8 @@ RUN rm /opt/grouper/2.3.0/grouper.apiBinary-2.3.0/conf/grouper.hibernate.propert rm /opt/grouper/2.3.0/grouper.ws-2.3.0/grouper-ws/build/dist/grouper-ws/WEB-INF/classes/grouper.hibernate.properties && \ ln -s /opt/etc/grouper.hibernate.properties /opt/grouper/2.3.0/grouper.ws-2.3.0/grouper-ws/build/dist/grouper-ws/WEB-INF/classes/grouper.hibernate.properties && \ rm /opt/grouper/2.3.0/grouper.ui-2.3.0/dist/grouper/WEB-INF/classes/grouper.hibernate.properties && \ - ln -s /opt/etc/grouper.hibernate.properties /opt/grouper/2.3.0/grouper.ui-2.3.0/dist/grouper/WEB-INF/classes/grouper.hibernate.properties + ln -s /opt/etc/grouper.hibernate.properties /opt/grouper/2.3.0/grouper.ui-2.3.0/dist/grouper/WEB-INF/classes/grouper.hibernate.properties && \ + /opt/autoexec/bin/onbuild.sh VOLUME /opt/grouper/$version/apache-tomcat-$TOMCAT_VERSION/logs VOLUME /etc/httpd/logs diff --git a/container_files/autoexec/firstrun/touch.sh b/container_files/autoexec/firstrun/touch.sh new file mode 100755 index 0000000..6d67992 --- /dev/null +++ b/container_files/autoexec/firstrun/touch.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +touch /opt/log/firstrun.log \ No newline at end of file diff --git a/container_files/autoexec/onbuild/touch.sh b/container_files/autoexec/onbuild/touch.sh new file mode 100755 index 0000000..b35fe31 --- /dev/null +++ b/container_files/autoexec/onbuild/touch.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +touch /opt/log/onbuild.log \ No newline at end of file diff --git a/tests/image.bats b/tests/image.bats index f64d3b6..4253666 100644 --- a/tests/image.bats +++ b/tests/image.bats @@ -15,4 +15,12 @@ load ../common @test "Contains java" { run docker run -i $maintainer/$imagename which java [ "$status" -eq 0 ] +} + +@test "Has fired autorun firstrun" { + docker run -i $maintainer/$imagename find /opt/log/firstrun.log +} + +@test "Has fired autorun onbuild" { + docker run -i $maintainer/$imagename find /opt/log/autoexec.build.log } \ No newline at end of file From 8deb6101fa0bcbe508471990196f04503ae0ce08 Mon Sep 17 00:00:00 2001 From: Jim Van Fleet Date: Wed, 14 Sep 2016 11:25:31 -0400 Subject: [PATCH 2/6] Fine-tuning test, and adding support for Jenkinsfile --- Jenkinsfile | 32 +++++++++++++++++++++++++++++++- bin/ci-run.sh | 8 ++++++++ bin/ci-stop.sh | 11 +++++++++++ bin/compose.sh | 4 ++++ bin/decompose.sh | 4 ++++ bin/download.sh | 8 ++++++++ bin/prune.sh | 7 +++++++ bin/recompose.sh | 3 +++ tests/image.bats | 4 ---- tests/running.bats | 7 +++++++ 10 files changed, 83 insertions(+), 5 deletions(-) create mode 100755 bin/ci-run.sh create mode 100755 bin/ci-stop.sh create mode 100755 bin/compose.sh create mode 100755 bin/decompose.sh create mode 100755 bin/download.sh create mode 100755 bin/prune.sh create mode 100755 bin/recompose.sh create mode 100644 tests/running.bats diff --git a/Jenkinsfile b/Jenkinsfile index fcbfdfc..849d18d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -45,6 +45,17 @@ node('docker') { handleError(message) } + stage 'Compose' + try{ + sh 'docker rm mariadb' + sh 'bin/compose.sh &> debug' + } catch(error) { + def error_details = readFile('./debug'); + def message = "BUILD ERROR: There was a problem composing Shibboleth appliance (${tag}). \n\n ${error_details}" + sh "rm -f ./debug" + handleError(message, tag) + } + stage 'Tests' try{ @@ -56,6 +67,10 @@ node('docker') { handleError(message) } + stage 'Clean Up' + + cleanup(tag) + stage 'Notify' slackSend color: 'good', message: "grouper-appliance (${tag}) passes test battery" @@ -72,10 +87,25 @@ def imagename() { matcher ? matcher[0][1] : null } -def handleError(String message){ +def handleError(String message, String tag, Boolean doCleanup = true){ echo "${message}" currentBuild.setResult("FAILED") slackSend color: 'danger', message: "${message}" //step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'chris.bynum@levvel.io', sendToIndividuals: true]) + if (doCleanup) { + cleanup(tag) + } sh 'exit 1' +} + +def cleanup(String tag) { + try{ + sh 'bin/decompose.sh &> debug' + sh 'bin/prune.sh &> debug' + } catch(error) { + def error_details = readFile('./debug'); + def message = "BUILD ERROR: There was a problem cleaning up Shibboleth appliance :${tag}. \n\n ${error_details}" + sh "rm -f ./debug" + handleError(message, tag, false) + } } \ No newline at end of file diff --git a/bin/ci-run.sh b/bin/ci-run.sh new file mode 100755 index 0000000..44c5a23 --- /dev/null +++ b/bin/ci-run.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# This file will run a container in the background +source common.bash . + +docker run -d --name=$imagename -v $PWD/logs/tomcat:/usr/local/tomcat/logs:rw \ + -v $PWD/logs/shibboleth_idp:/opt/shibboleth/shibboleth-identity-provider-$version/logs:rw \ + -p 8080:8080 $maintainer/$imagename \ No newline at end of file diff --git a/bin/ci-stop.sh b/bin/ci-stop.sh new file mode 100755 index 0000000..79d421c --- /dev/null +++ b/bin/ci-stop.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# This file will run a container in the background +source common.bash . + +rm logs/tomcat/* +rm logs/shibboleth_idp/* +echo "Cleaning up Docker image($maintainer/$imagename)" +docker stop $imagename >> /dev/null +docker rm $imagename +exit 0 \ No newline at end of file diff --git a/bin/compose.sh b/bin/compose.sh new file mode 100755 index 0000000..edb2141 --- /dev/null +++ b/bin/compose.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "Composing" +docker-compose up -d \ No newline at end of file diff --git a/bin/decompose.sh b/bin/decompose.sh new file mode 100755 index 0000000..754e6a4 --- /dev/null +++ b/bin/decompose.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "Decomposing" +docker-compose stop \ No newline at end of file diff --git a/bin/download.sh b/bin/download.sh new file mode 100755 index 0000000..b726b7a --- /dev/null +++ b/bin/download.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +source common.bash . + +rm -rf root +if [ ! -f shibboleth-identity-provider.tar.gz ]; then + git clone git@github.internet2.edu:docker/shib-idp-conftree.git --depth 1 --branch test root +fi \ No newline at end of file diff --git a/bin/prune.sh b/bin/prune.sh new file mode 100755 index 0000000..2efa97c --- /dev/null +++ b/bin/prune.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +result=$(docker volume ls -qf dangling=true) + +if [ ! -z "$result" ]; then + docker volume rm $result +fi diff --git a/bin/recompose.sh b/bin/recompose.sh new file mode 100755 index 0000000..6749985 --- /dev/null +++ b/bin/recompose.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +source bin/decompose.sh && source bin/destroy.sh && source bin/prune.sh && source bin/build.sh && source bin/compose.sh \ No newline at end of file diff --git a/tests/image.bats b/tests/image.bats index 4253666..cac9ec7 100644 --- a/tests/image.bats +++ b/tests/image.bats @@ -17,10 +17,6 @@ load ../common [ "$status" -eq 0 ] } -@test "Has fired autorun firstrun" { - docker run -i $maintainer/$imagename find /opt/log/firstrun.log -} - @test "Has fired autorun onbuild" { docker run -i $maintainer/$imagename find /opt/log/autoexec.build.log } \ No newline at end of file diff --git a/tests/running.bats b/tests/running.bats new file mode 100644 index 0000000..b9da100 --- /dev/null +++ b/tests/running.bats @@ -0,0 +1,7 @@ +#!/usr/bin/env bats + +load ../common + +@test "Has fired autorun firstrun" { + docker run -i $maintainer/$imagename find /opt/log/autoexec.firstrun.log +} From b1ae75b08db237c258f81057f9bc852cbaec92b9 Mon Sep 17 00:00:00 2001 From: Jim Van Fleet Date: Wed, 14 Sep 2016 11:46:29 -0400 Subject: [PATCH 3/6] Better test invocation, needs to hit the composed container that's now started --- tests/running.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/running.bats b/tests/running.bats index b9da100..879fe4c 100644 --- a/tests/running.bats +++ b/tests/running.bats @@ -3,5 +3,5 @@ load ../common @test "Has fired autorun firstrun" { - docker run -i $maintainer/$imagename find /opt/log/autoexec.firstrun.log + docker exec -i $imagename find /opt/log/autoexec.firstrun.log } From 96950ce09182c55d5283029b9269569c3397941b Mon Sep 17 00:00:00 2001 From: Jim Van Fleet Date: Wed, 14 Sep 2016 12:06:18 -0400 Subject: [PATCH 4/6] Further backporting Jenkinsfile advancement of handleError --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 849d18d..d5066f1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -42,7 +42,7 @@ node('docker') { 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) + handleError(message, tag) } stage 'Compose' @@ -64,7 +64,7 @@ node('docker') { 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) + handleError(message, tag) } stage 'Clean Up' From 92727ff3f514060c474139fbe006b2aba6e5da97 Mon Sep 17 00:00:00 2001 From: Jim Van Fleet Date: Wed, 14 Sep 2016 12:15:09 -0400 Subject: [PATCH 5/6] Still trying to get runthrough flat --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d5066f1..44e2444 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -47,8 +47,7 @@ node('docker') { stage 'Compose' try{ - sh 'docker rm mariadb' - sh 'bin/compose.sh &> debug' + sh 'bin/recompose.sh &> debug' } catch(error) { def error_details = readFile('./debug'); def message = "BUILD ERROR: There was a problem composing Shibboleth appliance (${tag}). \n\n ${error_details}" From e819edb60277763f60b8a9d2a842f42bfc5c2a9e Mon Sep 17 00:00:00 2001 From: Jim Van Fleet Date: Wed, 14 Sep 2016 12:21:36 -0400 Subject: [PATCH 6/6] Composing takes time --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 44e2444..a9f4c27 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,6 +58,7 @@ node('docker') { stage 'Tests' try{ + sh 'sleep 300' sh 'bin/test.sh &> debug' } catch(error) { def error_details = readFile('./debug');