Quick and Dirty Python Deployments with Heroku

  • Published on
    31-May-2015

  • View
    11.278

  • Download
    0

DESCRIPTION

Quickly build and deploy your own web apps to Heroku using these free and easy Python tools.

Transcript

  • 1. Quick and Dirty PythonDeployments with HerokuGuest starring Flask, CoffeeScript, Fabric, andSeatGeek Daniel Pritchett for MEMpy,March 19, 2012

2. Painless Heroku Startup 3. Requirements Python 2.7 virtualenv pip Rubygems Procfile / foreman 4. Get started Install git, foreman, pip, virtualenv Clone/create a repo with a Procfile thatstarts a HTTP service foreman start to test it locally heroku create app_name stack=cedar && git push herokumaster 5. 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/ | git@heroku.com: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! 6. Foremans Procfile defines the serviceweb: gunicorn app:APP -b 0.0.0.0:$PORT -w 3You can run the same thing at the console to test:$ gunicorn app:APP -b 0.0.0.0:$PORT -w 3 7. Heroku logging Captures stdout, stderr Youll 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 8. Remote console$ heroku run bashRunning bash attached to terminal... up, run.2~ $ find templatestemplatestemplates/index.html~ $ find staticstaticstatic/jsstatic/js/memphis_tickets.jsstatic/coffeestatic/coffee/memphis_tickets.coffeestatic/bootstrapstatic/bootstrap/jsstatic/bootstrap/js/bootstrap.js ...static/bootstrap/css/bootstrap.cssstatic/cssstatic/css/tickets.css~ $ 9. Sample Flask application: TicketsOfMemphis.com 10. The entire backend 11. HTML templating (Jinja2) 12. CoffeeScript excerpts 13. Data provided by SeatGeek API 14. 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: sync14: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 15. Heroku EcosystemPain points and add-ons 16. addons.heroku.com Databases Worker hours Email services DNS HTTPS and certificates Billing Message/Task Queues 17. LogEntries 18. LogEntries Alerts 19. Zerigo DNS 20. MongoHQ 21. Thank you!Try a copy of the code atgithub.com/dpritchett/wwebsite-pythonHeroku and Flask have great docs.Find me @dpritchett