Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 141 lines (110 sloc) 3.85 KB
#!/bin/bash -e
#
# S2I assemble script for the 'springboot-sti' image.
# The 'assemble' script builds your application source ready to run.
#
# For more information refer to the documentation:
# https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md
#
if [ "$1" = "-h" ]; then
# If the 'springboot-sti' assemble script is executed with '-h' flag,
# print the usage.
exec /usr/local/sti/usage
fi
# # Restore artifacts from the previous build (if they exist).
# #
# if [ "$(ls /tmp/artifacts/ 2>/dev/null)" ]; then
# echo "---> Restoring build artifacts"
# mv /tmp/artifacts/. ./
# fi
#
# echo "---> Installing application source"
# cp -Rf /tmp/src/. ./
#
# echo "---> Building application from source"
# # TODO: Add build steps for your application, eg npm install, bundle install
##############################################################################
# Source code provided to STI is at ${HOME}/source
HOME=/opt/app-root/src
LOCAL_SOURCE_DIR=${HOME}/source
mkdir -p $LOCAL_SOURCE_DIR
DEPLOY_DIR=/opt/openshift
# the subdirectory within LOCAL_SOURCE_DIR from where we should copy build artifacts
ARTIFACT_DIR=${ARTIFACT_DIR-target}
function copy_artifacts() {
if [ -d $LOCAL_SOURCE_DIR/$1 ]; then
echo "Copying all JAR artifacts from $LOCAL_SOURCE_DIR/$1 directory into $DEPLOY_DIR for later deployment..."
cp -v $LOCAL_SOURCE_DIR/$1/*.jar $DEPLOY_DIR 2> /dev/null
fi
}
# Copy the source for compilation
cp -ad /tmp/src/* $LOCAL_SOURCE_DIR
# If a pom.xml is present, this is a normal build scenario
# so run maven.
if [ -f "$LOCAL_SOURCE_DIR/pom.xml" ]; then
echo "Building with maven. $LOCAL_SOURCE_DIR/pom.xml found."
pushd $LOCAL_SOURCE_DIR &> /dev/null
if [ -z "$BUILDER_ARGS" ]; then
export BUILDER_ARGS="package -Popenshift -DskipTests -Dcom.redhat.xpaas.repo.redhatga"
fi
echo "Found pom.xml... attempting to build with 'mvn -e ${BUILDER_ARGS}'"
echo "Maven version:"
mvn --version
# Execute the actual build
mvn -e $BUILDER_ARGS
ERR=$?
if [ $ERR -ne 0 ]; then
echo "Aborting due to error code $ERR from Maven build"
exit $ERR
fi
# Copy built artifacts (if any!) from the target/ directory
# to the $DEPLOY_DIR directory for later deployment
copy_artifacts target
# clean up after maven
mvn clean
if [ -d "$HOME/.m2/repository" ]; then
rm -r "$HOME/.m2/repository"
fi
popd &> /dev/null
elif [ -f "$LOCAL_SOURCE_DIR/build.gradle" ]; then
echo "Building with gradle. $LOCAL_SOURCE_DIR/build.gradle found."
pushd $LOCAL_SOURCE_DIR &> /dev/null
if [ -z "$BUILDER_ARGS" ]; then
export BUILDER_ARGS="build -x test"
# TODO: Specify setting file with -c sss
fi
echo "Found gradle.build ... attempting to build with 'gradle -s ${BUILDER_ARGS}'"
echo "Gradle version:"
gradle --version
# Execute the actual build
gradle -s $BUILDER_ARGS
ERR=$?
if [ $ERR -ne 0 ]; then
echo "Aborting due to error code $ERR from Gradle build"
exit $ERR
fi
# Copy built artifacts (if any!) from the target/ directory
# to the $DEPLOY_DIR directory for later deployment
copy_artifacts build/libs
# clean up after maven
gradle clean
# if [ -d "$HOME/.m2/repository" ]; then
# rm -r "$HOME/.m2/repository"
# fi
popd &> /dev/null
fi
# Copy (probably binary) artifacts from the deployments/
# directory to the $DEPLOY_DIR directory for later deployment
# copy_artifacts "deployments"
# if [ -d $LOCAL_SOURCE_DIR/configuration ]; then
# echo "Copying config files from project..."
# cp -v $LOCAL_SOURCE_DIR/configuration/* $ARTIFACTS_HOME
# fi
# As SpringBoot you should only have 1 fat jar
if [ $(ls /opt/openshift/*.jar | wc -l) -eq 1 ]; then
mv /opt/openshift/*.jar /opt/openshift/app.jar
[ ! -f /opt/openshift/app.jar ] && echo "Application could not be properly built." && exit 1
echo "Application jar file is located in /opt/openshift/app.jar"
else
exit 1
fi