Created
February 6, 2012 21:44
-
-
Save joelhaasnoot/1755101 to your computer and use it in GitHub Desktop.
My very simple django deploy script
This file contains 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 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