Skip to content
Snippets Groups Projects
Commit 581177b2 authored by Kenneth Reitz's avatar Kenneth Reitz
Browse files

Merge pull request #273 from heroku/collectstatic

Collectstatic revamp
parents 3b35c2c2 669f0b0e
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,8 @@ export PATH=$PATH:$ROOT_DIR/vendor/pip-pop ...@@ -48,6 +48,8 @@ export PATH=$PATH:$ROOT_DIR/vendor/pip-pop
# Sanitizing environment variables. # Sanitizing environment variables.
unset GIT_DIR PYTHONHOME PYTHONPATH LD_LIBRARY_PATH LIBRARY_PATH 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 init $LOGPLEX_KEY
bpwatch build python $BUILDPACK_VERSION $REQUEST_ID bpwatch build python $BUILDPACK_VERSION $REQUEST_ID
......
#!/usr/bin/env bash #!/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 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=$(find . -maxdepth 3 -type f -name 'manage.py' -printf '%d\t%P\n' | sort -nk1 | cut -f2 | head -1)
MANAGE_FILE=${MANAGE_FILE:-fakepath} MANAGE_FILE=${MANAGE_FILE:-fakepath}
# Legacy file-based support for $DISABLE_COLLECTSTATIC
[ -f .heroku/collectstatic_disabled ] && DISABLE_COLLECTSTATIC=1 [ -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 bpwatch start collectstatic # metrics collection
set +e
echo "-----> Preparing static assets" if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALLED" ]; then
# Check if collectstatic is configured properly. set +e
python $MANAGE_FILE collectstatic --dry-run --noinput &> /dev/null && RUN_COLLECTSTATIC=true
# Compile assets if collectstatic appears to be kosher. echo "-----> Preparing static assets with 'collectstatic'"
if [ "$RUN_COLLECTSTATIC" ]; then
echo " Running collectstatic..." # Run collectstatic, cleanup some of the noisy output.
python $MANAGE_FILE collectstatic --noinput 2>&1 | sed '/^Copying/d;/^$/d;/^ /d' | indent 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 echo
fi fi
bpwatch stop collectstatic bpwatch stop collectstatic # metrics collection
...@@ -88,6 +88,10 @@ sub-env() { ...@@ -88,6 +88,10 @@ sub-env() {
WHITELIST=${2:-''} WHITELIST=${2:-''}
BLACKLIST=${3:-'^(GIT_DIR|PYTHONHOME|LD_LIBRARY_PATH|LIBRARY_PATH|PATH)$'} 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 if [ -d "$ENV_DIR" ]; then
for e in $(ls $ENV_DIR); do for e in $(ls $ENV_DIR); do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment