Skip to content

Instantly share code, notes, and snippets.

@JorgenEvens
Last active December 20, 2015 21:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JorgenEvens/6201280 to your computer and use it in GitHub Desktop.
Save JorgenEvens/6201280 to your computer and use it in GitHub Desktop.
Test the build using a custom heroku buildpack on your own machine.
#!/bin/sh
if [ -z $1 ]; then
echo "Usage: $0 project-location"
exit 1
fi
if [ ! -d $1 ]; then
echo "Could not find your project"
exit 2
fi
if [ -z $BUILDPACK_URL ]; then
echo "No buildpack specified, can only test custom buildpacks"
exit 3;
fi
# Setup directories
PROJECT="$1"
BASE=`mktemp`
PROJECT_TMP="$BASE/project"
BUILDPACK_TMP="$BASE/buildpack"
if [ -z "$CACHE_TMP" ]; then
CACHE_TMP="$BASE/cache"
fi
# Remove the temporary file, as we want a directory
rm -R "$BASE"
# Get buildpack
mkdir -p "$BUILDPACK_TMP"
git clone "${BUILDPACK_URL}" "$BUILDPACK_TMP"
# Create a copy of the project
cp -R "$PROJECT" "$PROJECT_TMP"
# Remove repository information
rm -Rf "$PROJECT_TMP/.git"
# Execute detection
APP=$(${BUILDPACK_TMP}/bin/detect "$PROJECT_TMP")
if [ $? -gt 0 ]; then
echo "No app detected"
exit 4
fi
echo "Detected $APP application"
# Execute buildpack
${BUILDPACK_TMP}/bin/compile "$PROJECT_TMP" "$CACHE_TMP"
# Create an archive of the result
tar -caf "build-$(date +%d-%m-%y_%H-%M).tar.gz" -C "$BASE" "$(basename $PROJECT_TMP)"
rm -Rf "$BASE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment