Skip to content

Commit

Permalink
Use Heroku's cache for downloaded jemalloc binaries
Browse files Browse the repository at this point in the history
GitHub's releases service recently had an issue where downloads were
failing. This attempts to fix two main issues: resilience for deploys
and improved error messages.

Using Heroku's cache we should only need to download each version once.
This will allow deploys should GitHub have issues in the future.

Before this change, if there was an error downloading the bundle then
the buildpack would fail with an error about bzip file formats. This now
checks the http status code and prints a more useful error should it
fail.

Fixes #13
  • Loading branch information
gaffneyc committed May 8, 2020
1 parent 3e369e3 commit c019bcd
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c019bcd

Please sign in to comment.