2015-09-18 20:20:48 +03:00
Deployment on Heroku
====================
2015-09-19 00:26:29 +03:00
.. index :: Heroku
2021-11-25 00:10:26 +03:00
Script
------
2019-04-02 12:33:38 +03:00
2017-02-13 21:41:01 +03:00
Run these commands to deploy the project to Heroku:
2015-09-18 20:20:48 +03:00
.. code-block :: bash
2021-11-26 18:41:50 +03:00
heroku create --buildpack heroku/python
2015-09-18 20:20:48 +03:00
2024-09-18 00:46:45 +03:00
# Note: this is not a free plan
heroku addons:create heroku-postgresql:essential-0
2018-11-17 12:59:38 +03:00
# On Windows use double quotes for the time zone, e.g.
# heroku pg:backups schedule --at "02:00 America/Los_Angeles" DATABASE_URL
2015-09-18 20:20:48 +03:00
heroku pg:backups schedule --at '02:00 America/Los_Angeles' DATABASE_URL
heroku pg:promote DATABASE_URL
2023-01-25 15:50:41 +03:00
heroku addons:create heroku-redis:mini
2015-09-18 20:20:48 +03:00
2021-11-25 00:10:26 +03:00
# Assuming you chose Mailgun as mail service (see below for others)
2018-05-27 22:36:13 +03:00
heroku addons:create mailgun:starter
heroku config:set PYTHONHASHSEED=random
2019-06-14 23:37:58 +03:00
2018-03-05 20:30:13 +03:00
heroku config:set WEB_CONCURRENCY=4
2019-06-14 23:37:58 +03:00
2018-05-27 22:36:13 +03:00
heroku config:set DJANGO_DEBUG=False
heroku config:set DJANGO_SETTINGS_MODULE=config.settings.production
heroku config:set DJANGO_SECRET_KEY="$(openssl rand -base64 64)"
2019-06-14 23:37:58 +03:00
# Generating a 32 character-long random string without any of the visually similar characters "IOl01":
2018-05-14 10:09:24 +03:00
heroku config:set DJANGO_ADMIN_URL="$(openssl rand -base64 4096 | tr -dc 'A-HJ-NP-Za-km-z2-9' | head -c 32)/"
2019-06-14 23:37:58 +03:00
2018-06-28 15:00:53 +03:00
# Set this to your Heroku app url, e.g. 'bionic-beaver-28392.herokuapp.com'
heroku config:set DJANGO_ALLOWED_HOSTS=
2019-06-14 23:37:58 +03:00
2018-06-28 15:00:53 +03:00
# Assign with AWS_ACCESS_KEY_ID
heroku config:set DJANGO_AWS_ACCESS_KEY_ID=
2019-06-14 23:37:58 +03:00
2018-06-28 15:00:53 +03:00
# Assign with AWS_SECRET_ACCESS_KEY
heroku config:set DJANGO_AWS_SECRET_ACCESS_KEY=
2019-06-14 23:37:58 +03:00
2018-06-28 15:00:53 +03:00
# Assign with AWS_STORAGE_BUCKET_NAME
heroku config:set DJANGO_AWS_STORAGE_BUCKET_NAME=
2015-09-18 20:20:48 +03:00
2024-04-01 21:11:25 +03:00
git push heroku main
2018-05-27 22:36:13 +03:00
2015-09-18 20:20:48 +03:00
heroku run python manage.py createsuperuser
2018-05-27 22:36:13 +03:00
heroku run python manage.py check --deploy
2015-09-18 20:20:48 +03:00
heroku open
2019-03-27 00:20:56 +03:00
2021-11-25 00:10:26 +03:00
Notes
-----
Email Service
+++++++++++++
The script above assumes that you've chose Mailgun as email service. If you want to use another one, check the `documentation for django-anymail <https://anymail.readthedocs.io> `_ to know which environment variables to set. Heroku provides other `add-ons for emails <https://elements.heroku.com/addons#email-sms> `_ (e.g. Sendgrid) which can be configured with a similar one line command.
2019-03-27 00:20:56 +03:00
2019-03-27 00:36:38 +03:00
.. warning ::
2024-10-07 22:25:38 +03:00
.. include :: ../includes/mailgun.rst
2019-03-27 00:36:38 +03:00
2021-11-25 00:10:26 +03:00
Heroku & Docker
+++++++++++++++
Although Heroku has some sort of `Docker support`_ , it's not supported by cookiecutter-django.
We invite you to follow Heroku documentation about it.
.. _Docker support: https://devcenter.heroku.com/articles/build-docker-images-heroku-yml
2019-03-27 00:36:38 +03:00
2019-03-27 00:20:56 +03:00
Optional actions
----------------
Celery
++++++
Celery requires a few extra environment variables to be ready operational. Also, the worker is created,
it's in the `` Procfile `` , but is turned off by default:
.. code-block :: bash
# Scale dyno to 1 instance
heroku ps:scale worker=1
Sentry
++++++
If you're opted for Sentry error tracking, you can either install it through the `Sentry add-on`_ :
.. code-block :: bash
heroku addons:create sentry:f1
Or add the DSN for your account, if you already have one:
.. code-block :: bash
heroku config:set SENTRY_DSN=https://xxxx@sentry.io/12345
.. _Sentry add-on: https://elements.heroku.com/addons/sentry
2023-01-29 15:12:12 +03:00
Gulp or Webpack
+++++++++++++++
2019-03-27 00:20:56 +03:00
2023-01-29 15:12:12 +03:00
If you've opted for Gulp or Webpack as frontend pipeline, you'll most likely need to setup
2019-03-27 00:20:56 +03:00
your app to use `multiple buildpacks`_ : one for Python & one for Node.js:
.. code-block :: bash
heroku buildpacks:add --index 1 heroku/nodejs
At time of writing, this should do the trick: during deployment,
the Heroku should run `` npm install `` and then `` npm build `` ,
2023-01-29 15:12:12 +03:00
which run the SASS compilation & JS bundling.
2019-03-27 00:20:56 +03:00
If things don't work, please refer to the Heroku docs.
2023-01-25 15:50:41 +03:00
.. _multiple buildpacks: https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app