Friday, March 28, 2014

Deploying a Python Django app to Heroku

Today I decided to try to deploy my app to Heroku.  Fortunately, I found a pretty good tutorial that shows me how to do this:

https://devcenter.heroku.com/articles/getting-started-with-django

I will be detailing my trials and tribulations as I attempt to do this.  My first issue was that I could not get foreman to work.  The gem foreman is not part of the django-toolbelt.  It is part of the Heroku ToolBelt.  I fixed this by uninstalling and reinstalling the gem.  I then discovered that the Procfile I created needed to be at the same level as the manage.py file.  Otherwise, I would get a bunch of this:

(tapeworm_django)christohersmbp2:tapeworm_django christopherspears$ foreman start
11:18:52 web.1  | started with pid 2122
11:18:52 web.1  | 2014-03-28 11:18:52 [2122] [INFO] Starting gunicorn 18.0
11:18:52 web.1  | 2014-03-28 11:18:52 [2122] [INFO] Listening at: http://0.0.0.0:5000 (2122)
11:18:52 web.1  | 2014-03-28 11:18:52 [2122] [INFO] Using worker: sync
11:18:52 web.1  | 2014-03-28 11:18:52 [2125] [INFO] Booting worker with pid: 2125
11:18:52 web.1  | 2014-03-28 11:18:52 [2125] [ERROR] Exception in worker process:
11:18:52 web.1  | Traceback (most recent call last):
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
11:18:52 web.1  |     worker.init_process()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
11:18:52 web.1  |     self.wsgi = self.app.wsgi()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
11:18:52 web.1  |     self.callable = self.load()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
11:18:52 web.1  |     return self.load_wsgiapp()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
11:18:52 web.1  |     return util.import_app(self.app_uri)
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
11:18:52 web.1  |     __import__(module)
11:18:52 web.1  | ImportError: No module named tapeworm.wsgi
11:18:52 web.1  | Traceback (most recent call last):
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
11:18:52 web.1  |     worker.init_process()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
11:18:52 web.1  |     self.wsgi = self.app.wsgi()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
11:18:52 web.1  |     self.callable = self.load()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
11:18:52 web.1  |     return self.load_wsgiapp()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
11:18:52 web.1  |     return util.import_app(self.app_uri)
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
11:18:52 web.1  |     __import__(module)
11:18:52 web.1  | ImportError: No module named tapeworm.wsgi
11:18:52 web.1  | 2014-03-28 11:18:52 [2125] [INFO] Worker exiting (pid: 2125)
11:18:52 web.1  | 2014-03-28 11:18:52 [2122] [INFO] Shutting down: Master
11:18:52 web.1  | 2014-03-28 11:18:52 [2122] [INFO] Reason: Worker failed to boot.
11:18:52 web.1  | exited with code 3

11:18:52 system | sending SIGTERM to all processes

By the way, I always forget to do this when creating a Heroku app:

(tapeworm_django)christohersmbp2:tapeworm_django christopherspears$ heroku apps:create tapeworm
Creating tapeworm... done, stack is cedar
http://tapeworm.herokuapp.com/ | git@heroku.com:tapeworm.git
Git remote heroku added

Otherwise, Heroku is going to give your app a name like "Flowing Downstream Leaves", which is annoying.  I managed to successfully push my app to Heroku.  The next step is to try to turn it on.

No comments:

Post a Comment