quick and dirty python deployments with heroku
DESCRIPTION
Quickly build and deploy your own web apps to Heroku using these free and easy Python tools.TRANSCRIPT
![Page 1: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/1.jpg)
Quick and Dirty Python
Deployments with HerokuDeployments with Heroku
Guest starring Flask, CoffeeScript, Fabric, and SeatGeek
Daniel Pritchett for MEMpy,
March 19, 2012
![Page 2: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/2.jpg)
Painless Heroku Startup
![Page 3: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/3.jpg)
Requirements
• Python 2.7
• virtualenv
• pip
• Rubygems• Rubygems
• Procfile / foreman
![Page 4: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/4.jpg)
Get started
• Install git, foreman, pip, virtualenv
• Clone/create a repo with a Procfile that
starts a HTTP service
• foreman start to test it locally• foreman start to test it locally
• heroku create app_name –
stack=cedar && git push heroku
master
![Page 5: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/5.jpg)
Setup log
$ virtualenv --no-site-packages heroku_demo
New python executable in heroku_demo/bin/python
Installing pip...............cdone.
$ cd heroku_demo/
$ . bin/activate
$ git clone git://github.com/dpritchett/wwebsite-python.git app
$ cd app
$ pip install -r ./requirements.txt
Successfully installed Flask Jinja2 Pygments Werkzeug chardet gunicorn
$ foreman start
13:20:18 web.1 | started with pid 17810
13:20:18 web.1 | 2012-03-19 13:20:18 [17810] [INFO] Starting gunicorn 0.14.1
13:20:18 web.1 | 2012-03-19 13:20:18 [17810] [INFO] Listening at: http://0.0.0.0:5000
$ heroku create mempy-demo --stack=cedar
Creating mempy-demo... done, stack is cedar
http://mempy-demo.herokuapp.com/ | [email protected]:mempy-demo.git
Git remote heroku added
$ git push heroku master
Procfile declares types -> web
http://mempy-demo.herokuapp.com deployed to Heroku
$ curl mempy-demo.herokuapp.com
Hello World!
![Page 6: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/6.jpg)
Foreman’s Procfile defines the service
web: gunicorn app:APP -b 0.0.0.0:$PORT -w 3
You can run the same thing at the console to test:You can run the same thing at the console to test:
$ gunicorn app:APP -b 0.0.0.0:$PORT -w 3
![Page 7: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/7.jpg)
Heroku logging• Captures stdout, stderr
• You’ll need it since you have no persistent disk
• Simplest case you can just use a print statement
• Free plan has limitations
• Consider an offsite log manager
![Page 8: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/8.jpg)
Remote console
$ heroku run bash
Running bash attached to terminal... up, run.2
~ $ find templates
templates
templates/index.html
~ $ find static
static
static/jsstatic/js
static/js/memphis_tickets.js
static/coffee
static/coffee/memphis_tickets.coffee
static/bootstrap
static/bootstrap/js
static/bootstrap/js/bootstrap.js
...
static/bootstrap/css/bootstrap.css
static/css
static/css/tickets.css
~ $
![Page 9: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/9.jpg)
Sample Flask application:
TicketsOfMemphis.com
![Page 10: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/10.jpg)
![Page 11: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/11.jpg)
The entire backend
![Page 12: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/12.jpg)
HTML templating (Jinja2)
![Page 13: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/13.jpg)
CoffeeScript excerpts
![Page 14: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/14.jpg)
Data provided by SeatGeek API
![Page 15: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/15.jpg)
Honorable mention: Fabric$ fab s
[localhost] local: coffee -o ../js/ --compile
./*coffee
[localhost] local: foreman start
14:11:29 web.1 | started with pid 24218
14:11:29 web.1 | 2012-03-19 14:11:29
[24218] [INFO] Starting gunicorn 0.14.1
14:11:29 web.1 | 2012-03-19 14:11:29
[24218] [INFO] Listening at: http://0.0.0.0:5000
(24218)
14:11:29 web.1 | 2012-03-19 14:11:29
[24218] [INFO] Using worker: sync[24218] [INFO] Using worker: sync
14:11:29 web.1 | 2012-03-19
14:11:29 [24225] [INFO] Booting worker with pid:
24225
14:11:29 web.1 | 2012-03-19 14:11:29
[24226] [INFO] Booting worker with pid: 24226
14:11:29 web.1 | 2012-03-19 14:11:29
[24227] [INFO] Booting worker with pid: 24227
![Page 16: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/16.jpg)
Heroku Ecosystem
Pain points and add-ons
![Page 17: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/17.jpg)
addons.heroku.com
• Databases
• Worker hours
• Email services
• DNS• DNS
• HTTPS and certificates
• Billing
• Message/Task Queues
![Page 18: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/18.jpg)
LogEntries
![Page 19: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/19.jpg)
LogEntries Alerts
![Page 20: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/20.jpg)
Zerigo DNS
![Page 21: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/21.jpg)
MongoHQ
![Page 22: Quick and Dirty Python Deployments with Heroku](https://reader034.vdocuments.site/reader034/viewer/2022052311/556a53d4d8b42a7a138b492d/html5/thumbnails/22.jpg)
Thank you!
Try a copy of the code at
github.com/dpritchett/wwebsite-python
Heroku and Flask have great docs.Heroku and Flask have great docs.
Find me @dpritchett