Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Fausto Bencosme committed Aug 11, 2014
2 parents 7792103 + 6e47cd4 commit f241be5
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 285 deletions.
13 changes: 12 additions & 1 deletion bin/common
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ get_supported_sbt_version() {
local ctxDir=$1
if _has_buildPropertiesFile $ctxDir; then
sbtVersionLine="$(grep -P '[ \t]*sbt\.version[ \t]*=' "${ctxDir}"/project/build.properties | sed -E -e 's/[ \t\r\n]//g')"
sbtVersion=$(expr "$sbtVersionLine" : 'sbt\.version=\(0\.1[1-3]\.[0-9]\)$')
sbtVersion=$(expr "$sbtVersionLine" : 'sbt\.version=\(0\.1[1-3]\.[0-9]\(-[a-zA-Z0-9_]*\)*\)$')
if [ "$sbtVersion" != 0 ] ; then
echo "$sbtVersion"
else
Expand Down Expand Up @@ -119,3 +119,14 @@ error() {
echo " ! $1"
exit 1
}

cache_copy() {
rel_dir=$1
from_dir=$2
to_dir=$3
rm -rf $to_dir/$rel_dir
if [ -d $from_dir/$rel_dir ]; then
mkdir -p $to_dir/$rel_dir
cp -pr $from_dir/$rel_dir/. $to_dir/$rel_dir
fi
}
57 changes: 29 additions & 28 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>
# bin/compile <build-dir> <cache-dir> <env-dir>

# fail fast
set -e
Expand All @@ -10,12 +10,20 @@ OPT_DIR=$BP_DIR/opt
. $BIN_DIR/common

# parse args
BUILD_DIR=$(cd $1; pwd)
APP_BUILD_DIR=$(cd $1; pwd)
CACHE_DIR=$2
ENV_DIR=$3

# Move app to a static build dir to keep paths the same between builds
BUILD_DIR="/tmp/scala_buildpack_build_dir"
mv $APP_BUILD_DIR $BUILD_DIR

curl --silent --location http://heroku-jvm-common.s3.amazonaws.com/jvm-buildpack-common.tar.gz | tar xz
. bin/util
. bin/java

export_env_dir $ENV_DIR

#create the cache dir if it doesn't exist
mkdir -p $CACHE_DIR

Expand Down Expand Up @@ -56,13 +64,9 @@ SBT_BINDIR="$SBT_USER_HOME"/bin
cd $BUILD_DIR

# unpack cache
CACHED_DIRS="$SBT_USER_HOME/.ivy2 $SBT_BINDIR"
CACHED_DIRS="$SBT_USER_HOME/.ivy2 $SBT_BINDIR target project/target project/boot"
for DIR in $CACHED_DIRS; do
rm -rf $DIR
if [ -d $CACHE_DIR/$DIR ]; then
mkdir -p $DIR
cp -r $CACHE_DIR/$DIR/. $DIR
fi
cache_copy $DIR $CACHE_DIR $BUILD_DIR
done

# these are preliminary checks. actual version check happens below when attempting to download sbt boot.properties
Expand All @@ -80,14 +84,17 @@ fi

SBT_VERSION="$(get_supported_sbt_version ${BUILD_DIR})"
SBT_JAR="sbt-launch.jar"
SBT_PROPS="sbt-$SBT_VERSION.boot.properties"
SBT_URL="http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.13.0/$SBT_JAR"
SBT_PROPS_URL="http://s3.amazonaws.com/heroku-jvm-langpack-scala/$SBT_PROPS"
SBT_URL="http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.13.5/$SBT_JAR"
## in 0.10 start-script will depend on package, if packaging
## is required - it may not be, we can run .class files or a package-war
## instead.
SBT_TASKS="clean compile stage"
SBT_TASKS="compile stage"

# To enable clean compiles, configure the environment to clean:
# $ heroku config:set SBT_CLEAN=true
# $ git push heroku master
# See: https://devcenter.heroku.com/articles/scala-support#clean-builds
[ "$SBT_CLEAN" = "true" ] && SBT_TASKS="clean $SBT_TASKS"

if [ ! -d .ivy2/cache ]; then
mkdir -p .ivy2/cache
Expand All @@ -100,31 +107,26 @@ if [ ! -f "$SBT_BINDIR"/"$SBT_JAR" ]; then
## clean up any old versions
/bin/rm -f sbt sbt-launch-*.jar || true

echo "-----> Building app with sbt"
echo -n "-----> Downloading SBT..."
curl --silent --max-time 60 -O --location $SBT_URL --fail || error "Failed to download $SBT_JAR"
echo "done"

echo "#!/usr/bin/env bash" > sbt
echo "/usr/bin/java -Dsbt.boot.properties=/app/.sbt_home/bin/sbt.boot.properties -Duser.home=/app/.sbt_home -Divy.default.ivy.user.dir=/app/.sbt_home/.ivy2 -jar /app/.sbt_home/bin/$SBT_JAR \"\$@\"" >> sbt
echo "java -Dsbt.boot.properties=/app/.sbt_home/bin/sbt.boot.properties -Duser.home=/app/.sbt_home -Divy.default.ivy.user.dir=/app/.sbt_home/.ivy2 -jar /app/.sbt_home/bin/$SBT_JAR \"\$@\"" >> sbt
chmod a+x sbt

cd $BUILD_DIR
fi

if [ -f $OPT_DIR/$SBT_PROPS ]; then
cp $OPT_DIR/$SBT_PROPS $SBT_BINDIR/sbt.boot.properties
else
error "Error, SBT version $SBT_VERSION not supported"
fi

# copy in heroku sbt plugin
HEROKU_PLUGIN="HerokuPlugin.scala"
mkdir -p "$SBT_USER_HOME/.sbt/plugins"
cp $OPT_DIR/$HEROKU_PLUGIN $SBT_USER_HOME/.sbt/plugins/$HEROKU_PLUGIN
cp -p $OPT_DIR/$HEROKU_PLUGIN $SBT_USER_HOME/.sbt/plugins/$HEROKU_PLUGIN

# build app
echo "-----> Running: sbt $SBT_TASKS"
test -e "$SBT_BINDIR"/sbt.boot.properties && PROPS_OPTION="-Dsbt.boot.properties=$SBT_BINDIR/sbt.boot.properties"
HOME="$SBT_USER_HOME_ABSOLUTE" java -Xms768M -Xmx1024M -XX:MaxPermSize=512M -XX:+CMSClassUnloadingEnabled -Dfile.encoding=UTF8 -Duser.home="$SBT_USER_HOME_ABSOLUTE" -Dsbt.log.noformat=true -Divy.default.ivy.user.dir="$SBT_USER_HOME_ABSOLUTE/.ivy2" $PROPS_OPTION -jar "$SBT_BINDIR"/$SBT_JAR $SBT_TASKS 2>&1 | sed -u 's/^/ /'
HOME="$SBT_USER_HOME_ABSOLUTE" java -Xms768M -Xmx1024M -Xss4M -XX:MaxPermSize=512M -XX:+CMSClassUnloadingEnabled -Dfile.encoding=UTF8 -Duser.home="$SBT_USER_HOME_ABSOLUTE" -Dsbt.log.noformat=true -Divy.default.ivy.user.dir="$SBT_USER_HOME_ABSOLUTE/.ivy2" -Dsbt.global.base="$SBT_USER_HOME_ABSOLUTE" -jar "$SBT_BINDIR"/$SBT_JAR $SBT_TASKS 2>&1 | sed -u 's/^/ /'
if [ "${PIPESTATUS[*]}" != "0 0" ]; then
echo " ! Failed to build app with sbt"
exit 1
Expand All @@ -136,12 +138,8 @@ echo 'export PATH="/app/.jdk/bin:$PATH"' >> $PROFILE_PATH

# repack cache
mkdir -p $CACHE_DIR
for DIR in $CACHED_DIRS ; do
rm -rf $CACHE_DIR/$DIR
mkdir -p $CACHE_DIR/$DIR
if [ -d $DIR ] ; then
cp -r $DIR/. $CACHE_DIR/$DIR
fi
for DIR in $CACHED_DIRS; do
cache_copy $DIR $BUILD_DIR $CACHE_DIR
done

# drop useless directories from slug for play only
Expand All @@ -161,3 +159,6 @@ if is_play $BUILD_DIR ; then
rm -rf $BUILD_DIR/target/resolution-cache
fi
fi

# Move compiled app back to where Heroku expects it
mv $BUILD_DIR $APP_BUILD_DIR
24 changes: 0 additions & 24 deletions opt/sbt-0.11.0-RC1.boot.properties

This file was deleted.

24 changes: 0 additions & 24 deletions opt/sbt-0.11.0.boot.properties

This file was deleted.

20 changes: 0 additions & 20 deletions opt/sbt-0.11.1.boot.properties

This file was deleted.

20 changes: 0 additions & 20 deletions opt/sbt-0.11.2.boot.properties

This file was deleted.

20 changes: 0 additions & 20 deletions opt/sbt-0.11.3.boot.properties

This file was deleted.

20 changes: 0 additions & 20 deletions opt/sbt-0.12.0.boot.properties

This file was deleted.

20 changes: 0 additions & 20 deletions opt/sbt-0.12.1.boot.properties

This file was deleted.

20 changes: 0 additions & 20 deletions opt/sbt-0.12.2.boot.properties

This file was deleted.

20 changes: 0 additions & 20 deletions opt/sbt-0.12.3.boot.properties

This file was deleted.

20 changes: 0 additions & 20 deletions opt/sbt-0.12.4.boot.properties

This file was deleted.

22 changes: 0 additions & 22 deletions opt/sbt-0.13.0.boot.properties

This file was deleted.

Loading

0 comments on commit f241be5

Please sign in to comment.