forked from jorgemoralespou/s2i-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated scripts. Right now, only for maven
- Loading branch information
1 parent
2ebc482
commit 797a3d3
Showing
3 changed files
with
139 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,153 +1,95 @@ | ||
#!/bin/bash - | ||
|
||
## S2I assemble script for the 's2i-java' 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 's2i-java' assemble script is executed with '-h' flag, | ||
# print the usage. | ||
exec /usr/local/sti/usage | ||
fi | ||
#!/bin/bash | ||
. $(dirname $0)/functions | ||
|
||
# # 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 | ||
|
||
############################################################################## | ||
# | ||
# BUILD ENVs: | ||
# APP_SUFFIX = Jar file suffix of the application (e.g. xxxxx${APP_SUFFIX}.jar) | ||
# BUILDER_ARGS = Builder arguments | ||
# | ||
# RUN ENVs: | ||
# APP_OPTIONS = Options to pass to java command line | ||
|
||
# Source code provided to STI is at ${HOME}/source | ||
HOME=/opt/app-root/src | ||
|
||
# we will move any code provided by s2i to here | ||
LOCAL_SOURCE_DIR=${HOME}/source | ||
mkdir -p $LOCAL_SOURCE_DIR | ||
# TODO: Verify a $HOME is set | ||
|
||
# Resulting artifact files will be deployed to /opt/openshift | ||
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 | ||
} | ||
# the subdirectory within LOCAL_SOURCE_DIR from where we should copy build | ||
# artifacts (*.war, *.jar) | ||
ARTIFACT_DIR=${ARTIFACT_DIR:-target} | ||
|
||
# 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}'" | ||
# TODO: Remove. Why do we need to move the source??? | ||
if compgen -G "/tmp/src/*" >/dev/null; then | ||
mkdir -p $LOCAL_SOURCE_DIR | ||
cp -ad /tmp/src/* $LOCAL_SOURCE_DIR | ||
fi | ||
|
||
echo "Maven version:" | ||
mvn --version | ||
|
||
# Execute the actual build | ||
mvn -e $BUILDER_ARGS | ||
if [ -d $LOCAL_SOURCE_DIR/configuration ]; then | ||
echo "Copying config files from project..." | ||
|
||
ERR=$? | ||
if [ $ERR -ne 0 ]; then | ||
echo "Aborting due to error code $ERR from Maven build" | ||
exit $ERR | ||
if [ -f $LOCAL_SOURCE_DIR/configuration/settings.xml ]; then | ||
mkdir -p $HOME/.m2 | ||
mv $LOCAL_SOURCE_DIR/configuration/settings.xml $HOME/.m2 | ||
fi | ||
|
||
# Copy built artifacts (if any!) from the target/ directory | ||
# to the $DEPLOY_DIR directory for later deployment | ||
if [ "${PROJECT}" == "" ]; then | ||
copy_artifacts ${PROJECT}/target | ||
else | ||
copy_artifacts target | ||
fi | ||
# We move the rest of the configuration, if provided to the place where the app will run | ||
cp -v $LOCAL_SOURCE_DIR/configuration/* $DEPLOY_DIR | ||
fi | ||
|
||
# clean up after maven | ||
mvn clean | ||
if [ -d "$HOME/.m2/repository" ]; then | ||
rm -r "$HOME/.m2/repository" | ||
fi | ||
configure_proxy | ||
configure_mirrors | ||
|
||
popd &> /dev/null | ||
elif [ -f "$LOCAL_SOURCE_DIR/build.gradle" ]; then | ||
echo "Building with gradle. $LOCAL_SOURCE_DIR/build.gradle found." | ||
manage_incremental_build | ||
|
||
pushd $LOCAL_SOURCE_DIR &> /dev/null | ||
# If a pom.xml is present, this is a normal build scenario | ||
# so run maven. | ||
if [ -f "$LOCAL_SOURCE_DIR/pom.xml" ]; then | ||
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 | ||
MAVEN_ARGS=${MAVEN_ARGS--e -Popenshift -DskipTests -Dcom.redhat.xpaas.repo.redhatga package} | ||
|
||
# Always force IPv4 (CLOUD-188) | ||
# Append user-supplied arguments (CLOUD-412) | ||
MAVEN_ARGS="$MAVEN_ARGS -Djava.net.preferIPv4Stack=true ${MAVEN_ARGS_APPEND}" | ||
|
||
echo "Found gradle.build ... attempting to build with 'gradle -s ${BUILDER_ARGS}'" | ||
echo "Found pom.xml... attempting to build with 'mvn ${MAVEN_ARGS}'" | ||
|
||
echo "Gradle version:" | ||
gradle --version | ||
echo "Using $(mvn --version)" | ||
|
||
# Execute the actual build | ||
gradle -s $BUILDER_ARGS | ||
mvn $MAVEN_ARGS | ||
|
||
ERR=$? | ||
if [ $ERR -ne 0 ]; then | ||
echo "Aborting due to error code $ERR from Gradle build" | ||
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 build/libs | ||
|
||
# (or $ARTIFACT_DIR if specified) | ||
# to the $JBOSS_HOME/standalone/deployments/ directory for | ||
# later deployment | ||
copy_artifacts "$ARTIFACT_DIR" war ear rar jar | ||
|
||
# clean up after maven | ||
gradle clean | ||
# if [ -d "$HOME/.m2/repository" ]; then | ||
# rm -r "$HOME/.m2/repository" | ||
# fi | ||
# optionally clear the local maven repository after the build | ||
clear_maven_repository | ||
|
||
popd &> /dev/null | ||
else | ||
# For binary builds | ||
copy_artifacts "." war ear rar jar | ||
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 | ||
# As Microservices you should only have 1 fat jar | ||
# if compgen -G "/tmp/src/*" >/dev/null; then | ||
# TODO: Review how best move these | ||
if [ $(ls ${DEPLOY_DIR}/*${APP_SUFFIX}.jar | wc -l) -eq 1 ]; then | ||
echo "[INFO] Copying ${DEPLOY_DIR}/*${APP_SUFFIX}.jar into ${DEPLOY_DIR}/app.jar" | ||
mv ${DEPLOY_DIR}/*${APP_SUFFIX}.jar ${DEPLOY_DIR}/app.jar | ||
cp ${DEPLOY_DIR}/*${APP_SUFFIX}.jar ${DEPLOY_DIR}/app.jar | ||
[ ! -f ${DEPLOY_DIR}/app.jar ] && echo "Application could not be properly built." && exit 1 | ||
echo "[INFO] Application jar file is located in ${DEPLOY_DIR}/app.jar" | ||
else | ||
echo "[ERROR] No app.jar file located in ${DEPLOY_DIR}" | ||
exit 1 | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# common shell routines for s2i scripts | ||
|
||
# insert settings for HTTP proxy into settings.xml if supplied | ||
function configure_proxy() { | ||
if [ -n "$HTTP_PROXY_HOST" -a -n "$HTTP_PROXY_PORT" ]; then | ||
xml="<proxy>\ | ||
<id>genproxy</id>\ | ||
<active>true</active>\ | ||
<protocol>http</protocol>\ | ||
<host>$HTTP_PROXY_HOST</host>\ | ||
<port>$HTTP_PROXY_PORT</port>" | ||
if [ -n "$HTTP_PROXY_USERNAME" -a -n "$HTTP_PROXY_PASSWORD" ]; then | ||
xml="$xml\ | ||
<username>$HTTP_PROXY_USERNAME</username>\ | ||
<password>$HTTP_PROXY_PASSWORD</password>" | ||
fi | ||
if [ -n "$HTTP_PROXY_NONPROXYHOSTS" ]; then | ||
xml="$xml\ | ||
<nonProxyHosts>$HTTP_PROXY_NONPROXYHOSTS</nonProxyHosts>" | ||
fi | ||
xml="$xml\ | ||
</proxy>" | ||
sed -i "s|<!-- ### configured http proxy ### -->|$xml|" $HOME/.m2/settings.xml | ||
fi | ||
} | ||
|
||
# insert settings for mirrors/repository managers into settings.xml if supplied | ||
function configure_mirrors() { | ||
if [ -n "$MAVEN_MIRROR_URL" ]; then | ||
xml=" <mirror>\ | ||
<id>mirror.default</id>\ | ||
<url>$MAVEN_MIRROR_URL</url>\ | ||
<mirrorOf>external:*</mirrorOf>\ | ||
</mirror>" | ||
sed -i "s|<!-- ### configured mirrors ### -->|$xml|" $HOME/.m2/settings.xml | ||
fi | ||
} | ||
|
||
|
||
function copy_artifacts() { | ||
dir=$1 | ||
types= | ||
shift | ||
while [ $# -gt 0 ]; do | ||
types="$types;$1" | ||
shift | ||
done | ||
|
||
for d in $(echo $dir | tr "," "\n") | ||
do | ||
shift | ||
for t in $(echo $types | tr ";" "\n") | ||
do | ||
echo "Copying all $t artifacts from $LOCAL_SOURCE_DIR/$d directory into $DEPLOY_DIR for later deployment..." | ||
cp -rfv $LOCAL_SOURCE_DIR/$d/*.$t $DEPLOY_DIR 2> /dev/null | ||
done | ||
done | ||
} | ||
|
||
# handle incremental builds. If we have been passed build artifacts, untar | ||
# them over the supplied source. | ||
manage_incremental_build() { | ||
if [ -d /tmp/artifacts ]; then | ||
echo "Expanding artifacts from incremental build..." | ||
( cd /tmp/artifacts && tar cf - . ) | ( cd ${HOME} && tar xvf - ) | ||
rm -rf /tmp/artifacts | ||
fi | ||
} | ||
|
||
# s2i 'save-artifacts' routine | ||
s2i_save_build_artifacts() { | ||
cd ${HOME} | ||
tar cf - .m2 | ||
} | ||
|
||
# optionally clear the local maven repository after the build | ||
clear_maven_repository() { | ||
mcr=$(echo "${MAVEN_CLEAR_REPO}" | tr [:upper:] [:lower:]) | ||
if [ "${mcr}" = "true" ]; then | ||
rm -rf ${HOME}/.m2/repository/* | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
#!/bin/sh -e | ||
# | ||
# S2I save-artifacts script for the 'springboot-sti' image. | ||
# The save-artifacts script streams a tar archive to standard output. | ||
# The archive contains the files and folders you want to re-use in the next build. | ||
# | ||
# For more information see the documentation: | ||
# https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md | ||
# | ||
# tar cf - <list of files and folders> | ||
#!/bin/sh | ||
set -ue | ||
. $(dirname $0)/functions | ||
s2i_save_build_artifacts |