Skip to content

Instantly share code, notes, and snippets.

@carlosrberto
Created July 24, 2012 11:30
Show Gist options
  • Save carlosrberto/3169477 to your computer and use it in GitHub Desktop.
Save carlosrberto/3169477 to your computer and use it in GitHub Desktop.
Fabfile exemplo
# coding: utf-8
import os
from fabric.api import run, env, local
# local
env.local_root = os.path.abspath( os.path.dirname(__file__) )
# remote
env.hosts = [
'[email protected]',
# '[email protected]',
]
env.home_dir = '/home/pubdesign/'
env.repository = 'git://github.com/django/django.git'
env.virtualenv = '/home/pubdesign/env/'
env.requirements = '/home/pubdesign/project/requirements.txt'
def commit():
local( 'cd %s && git add . && git commmit -m "asdasdasd"' % env.local_root )
def deploy():
run('cd %s && git clone %s project' % (env.home_dir, env.repository))
requirements()
collectstatic()
syncdb()
migrate(fake=True)
# restart service uwsgi
def up():
deploy_code()
requirements()
collectstatic()
migrate()
# restart service uwsgi
def deploy_code():
run('cd %s && git pull' % env.home_dir)
def run_env(cmd):
run('source %sbin/activate && %s' % (env.virtualenv, cmd))
def requirements():
run_env('pip install -r %s' % env.requirements)
def collectstatic():
manage_py('collectstatic --noinput')
def migrate(fake=False):
if fake:
manage_py('migrate --fake')
else:
manage_py('migrate')
def syncdb():
manage_py('syncdb --all')
def manage_py(cmd):
run('%sbin/python %sproject/manage.py %s' % (env.home_dir, env.virtualenv, cmd))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment