-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile
executable file
·154 lines (126 loc) · 5.09 KB
/
compile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir> <env-dir>
# fail fast
set -e
BP_DIR=$(cd $(dirname $0)/..; pwd) # absolute path
BIN_DIR=$BP_DIR/bin
OPT_DIR=$BP_DIR/opt
. $BIN_DIR/common
# parse args
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
# create default system.properties
if [ ! -f ${BUILD_DIR}/system.properties ]; then
echo "java.runtime.version=1.6" > ${BUILD_DIR}/system.properties
fi
# install JDK
javaVersion=$(detect_java_version ${BUILD_DIR})
echo -n "-----> Installing OpenJDK ${javaVersion}..."
install_java ${BUILD_DIR} ${javaVersion}
jdk_overlay ${BUILD_DIR}
echo "done"
# home directory from perspective of SBT; we rename
# it because otherwise the project root and $HOME
# are the same, and by default .sbt has a (different)
# meaning in those two places
SBT_USER_HOME=".sbt_home"
SBT_USER_HOME_ABSOLUTE="$BUILD_DIR/$SBT_USER_HOME"
# where we put the SBT binaries
SBT_BINDIR="$SBT_USER_HOME"/bin
# chdir as sbt expects
cd $BUILD_DIR
# unpack cache
CACHED_DIRS="$SBT_USER_HOME/.ivy2 $SBT_BINDIR target project/target project/boot"
for DIR in $CACHED_DIRS; do
cache_copy $DIR $CACHE_DIR $BUILD_DIR
done
# these are preliminary checks. actual version check happens below when attempting to download sbt boot.properties
if ! test -e project/build.properties; then
echo " ! Error, your scala project must include project/build.properties and define sbt.version"
echo " ! You must use a release verison of sbt, sbt.version=0.11.0 or greater"
exit 1
fi
if ! has_supported_sbt_version ${BUILD_DIR}; then
echo " ! Error, you have defined an unsupported sbt.version in project/build.properties"
echo " ! You must use a release verison of sbt, sbt.version=0.11.0 or greater"
exit 1
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.1/$SBT_JAR"
SBT_PROPS_URL="http://s3.amazonaws.com/heroku-jvm-langpack-scala/$SBT_PROPS"
## 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="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
fi
if [ ! -f "$SBT_BINDIR"/"$SBT_JAR" ]; then
mkdir -p "$SBT_BINDIR"
cd "$SBT_BINDIR"
## clean up any old versions
/bin/rm -f sbt sbt-launch-*.jar || true
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 "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
# copy in heroku sbt plugin
HEROKU_PLUGIN="HerokuPlugin.scala"
mkdir -p "$SBT_USER_HOME/.sbt/plugins"
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" -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
fi
PROFILE_PATH="$BUILD_DIR/.profile.d/scala.sh"
mkdir -p $(dirname $PROFILE_PATH)
echo 'export PATH="/app/.jdk/bin:$PATH"' >> $PROFILE_PATH
# repack cache
mkdir -p $CACHE_DIR
for DIR in $CACHED_DIRS; do
cache_copy $DIR $BUILD_DIR $CACHE_DIR
done
# drop useless directories from slug for play only
if is_play $BUILD_DIR ; then
if [ -d $SBT_USER_HOME/.ivy2 ]; then
echo "-----> Dropping ivy cache from the slug"
rm -rf $SBT_USER_HOME/.ivy2
fi
if [ -d $BUILD_DIR/project/boot ] ; then
echo "-----> Dropping project boot dir from the slug"
rm -rf $BUILD_DIR/project/boot
fi
if [ -d $BUILD_DIR/target ] ; then
echo "-----> Dropping compilation artifacts from the slug"
rm -rf $BUILD_DIR/target/scala-*
rm -rf $BUILD_DIR/target/streams
rm -rf $BUILD_DIR/target/resolution-cache
fi
fi
# Move compiled app back to where Heroku expects it
mv $BUILD_DIR $APP_BUILD_DIR