From 56336a03a589615006e0fabc25c202667c194990 Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Fri, 27 Oct 2017 12:04:45 +0300 Subject: [PATCH] feat: build script improvements. --- .gitmodules | 2 +- bin/build.sh | 196 ++++++++++++++++++------- images/maven-with-repo/Dockerfile | 15 ++ images/openshift-jenkins | 2 +- plugins/durable-task-plugin | 2 +- plugins/kubernetes-pipeline-plugin | 2 +- plugins/kubernetes-plugin | 2 +- plugins/workflow-cps-global-lib-plugin | 2 +- 8 files changed, 160 insertions(+), 63 deletions(-) create mode 100644 images/maven-with-repo/Dockerfile diff --git a/.gitmodules b/.gitmodules index 06dbdbd..ccaba1b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -24,4 +24,4 @@ url = https://github.com/syndesisio/syndesis-system-tests.git [submodule "images/nsswrapper-glibc"] path = images/nsswrapper-glibc - url = git@github.com:syndesisio/nsswrapper-glibc.git + url = https://github.com/syndesisio/nsswrapper-glibc.git diff --git a/bin/build.sh b/bin/build.sh index f8478c6..26c3ab2 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -1,4 +1,4 @@ - #!/bin/bash +#!/bin/bash # Exit if any error occurs set -e @@ -19,11 +19,11 @@ function displayHelp() { # # Aliases pushd () { - command pushd "$@" > /dev/null + command pushd "$@" > /dev/null } popd () { - command popd "$@" > /dev/null + command popd "$@" > /dev/null } # @@ -73,122 +73,204 @@ function copyplugin() { fi } +# +# Maven build +function mvnbuild() { + echo "Getting project version from: $(pwd)" + version=$(pomversion) + echo "Current project version: $version" + newversion=${version/SNAPSHOT/"syndesis-$VERSION"} + echo "Changing project version: $newversion" + mvn versions:set -DnewVersion=$newversion + echo "Performing maven build: mvn clean install $MAVEN_OPTS" + mvn clean install $MAVEN_OPTS + echo "Changing project version: $version" + mvn versions:set -DnewVersion=$version +} + +fromimagename() { + cat $1 | grep FROM | awk -F "[: ]" '{print $2}' +} + +# +# Perform a dockerbuild via build config. function dockerbuild() { DOCKERFILE=$1 IMAGESTREAM=$2 + BUILDER_IMAGESTREAM=$3 + BUILDER_TAG=${4:-"latest"} + BC_OPTS="" + if [ -n "$BUILDER_IMAGESTREAM" ];then + echo "Using image stream: $BUILDER_IMAGESTREAM" + BC_OPTS=" --image-stream=$BUILDER_IMAGESTREAM:${BUILDER_TAG}" + fi + + if [ -n "$BUILDER_TAG" ]; then + echo "Using image stream tag: $BUILDER_TAG" + cp $DOCKERFILE ${DOCKERFILE}.original + from=$(fromimagename $DOCKERFILE) + echo "Replace image FROM: $from with $from:$BUILDER_TAG" + sed -E "s|FROM ([a-zA-Z0-9\.\/:]+)|FROM ${from}:${BUILDER_TAG}|g" $DOCKERFILE > ${DOCKERFILE}.${BUILDER_TAG} + cp ${DOCKERFILE}.${BUILDER_TAG} $DOCKERFILE + fi + NAME="$ARTIFACT_PREFIX$IMAGESTREAM" BUILD_CONFIG=`oc get bc $OC_OPTS | grep $NAME || echo ""` + if [ -n "$BUILD_CONFIG" ]; then + # Build config contains a copy of the dockerfile, so we need to always recreate it. + echo "Removing Build Conifg: $NAME" + oc delete bc $NAME $OC_OPTS + fi + echo "Creating Build Conifg: $NAME" + cat $DOCKERFILE | oc new-build --name=$NAME --dockerfile=- --to=syndesis/$NAME:$VERSION --strategy=docker $BC_OPTS $OC_OPTS || true + + # Verify that the build config has been created. + BUILD_CONFIG=`oc get bc $OC_OPTS | grep $NAME || echo ""` if [ -z "$BUILD_CONFIG" ]; then - echo "Creating Build Conifg: $NAME" - cat $DOCKERFILE | oc new-build --name=$NAME --dockerfile=- --to=syndesis/$NAME:$VERSION --strategy=docker $OC_OPTS || true - - # Verify that the build config has been created. - BUILD_CONFIG=`oc get bc $OC_OPTS | grep $NAME || echo ""` - if [ -z "$BUILD_CONFIG" ]; then - echo "Failed to create Build Config: $NAME" - exit 1 - fi + echo "Failed to create Build Config: $NAME" + exit 1 + fi + + if [ -f /tmp/archive.tar.gz ]; then + rm /tmp/archive.tar.gz fi - tar -cvf archive.tar . - oc start-build $NAME $OC_OPTS --from-archive=archive.tar --follow + tar -czvf /tmp/archive.tar.gz . --exclude='.git' + oc start-build $NAME --from-archive=/tmp/archive.tar.gz $OC_OPTS --follow + rm /tmp/archive.tar.gz } +# +# Finds the docker image reference of an image stream tag function istag2docker() { ISTAG=$1 oc get istag $OC_OPTS | grep $ISTAG | awk -F " " '{print $2}' } +# +# Prints the version of the pom +function pomversion() { + # The version is 8 lines from the end. + # We ditch the rest, cause we can't filter them out (don't have a common pattern). + # The last 7 lines all start with '['. + mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -v "\[" | tail -n 1 +} + +function modules_to_build() { + modules="plugins agentimages images tools" + if [ "x${RF}" != x ]; then + modules=$(echo $modules | sed -e "s/^.*$RF/$RF/") + fi + echo $modules +} + +# +# Build Modules / Components +# + +function plugins() { + pushd plugins + #Kubernetes Plugin + pushd kubernetes-plugin + git pull --rebase origin master || true + mvnbuild + popd + + #Kubernetes Pipeline Plugin + pushd kubernetes-pipeline-plugin + git pull --rebase origin master || true + mvnbuild + popd + + #Durable Task Pluginresource(s) were provided, but no name, label selector, or --all flag specified + pushd durable-task-plugin + git pull --rebase origin master || true + mvnbuild + popd + + #Groovy Pipeline Libraries + pushd workflow-cps-global-lib-plugin + git pull --rebase origin master || true + mvnbuild + popd + + popd +} + function images() { - pushd images + pushd images # Openshift Jenkins pushd openshift-jenkins/2 - dockerbuild Dockerfile openshift-jenkins + git pull --rebase origin master || true + + # Import requirements + oc import-image origin:v3.6.0 --from=docker.io/openshift/origin:v3.6.0 --confirm || true + dockerbuild Dockerfile openshift-jenkins origin v3.6.0 popd # Syndesis Jenkins pushd syndesis-jenkins + git pull --rebase origin master || true # Let's copy the plugins copyplugin kubernetes copyplugin durable-task-plugin copyplugin workflow-cps-global-lib # This is a multimodule project so it does get a little bit more complicated copyplugin kubernetes-pipeline-arquillian-steps ../../plugins/kubernetes-pipeline-plugin/arquillian-steps/target/ - OPENSHIFT_JENKINS_DOCKER_IMAGE=$(istag2docker "${ARTIFACT_PREFIX}openshift-jenkins") - oc new-build --name ${ARTIFACT_PREFIX}syndesis-jenkins --binary=true --docker-image=$OPENSHIFT_JENKINS_DOCKER_IMAGE --to=syndesis/${ARTIFACT_PREFIX}syndesis-jenkins:latest --strategy=source $OC_OPTS || true - tar -cvf archive.tar bin configuration plugins plugins.txt - oc start-build ${ARTIFACT_PREFIX}syndesis-jenkins $OC_OPTS --from-archive=archive.tar --follow + + # We could possibly remove this? + #OPENSHIFT_JENKINS_DOCKER_IMAGE=$(istag2docker "${ARTIFACT_PREFIX}openshift-jenkins") + oc new-build --name ${ARTIFACT_PREFIX}syndesis-jenkins --binary=true --image-stream=${ARTIFACT_PREFIX}openshift-jenkins:$VERSION --to=syndesis/${ARTIFACT_PREFIX}syndesis-jenkins:${VERSION} --strategy=source $OC_OPTS || true + tar -czvf /tmp/archive.tar.gz bin configuration plugins plugins.txt + oc start-build ${ARTIFACT_PREFIX}syndesis-jenkins $OC_OPTS --from-archive=/tmp/archive.tar.gz --follow + rm /tmp/archive.tar.gz popd popd } function agentimages() { - pushd images/openshift-jenkins + pushd images/openshift-jenkins # # Jenkins Agents pushd slave-base - dockerbuild Dockerfile jenkins-slave-base-centos7 + oc import-image origin:v3.6.0 --from=docker.io/openshift/origin:v3.6.0 --confirm || true + dockerbuild Dockerfile jenkins-slave-base-centos7 origin v3.6.0 popd pushd slave-nodejs - dockerbuild Dockerfile jenkins-slave-nodejs-centos7 + dockerbuild Dockerfile jenkins-slave-nodejs-centos7 jenkins-slave-base-centos7 $VERSION popd pushd slave-maven - dockerbuild Dockerfile jenkins-slave-maven-centos7 + dockerbuild Dockerfile jenkins-slave-maven-centos7 jenkins-slave-base-centos7 $VERSION popd popd } -function plugins() { - pushd plugins - #Kubernetes Plugin - pushd kubernetes-plugin - mvn clean install $MAVEN_OPTS - popd - - #Kubernetes Pipeline Plugin - pushd kubernetes-pipeline-plugin - mvn clean install $MAVEN_OPTS - popd - - #Durable Task Plugin - pushd durable-task-plugin - mvn clean install $MAVEN_OPTS - popd - - #Groovy Pipeline Libraries - pushd workflow-cps-global-lib-plugin - mvn clean install $MAVEN_OPTS - popd - - popd -} function tools() { pushd images/nsswrapper-glibc - dockerbuild Dockerfile nsswrapper-glibc + oc import-image centos:centos7 --from=docker.io/library/centos:centos7 --confirm || true + dockerbuild Dockerfile nsswrapper-glibc centos centos7 popd -} -function modules_to_build() { - modules="plugins agentimages images tools" - if [ "x${RF}" != x ]; then - modules=$(echo $modules | sed -e "s/^.*$RF/$RF/") - fi - echo $modules + pushd images/maven-with-repo + oc import-image maven:3.5.0 --from=docker.io/library/maven:3.5.0 --confirm || true + dockerbuild Dockerfile maven-with-repo maven 3.5.0 + popd } + # # Options and flags SKIP_TESTS=$(hasflag --skip-tests "$@" 2> /dev/null) CLEAN=$(hasflag --clean "$@" 2> /dev/null) ARTIFACT_PREFIX=$(readopt --artifact-prefix "$@" 2> /dev/null) -NAMESPACE=$(readopt --namespace "$@" 2> /dev/null) +NAMESPACE=$(or $(readopt --namespace "$@" 2> /dev/null) $(oc project -q)) VERSION=$(or $(readopt --version "$@" 2> /dev/null) "latest") RESUME_FROM=$(readopt --resume-from "$@" 2> /dev/null) HELP=$(hasflag --help "$@" 2> /dev/null) diff --git a/images/maven-with-repo/Dockerfile b/images/maven-with-repo/Dockerfile new file mode 100644 index 0000000..2ec39f2 --- /dev/null +++ b/images/maven-with-repo/Dockerfile @@ -0,0 +1,15 @@ +FROM maven:3.5.0 + +ENV MAVEN_OPTS=-Dmaven.repo.local=/usr/local/share/maven/repository + +RUN mkdir -p /usr/local/share/maven/repository + +RUN mkdir -p /usr/local/src && \ + cd /usr/local/src && \ + git clone https://github.com/syndesisio/syndesis.git && \ + cd syndesis && \ + git submodule init && git submodule update + +RUN cd /usr/local/src/syndesis/rest && mvn clean install -DskipTests + +RUN rm -rf /usr/loca/src/syndesis diff --git a/images/openshift-jenkins b/images/openshift-jenkins index 01c8bb3..e5004bf 160000 --- a/images/openshift-jenkins +++ b/images/openshift-jenkins @@ -1 +1 @@ -Subproject commit 01c8bb32d419afa528ce876b85a88c3affd8015c +Subproject commit e5004bf82bb0b6ea1afa8bce391d8f615b5a22ce diff --git a/plugins/durable-task-plugin b/plugins/durable-task-plugin index 5057616..e3856f7 160000 --- a/plugins/durable-task-plugin +++ b/plugins/durable-task-plugin @@ -1 +1 @@ -Subproject commit 50576166b076d9835320dbc4ad62ee5fb98cbe98 +Subproject commit e3856f706549f74b527dcc5ddb5e887802425395 diff --git a/plugins/kubernetes-pipeline-plugin b/plugins/kubernetes-pipeline-plugin index db0ac62..90c745a 160000 --- a/plugins/kubernetes-pipeline-plugin +++ b/plugins/kubernetes-pipeline-plugin @@ -1 +1 @@ -Subproject commit db0ac62eb9e6d997f80fe8b4c12f925b9e074e14 +Subproject commit 90c745a2e76d3f77bafecec429cc563cbb6aa2d9 diff --git a/plugins/kubernetes-plugin b/plugins/kubernetes-plugin index 36f390d..bea1ce5 160000 --- a/plugins/kubernetes-plugin +++ b/plugins/kubernetes-plugin @@ -1 +1 @@ -Subproject commit 36f390df18ae730548f2e9de73ab78b1c67b7534 +Subproject commit bea1ce59815dc30c2278146bb1f9f8decee0539b diff --git a/plugins/workflow-cps-global-lib-plugin b/plugins/workflow-cps-global-lib-plugin index 64bbefa..5a59c42 160000 --- a/plugins/workflow-cps-global-lib-plugin +++ b/plugins/workflow-cps-global-lib-plugin @@ -1 +1 @@ -Subproject commit 64bbefaede3e1d5dca83a02aa66befd8263c08a2 +Subproject commit 5a59c4225569efa7455ea78d64f5435fcf0efae9