From 7de06ccc74f18e2044ff6737744e6db481a7ddae Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Sat, 6 Oct 2018 09:14:59 +0200 Subject: [PATCH] Apply the latest version of build scripts (copied from master to this branch) --- Dockerfile | 6 +++--- Jenkinsfile | 13 ++++++++----- build.sh | 31 +++++++++++++++++++++++++------ common.bash | 2 +- download-midpoint | 19 ++++++++++++++----- jenkins-rebuild.sh | 19 ------------------- tests/main.bats | 4 ++-- 7 files changed, 53 insertions(+), 41 deletions(-) delete mode 100755 jenkins-rebuild.sh diff --git a/Dockerfile b/Dockerfile index f1476a5..7a76f7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # -# Building assumes midpoint-3.9-SNAPSHOT-dist.tar.gz is present in the current directory. +# Building assumes midpoint-dist.tar.gz is present in the current directory. # FROM tier/shibboleth_sp @@ -50,7 +50,7 @@ RUN cp /dev/null /etc/httpd/conf.d/ssl.conf \ # Build arguments ARG MP_VERSION=3.9-SNAPSHOT -ARG MP_DIST_FILE=midpoint-${MP_VERSION}-dist.tar.gz +ARG MP_DIST_FILE=midpoint-dist.tar.gz ENV MP_DIR /opt/midpoint @@ -60,7 +60,7 @@ COPY ${MP_DIST_FILE} ${MP_DIR} COPY container_files/mp-dir/ ${MP_DIR}/ RUN echo 'Extracting midPoint archive...' \ - && tar xzf ${MP_DIR}/midpoint-${MP_VERSION}-dist.tar.gz -C ${MP_DIR} --strip-components=1 + && tar xzf ${MP_DIR}/${MP_DIST_FILE} -C ${MP_DIR} --strip-components=1 VOLUME ${MP_DIR}/var diff --git a/Jenkinsfile b/Jenkinsfile index 5a2f10f..cef7264 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,6 +27,9 @@ pipeline { sh 'ls' sh 'mv bin/* ../bin/.' } + // Build and test scripts expect that 'tag' is present in common.bash. This is necessary for both Jenkins and standalone testing. + // We don't care if there are more 'tag' assignments there. The latest one wins. + sh "echo >> common.bash ; echo \"tag=\\\"${tag}\\\"\" >> common.bash ; echo common.bash ; cat common.bash" } } } @@ -34,8 +37,8 @@ pipeline { steps { script { try { - sh './download-midpoint 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0' - sh './jenkins-rebuild.sh 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0' // temporary + // using custom ./build.sh instead of bin/rebuild.sh because the bin/ version does not support building specific tag yet + sh './build.sh -r 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0' } catch (error) { def error_details = readFile('./debug') def message = "BUILD ERROR: There was a problem building ${imagename}:${tag}. \n\n ${error_details}" @@ -54,9 +57,9 @@ pipeline { sh 'echo Docker containers before compositions tests ; docker ps -a' // temporary sh '(cd demo/simple ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0' - sh '(cd demo/shibboleth ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0' - sh '(cd demo/postgresql ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0' - sh '(cd demo/complex ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0' + //sh '(cd demo/shibboleth ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0' + //sh '(cd demo/postgresql ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0' + //sh '(cd demo/complex ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0' } catch (error) { def error_details = readFile('./debug') def message = "BUILD ERROR: There was a problem testing ${imagename}:${tag}. \n\n ${error_details}" diff --git a/build.sh b/build.sh index c609b49..cb5d55c 100755 --- a/build.sh +++ b/build.sh @@ -1,16 +1,35 @@ #!/bin/bash cd "$(dirname "$0")" +source common.bash + SKIP_DOWNLOAD=0 -while getopts "nh?" opt; do +while getopts "nhr?" opt; do case $opt in - n) SKIP_DOWNLOAD=1 ;; - h | ?) echo "Options: -n skip download" ; exit 0 ;; - *) echo "Unknown option: $opt" ; exit 1 ;; + n) + SKIP_DOWNLOAD=1 + ;; + r) + result=$(docker ps -a | grep $maintainer/$imagename:$tag) + if [ ! -z "$result" ]; then + echo "Cleaning up $maintainer/$imagename:$tag..." + docker rm -f $(docker ps -a | grep $maintainer/$imagename:$tag | awk '{print $1}') + docker rmi -f $maintainer/$imagename:$tag + echo "Done" + fi + ;; + h | ?) + echo "Options: -n skip download" + exit 0 + ;; + *) + echo "Unknown option: $opt" + exit 1 + ;; esac done -if [ "$SKIP_DOWNLOAD" = "0" ]; then ./download-midpoint; fi -docker build --tag tier/midpoint:3.9-SNAPSHOT-stable . +if [ "$SKIP_DOWNLOAD" = "0" ]; then ./download-midpoint || exit 1; fi +docker build --tag $maintainer/$imagename:$tag --build-arg maintainer=$maintainer --build-arg imagename=$imagename . || exit 1 echo "---------------------------------------------------------------------------------------" echo "The midPoint containers were successfully built. To start them, execute the following:" echo "" diff --git a/common.bash b/common.bash index 159ddd2..3e3351b 100644 --- a/common.bash +++ b/common.bash @@ -1,3 +1,3 @@ maintainer="tier" imagename="midpoint" -version="3.9-SNAPSHOT-stable" +tag="3.9-SNAPSHOT-stable" diff --git a/download-midpoint b/download-midpoint index b00f1c1..a803f95 100755 --- a/download-midpoint +++ b/download-midpoint @@ -1,16 +1,25 @@ #!/bin/bash -dir=`dirname "$0"` -echo "Downloading midPoint 3.9-SNAPSHOT" +DIR=`dirname "$0"` +source $DIR/common.bash +if [[ -n "$1" ]]; then + MP_VERSION=$1 +else + if [[ $tag == "latest" ]]; then + MP_VERSION=3.9-SNAPSHOT + else + MP_VERSION=$tag + fi +fi +echo "Downloading midPoint $MP_VERSION" echo "-----------------------------------------" -curl --output $dir/midpoint-3.9-SNAPSHOT-dist.tar.gz "https://evolveum.com/downloads/midpoint-tier/midpoint-3.9-SNAPSHOT-stable-dist.tar.gz" +curl --output $DIR/midpoint-dist.tar.gz "https://evolveum.com/downloads/midpoint-tier/midpoint-$MP_VERSION-dist.tar.gz" echo "-----------------------------------------" echo "Checking the download..." -if tar -tf $dir/midpoint-3.9-SNAPSHOT-dist.tar.gz >/dev/null; then +if tar -tf $DIR/midpoint-dist.tar.gz >/dev/null; then echo "OK" exit 0 else echo "The file was not downloaded correctly" exit 1 fi - diff --git a/jenkins-rebuild.sh b/jenkins-rebuild.sh deleted file mode 100755 index 6e778f0..0000000 --- a/jenkins-rebuild.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# Temporary workaround for docker/util not rebuilding the specific version of the image - -source common.bash . - -# from destroy.sh (adapted) - -result=$(docker ps -a | grep $maintainer/$imagename:$version) - -if [ ! -z "$result" ]; then - docker rm -f $(docker ps -a | grep $maintainer/$imagename:$version | awk '{print $1}') - docker rmi -f $maintainer/$imagename:$version -fi - -# from build.sh (adapted) - -echo "Building new Docker image($maintainer/$imagename:$version)" -docker build --rm -t $maintainer/$imagename:$version --build-arg maintainer=$maintainer --build-arg imagename=$imagename --build-arg version=$version . diff --git a/tests/main.bats b/tests/main.bats index b262604..7d7f2c7 100755 --- a/tests/main.bats +++ b/tests/main.bats @@ -3,11 +3,11 @@ load ../common @test "010 Image is present" { - docker image inspect tier/midpoint:3.9-SNAPSHOT-stable + docker image inspect tier/midpoint:$tag } @test "020 Check basic components" { - docker run -i $maintainer/$imagename \ + docker run -i $maintainer/$imagename:$tag \ find \ /usr/local/bin/startup.sh \ /opt/midpoint/var/ \