Friday, February 22, 2013

Lessons Working with Heroku: Windows Need Not Apply



In learning about Serious Game Development and the tools that will be useful in exploring this venture I began my journey into learning about Heroku (http://www.heroku.com/) a cloud application platform were one can remotely deploy applications as a way to test (or with monetary investment) establish applications to run on a system. Heroku is a powerful tool, and combined with tools like Django (https://www.djangoproject.com/) and Git (http://git-scm.com/) allow a person to not just design web-based server concepts, but manage their project, and have it running online in a test platform easily.

Unfortunately, when I say easily, I merely mean in concept, as the devil is in the very details of this ease. In working with Heroku and developing, there were many little mis-steps that can make the whole experience more daunting than it appears looking through it. Therefore, In order to try to alleviate some of the pain I will attempt to put together a list of items to make the process easier. It should be noted that in trying to recreate the issues and the process I went through initially I ran into several steps that since I have already done them are not as problematic as they were initially. Steps will be as clear as possible, but possible issues may still be present which I did not mention. It is also noted that in my original attempt I had tried to go through Windows, before switching to Linux, meaning in running through this process 3 times, I may have mixed up concepts, I will try to be as clear as possible for your convenience.
Please note that I will not be going through the entire tutorial just pointing out rough patches that need a little extra attention.

Prologue: So you want to try out Heroku.
You  want to use Heroku, that's great and there are things about it which are accessible through any system, be it Windows, MacOS, or Linux. This unfortunately has one major caveat to it, while it may run mostly in a Windows environment, it and many of the tutorials do not run with Windows computers in mind. Knowing this trouble, especially when realizing that you cannot check webpages under 0.0.0.0 on a windows setup without more work, and that items used in Heroku tutorials do not have working equivalents in Windows, like Gunicorn. That said I would suggest that one immediately avoid the headaches and troubles of attempting use in a Windows machine for now (and hopefully sometime in the future this will not be needed) and if you are a Windows user you aim to virtualize your efforts using a Virtual Machine and a Linux installation.

Suggested Virtual Machine: Virtual Box (https://www.virtualbox.org/)
Suggested Linux Distribution: Ubuntu 12.04 LTS (http://www.ubuntu.com/download/desktop)

Your experiences may vary, but this combination on my Windows 7 Ultimate running laptop proved friendly enough to install and smooth enough to run without problems.
Since this is not a tutorial on VM technology I will not go into too many details on this process, but I would suggest using at least 2GB of ram, and if you have more than 2 processors at least 2 processors at 100% execution cap in order to optimize usage. This should be more than enough to run through the Heroku tutorial for Django.

Going through the Heroku with Django Tutorial: https://devcenter.heroku.com/articles/django

Installing Basics

Given as prerequisites but not focused on Heroku points out the need for the Heroku toolbelt, Python, and Virtualenv
Their guide provides links out, but for simplicity, you will need to do the following commands:

For the toolbelt: wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
For Git: apt-get install git
For Python-Dev: apt-get install python-dev

Besides the toolbelt, the programs here are implied to be installed, with Python-dev not being included but necessary for working with some of the other components. It is worth note that while looking into the install guides for virtualenv you will be installing other  programs as well, these should make running through the tutorials easier as well.

Working with PostgreSQL

The configuration necessary for PostgreSQL is probably one of the most daunting to do.
Installation is simple, simply run the command:
  apt-get install postgresql-9.1

As found in the PostgreSQL webpage: http://www.postgresql.org/download/linux/ubuntu/
PostgreSQL is used for managing the database in the tutorial and is useful for its integration in the Heroku system, but it cannot be run locally without a small tweak to the system. You'll run into several issues. For example after going through the total you may run into an error with psycopg2 (installed at the beginning of the tutorial) stating:

psycopg2.OperationalError: FATAL: Ident authentication failed for user "postgres"

This problem can be fixed by finding the trusted section in pg_hba.conf for postgres (found in etc/postgresql/9.1/main/pg_hba.conf) and adding in:

host    all         all         127.0.0.1/32          trust

One of many possible solutions provided by a question on superuser.com: http://superuser.com/questions/179238/postgres-ident-authentication-failed

Also not in order to get to this file to modify it, you will need superuser permission on your linux system. An easy way to access this file for editing without too much trouble is to do the following command in a terminal window:

sudo gedit /etc/postgres/9.1/main/pg_hba.conf

This will open the file in gedit for editing when double clicking the file normally would not allow modifications.

Adding user to PostgreSQL

One thing they don't make clear in the tutorials is how to operate PostgreSQL, the result is that if you are attempting to create a database and user while in your virtual environment you'll run into issues.

The following link leads to a tutorial on how to add in a user and database to work with locally: 

Without this information, you'll find the only way to work on your database would be to leave your environment temporarily to become the postgres superuser and modify things there. By doing this first you avoid the trouble working in the virtual environment you make for the project.

Closing Statements

After taking care of these issues, the tutorials provided by the Heroku can be completed without running into significant problems.

As people create and use technologies they come to expect certain levels of already fulfilled requirements, and this can be a problem when stepping into a new situation. If you are like me and shifted into the Linux environment from a pre-existing functioning python/django environment in Windows, you might find yourself forgetting simple concepts and ideas, like that you need to install systems that you previously had running into your new system for example. These problems are small, but can lead to more frustration as time goes on, so it's important to try to trace your work as best you can.
At the same time you may feel a bit discourage by the number of tutorials you will have to run through to get through the 1 tutorial we focus on here, don't be. Since this is the set up for the system it should prove to be a one-time problem and once you fix them you won't have the issue again on the system you setup.

In addition several sites are available for assistance which were used when I originally ran into these problems, including http://superuser.com/, http://stackoverflow.com/, http://www.postgresql.org (and its community), and https://help.ubuntu.com

Being a programmer may mean you are creating things for others, but it doesn't mean you are alone, sometimes [search engine of your choice] may be your best friend and help you find places that can help you. As for this retrospective, it may not have everything, but it is an artifact of the troubles that can happen to anyone. Hopefully, this may help someone avoid them just a little bit more than before.

Happy Coding.

No comments:

Post a Comment