Last active
December 23, 2015 04:59
-
-
Save beholderrk/6584131 to your computer and use it in GitHub Desktop.
fabfile for django deploy
usage:
fab deploy
fab update
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 contextlib import contextmanager | |
from fabric.api import local, settings, abort, run, cd, env, prefix | |
PROJECT_DIR = '~/path-to-ptoject' | |
env.user = 'user' | |
env.hosts = ['host.ru'] | |
@contextmanager | |
def virtualenv(): | |
with prefix('source %s/envi/bin/activate' % PROJECT_DIR): | |
yield | |
def deploy(): | |
with settings(warn_only=True): | |
with cd(PROJECT_DIR): | |
if run('test -d %s/.git' % PROJECT_DIR).failed: | |
run('rm -rf app media static') | |
run('git init') | |
run('git remote add origin [email protected]:beholderrk/repo.git') | |
run('mkdir media/static') | |
run('mkdir media/uploads') | |
if run('test -d %s/envi' % PROJECT_DIR).failed: | |
run('virtualenv --setuptools envi') | |
with virtualenv(): | |
run('pip install -r requirements.txt --upgrade') | |
with cd('envi/lib/python2.6/site-packages/rollyourown/'): | |
run('touch __init__.py') | |
with cd('envi/lib/python2.6/site-packages/'): | |
run('git clone https://github.com/beholderrk/commonapps.git') | |
with cd('commonapps/'): | |
run('git checkout -b django15 origin/django15') | |
run('ln -s commonapps/annoying') | |
run('ln -s commonapps/django_generic_flatblocks') | |
run('ln -s commonapps/feincms') | |
run('git pull origin master') | |
with virtualenv(): | |
run('python manage.py collectstatic') | |
run('python manage.py syncdb') | |
run('python manage.py migrate --all') | |
run('python manage.py syncdb') | |
def gitup(): | |
with cd(PROJECT_DIR): | |
run('git pull origin master') | |
def update(): | |
gitup() | |
with cd(PROJECT_DIR): | |
with virtualenv(): | |
run('python manage.py migrate --all') | |
run('touch django.wsgi') | |
with virtualenv(): | |
run('python manage.py collectstatic') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment