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/Jenkinsfile b/Jenkinsfile index fcbfdfc..a9f4c27 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -42,20 +42,35 @@ 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' + try{ + 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}" + sh "rm -f ./debug" + handleError(message, tag) + } + stage 'Tests' try{ + sh 'sleep 300' 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) + handleError(message, tag) } + 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/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..cac9ec7 100644 --- a/tests/image.bats +++ b/tests/image.bats @@ -15,4 +15,8 @@ load ../common @test "Contains java" { run docker run -i $maintainer/$imagename which java [ "$status" -eq 0 ] +} + +@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..879fe4c --- /dev/null +++ b/tests/running.bats @@ -0,0 +1,7 @@ +#!/usr/bin/env bats + +load ../common + +@test "Has fired autorun firstrun" { + docker exec -i $imagename find /opt/log/autoexec.firstrun.log +}