Deploying the app on Heroku - psvaiter/knoweak-api GitHub Wiki

Requirements

  • Heroku account
  • Heroku CLI installed
  • Python 3.6 and pipenv installed (pip install pipenv)

Create the app on Heroku

Open your terminal/console, go to your app directory and login on heroku.

> heroku login

Create the app on your Heroku account and push the source code.

> heroku create
> git push heroku master

Test your app trying to GET /version.

> curl https://your-app-name.herokuapp.com/version

Add a MySQL database server add-on of your choice

Here I chose JawsDB Kitefin plan.

> heroku addons:create jawsdb:kitefin

JawsDB will set a config var called JAWSDB_URL in your app. Set the config vars listed below with values present in JAWSDB_URL.

DB_HOST=
DB_PORT=
DB_USERNAME=
DB_PASSWORD=
DB_NAME=

You can use MySQL Workbench or other client to connect to the server and deploy your database schema.

The JawsDB Kitefin is free plan that provides an instance with shared resources. In this limited version you'll have only one database with 5MB of storage available and you'll not be able to alter the name of the database (schema).

Note: if JawsDB updates its host you'll have to manually update DB_HOST config var.

Test locally

If you haven't run pipenv install inside your cloned repo yet, do it now.

Heroku lets you test your app locally with a heroku local command, but you need to be within the virtual environment just created. Otherwise the app dependencies will not be found.

Consider your are on Windows. The sequence of commands to execute is listed below.

> pipenv install
> pipenv shell
> heroku local web -f ./Procfile.windows

On Linux you can just omit the Procfile provided as argument and it'll use the default one.

Now you should be able to make a request to localhost on the port defined in the corresponding Procfile.

> curl http://localhost:8000/version