From 48902da7fe47dfdbe2cc765bf4df03eb3dbc9da4 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Tue, 1 May 2018 17:14:49 +0200 Subject: [PATCH 1/5] make DEPLOYMENTS_DIR overridable (#146) and mkdir -p it, because it can (and in our use case does) not exist, yet. --- java/images/jboss/s2i/assemble | 1 + java/images/jboss/s2i/s2i-setup | 2 +- java/images/rhel/s2i/assemble | 1 + java/images/rhel/s2i/s2i-setup | 2 +- java/templates/s2i/assemble | 1 + java/templates/s2i/s2i-setup | 2 +- 6 files changed, 6 insertions(+), 3 deletions(-) diff --git a/java/images/jboss/s2i/assemble b/java/images/jboss/s2i/assemble index 27c4afe6..489dddec 100644 --- a/java/images/jboss/s2i/assemble +++ b/java/images/jboss/s2i/assemble @@ -165,6 +165,7 @@ function build_maven() { echo "==================================================================" echo "Starting S2I Java Build ....." +mkdir -p ${DEPLOYMENTS_DIR} if [ -f "${S2I_SOURCE_DIR}/pom.xml" ]; then echo "S2I source build for Maven detected" build_dir=$(get_output_dir) diff --git a/java/images/jboss/s2i/s2i-setup b/java/images/jboss/s2i/s2i-setup index c3b675c3..fef03cb2 100644 --- a/java/images/jboss/s2i/s2i-setup +++ b/java/images/jboss/s2i/s2i-setup @@ -2,5 +2,5 @@ S2I_DESTINATION=${S2I_DESTINATION:-/tmp} S2I_SOURCE_DIR="${S2I_DESTINATION}/src" S2I_ARTIFACTS_DIR="${S2I_DESTINATION}/artifacts" -DEPLOYMENTS_DIR="/deployments" +DEPLOYMENTS_DIR="${DEPLOYMENTS_DIR:-/deployments}" RUN_JAVA_DIR=/opt/run-java diff --git a/java/images/rhel/s2i/assemble b/java/images/rhel/s2i/assemble index 27c4afe6..489dddec 100644 --- a/java/images/rhel/s2i/assemble +++ b/java/images/rhel/s2i/assemble @@ -165,6 +165,7 @@ function build_maven() { echo "==================================================================" echo "Starting S2I Java Build ....." +mkdir -p ${DEPLOYMENTS_DIR} if [ -f "${S2I_SOURCE_DIR}/pom.xml" ]; then echo "S2I source build for Maven detected" build_dir=$(get_output_dir) diff --git a/java/images/rhel/s2i/s2i-setup b/java/images/rhel/s2i/s2i-setup index c3b675c3..fef03cb2 100644 --- a/java/images/rhel/s2i/s2i-setup +++ b/java/images/rhel/s2i/s2i-setup @@ -2,5 +2,5 @@ S2I_DESTINATION=${S2I_DESTINATION:-/tmp} S2I_SOURCE_DIR="${S2I_DESTINATION}/src" S2I_ARTIFACTS_DIR="${S2I_DESTINATION}/artifacts" -DEPLOYMENTS_DIR="/deployments" +DEPLOYMENTS_DIR="${DEPLOYMENTS_DIR:-/deployments}" RUN_JAVA_DIR=/opt/run-java diff --git a/java/templates/s2i/assemble b/java/templates/s2i/assemble index 27c4afe6..489dddec 100755 --- a/java/templates/s2i/assemble +++ b/java/templates/s2i/assemble @@ -165,6 +165,7 @@ function build_maven() { echo "==================================================================" echo "Starting S2I Java Build ....." +mkdir -p ${DEPLOYMENTS_DIR} if [ -f "${S2I_SOURCE_DIR}/pom.xml" ]; then echo "S2I source build for Maven detected" build_dir=$(get_output_dir) diff --git a/java/templates/s2i/s2i-setup b/java/templates/s2i/s2i-setup index c3b675c3..fef03cb2 100644 --- a/java/templates/s2i/s2i-setup +++ b/java/templates/s2i/s2i-setup @@ -2,5 +2,5 @@ S2I_DESTINATION=${S2I_DESTINATION:-/tmp} S2I_SOURCE_DIR="${S2I_DESTINATION}/src" S2I_ARTIFACTS_DIR="${S2I_DESTINATION}/artifacts" -DEPLOYMENTS_DIR="/deployments" +DEPLOYMENTS_DIR="${DEPLOYMENTS_DIR:-/deployments}" RUN_JAVA_DIR=/opt/run-java From b77b0a8cecc0564619efb0a06ecdfc9f416a1007 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Sun, 4 Mar 2018 14:18:54 +0100 Subject: [PATCH 2/5] add Gradle build support, initial version (fixes #118) --- java/images/jboss/s2i/assemble | 88 ++++++++++++++++++++++++++++++++-- java/images/rhel/s2i/assemble | 88 ++++++++++++++++++++++++++++++++-- java/templates/s2i/assemble | 88 ++++++++++++++++++++++++++++++++-- 3 files changed, 252 insertions(+), 12 deletions(-) diff --git a/java/images/jboss/s2i/assemble b/java/images/jboss/s2i/assemble index 489dddec..ac36577b 100644 --- a/java/images/jboss/s2i/assemble +++ b/java/images/jboss/s2i/assemble @@ -17,7 +17,7 @@ function check_error() { fi } -function get_output_dir() { +function get_maven_output_dir() { local dir="" # If multi module build and no ARTIFACT_DIR is set --> error @@ -47,6 +47,32 @@ function get_output_dir() { echo ${dir} } +function get_gradle_output_dir() { + local dir="" + + # If multi module build and no ARTIFACT_DIR is set --> error + if [ x"${ARTIFACT_DIR}" = x ]; then + dir="${S2I_SOURCE_DIR}/build/libs" + else + if [ "${ARTIFACT_DIR:0:1}" = "/" ]; then + echo "ARTIFACT_DIR \"${ARTIFACT_DIR}\" must not be absolute but relative to the source directory" + exit 1 + fi + dir="${S2I_SOURCE_DIR}/${ARTIFACT_DIR}" + fi + + # Normalize dir + # TODO how do you get this to check not one but two (../..) up? +# dir=$(echo ${dir} | tr -s /) +# dir=${dir%/} +# # The parent must exist but build/libs/ won't exist yet +# if [ ! -d $(dirname "${dir}"}) ]; then +# echo "Please specify an existing build directory ARTIFACT_DIR (tried '$(dirname "${dir}")' which does not exist)" +# exit 1 +# fi + echo ${dir} +} + function copy_dir() { local src=$1 local dest=$2 @@ -74,7 +100,6 @@ function copy_artifacts() { } function setup_maven() { - if [ -n "$HTTP_PROXY_HOST" -a -n "$HTTP_PROXY_PORT" ]; then xml="\ genproxy\ @@ -111,6 +136,10 @@ function setup_maven() { fi } +function setup_gradle() { + echo "TODO ;) set up possibly HTTP proxy server for Gradle build (not yet implemented)..." +} + function build_maven() { # Where artifacts are created during build local build_dir=$1 @@ -131,7 +160,6 @@ function build_maven() { fi echo "Found pom.xml ... " - echo "Running 'mvn ${maven_env_args} ${maven_args} ${MAVEN_ARGS_APPEND}'" local old_dir=$(pwd) cd ${S2I_SOURCE_DIR} @@ -139,6 +167,7 @@ function build_maven() { # ========= # Run Maven + echo "Running 'mvn ${maven_env_args} ${maven_args} ${MAVEN_ARGS_APPEND}'" mvn ${maven_env_args} --version mvn ${maven_env_args} ${maven_args} ${MAVEN_ARGS_APPEND} check_error "Maven build" $? @@ -160,6 +189,51 @@ function build_maven() { cd ${old_dir} } +function build_gradle() { + # Where artifacts are created during build + local build_dir=$1 + + # Where to put the artifacts + local app_dir=$2 + + # Default args + local gradle_args=${GRADLE_ARGS:-build -x test} + + # If there is no user provided GRADLE_OPTS, use options from run-java.sh + if [ -f ${RUN_JAVA_DIR}/run-java.sh -a -z "${GRADLE_OPTS}" ]; then + export GRADLE_OPTS=$(${RUN_JAVA_DIR}/run-java.sh options) + fi + + if [ ! -z "${GRADLE_OPTS}" ]; then + echo "Using GRADLE_OPTS '${GRADLE_OPTS}'" + fi + + local old_dir=$(pwd) + cd ${S2I_SOURCE_DIR} + check_error "changing directory to ${S2I_SOURCE_DIR}" $? + + # ========= + # Run Gradle + echo "Running './gradlew ${gradle_args} ${GRADLE_ARGS_APPEND}'" + ./gradlew ${gradle_args} ${GRADLE_ARGS_APPEND} + check_error "Gradle build" $? + + # ============== + # Copy artifacts + echo "Copying Gradle artifacts from ${build_dir} to ${app_dir} ..." + copy_artifacts ${build_dir} ${app_dir} + check_error "copying artifacts from ${build_dir} to ${app_dir}" $? + + # ====================== + # TODO Remove repo if desired +# if [ "x${MAVEN_CLEAR_REPO}" != "x" ]; then +# rm -rf "${S2I_ARTIFACTS_DIR}/m2" +# check_error "Cannot remove local Maven repository ${S2I_ARTIFACTS_DIR}/m2" $? +# fi + + cd ${old_dir} +} + # ========================================================================= # Main @@ -168,7 +242,7 @@ echo "Starting S2I Java Build ....." mkdir -p ${DEPLOYMENTS_DIR} if [ -f "${S2I_SOURCE_DIR}/pom.xml" ]; then echo "S2I source build for Maven detected" - build_dir=$(get_output_dir) + build_dir=$(get_maven_output_dir) check_error "Cannot get output dir: $build_dir" $? # If a pom.xml is present use maven setup_maven @@ -189,6 +263,12 @@ elif [ -f "${S2I_SOURCE_DIR}/Dockerfile" ]; then echo "Copying binaries from ${binary_dir} to ${DEPLOYMENTS_DIR} ..." copy_dir ${binary_dir} ${DEPLOYMENTS_DIR} check_error "copying ${binary_dir} to ${DEPLOYMENTS_DIR}" $? +elif ls ${S2I_SOURCE_DIR}/*.gradle* &> /dev/null; then + echo "S2I source build for Gradle detected, due to presence of a *.gradle* in ${S2I_SOURCE_DIR}" + build_dir=$(get_gradle_output_dir) + check_error "Cannot get output dir: $build_dir" $? + setup_gradle + build_gradle ${build_dir} ${DEPLOYMENTS_DIR} else echo "S2I source build with plain binaries detected" if [ -d "${S2I_SOURCE_DIR}/deployments" ]; then diff --git a/java/images/rhel/s2i/assemble b/java/images/rhel/s2i/assemble index 489dddec..ac36577b 100644 --- a/java/images/rhel/s2i/assemble +++ b/java/images/rhel/s2i/assemble @@ -17,7 +17,7 @@ function check_error() { fi } -function get_output_dir() { +function get_maven_output_dir() { local dir="" # If multi module build and no ARTIFACT_DIR is set --> error @@ -47,6 +47,32 @@ function get_output_dir() { echo ${dir} } +function get_gradle_output_dir() { + local dir="" + + # If multi module build and no ARTIFACT_DIR is set --> error + if [ x"${ARTIFACT_DIR}" = x ]; then + dir="${S2I_SOURCE_DIR}/build/libs" + else + if [ "${ARTIFACT_DIR:0:1}" = "/" ]; then + echo "ARTIFACT_DIR \"${ARTIFACT_DIR}\" must not be absolute but relative to the source directory" + exit 1 + fi + dir="${S2I_SOURCE_DIR}/${ARTIFACT_DIR}" + fi + + # Normalize dir + # TODO how do you get this to check not one but two (../..) up? +# dir=$(echo ${dir} | tr -s /) +# dir=${dir%/} +# # The parent must exist but build/libs/ won't exist yet +# if [ ! -d $(dirname "${dir}"}) ]; then +# echo "Please specify an existing build directory ARTIFACT_DIR (tried '$(dirname "${dir}")' which does not exist)" +# exit 1 +# fi + echo ${dir} +} + function copy_dir() { local src=$1 local dest=$2 @@ -74,7 +100,6 @@ function copy_artifacts() { } function setup_maven() { - if [ -n "$HTTP_PROXY_HOST" -a -n "$HTTP_PROXY_PORT" ]; then xml="\ genproxy\ @@ -111,6 +136,10 @@ function setup_maven() { fi } +function setup_gradle() { + echo "TODO ;) set up possibly HTTP proxy server for Gradle build (not yet implemented)..." +} + function build_maven() { # Where artifacts are created during build local build_dir=$1 @@ -131,7 +160,6 @@ function build_maven() { fi echo "Found pom.xml ... " - echo "Running 'mvn ${maven_env_args} ${maven_args} ${MAVEN_ARGS_APPEND}'" local old_dir=$(pwd) cd ${S2I_SOURCE_DIR} @@ -139,6 +167,7 @@ function build_maven() { # ========= # Run Maven + echo "Running 'mvn ${maven_env_args} ${maven_args} ${MAVEN_ARGS_APPEND}'" mvn ${maven_env_args} --version mvn ${maven_env_args} ${maven_args} ${MAVEN_ARGS_APPEND} check_error "Maven build" $? @@ -160,6 +189,51 @@ function build_maven() { cd ${old_dir} } +function build_gradle() { + # Where artifacts are created during build + local build_dir=$1 + + # Where to put the artifacts + local app_dir=$2 + + # Default args + local gradle_args=${GRADLE_ARGS:-build -x test} + + # If there is no user provided GRADLE_OPTS, use options from run-java.sh + if [ -f ${RUN_JAVA_DIR}/run-java.sh -a -z "${GRADLE_OPTS}" ]; then + export GRADLE_OPTS=$(${RUN_JAVA_DIR}/run-java.sh options) + fi + + if [ ! -z "${GRADLE_OPTS}" ]; then + echo "Using GRADLE_OPTS '${GRADLE_OPTS}'" + fi + + local old_dir=$(pwd) + cd ${S2I_SOURCE_DIR} + check_error "changing directory to ${S2I_SOURCE_DIR}" $? + + # ========= + # Run Gradle + echo "Running './gradlew ${gradle_args} ${GRADLE_ARGS_APPEND}'" + ./gradlew ${gradle_args} ${GRADLE_ARGS_APPEND} + check_error "Gradle build" $? + + # ============== + # Copy artifacts + echo "Copying Gradle artifacts from ${build_dir} to ${app_dir} ..." + copy_artifacts ${build_dir} ${app_dir} + check_error "copying artifacts from ${build_dir} to ${app_dir}" $? + + # ====================== + # TODO Remove repo if desired +# if [ "x${MAVEN_CLEAR_REPO}" != "x" ]; then +# rm -rf "${S2I_ARTIFACTS_DIR}/m2" +# check_error "Cannot remove local Maven repository ${S2I_ARTIFACTS_DIR}/m2" $? +# fi + + cd ${old_dir} +} + # ========================================================================= # Main @@ -168,7 +242,7 @@ echo "Starting S2I Java Build ....." mkdir -p ${DEPLOYMENTS_DIR} if [ -f "${S2I_SOURCE_DIR}/pom.xml" ]; then echo "S2I source build for Maven detected" - build_dir=$(get_output_dir) + build_dir=$(get_maven_output_dir) check_error "Cannot get output dir: $build_dir" $? # If a pom.xml is present use maven setup_maven @@ -189,6 +263,12 @@ elif [ -f "${S2I_SOURCE_DIR}/Dockerfile" ]; then echo "Copying binaries from ${binary_dir} to ${DEPLOYMENTS_DIR} ..." copy_dir ${binary_dir} ${DEPLOYMENTS_DIR} check_error "copying ${binary_dir} to ${DEPLOYMENTS_DIR}" $? +elif ls ${S2I_SOURCE_DIR}/*.gradle* &> /dev/null; then + echo "S2I source build for Gradle detected, due to presence of a *.gradle* in ${S2I_SOURCE_DIR}" + build_dir=$(get_gradle_output_dir) + check_error "Cannot get output dir: $build_dir" $? + setup_gradle + build_gradle ${build_dir} ${DEPLOYMENTS_DIR} else echo "S2I source build with plain binaries detected" if [ -d "${S2I_SOURCE_DIR}/deployments" ]; then diff --git a/java/templates/s2i/assemble b/java/templates/s2i/assemble index 489dddec..ac36577b 100755 --- a/java/templates/s2i/assemble +++ b/java/templates/s2i/assemble @@ -17,7 +17,7 @@ function check_error() { fi } -function get_output_dir() { +function get_maven_output_dir() { local dir="" # If multi module build and no ARTIFACT_DIR is set --> error @@ -47,6 +47,32 @@ function get_output_dir() { echo ${dir} } +function get_gradle_output_dir() { + local dir="" + + # If multi module build and no ARTIFACT_DIR is set --> error + if [ x"${ARTIFACT_DIR}" = x ]; then + dir="${S2I_SOURCE_DIR}/build/libs" + else + if [ "${ARTIFACT_DIR:0:1}" = "/" ]; then + echo "ARTIFACT_DIR \"${ARTIFACT_DIR}\" must not be absolute but relative to the source directory" + exit 1 + fi + dir="${S2I_SOURCE_DIR}/${ARTIFACT_DIR}" + fi + + # Normalize dir + # TODO how do you get this to check not one but two (../..) up? +# dir=$(echo ${dir} | tr -s /) +# dir=${dir%/} +# # The parent must exist but build/libs/ won't exist yet +# if [ ! -d $(dirname "${dir}"}) ]; then +# echo "Please specify an existing build directory ARTIFACT_DIR (tried '$(dirname "${dir}")' which does not exist)" +# exit 1 +# fi + echo ${dir} +} + function copy_dir() { local src=$1 local dest=$2 @@ -74,7 +100,6 @@ function copy_artifacts() { } function setup_maven() { - if [ -n "$HTTP_PROXY_HOST" -a -n "$HTTP_PROXY_PORT" ]; then xml="\ genproxy\ @@ -111,6 +136,10 @@ function setup_maven() { fi } +function setup_gradle() { + echo "TODO ;) set up possibly HTTP proxy server for Gradle build (not yet implemented)..." +} + function build_maven() { # Where artifacts are created during build local build_dir=$1 @@ -131,7 +160,6 @@ function build_maven() { fi echo "Found pom.xml ... " - echo "Running 'mvn ${maven_env_args} ${maven_args} ${MAVEN_ARGS_APPEND}'" local old_dir=$(pwd) cd ${S2I_SOURCE_DIR} @@ -139,6 +167,7 @@ function build_maven() { # ========= # Run Maven + echo "Running 'mvn ${maven_env_args} ${maven_args} ${MAVEN_ARGS_APPEND}'" mvn ${maven_env_args} --version mvn ${maven_env_args} ${maven_args} ${MAVEN_ARGS_APPEND} check_error "Maven build" $? @@ -160,6 +189,51 @@ function build_maven() { cd ${old_dir} } +function build_gradle() { + # Where artifacts are created during build + local build_dir=$1 + + # Where to put the artifacts + local app_dir=$2 + + # Default args + local gradle_args=${GRADLE_ARGS:-build -x test} + + # If there is no user provided GRADLE_OPTS, use options from run-java.sh + if [ -f ${RUN_JAVA_DIR}/run-java.sh -a -z "${GRADLE_OPTS}" ]; then + export GRADLE_OPTS=$(${RUN_JAVA_DIR}/run-java.sh options) + fi + + if [ ! -z "${GRADLE_OPTS}" ]; then + echo "Using GRADLE_OPTS '${GRADLE_OPTS}'" + fi + + local old_dir=$(pwd) + cd ${S2I_SOURCE_DIR} + check_error "changing directory to ${S2I_SOURCE_DIR}" $? + + # ========= + # Run Gradle + echo "Running './gradlew ${gradle_args} ${GRADLE_ARGS_APPEND}'" + ./gradlew ${gradle_args} ${GRADLE_ARGS_APPEND} + check_error "Gradle build" $? + + # ============== + # Copy artifacts + echo "Copying Gradle artifacts from ${build_dir} to ${app_dir} ..." + copy_artifacts ${build_dir} ${app_dir} + check_error "copying artifacts from ${build_dir} to ${app_dir}" $? + + # ====================== + # TODO Remove repo if desired +# if [ "x${MAVEN_CLEAR_REPO}" != "x" ]; then +# rm -rf "${S2I_ARTIFACTS_DIR}/m2" +# check_error "Cannot remove local Maven repository ${S2I_ARTIFACTS_DIR}/m2" $? +# fi + + cd ${old_dir} +} + # ========================================================================= # Main @@ -168,7 +242,7 @@ echo "Starting S2I Java Build ....." mkdir -p ${DEPLOYMENTS_DIR} if [ -f "${S2I_SOURCE_DIR}/pom.xml" ]; then echo "S2I source build for Maven detected" - build_dir=$(get_output_dir) + build_dir=$(get_maven_output_dir) check_error "Cannot get output dir: $build_dir" $? # If a pom.xml is present use maven setup_maven @@ -189,6 +263,12 @@ elif [ -f "${S2I_SOURCE_DIR}/Dockerfile" ]; then echo "Copying binaries from ${binary_dir} to ${DEPLOYMENTS_DIR} ..." copy_dir ${binary_dir} ${DEPLOYMENTS_DIR} check_error "copying ${binary_dir} to ${DEPLOYMENTS_DIR}" $? +elif ls ${S2I_SOURCE_DIR}/*.gradle* &> /dev/null; then + echo "S2I source build for Gradle detected, due to presence of a *.gradle* in ${S2I_SOURCE_DIR}" + build_dir=$(get_gradle_output_dir) + check_error "Cannot get output dir: $build_dir" $? + setup_gradle + build_gradle ${build_dir} ${DEPLOYMENTS_DIR} else echo "S2I source build with plain binaries detected" if [ -d "${S2I_SOURCE_DIR}/deployments" ]; then From d4c98e4a91b0df7a44e9b3e215f07580292c9587 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Wed, 2 May 2018 01:05:37 +0200 Subject: [PATCH 3/5] clean up Gradle support (#118) --- java/images/jboss/s2i/assemble | 24 +++++------------------- java/images/rhel/s2i/assemble | 24 +++++------------------- java/templates/s2i/assemble | 24 +++++------------------- 3 files changed, 15 insertions(+), 57 deletions(-) diff --git a/java/images/jboss/s2i/assemble b/java/images/jboss/s2i/assemble index ac36577b..392c2f59 100644 --- a/java/images/jboss/s2i/assemble +++ b/java/images/jboss/s2i/assemble @@ -61,15 +61,6 @@ function get_gradle_output_dir() { dir="${S2I_SOURCE_DIR}/${ARTIFACT_DIR}" fi - # Normalize dir - # TODO how do you get this to check not one but two (../..) up? -# dir=$(echo ${dir} | tr -s /) -# dir=${dir%/} -# # The parent must exist but build/libs/ won't exist yet -# if [ ! -d $(dirname "${dir}"}) ]; then -# echo "Please specify an existing build directory ARTIFACT_DIR (tried '$(dirname "${dir}")' which does not exist)" -# exit 1 -# fi echo ${dir} } @@ -136,10 +127,6 @@ function setup_maven() { fi } -function setup_gradle() { - echo "TODO ;) set up possibly HTTP proxy server for Gradle build (not yet implemented)..." -} - function build_maven() { # Where artifacts are created during build local build_dir=$1 @@ -225,11 +212,11 @@ function build_gradle() { check_error "copying artifacts from ${build_dir} to ${app_dir}" $? # ====================== - # TODO Remove repo if desired -# if [ "x${MAVEN_CLEAR_REPO}" != "x" ]; then -# rm -rf "${S2I_ARTIFACTS_DIR}/m2" -# check_error "Cannot remove local Maven repository ${S2I_ARTIFACTS_DIR}/m2" $? -# fi + # Remove repo if desired + if [ "x${GRADLE_CLEAR_REPO}" != "x" ]; then + rm -rf "${S2I_ARTIFACTS_DIR}/gradle" + check_error "Cannot remove local Gradle repository ${S2I_ARTIFACTS_DIR}/gradle" $? + fi cd ${old_dir} } @@ -267,7 +254,6 @@ elif ls ${S2I_SOURCE_DIR}/*.gradle* &> /dev/null; then echo "S2I source build for Gradle detected, due to presence of a *.gradle* in ${S2I_SOURCE_DIR}" build_dir=$(get_gradle_output_dir) check_error "Cannot get output dir: $build_dir" $? - setup_gradle build_gradle ${build_dir} ${DEPLOYMENTS_DIR} else echo "S2I source build with plain binaries detected" diff --git a/java/images/rhel/s2i/assemble b/java/images/rhel/s2i/assemble index ac36577b..392c2f59 100644 --- a/java/images/rhel/s2i/assemble +++ b/java/images/rhel/s2i/assemble @@ -61,15 +61,6 @@ function get_gradle_output_dir() { dir="${S2I_SOURCE_DIR}/${ARTIFACT_DIR}" fi - # Normalize dir - # TODO how do you get this to check not one but two (../..) up? -# dir=$(echo ${dir} | tr -s /) -# dir=${dir%/} -# # The parent must exist but build/libs/ won't exist yet -# if [ ! -d $(dirname "${dir}"}) ]; then -# echo "Please specify an existing build directory ARTIFACT_DIR (tried '$(dirname "${dir}")' which does not exist)" -# exit 1 -# fi echo ${dir} } @@ -136,10 +127,6 @@ function setup_maven() { fi } -function setup_gradle() { - echo "TODO ;) set up possibly HTTP proxy server for Gradle build (not yet implemented)..." -} - function build_maven() { # Where artifacts are created during build local build_dir=$1 @@ -225,11 +212,11 @@ function build_gradle() { check_error "copying artifacts from ${build_dir} to ${app_dir}" $? # ====================== - # TODO Remove repo if desired -# if [ "x${MAVEN_CLEAR_REPO}" != "x" ]; then -# rm -rf "${S2I_ARTIFACTS_DIR}/m2" -# check_error "Cannot remove local Maven repository ${S2I_ARTIFACTS_DIR}/m2" $? -# fi + # Remove repo if desired + if [ "x${GRADLE_CLEAR_REPO}" != "x" ]; then + rm -rf "${S2I_ARTIFACTS_DIR}/gradle" + check_error "Cannot remove local Gradle repository ${S2I_ARTIFACTS_DIR}/gradle" $? + fi cd ${old_dir} } @@ -267,7 +254,6 @@ elif ls ${S2I_SOURCE_DIR}/*.gradle* &> /dev/null; then echo "S2I source build for Gradle detected, due to presence of a *.gradle* in ${S2I_SOURCE_DIR}" build_dir=$(get_gradle_output_dir) check_error "Cannot get output dir: $build_dir" $? - setup_gradle build_gradle ${build_dir} ${DEPLOYMENTS_DIR} else echo "S2I source build with plain binaries detected" diff --git a/java/templates/s2i/assemble b/java/templates/s2i/assemble index ac36577b..392c2f59 100755 --- a/java/templates/s2i/assemble +++ b/java/templates/s2i/assemble @@ -61,15 +61,6 @@ function get_gradle_output_dir() { dir="${S2I_SOURCE_DIR}/${ARTIFACT_DIR}" fi - # Normalize dir - # TODO how do you get this to check not one but two (../..) up? -# dir=$(echo ${dir} | tr -s /) -# dir=${dir%/} -# # The parent must exist but build/libs/ won't exist yet -# if [ ! -d $(dirname "${dir}"}) ]; then -# echo "Please specify an existing build directory ARTIFACT_DIR (tried '$(dirname "${dir}")' which does not exist)" -# exit 1 -# fi echo ${dir} } @@ -136,10 +127,6 @@ function setup_maven() { fi } -function setup_gradle() { - echo "TODO ;) set up possibly HTTP proxy server for Gradle build (not yet implemented)..." -} - function build_maven() { # Where artifacts are created during build local build_dir=$1 @@ -225,11 +212,11 @@ function build_gradle() { check_error "copying artifacts from ${build_dir} to ${app_dir}" $? # ====================== - # TODO Remove repo if desired -# if [ "x${MAVEN_CLEAR_REPO}" != "x" ]; then -# rm -rf "${S2I_ARTIFACTS_DIR}/m2" -# check_error "Cannot remove local Maven repository ${S2I_ARTIFACTS_DIR}/m2" $? -# fi + # Remove repo if desired + if [ "x${GRADLE_CLEAR_REPO}" != "x" ]; then + rm -rf "${S2I_ARTIFACTS_DIR}/gradle" + check_error "Cannot remove local Gradle repository ${S2I_ARTIFACTS_DIR}/gradle" $? + fi cd ${old_dir} } @@ -267,7 +254,6 @@ elif ls ${S2I_SOURCE_DIR}/*.gradle* &> /dev/null; then echo "S2I source build for Gradle detected, due to presence of a *.gradle* in ${S2I_SOURCE_DIR}" build_dir=$(get_gradle_output_dir) check_error "Cannot get output dir: $build_dir" $? - setup_gradle build_gradle ${build_dir} ${DEPLOYMENTS_DIR} else echo "S2I source build with plain binaries detected" From a0121b687ff94413f102a4b292a9e30217a4b955 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Wed, 2 May 2018 01:19:07 +0200 Subject: [PATCH 4/5] enable Gradle support only in community image, initially (#118) --- java/images/jboss/s2i/assemble | 6 ++++ java/images/rhel/s2i/assemble | 64 +--------------------------------- java/templates/s2i/assemble | 6 ++++ 3 files changed, 13 insertions(+), 63 deletions(-) diff --git a/java/images/jboss/s2i/assemble b/java/images/jboss/s2i/assemble index 392c2f59..5f71a2c0 100644 --- a/java/images/jboss/s2i/assemble +++ b/java/images/jboss/s2i/assemble @@ -47,6 +47,7 @@ function get_maven_output_dir() { echo ${dir} } + function get_gradle_output_dir() { local dir="" @@ -64,6 +65,7 @@ function get_gradle_output_dir() { echo ${dir} } + function copy_dir() { local src=$1 local dest=$2 @@ -176,6 +178,7 @@ function build_maven() { cd ${old_dir} } + function build_gradle() { # Where artifacts are created during build local build_dir=$1 @@ -221,6 +224,7 @@ function build_gradle() { cd ${old_dir} } + # ========================================================================= # Main @@ -250,11 +254,13 @@ elif [ -f "${S2I_SOURCE_DIR}/Dockerfile" ]; then echo "Copying binaries from ${binary_dir} to ${DEPLOYMENTS_DIR} ..." copy_dir ${binary_dir} ${DEPLOYMENTS_DIR} check_error "copying ${binary_dir} to ${DEPLOYMENTS_DIR}" $? + elif ls ${S2I_SOURCE_DIR}/*.gradle* &> /dev/null; then echo "S2I source build for Gradle detected, due to presence of a *.gradle* in ${S2I_SOURCE_DIR}" build_dir=$(get_gradle_output_dir) check_error "Cannot get output dir: $build_dir" $? build_gradle ${build_dir} ${DEPLOYMENTS_DIR} + else echo "S2I source build with plain binaries detected" if [ -d "${S2I_SOURCE_DIR}/deployments" ]; then diff --git a/java/images/rhel/s2i/assemble b/java/images/rhel/s2i/assemble index 392c2f59..6cb12128 100644 --- a/java/images/rhel/s2i/assemble +++ b/java/images/rhel/s2i/assemble @@ -47,22 +47,7 @@ function get_maven_output_dir() { echo ${dir} } -function get_gradle_output_dir() { - local dir="" - # If multi module build and no ARTIFACT_DIR is set --> error - if [ x"${ARTIFACT_DIR}" = x ]; then - dir="${S2I_SOURCE_DIR}/build/libs" - else - if [ "${ARTIFACT_DIR:0:1}" = "/" ]; then - echo "ARTIFACT_DIR \"${ARTIFACT_DIR}\" must not be absolute but relative to the source directory" - exit 1 - fi - dir="${S2I_SOURCE_DIR}/${ARTIFACT_DIR}" - fi - - echo ${dir} -} function copy_dir() { local src=$1 @@ -176,50 +161,7 @@ function build_maven() { cd ${old_dir} } -function build_gradle() { - # Where artifacts are created during build - local build_dir=$1 - - # Where to put the artifacts - local app_dir=$2 - - # Default args - local gradle_args=${GRADLE_ARGS:-build -x test} - - # If there is no user provided GRADLE_OPTS, use options from run-java.sh - if [ -f ${RUN_JAVA_DIR}/run-java.sh -a -z "${GRADLE_OPTS}" ]; then - export GRADLE_OPTS=$(${RUN_JAVA_DIR}/run-java.sh options) - fi - - if [ ! -z "${GRADLE_OPTS}" ]; then - echo "Using GRADLE_OPTS '${GRADLE_OPTS}'" - fi - local old_dir=$(pwd) - cd ${S2I_SOURCE_DIR} - check_error "changing directory to ${S2I_SOURCE_DIR}" $? - - # ========= - # Run Gradle - echo "Running './gradlew ${gradle_args} ${GRADLE_ARGS_APPEND}'" - ./gradlew ${gradle_args} ${GRADLE_ARGS_APPEND} - check_error "Gradle build" $? - - # ============== - # Copy artifacts - echo "Copying Gradle artifacts from ${build_dir} to ${app_dir} ..." - copy_artifacts ${build_dir} ${app_dir} - check_error "copying artifacts from ${build_dir} to ${app_dir}" $? - - # ====================== - # Remove repo if desired - if [ "x${GRADLE_CLEAR_REPO}" != "x" ]; then - rm -rf "${S2I_ARTIFACTS_DIR}/gradle" - check_error "Cannot remove local Gradle repository ${S2I_ARTIFACTS_DIR}/gradle" $? - fi - - cd ${old_dir} -} # ========================================================================= # Main @@ -250,11 +192,7 @@ elif [ -f "${S2I_SOURCE_DIR}/Dockerfile" ]; then echo "Copying binaries from ${binary_dir} to ${DEPLOYMENTS_DIR} ..." copy_dir ${binary_dir} ${DEPLOYMENTS_DIR} check_error "copying ${binary_dir} to ${DEPLOYMENTS_DIR}" $? -elif ls ${S2I_SOURCE_DIR}/*.gradle* &> /dev/null; then - echo "S2I source build for Gradle detected, due to presence of a *.gradle* in ${S2I_SOURCE_DIR}" - build_dir=$(get_gradle_output_dir) - check_error "Cannot get output dir: $build_dir" $? - build_gradle ${build_dir} ${DEPLOYMENTS_DIR} + else echo "S2I source build with plain binaries detected" if [ -d "${S2I_SOURCE_DIR}/deployments" ]; then diff --git a/java/templates/s2i/assemble b/java/templates/s2i/assemble index 392c2f59..caf789b1 100755 --- a/java/templates/s2i/assemble +++ b/java/templates/s2i/assemble @@ -47,6 +47,7 @@ function get_maven_output_dir() { echo ${dir} } +{{? fp.param.base != "rhel"}} function get_gradle_output_dir() { local dir="" @@ -63,6 +64,7 @@ function get_gradle_output_dir() { echo ${dir} } +{{?}} function copy_dir() { local src=$1 @@ -176,6 +178,7 @@ function build_maven() { cd ${old_dir} } +{{? fp.param.base != "rhel"}} function build_gradle() { # Where artifacts are created during build local build_dir=$1 @@ -220,6 +223,7 @@ function build_gradle() { cd ${old_dir} } +{{?}} # ========================================================================= # Main @@ -250,11 +254,13 @@ elif [ -f "${S2I_SOURCE_DIR}/Dockerfile" ]; then echo "Copying binaries from ${binary_dir} to ${DEPLOYMENTS_DIR} ..." copy_dir ${binary_dir} ${DEPLOYMENTS_DIR} check_error "copying ${binary_dir} to ${DEPLOYMENTS_DIR}" $? +{{? fp.param.base != "rhel"}} elif ls ${S2I_SOURCE_DIR}/*.gradle* &> /dev/null; then echo "S2I source build for Gradle detected, due to presence of a *.gradle* in ${S2I_SOURCE_DIR}" build_dir=$(get_gradle_output_dir) check_error "Cannot get output dir: $build_dir" $? build_gradle ${build_dir} ${DEPLOYMENTS_DIR} +{{?}} else echo "S2I source build with plain binaries detected" if [ -d "${S2I_SOURCE_DIR}/deployments" ]; then From c0c1cfa62180613f4a31880a20ebcc3688b774aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Mon, 14 May 2018 17:37:29 -0700 Subject: [PATCH 5/5] chore: Add binary flag for Gradle support --- java/images.yml | 2 ++ java/images/jboss/s2i/assemble | 40 ++++++++++++++++--------------- java/images/rhel/s2i/assemble | 3 +-- java/templates/s2i/assemble | 44 ++++++++++++++++++---------------- 4 files changed, 47 insertions(+), 42 deletions(-) diff --git a/java/images.yml b/java/images.yml index ad00d689..e03a99a2 100644 --- a/java/images.yml +++ b/java/images.yml @@ -8,6 +8,7 @@ fish-pepper: config: base: jboss: + withGradle: true from: "jboss/base-jdk:8" user: "jboss" home: "/opt/jboss" @@ -18,6 +19,7 @@ config: jolokia: "1.5.0" jmxexporter: "0.1.0" rhel: + withGradle: false from: "jboss/openjdk18-rhel7:1.1-7" user: "jboss" home: "/home/jboss" diff --git a/java/images/jboss/s2i/assemble b/java/images/jboss/s2i/assemble index 5f71a2c0..75f3c325 100644 --- a/java/images/jboss/s2i/assemble +++ b/java/images/jboss/s2i/assemble @@ -47,25 +47,6 @@ function get_maven_output_dir() { echo ${dir} } - -function get_gradle_output_dir() { - local dir="" - - # If multi module build and no ARTIFACT_DIR is set --> error - if [ x"${ARTIFACT_DIR}" = x ]; then - dir="${S2I_SOURCE_DIR}/build/libs" - else - if [ "${ARTIFACT_DIR:0:1}" = "/" ]; then - echo "ARTIFACT_DIR \"${ARTIFACT_DIR}\" must not be absolute but relative to the source directory" - exit 1 - fi - dir="${S2I_SOURCE_DIR}/${ARTIFACT_DIR}" - fi - - echo ${dir} -} - - function copy_dir() { local src=$1 local dest=$2 @@ -179,6 +160,26 @@ function build_maven() { } +# ========================================================================= +# Gradle support + +function get_gradle_output_dir() { + local dir="" + + # If multi module build and no ARTIFACT_DIR is set --> error + if [ x"${ARTIFACT_DIR}" = x ]; then + dir="${S2I_SOURCE_DIR}/build/libs" + else + if [ "${ARTIFACT_DIR:0:1}" = "/" ]; then + echo "ARTIFACT_DIR \"${ARTIFACT_DIR}\" must not be absolute but relative to the source directory" + exit 1 + fi + dir="${S2I_SOURCE_DIR}/${ARTIFACT_DIR}" + fi + + echo ${dir} +} + function build_gradle() { # Where artifacts are created during build local build_dir=$1 @@ -225,6 +226,7 @@ function build_gradle() { } + # ========================================================================= # Main diff --git a/java/images/rhel/s2i/assemble b/java/images/rhel/s2i/assemble index 6cb12128..4738d822 100644 --- a/java/images/rhel/s2i/assemble +++ b/java/images/rhel/s2i/assemble @@ -47,8 +47,6 @@ function get_maven_output_dir() { echo ${dir} } - - function copy_dir() { local src=$1 local dest=$2 @@ -163,6 +161,7 @@ function build_maven() { + # ========================================================================= # Main diff --git a/java/templates/s2i/assemble b/java/templates/s2i/assemble index caf789b1..d4431f81 100755 --- a/java/templates/s2i/assemble +++ b/java/templates/s2i/assemble @@ -47,25 +47,6 @@ function get_maven_output_dir() { echo ${dir} } -{{? fp.param.base != "rhel"}} -function get_gradle_output_dir() { - local dir="" - - # If multi module build and no ARTIFACT_DIR is set --> error - if [ x"${ARTIFACT_DIR}" = x ]; then - dir="${S2I_SOURCE_DIR}/build/libs" - else - if [ "${ARTIFACT_DIR:0:1}" = "/" ]; then - echo "ARTIFACT_DIR \"${ARTIFACT_DIR}\" must not be absolute but relative to the source directory" - exit 1 - fi - dir="${S2I_SOURCE_DIR}/${ARTIFACT_DIR}" - fi - - echo ${dir} -} -{{?}} - function copy_dir() { local src=$1 local dest=$2 @@ -178,7 +159,27 @@ function build_maven() { cd ${old_dir} } -{{? fp.param.base != "rhel"}} +{{? fp.config.base.withGradle }} +# ========================================================================= +# Gradle support + +function get_gradle_output_dir() { + local dir="" + + # If multi module build and no ARTIFACT_DIR is set --> error + if [ x"${ARTIFACT_DIR}" = x ]; then + dir="${S2I_SOURCE_DIR}/build/libs" + else + if [ "${ARTIFACT_DIR:0:1}" = "/" ]; then + echo "ARTIFACT_DIR \"${ARTIFACT_DIR}\" must not be absolute but relative to the source directory" + exit 1 + fi + dir="${S2I_SOURCE_DIR}/${ARTIFACT_DIR}" + fi + + echo ${dir} +} + function build_gradle() { # Where artifacts are created during build local build_dir=$1 @@ -225,6 +226,7 @@ function build_gradle() { } {{?}} + # ========================================================================= # Main @@ -254,7 +256,7 @@ elif [ -f "${S2I_SOURCE_DIR}/Dockerfile" ]; then echo "Copying binaries from ${binary_dir} to ${DEPLOYMENTS_DIR} ..." copy_dir ${binary_dir} ${DEPLOYMENTS_DIR} check_error "copying ${binary_dir} to ${DEPLOYMENTS_DIR}" $? -{{? fp.param.base != "rhel"}} +{{? fp.config.base.withGradle }} elif ls ${S2I_SOURCE_DIR}/*.gradle* &> /dev/null; then echo "S2I source build for Gradle detected, due to presence of a *.gradle* in ${S2I_SOURCE_DIR}" build_dir=$(get_gradle_output_dir)