diff --git a/bin/compile b/bin/compile index 26930bb802d45c8c9dc0da0290bc1d9f58d2509f..f932cb56dda02db73778bfa168e092f58bbe1e95 100755 --- a/bin/compile +++ b/bin/compile @@ -48,6 +48,8 @@ export PATH=$PATH:$ROOT_DIR/vendor/pip-pop # Sanitizing environment variables. unset GIT_DIR PYTHONHOME PYTHONPATH LD_LIBRARY_PATH LIBRARY_PATH +unset RECEIVE_DATA SOURCE_VERSION RUN_KEY BUILD_INFO DEPLOY +unset LOG_TOKEN DYNO CYTOKINE_LOG_FILE GEM_PATH bpwatch init $LOGPLEX_KEY bpwatch build python $BUILDPACK_VERSION $REQUEST_ID diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index 7ed9f4224906448bf9f65d525096689fcdbefda1..4b095fefe53c9227565fc4d56b682eaf90c65602 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -1,36 +1,62 @@ #!/usr/bin/env bash +# Django Collectstatic runner. If you have Django installed, collectstatic will +# automatically be executed as part of the build process. If collectstatic +# fails, your build fails. + +# This functionality will only activate if Django is in requirements.txt. + +# Runtime arguments: +# - $DISABLE_COLLECTSTATIC: disables this functionality. +# - $DEBUG_COLLECTSTATIC: upon failure, print out environment variables. + source $BIN_DIR/utils +# Location of 'manage.py', if it exists. MANAGE_FILE=$(find . -maxdepth 3 -type f -name 'manage.py' -printf '%d\t%P\n' | sort -nk1 | cut -f2 | head -1) MANAGE_FILE=${MANAGE_FILE:-fakepath} +# Legacy file-based support for $DISABLE_COLLECTSTATIC [ -f .heroku/collectstatic_disabled ] && DISABLE_COLLECTSTATIC=1 -bpwatch start collectstatic +# Ensure that Django is explicitily specified in requirments.txt +pip-grep -s requirements.txt django Django && DJANGO_INSTALLED=1 -if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ]; then - set +e +bpwatch start collectstatic # metrics collection - echo "-----> Preparing static assets" - # Check if collectstatic is configured properly. - python $MANAGE_FILE collectstatic --dry-run --noinput &> /dev/null && RUN_COLLECTSTATIC=true +if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALLED" ]; then + set +e - # Compile assets if collectstatic appears to be kosher. - if [ "$RUN_COLLECTSTATIC" ]; then + echo "-----> Preparing static assets with 'collectstatic'" - echo " Running collectstatic..." - python $MANAGE_FILE collectstatic --noinput 2>&1 | sed '/^Copying/d;/^$/d;/^ /d' | indent + # Run collectstatic, cleanup some of the noisy output. + python $MANAGE_FILE collectstatic --noinput --traceback 2>&1 | sed '/^Copying/d;/^$/d;/^ /d' | indent + echo + python $MANAGE_FILE collectstatic 2>&1 | sed '/^Copying/d;/^$/d' | indent + COLLECTSTATIC_STATUS="${PIPESTATUS[0]}" + + set -e + + # Display a warning if collectstatic failed. + [ $COLLECTSTATIC_STATUS -ne 0 ] && { + echo + echo " ! Error while runnning '$ python $MANAGE_FILE collectstatic --noinput'." + echo " See traceback above for more details." + echo " More info: http://devcenter.heroku.com/articles/django-assets" + + # Additionally, dump out the environment, if debug mode is on. + if [ "$DEBUG_COLLECTSTATIC" ]; then + echo + echo "****** Collectstatic environment variables:" + echo + env | indent + fi + + # Abort the build. + exit 1 + } - [ $? -ne 0 ] && { - echo " ! Error running 'manage.py collectstatic'. More info:" - echo " http://devcenter.heroku.com/articles/django-assets" - } - else - echo " Collectstatic configuration error. To debug, run:" - echo " $ heroku run python $MANAGE_FILE collectstatic --noinput" - fi echo fi -bpwatch stop collectstatic +bpwatch stop collectstatic # metrics collection diff --git a/bin/utils b/bin/utils index 365514288049e67c7c3c3e4414082c00efa1ebf8..ff93b53c1b15d229481fd5fe585b4569edc9b557 100755 --- a/bin/utils +++ b/bin/utils @@ -88,6 +88,10 @@ sub-env() { WHITELIST=${2:-''} BLACKLIST=${3:-'^(GIT_DIR|PYTHONHOME|LD_LIBRARY_PATH|LIBRARY_PATH|PATH)$'} + # Python-specific variables. + export PYHONHOME=$BUILD_DIR/.heroku/python + export PYTHONPATH=$BUILD_DIR/ + ( if [ -d "$ENV_DIR" ]; then for e in $(ls $ENV_DIR); do