#!/bin/bash -e # Tasks run by the Heroku Python buildpack after the compile step. # Make the current Git revision accessible at /revision.txt echo $SOURCE_VERSION > ui/revision.txt # Create a `dist/` directory containing built/minified versions of the `ui/` assets. # Uses the node binaries/packages installed by the nodejs buildpack previously. yarn run build # Generate gzipped versions of files that would benefit from compression, that # WhiteNoise can then serve in preference to the originals. This is required # since WhiteNoise's Django storage backend only gzips assets handled by # collectstatic, and so does not affect files in the `dist/` directory. python -m whitenoise.compress dist # The post_compile script is run in a sub-shell, so we need to source the # buildpack's utils script again, so we can use set-env/set-default-env: # https://github.com/heroku/heroku-buildpack-python/blob/master/bin/utils source $BIN_DIR/utils # Add environment variables to the profile script run on Dyno startup. # Only variables that are rarely changed and not site-specific should # be set here. Set everything else using Heroku's CLI / dashboard. set-env IS_HEROKU 1 # Override the hostname that is displayed in New Relic, so the Dyno name # (eg "web.1") is shown, rather than "Dynamic Hostname". $DYNO is quoted # so that it's expanded at runtime on each dyno, rather than now. set-env NEW_RELIC_PROCESS_HOST_DISPLAY_NAME '$DYNO' # Remove nodejs files to reduce slug size (and avoid environment variable # pollution from the nodejs profile script), since they are no longer # required once `yarn run build` has run. The buildpack cache will still # contain them, so this doesn't slow down the next slug compile. rm -r .heroku/node/ rm -r .heroku/yarn/ rm -r .profile.d/nodejs.sh rm -r node_modules/