Skip to content

Commit

Permalink
Add post_compile hook for Heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanw committed Mar 13, 2014
1 parent fcd7852 commit 5d7e57f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Empty file added .heroku/collectstatic_disabled
Empty file.
59 changes: 59 additions & 0 deletions bin/post_compile
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
set -eo pipefail

# The post_compile hook is run by heroku-buildpack-python

indent() {
RE="s/^/ /"
[ $(uname) == "Darwin" ] && sed -l "$RE" || sed -u "$RE"
}

echo "-----> In post-compile hook"

if [ ! -d $TARGET_DIR/gettext ]; then
echo "-----> Installing gettext msgfmt..."

GETTEXT_CHECKSUM="ceZfT0KqGBZyr52s/9yULR3vsmXPS5HmUcs+dup/DXg="
GETTEXT_TARBALL=https://s3-eu-west-1.amazonaws.com/midgard-heroku/gettext.tar.gz

# tempdir="$( mktemp -t gettext_XXXX )"
# rm -rf $tempdir
# mkdir -p $tempdir
pushd $BUILD_DIR >/dev/null
rm -f tmp-gettext.tar.gz

curl -s -L -o tmp-gettext.tar.gz "$GETTEXT_TARBALL"
if [ "$GETTEXT_CHECKSUM" != "$(openssl sha -sha256 -binary tmp-gettext.tar.gz | openssl base64)" ]; then
echo "Checksum DOES NOT match. Gettext will not be installed."
exit 1
fi
tar -zxvf tmp-gettext.tar.gz > /dev/null
rm tmp-gettext.tar.gz
popd >/dev/null

export PATH=$BUILD_DIR/gettext/bin:$PATH

# ln -s -f ../../vendor/gettext/bin/msgfmt .heroku/python/bin/msgfmt

echo "-----> done installing gettext msgfmt"
fi


MANAGE_FILE=$(find . -maxdepth 3 -type f -name 'manage.py' | head -1)
MANAGE_FILE=${MANAGE_FILE:2}

echo "-----> Compiling translation files"
python "$MANAGE_FILE" compilemessages 2>&1 | indent
rm -rf .heroku/vendor/gettext/

echo "-----> Collecting static files"
python "$MANAGE_FILE" collectstatic --noinput 2>&1 |
sed '/^Copying/d;/^$/d;/^ /d' |
indent

if [ "$DJANGO_COMPRESS_OFFLINE" = "true" ]; then
echo "-----> Compressing static files"
python "$MANAGE_FILE" compress 2>&1 | indent
fi

echo "-----> Post-compile done"

0 comments on commit 5d7e57f

Please sign in to comment.