Skip to content

Commit

Permalink
Merge pull request #4 from docker/autorun-testing
Browse files Browse the repository at this point in the history
Autorun testing
  • Loading branch information
Jim Van Fleet committed Sep 14, 2016
2 parents 0808208 + e819edb commit 57d415d
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM bigfleet/grouper
FROM tier/grouper

ARG maintainer=my
ARG imagename=grouper
Expand All @@ -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
36 changes: 33 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
}
8 changes: 8 additions & 0 deletions bin/ci-run.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions bin/ci-stop.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions bin/compose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "Composing"
docker-compose up -d
4 changes: 4 additions & 0 deletions bin/decompose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "Decomposing"
docker-compose stop
8 changes: 8 additions & 0 deletions bin/download.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions bin/prune.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

result=$(docker volume ls -qf dangling=true)

if [ ! -z "$result" ]; then
docker volume rm $result
fi
3 changes: 3 additions & 0 deletions bin/recompose.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions container_files/autoexec/firstrun/touch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

touch /opt/log/firstrun.log
3 changes: 3 additions & 0 deletions container_files/autoexec/onbuild/touch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

touch /opt/log/onbuild.log
4 changes: 4 additions & 0 deletions tests/image.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 7 additions & 0 deletions tests/running.bats
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 57d415d

Please sign in to comment.