Skip to content

Instantly share code, notes, and snippets.

@joelhaasnoot
Created February 6, 2012 21:44
Show Gist options
  • Save joelhaasnoot/1755101 to your computer and use it in GitHub Desktop.
Save joelhaasnoot/1755101 to your computer and use it in GitHub Desktop.
My very simple django deploy script
from fabric.api import task, cd, sudo, run, env, prefix
from contextlib import contextmanager as _contextmanager
@task(default=True)
def live():
env.hosts = ['ssh.myserver.com']
env.virtualenv = "project-release"
env.parent = "github"
env.branch = "master"
env.user = "user"
env.key_filename = ["~/.ssh/id_rsa"]
env.code_dir = ''
@task(default=True)
def deploy():
pull(env.parent, env.branch)
dependencies()
files()
migrate()
translate()
apache_restart()
@task
def test():
with virtualenv(), path():
run("./manage.py test")
@task
def dependencies():
with virtualenv(), path():
run("pip install -r requirements/base.txt")
@task
def pull(parent="github", branch="master"):
with path():
run("git pull") # %(parent)s %(branch)s" % {'parent' : parent, 'branch' : branch })
@task
def migrate():
with virtualenv(), path():
run("./manage.py syncdb --noinput")
run("./manage.py migrate --noinput")
@task
def translate():
with virtualenv(), path():
run("django-admin.py compilemessages")
@task
def files():
with virtualenv(), path():
run("./manage.py collectstatic --noinput")
@task
def apache_restart():
sudo('/etc/init.d/httpd restart')
@_contextmanager
def virtualenv():
with prefix("workon %s" % env.virtualenv):
yield
@_contextmanager
def path():
with cd(env.code_dir):
yield
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment