๐Ÿš€Deploy

Here are the steps to deploy your application to Heroku, a popular cloud platform service that enables developers to build, run, and operate applications entirely in the cloud.

Even though this guide is specific to deploying to Heroku, you can choose any other provider you prefer. Fortunately, there are quite a few options out there. Through customer feedback, Heroku has proven to be amongst the easiest to setup (especially for beginners).

1. Create a Heroku App

Firstly, go to https://heroku.com/ and create an account.

Run the following command to create a new app within Heroku, where my-app-name is the unique name for your app:

heroku apps:create my-app-name

2. Environment Variables

In Heroku's dashboard, under your app's settings, use 'Reveal config vars' to add your production environment variables. These are key-value pairs that your application will use in production.

In order for your app to run smoothly, you'll need to include at least the following variables:

3. Background Workers (Redis)

In order to have workers running you need to setup Redis, which provides an in-memory data structure store, used as a database, cache, and message broker.

Run the following command to add the Redis addon to your Heroku app

heroku addons:create heroku-redis -a my-app-name

Remember to replace my-app-name with the name you used in step 1

4. Database Setup

Like for the local setup, you'll need to create a Postgres database for your app to run as expected.

Heroku Postgres is a managed SQL database service provided by Heroku.

To create a Postgres database in Heroku run the following command:

make sure you chose your desired database size before running the command. The sample command below, specifies the basic tier. You can see the list Heroku Postgres database tiers here.

heroku addons:create heroku-postgresql:basic -a my-app-name

5. Deploy

Heroku offers a variety of options for how to deploy your app.

If you choose to use Github to store your code, then the Github deployment method will be the most convenient for you.

Alternatively, you can deploy your app manually using the following Heroku CLI command:

git push heroku master

Take a look at the Procfile within the Ready SaaS repo. This file specifies the commands that are executed by the app on startup (on each deployment). Docs about the Heroku Procfile

6. Create an admin user

This command runs Django's createsuperuser management command on Heroku, allowing you to create an admin user to access the Django admin dashboard.

heroku run python manage.py createsuperuser -a my-app-name

Now you can navigate to your app's url, and add /admin to the url path to access your admin dashboard.

You can get your Heroku App's url by clicking this button:

Within your admin dashboard, make sure to create all the necessary objects required to run your app. If you're running the project "as is", make sure to create subscription plans for the landing page to load without errors.

7. Setup Background Workers

For your background tasks to work in your production Heroku app, you need to spin up a Heroku Dyno for the worker and for the celery beat. These commands scale up your worker and Celery beat dynos to ensure that background tasks and periodic tasks are handled properly in your production environment:

heroku ps:scale worker=1 -a my-app-name
heroku ps:scale celery_beat=1 -a my-app-name

What's great about Heroku Dynos is that you can scale to any amount needed by your site.

Last updated