From a2ee94a8fbce1e54f533939ad8f37543f2dc5007 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 4 Feb 2016 22:02:24 -0500 Subject: [PATCH 01/14] first pass at new collectstatic logic --- bin/steps/collectstatic | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index 7ed9f42..409c81e 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -6,30 +6,27 @@ MANAGE_FILE=$(find . -maxdepth 3 -type f -name 'manage.py' -printf '%d\t%P\n' | MANAGE_FILE=${MANAGE_FILE:-fakepath} [ -f .heroku/collectstatic_disabled ] && DISABLE_COLLECTSTATIC=1 +pip-grep -s requirements.txt django Django && DJANGO_INSTALLED=1 bpwatch start collectstatic -if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ]; then +if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALLED" ]; then set +e echo "-----> Preparing static assets" - # Check if collectstatic is configured properly. - python $MANAGE_FILE collectstatic --dry-run --noinput &> /dev/null && RUN_COLLECTSTATIC=true - # Compile assets if collectstatic appears to be kosher. - if [ "$RUN_COLLECTSTATIC" ]; then + echo " Running collectstatic..." + python $MANAGE_FILE collectstatic --noinput 2>&1 | sed '/^Copying/d;/^$/d;/^ /d' | indent - echo " Running collectstatic..." - python $MANAGE_FILE collectstatic --noinput 2>&1 | sed '/^Copying/d;/^$/d;/^ /d' | indent + # Display a warning if collectstatic failed. + [ $? -ne 0 ] && { + 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" + 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 + set -e echo fi From b97a104ad6ff1d81a5e9da8527dd3a2341325d6e Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 4 Feb 2016 23:05:38 -0500 Subject: [PATCH 02/14] better messaging --- bin/steps/collectstatic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index 409c81e..54a9112 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -13,7 +13,7 @@ bpwatch start collectstatic if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALLED" ]; then set +e - echo "-----> Preparing static assets" + echo "-----> Preparing static assets with 'collectstatic'." echo " Running collectstatic..." python $MANAGE_FILE collectstatic --noinput 2>&1 | sed '/^Copying/d;/^$/d;/^ /d' | indent From d46e0efc166cef6efaac798683763e7f8e17d1c4 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 4 Feb 2016 23:05:56 -0500 Subject: [PATCH 03/14] sub-env now has a few python variables, just in case. --- bin/utils | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/utils b/bin/utils index 3655142..ff93b53 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 From 359a3b0d613f31dd315f69346b00a331cbb439ae Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 4 Feb 2016 23:20:40 -0500 Subject: [PATCH 04/14] collectstatic improvements. --- bin/steps/collectstatic | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index 54a9112..c2856d8 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -1,21 +1,35 @@ #!/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 + +# Ensure that Django is explicitily specified in requirments.txt pip-grep -s requirements.txt django Django && DJANGO_INSTALLED=1 -bpwatch start collectstatic +bpwatch start collectstatic # metrics collection if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALLED" ]; then set +e echo "-----> Preparing static assets with 'collectstatic'." - echo " Running collectstatic..." + # Run collectstatic, cleanup some of the noisy output. python $MANAGE_FILE collectstatic --noinput 2>&1 | sed '/^Copying/d;/^$/d;/^ /d' | indent # Display a warning if collectstatic failed. @@ -23,6 +37,16 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALL 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 + fi + + # Abort the build. exit 1 } @@ -30,4 +54,4 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALL echo fi -bpwatch stop collectstatic +bpwatch stop collectstatic # metrics collection From b0568b5f90628b4bd60b72ad907baf9a8ad7bc85 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 4 Feb 2016 23:25:41 -0500 Subject: [PATCH 05/14] PIPESTATUS --- bin/steps/collectstatic | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index c2856d8..fea3258 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -31,9 +31,12 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALL # Run collectstatic, cleanup some of the noisy output. python $MANAGE_FILE collectstatic --noinput 2>&1 | sed '/^Copying/d;/^$/d;/^ /d' | indent + COLLECTSTATIC_STATUS="${PIPESTATUS[0]}" + + set -e # Display a warning if collectstatic failed. - [ $? -ne 0 ] && { + [ $COLLECTSTATIC_STATUS -ne 0 ] && { 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" @@ -50,7 +53,6 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALL exit 1 } - set -e echo fi From 031c9d576f4fd27cca22702dff765aea58de55c7 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 4 Feb 2016 23:32:45 -0500 Subject: [PATCH 06/14] cleanup output --- bin/steps/collectstatic | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index fea3258..6c30c1b 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -27,7 +27,7 @@ bpwatch start collectstatic # metrics collection if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALLED" ]; then set +e - echo "-----> Preparing static assets with 'collectstatic'." + echo "-----> Preparing static assets with 'collectstatic'" # Run collectstatic, cleanup some of the noisy output. python $MANAGE_FILE collectstatic --noinput 2>&1 | sed '/^Copying/d;/^$/d;/^ /d' | indent @@ -37,6 +37,7 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALL # 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" From 53eee452eb1be82073d418d1f3ccdabf2c10ed4b Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 4 Feb 2016 23:33:59 -0500 Subject: [PATCH 07/14] --traceback --- bin/steps/collectstatic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index 6c30c1b..cef4979 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -30,7 +30,7 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALL echo "-----> Preparing static assets with '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 COLLECTSTATIC_STATUS="${PIPESTATUS[0]}" set -e From 7f475977b51e2943758a4b2d3be26c290b228a96 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 4 Feb 2016 23:35:13 -0500 Subject: [PATCH 08/14] debugging --- bin/steps/collectstatic | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index cef4979..71e7235 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -31,6 +31,8 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALL # 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 COLLECTSTATIC_STATUS="${PIPESTATUS[0]}" set -e From 8615bf52720be5f30bdc7935e12f6bb282aba8c7 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 4 Feb 2016 23:36:19 -0500 Subject: [PATCH 09/14] debug --- bin/steps/collectstatic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index 71e7235..9766c0f 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -32,7 +32,7 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALL # 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 + python $MANAGE_FILE collectstatic | indent COLLECTSTATIC_STATUS="${PIPESTATUS[0]}" set -e From b6607f0f42d6503d1fc1e88574110716a85f75d3 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 4 Feb 2016 23:37:44 -0500 Subject: [PATCH 10/14] debug --- bin/steps/collectstatic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index 9766c0f..20ffe76 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -32,7 +32,7 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALL # 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 | indent + python $MANAGE_FILE collectstatic 2>&1 | indent COLLECTSTATIC_STATUS="${PIPESTATUS[0]}" set -e From 1e8ad56b0f8258af3d51a6e97d9add2ab606a1fe Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 4 Feb 2016 23:43:30 -0500 Subject: [PATCH 11/14] sed debug --- bin/steps/collectstatic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index 20ffe76..9ab29f5 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -32,7 +32,7 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALL # 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 | indent + python $MANAGE_FILE collectstatic 2>&1 | sed '/^Copying/d;/^$/d' | indent COLLECTSTATIC_STATUS="${PIPESTATUS[0]}" set -e From e5ac89c4df9ac3cb05a91235e58640d0a5663faf Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 4 Feb 2016 23:56:18 -0500 Subject: [PATCH 12/14] indent env output --- bin/steps/collectstatic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/steps/collectstatic b/bin/steps/collectstatic index 9ab29f5..4b095fe 100755 --- a/bin/steps/collectstatic +++ b/bin/steps/collectstatic @@ -49,7 +49,7 @@ if [ ! "$DISABLE_COLLECTSTATIC" ] && [ -f "$MANAGE_FILE" ] && [ "$DJANGO_INSTALL echo echo "****** Collectstatic environment variables:" echo - env + env | indent fi # Abort the build. From 669f0b0e2a7ad7f6e0cdf76db5019d01b95c3cdd Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 4 Feb 2016 23:56:29 -0500 Subject: [PATCH 13/14] unset extra environment variables --- bin/compile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/compile b/bin/compile index 26930bb..f932cb5 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 From 9a024b85950eeedd364e2ce26307fd18aee87dae Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 5 Feb 2016 00:01:36 -0500 Subject: [PATCH 14/14] Update Readme.md --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index a0d4830..6849c86 100644 --- a/Readme.md +++ b/Readme.md @@ -1,4 +1,4 @@ -# Heroku buildpack: Python +# Heroku Buildpack: Python ![python-banner](https://cloud.githubusercontent.com/assets/51578/8914205/ecf2047c-346b-11e5-98c5-42547f9f4410.jpg) This is a [Heroku buildpack](http://devcenter.heroku.com/articles/buildpacks) for Python apps, powered by [pip](http://www.pip-installer.org/). @@ -42,7 +42,7 @@ Specify a Runtime You can also provide arbitrary releases Python with a `runtime.txt` file. $ cat runtime.txt - python-3.5.0 + python-3.5.1 Runtime options include: