Created
December 20, 2010 16:03
-
-
Save konryd/748557 to your computer and use it in GitHub Desktop.
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 __future__ import with_statement | |
from fabric.api import * | |
from fabric.contrib import django | |
env.hosts = ["[email protected]"] | |
REMOTE_PROJECT_ROOT = '/path/to/project/root/' | |
def _run_django_prod(command): | |
""" Run a django command remotely using production settings """ | |
return run("PYTHONPATH=$PYTHONPATH:src bin/django-admin.py %s --settings=myapp.production" % command) | |
def deploy(): | |
# will fail if files are changed and not checked in | |
# (it still wouldn't detect untracked files!) | |
local("git diff-index --quiet HEAD") | |
# archive HEAD | |
local("git archive --format=tar HEAD | gzip > /tmp/papu.tgz") | |
# send to server | |
put('/tmp/papu.tgz', '/tmp/') | |
with cd(REMOTE_PROJECT_ROOT): | |
# unpack | |
run('tar xzf /tmp/papu.tgz') | |
_run_django_prod('syncdb') | |
_run_django_prod('migrate') | |
_run_django_prod('collectstatic --noinput') | |
# restart the server - will fail if server wasn't running | |
with settings(warn_only=True): | |
run('pkill python') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment