Migrating to Heroku

To cut some personal costs and simply because I was interested in it, I recently moved this blog to Heroku, the popular cloud hosting platform.

Since 2011 Heroku officially supports Python deployments. Running on a single dyno it is even for free. Following the official guide to deploy a Django application, the transition from my VPS to Heroku was pretty straight-forward and easy. Additionally Heroku enforces good practices, like using virtualenv, and supports more and more popular technologies, like the Python WSGI server Gunicorn.

Following a short general guide of what had to be done from my side to do the transition:

  • Create a fixture file from your database via the dumpdata command.
  • Since I didn't want to add any billing information to Heroku yet, I had to rewrite everything related to sending emails from my web server, to save the incoming contact request in the database instead. That was pretty much just the creation of a new model and a one-liner to save it to the DB instead of sending an email,
  • Already using virtualenv, the rest was simply adding or changing requirements. In addition of removing the MySQL bindings for python I added the following libaries:

    dj-database-url==0.2.1
    django-heroku-memcacheify==0.4
    django-pylibmc-sasl==0.2.4
    gevent==0.13.8
    greenlet==0.4.0
    gunicorn==0.17.2
    psycopg2==2.4.6
    pylibmc==1.2.3
    

  • Static files are served via Django directly for the time being, since a Web-Dyno using Python can not serve them the normal way. I will move them to be served by a solution like Amazon S3 in the future. Therefore I added the following to my urlconf:

    urlpatterns += patterns(
        '',
        url(r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
    )
    

  • Running the dyno via Gunicorn with gevent support was a single line in the Procfile:

    web: gunicorn -k gevent wsgi:application

  • Finally:

    git push heroku master

So far I am quite happy with Heroku. I didn't recognize any differences to previous VPS hosting and I don't have to deal with server maintenance anymore, even it was an experience I don't want to miss. Goodbye VPS, welcome Heroku!

6 Comment(s)