Slide 1

Slide 1 text

Running Django Apps on Heroku Randall Degges (@rdegges)

Slide 2

Slide 2 text

Heroku = python + zombies

Slide 3

Slide 3 text

Hosting Yourself vs PaaS Pros ● Cheaper. ● Teaches your more. ● More flexible. Cons ● Requires time. ● Requires knowledge. ● Requires maintenance. ● Requires constant revisions (architecture). ● Less time for coding. Pros ● Simple. ● Scalable. ● Managed. ● More time for coding. Cons ● Costly. ● You're betting on the company.

Slide 4

Slide 4 text

Getting Started (on Ubuntu) $ sudo aptitude install python-software-properties curl $ sudo apt-add-repository 'deb http://toolbelt.herokuapp.com/ubuntu ./' $ curl http://toolbelt.herokuapp.com/apt/release.key | sudo apt-key add - $ sudo aptitude -y update $ sudo aptitude -y install libpq-dev python-pip heroku-toolbelt ruby git $ sudo pip install -U virtualenv $ heroku login

Slide 5

Slide 5 text

Hello, #pyladies $ mkdir helloladies && cd helloladies $ git init $ echo "Django==1.3" > requirements.txt $ echo "psycopg2==2.4.2" >> requirements.txt $ echo "env" > .gitignore $ virtualenv --no-site-packages env $ . env/bin/activate $ pip install -r requirements.txt $ django-admin.py startproject helloladies $ git add --all $ git commit -m "woot"

Slide 6

Slide 6 text

On.... Heroku! $ heroku create --stack cedar $ git push heroku master

Slide 7

Slide 7 text

Useful Information # View your processes: $ heroku ps # View your logs: $ heroku logs # Run custom stuff: $ heroku run python manage.py syncdb $ heroku run python manage.py shell # Deploy new code: $ git push heroku master

Slide 8

Slide 8 text

Heroku + gunicorn ● Real programmers use real web servers. ● Let's use gunicorn! $ echo "gunicorn==0.13.4" >> requirements.txt # settings.py - INSTALLED_APPS 'gunicorn', $ echo 'web: python helloladies/manage.py run_gunicorn -b "0.0.0.0:$PORT" -w 3' > Procfile $ git add --all; git commit -m "use gunicorn"; git push heroku master

Slide 9

Slide 9 text

Queue Processing with Celery $ pip install django-celery django-kombu $ pip freeze > requirements.txt # settings.py - INSTALLED_APPS 'djcelery', 'djkombu', # settings.py import djcelery djcelery.setup_loader() BROKER_BACKEND = 'djkombu.transport.DatabaseTransport' CELERY_RESULT_DBURI = DATABASES['default'] $ echo 'worker: python helloladies/manage.py celeryd -E -B --loglevel=INFO' >> Procfile $ git add --all; git commit -m 'use celery'; git push heroku master $ heroku run python helloladies/manage.py syncdb $ heroku scale worker=1 # Verify it's working: $ heroku ps

Slide 10

Slide 10 text

Resources ● Django: https://www.djangoproject.com/ ● Heroku: http://www.heroku.com/ ● gunicorn: http://gunicorn.org/ ● celery: http://celeryproject.org/