Created
May 11, 2012 02:21
-
-
Save jiaaro/2657094 to your computer and use it in GitHub Desktop.
Brubeck on heroku with gunicorn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Note: This is the only file you *really* need. I've copied the contents | |
# of the important files that are part of our git repo for easier reading | |
# below :) | |
# | |
# I've prefixed this file with two dots to make it rise to the top of the | |
# gist. you can ignore those | |
# | |
# Create and enter a virtualenv called "myapp" | |
mkvirtualenv myapp --no-site-packages | |
workon myapp | |
mkdir myapp | |
cd myapp | |
# Install the dependencies and throw it in a requirements file (used by heroku) | |
pip install git+git://github.com/j2labs/brubeck.git dictshield ujson gevent gunicorn | |
pip freeze > requirements.txt | |
# This is a basic app | |
cat << EOF > app.py | |
from brubeck.request_handling import Brubeck, WebMessageHandler | |
from brubeck.connections import WSGIConnection | |
class DemoHandler(WebMessageHandler): | |
def get(self): | |
self.set_body("Hello, from Brubeck!") | |
return self.render() | |
config = { | |
'msg_conn': WSGIConnection(), | |
'handler_tuples': [ | |
(r'^/', DemoHandler) | |
] | |
} | |
app = Brubeck(**config) | |
# This is the wsgi handler used by gunicorn | |
def application(environ, callback): | |
return app.msg_conn.process_message(app, environ, callback) | |
EOF | |
# Tell heroku how to run it | |
cat << EOF > Procfile | |
web: gunicorn app --bind "0.0.0.0:\$PORT" --workers 3 | |
EOF | |
cat << EOF > .gitignore | |
*.pyc | |
EOF | |
# create a git repo for the code so we can push it into heroku | |
git init . | |
git add . | |
git commit -a -m "initial commit" | |
# create the heroku app and push our app into it | |
heroku create --stack cedar | |
git push heroku master | |
# open the site we just created | |
heroku open |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.pyc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from brubeck.request_handling import Brubeck, WebMessageHandler | |
from brubeck.connections import WSGIConnection | |
class DemoHandler(WebMessageHandler): | |
def get(self): | |
self.set_body("Hello, from Brubeck!") | |
return self.render() | |
config = { | |
'msg_conn': WSGIConnection(), | |
'handler_tuples': [ | |
(r'^/', DemoHandler) | |
] | |
} | |
app = Brubeck(**config) | |
def application(environ, callback): | |
return app.msg_conn.process_message(app, environ, callback) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: gunicorn app --bind "0.0.0.0:$PORT" --workers 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
brubeck==0.4.0 | |
dictshield==0.4.3 | |
gevent==0.13.7 | |
greenlet==0.3.4 | |
gunicorn==0.14.2 | |
ujson==1.18 | |
wsgiref==0.1.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That makes sense. Thank you for the explanation!
Would you be willing to write that section and submit a pull request? I'd be happy to put your comments in the Brubeck docs if you're short on time, but I like trying to maintain an accurate account of where ideas come from.