Skip to content

Instantly share code, notes, and snippets.

@KWMalik
Created October 12, 2012 21:56
Show Gist options
  • Save KWMalik/3881785 to your computer and use it in GitHub Desktop.
Save KWMalik/3881785 to your computer and use it in GitHub Desktop.
Create and deploy a Python/Flask "hello world" app on Heroku.
#!/bin/bash
# Create and deploy a Python/Flask "hello world" app on Heroku.
# by James Thornton, http://jamesthornton.com
# To run it, do:
# $ heroku login
# $ bash setup.sh helloworld
# $ cd helloworld
# $ git push heroku master
read -d '' APP <<"EOF"
import os
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World!'
if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)
EOF
mkdir $1 && cd $1
heroku create --stack cedar
virtualenv env --distribute
source env/bin/activate
pip install flask
pip install gunicorn
pip freeze >requirements.txt
echo "${APP}" >app.py
echo "web: gunicorn app:app -b \"0.0.0.0:\$PORT\" -w 3" >Procfile
echo "env" >>.gitignore
echo "*.pyc" >>.gitignore
git init
git add .
git commit -m "initial push"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment