diff --git a/bin/compile b/bin/compile index 6ba0a39..981fc99 100755 --- a/bin/compile +++ b/bin/compile @@ -15,16 +15,45 @@ if [ -f $ENV_DIR/JEMALLOC_VERSION ]; then version=$(cat $ENV_DIR/JEMALLOC_VERSION) fi -url="https://github.com/gaffneyc/heroku-buildpack-jemalloc/releases/download/$STACK/jemalloc-$version.tar.bz2" +# dest is the path in the application that jemalloc will be extracted to. dest="$BUILD_DIR/vendor/jemalloc" -echo "-----> Vendoring jemalloc $version" -echo " Fetching $url" +# bundle is the full path to the cached jemalloc binaries for this version. +bundle=$CACHE_DIR/jemalloc/$version + +function download_jemalloc() { + url="https://github.com/gaffneyc/heroku-buildpack-jemalloc/releases/download/$STACK/jemalloc-$version.tar.bz2" + + # Disable exit on command failure so we can provide better error messages + set +e + + echo " Fetching $url" + status=$(curl -sL -f -w "%{http_code}" -o /tmp/jemalloc.tar.bz2 $url) + + if [[ $status -ge 300 ]]; then + echo " ! jemalloc: Server returned HTTP $status" + exit 1 + fi + + # Reenable exit on failure + set -e + + mkdir -p $bundle + tar -xj -f /tmp/jemalloc.tar.bz2 -C $bundle +} + +echo "-----> jemalloc: Vendoring $version" + +# Check if this version of jemalloc is in the cache and download it if it +# doesn't exist. +if [[ ! -f $bundle ]]; then + download_jemalloc +fi mkdir -p $dest -curl -sL $url | tar -C $dest -xj +cp -r $bundle -T $dest/ -echo "-----> Building runtime environment" +echo "-----> jemalloc: Building runtime environment" mkdir -p $BUILD_DIR/.profile.d cat <<'EOF' > $BUILD_DIR/.profile.d/jemalloc.sh