Skip to content

Heroku installation

kynan edited this page Apr 15, 2013 · 2 revisions

These are the installation instructions for deploying to your own Heroku instance. It will take you from installing VirtualEnv and setting up your Python environment to cloning from the Taarifa Github instance (where this wiki is located) to setting up and deploying to Heroku.

System Settings

Install VirtualEnv

$ sudo easy_install pip $ pip virtualenv $ pip virtualenvwrapper $ mkdir ~/.virtualenvs

Run following command to start a new virtual environment –

$ virtualenv taarifa-backend --no-site-packages

Then run following to activate virtualenv

$ source taarifa-backend/bin/activate

You should now see (taarifa-backend) as a precursor to the name of your machine in the command line.

Install Heroku command-line client

Clone the repository off Github;

$ git clone https://github.com/taarifa/taarifa_backend.git

Then create a Heroku stack by calling;

$ heroku create

This will integrate the Heroku stack with your current Github repository for Taarifa-Backend. It will create a git remote linking with your newly Heroku application stack. To verify this try

$ git remote -v

You will see something like the following;

heroku	[email protected]:desolate-harbor-5040.git (fetch)
heroku	[email protected]:desolate-harbor-5040.git (push)
origin	https://github.com/taarifa/taarifa_backend.git (fetch)
origin	https://github.com/taarifa/taarifa_backend.git (push)

This shows the various (upstream) repositories that can you push (ie. send commits) and fetch (receive commits). You'll have two upstream repositories to keep updated. One being the Taarifa github repository where new commits and updates will be found and your own Heroku branch.

Taarifa File Structure and Settings

Procfile

web: python taarifa_backend/manage.py runserver -p $PORT

The Procfile is to help Herkou launch the application by default in a dyno process. It is important that the -p flag is lowercase and the variable $PORT is left alone. This is a variable which the system determines at runtime.

If you wish to launch Taarifa manually or do not have a Procfile you will need to launch the Taarifa API with the command;

$ heroku run python taarifa_backend/manage.py runserver

MongoDB Settings

You will need to add the MongoLab to your Heroku app

$ heroku addons:add mongolab:starter

This requires a verified Heroku account (for me this meant providing a payment card).

Heroku will automatically set a configuration variable MONGOLAB_URI, which you can read with

$ heroku config

You'll get a response which will be in this format;

mongodb://dbuser:dbpass@host:port/dbname

Launch to heroku

First you'll need to merge the development branches into master, as the free version of Heroku does not allow for anything other than the master branch to be built as a Heroku application.

Once this is done, you should be ready to deploy the Taarifa API. To do this you add to the master branch of the Heroku remote.

$ git push heroku master

Alternatively, push another branch branch as the heroku master with

$ git push heroku branch:master

Finally, once the application has been built, you need to open it.

$ heroku open

This will open your default web browser to the applicaton.

Troubleshooting

To get this deployed took quite a lot of methodical checking of the right case for inputs, port numbers and passwords linking with Heroku. But perservere! If you start to have issues, use;

$ heroku logs

This shows the server logs and where the point of failure is for the application. Look at the code of the framework, it's quite clear and documented. If that doesn't work, submit a bug report and get in touch on the mailing list