Heroku deployment - UB-ES-2021-A4/Booksy GitHub Wiki

Frontend

Everytime we change the frontend we need to do the following steps to show them on heroku:

$ npm run build

This will generate a build folder. Inside this folder you will find a folder called static. Copy the static folder to the root of the project (It should be on the same level as manage.py and requirements.txt)

Now create a folder called templates, copy to this folder the index.html file that you will find on your build folder.

Database

Every time we change the database we need to perform the following operations to upload it to heroku.

Go to our heroku project and click on heroku postgres below Installed add-ons label. Go to Settings and on Database Credentials click on View Credentials at the right.

We need to modify booksy/setting.py:

You will find this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': '',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

Copy from heroku's databes credentials to settings.py:

  • Database -> Name
  • User -> USER
  • Port -> PORT
  • Password -> PASSWORD
  • Host -> HOST

It should look something like this (an example with fake credentials):

   DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'a7daijgja92ms',
            'USER': 'asfasdfsd',
            'PASSWORD': 'sdsd89889099sadc909999asd8990asc0sa0d9a909asdasd',
            'HOST': 'a2-b7-d8.usa-west-1amazon.com-',
            'PORT': '2345',
        }
    }

DISCLAIMER! DO NOT upload heroku's database credentials to github!!!!! LOCALLY (NOT IN HEROKU):

  • python manage.py makemigrations accounts
  • python manage.py migrate

How to deploy on heroku:

First of all we will need the heroku client, if u don't have it download it here: https://devcenter.heroku.com/articles/heroku-cli#download-and-install

Once installed you have to log in our account of heroku (https://github.com/UB-ES-2021-A4/Booksy/issues/11#issue-1027456362) with the next command:

$ heroku login

After you put the credentials link your local repository to heroku:

$ heroku git:remote -a booksy-es2021

Now you can start the deployment:

  • $ git add *
  • $ git commit -a -m "your-commit-message"
  • $ git push heroku HEAD:master

The application should now be deployed.

Open it with:

heroku open -a booksy-es2021

LOGS

For debugging you can check the logs of heroku with:

$ heroku logs -a booksy-es2021

Notes

You can check deployment branch as an example of how it should look like.

We are using heroku's free plan, which have the following limitations:

  • The application “sleeps” after 30 minutes of inactivity. The first access after it might be slow.
  • The free PostgreSQL database has a limitation of 10K rows.
  • Heroku deploys in https protocol, instead of http. So all the links must be changed to https protocol