Skip to content

Instantly share code, notes, and snippets.

@rnix
Created November 30, 2012 14:44
Show Gist options
  • Save rnix/4176180 to your computer and use it in GitHub Desktop.
Save rnix/4176180 to your computer and use it in GitHub Desktop.
Heroku Django

Usage:

curl -Lks https://raw.github.com/gist/4176180/install.sh | sh -s -- [app [ssh-host]]

Implements the steps from this heroku/django article

venv
*.pyc
.*.log
#!/bin/sh
app=${1:-django-heroku-$(date +%Y%m%dt%H%M%S)-$$${RANDOM}}
sshhost=${2}
mkdir ${app} || exit ${LINENO}
cd ${app} || exit ${LINENO}
exec 3>&1 4>&2
exec >.install.log 2>&1
set -xv
is() { printf '\e[80D\e[K%s ' "${*}" >&3 ; }
is Configuring Python
virtualenv venv --distribute
source venv/bin/activate
is Configuring Django
pip install Django psycopg2 dj-database-url
django-admin.py startproject ${app} .
pip freeze > requirements.txt
is Pulling updates
gist='https://raw.github.com/gist/4176180'
curl -Lks ${gist}/gitignore >.gitignore
curl -LksO ${gist}/Procfile
curl -Lks ${gist}/settings.py >> ${app}/settings.py
is Initializing git
git init
git add .
git commit -m "init" || exit ${LINENO}
heroku apps:create ${app} || heroku create || exit ${LINENO}
is Pushing to heroku
# if heroku ssh is a different host than heroku.com, e.g.
# because of using a different id_rsa in ~/.ssh/config,
# then this allows an update to .git/config prior to push.
[ "${sshhost}" ] && {
perl -pi -e 's/(url = git[@])(heroku.com)/$1'${sshhost}'.$2/' .git/config
}
git push heroku master
heroku apps:open ${app}
is Done
echo >&3
web: python manage.py runserver 0.0.0.0:$PORT --noreload
# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] = dj_database_url.config()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment