|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# restore maven dependencies downloaded in a previous build, |
| 4 | +# so they do not have to be downloaded again. |
| 5 | +# /tmp/artifacts will only be present in the incremental build scenario |
| 6 | +# in which the target image name is an existing docker image which contains |
| 7 | +# dependencies from a prior build execution. |
| 8 | +function restore_saved_artifacts() { |
| 9 | + if [ -f /tmp/artifacts/maven.tar.gz ]; then |
| 10 | + pushd / &> /dev/null |
| 11 | + echo -n "Restoring saved artifacts from prior build..." |
| 12 | + tar zxf /tmp/artifacts/maven.tar.gz |
| 13 | + echo "...done" |
| 14 | + popd &> /dev/null |
| 15 | + fi |
| 16 | +} |
| 17 | + |
| 18 | +# Source code provided to STI will be bind-mounted at /tmp/src |
| 19 | +# and then copied into /opt/wildfly/source for building. |
| 20 | +local_source_dir=/opt/wildfly/source |
| 21 | +mkdir -p $local_source_dir |
| 22 | + |
| 23 | +# Resulting WAR files will be deployed to /wildfly/standalone/deployments |
| 24 | +deploy_dir=/wildfly/standalone/deployments |
| 25 | +mkdir -p $deploy_dir |
| 26 | + |
| 27 | +# Copy the source from the bind mount in preparation for compilation |
| 28 | +cp -ad /tmp/src/* $local_source_dir |
| 29 | + |
| 30 | +# If a pom.xml is present, this is a normal build scenario |
| 31 | +# so run maven. |
| 32 | +if [ -f "$local_source_dir/pom.xml" ]; then |
| 33 | + # restore any maven dependencies which will be present if this is an |
| 34 | + # incremental build |
| 35 | + restore_saved_artifacts |
| 36 | + |
| 37 | + pushd $local_source_dir &> /dev/null |
| 38 | + JAVA_HOME=/etc/alternatives/java_sdk_1.7.0 |
| 39 | + mvn clean package -Popenshift -DskipTests |
| 40 | + err=$? |
| 41 | + if [ $err -ne 0 ]; then |
| 42 | + echo "Aborting due to error code $err from mvn package" |
| 43 | + exit $err |
| 44 | + fi |
| 45 | + |
| 46 | + echo "Copying built war files into $deploy_dir for later deployment..." |
| 47 | + if [ -d $local_source_dir/target ]; then |
| 48 | + cp $local_source_dir/target/*.war $deploy_dir >& /dev/null |
| 49 | + fi |
| 50 | + if [ -d $local_source_dir/deployments ]; then |
| 51 | + cp $local_source_dir/deployments/*.war $deploy_dir >& /dev/null |
| 52 | + fi |
| 53 | + |
| 54 | + if [ -d $local_source_dir/cfg ]; then |
| 55 | + echo "Copying config files from project..." |
| 56 | + cp cfg/* /wildfly/standalone/configuration |
| 57 | + fi |
| 58 | + |
| 59 | + if [ -d $local_source_dir/modules ]; then |
| 60 | + echo "Copying modules from project..." |
| 61 | + mkdir /wildfly/provided_modules |
| 62 | + cp -r modules/* /wildfly/provided_modules |
| 63 | + fi |
| 64 | + |
| 65 | + echo "...done" |
| 66 | + |
| 67 | + popd &> /dev/null |
| 68 | +else |
| 69 | + echo "Copying binaries in source directory into $deploy_dir for later deployment..." |
| 70 | + if [ -d $local_source_dir/target ]; then |
| 71 | + cp $local_source_dir/target/*.war $deploy_dir >& /dev/null |
| 72 | + fi |
| 73 | + if [ -d $local_source_dir/deployments ]; then |
| 74 | + cp $local_source_dir/deployments/*.war $deploy_dir >& /dev/null |
| 75 | + fi |
| 76 | + if [ -d $local_source_dir/cfg ]; then |
| 77 | + echo "Copying config files from project..." |
| 78 | + cp cfg/* /wildfly/standalone/configuration |
| 79 | + fi |
| 80 | + |
| 81 | + if [ -d $local_source_dir/modules ]; then |
| 82 | + echo "Copying modules from project..." |
| 83 | + mkdir /wildfly/provided_modules |
| 84 | + cp -r modules/* /wildfly/provided_modules |
| 85 | + fi |
| 86 | + echo "...done" |
| 87 | +fi |
0 commit comments