From 8a2e11cfa521700ff94544ebc9dd722bcaf1b8e3 Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Wed, 26 Sep 2018 13:50:37 +0200 Subject: [PATCH] Do first attempt at testing midPoint container --- Jenkinsfile | 7 ++----- midpoint/test.sh | 22 ++++++++++++++++++++++ midpoint/test/wait-for-start.sh | 16 ++++++++++++++++ test.sh | 10 ++++++++++ test/common.sh | 18 ++++++++++++++++++ 5 files changed, 68 insertions(+), 5 deletions(-) create mode 100755 midpoint/test.sh create mode 100755 midpoint/test/wait-for-start.sh create mode 100755 test.sh create mode 100755 test/common.sh diff --git a/Jenkinsfile b/Jenkinsfile index 9a52a9d..d646d1a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -48,12 +48,9 @@ pipeline { steps { script { sh 'midpoint/download-midpoint' - docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") { + docker.withRegistry('https://registry.hub.docker.com/', "dockerhub-$maintainer") { def baseImg = docker.build("$maintainer/$imagename", "--no-cache midpoint/midpoint-server") - // test the environment - // sh 'cd test-compose && ./compose.sh' - // bring down after testing - // sh 'cd test-compose && docker-compose down' + sh './test.sh' baseImg.push("$tag") } } diff --git a/midpoint/test.sh b/midpoint/test.sh new file mode 100755 index 0000000..96071d9 --- /dev/null +++ b/midpoint/test.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +trap 'exitcode=$? ; echo "Exiting midpoint/test.sh because of an error ($exitcode) occurred" ; exit $exitcode' ERR + +cd "$(dirname "$0")" +. ../test/common.sh + +yellow "*** Composing midPoint..." +docker-compose up --no-start +green "==> midPoint composed OK" +echo +yellow "*** Starting midPoint..." +docker-compose start +green "==> midPoint started OK" +echo +yellow "*** Waiting for midPoint to start..." +test/wait-for-start.sh +green "==> midPoint started" +echo +yellow "*** Checking health via HTTP..." +(set -o pipefail ; curl -k -f https://localhost:8443/midpoint/actuator/health | tr -d '[:space:]' | grep -q "\"status\":\"UP\"") +green "==> Health is OK" diff --git a/midpoint/test/wait-for-start.sh b/midpoint/test/wait-for-start.sh new file mode 100755 index 0000000..ddb7a92 --- /dev/null +++ b/midpoint/test/wait-for-start.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +ATTEMPT=0 +MAX_ATTEMPTS=20 +DELAY=10 + +until [[ $ATTEMPT = $MAX_ATTEMPTS ]]; do + ATTEMPT=$((ATTEMPT+1)) + echo "Waiting $DELAY seconds for midPoint to start (attempt $ATTEMPT) ..." + sleep $DELAY + docker ps + ( docker logs midpoint_midpoint-server_1 2>&1 | grep "INFO (com.evolveum.midpoint.web.boot.MidPointSpringApplication): Started MidPointSpringApplication in" ) && exit 0 +done + +echo midPoint did not start in $(( $MAX_ATTEMPTS * $DELAY )) seconds +exit 1 diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..3c34e42 --- /dev/null +++ b/test.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +. test/common.sh + +trap 'exitcode=$? ; red "Exiting test.sh because of an error ($exitcode) occurred" ; exit $exitcode' ERR +echo "**************************************************************************************" +echo "*** Testing midPoint image ***" +echo "**************************************************************************************" +echo +midpoint/test.sh diff --git a/test/common.sh b/test/common.sh new file mode 100755 index 0000000..68c5327 --- /dev/null +++ b/test/common.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +RED='\033[1;31m' +YELLOW='\033[1;33m' +GREEN='\033[1;32m' +NC='\033[0m' + +function red () { + echo -e ${RED}$*${NC} +} + +function yellow () { + echo -e ${YELLOW}$*${NC} +} + +function green () { + echo -e ${GREEN}$*${NC} +}