Collection of snippets that solve certain problems while deploying Django apps to Heroku
Collection of snippets and scripts that solve certain problems when deploying Django apps to Heroku.
Scripts in the
bindirectory are post-compile hooks that are invoked by the
heroku-buildpack-python's compile step. You can install them by copying the
bindirectory into the root directory of your Heroku application repository.
Heroku provides a bunch of different buildpacks that target many popular platforms like Python, Ruby, NodeJS and Java web apps and backends. While this is great and allows you to deploy virtually anything with a simple git command, the out-of-the-box solutions offer a limited set of utilities that are available during the Slug compilation phase. In particular no NodeJS, NPM or LESS Compiler is available in the
heroku-buildpack-python. This means that there is no straightforward way of compiling
.lessstylesheets during the app deployment.
Fortunately, the Python buildpack provides hooks for running pre-compile and post-compile scripts. This can be used for customizing the compilation step and running additional commands without the necessity of maintaining a separate fork of Heroku's buildpack. The only thing you need to do is to create a proper
bin/post_compilebash script in the root directory of your application.
manage.py compresscommands in your Django application:
Just copy them over to your app reposiory and have your Less stylesheets compiled with an assets compressor like Django Compressor.
Note: the empty
/.heroku/collectstatic_disabledfile deactivates the default collectstatic build step that is part of the Heroku's buildpack. This will prevent the build script from doing unnecessary work that is already handled by the above scripts.
A note on hosting static files on Amazon S3. Remember to enable the environment variables if you are using django-storages and uploading static assets to S3:
heroku labs:enable user-env-compile
django-herokuify is a Django settings helper that makes is very easy to configure database, cache, storage, email and other common services for your Django project running on Heroku:
from herokuify.common import * # Common settings, SSL proxy header from herokuify.aws import * # AWS access keys as configured in env from herokuify.mail.mailgun import * # Email settings for Mailgun add-on
DATABASES = herokuify.get_db_config() # Database config CACHES = herokuify.get_cache_config() # Cache config for Memcache/MemCachier
See the project page for more information.
Django Modern Template is a project template for easy bootstrapping a Django project that can be deployed on Heroku.
Heroku caches Python virtual environment and all installed packages between project deploys.
CLEAN_VIRTUALENVflag has been removed from the buildpack, currently the only way to clean app cache is by changing the runtime.