Skip to content

Instantly share code, notes, and snippets.

@f213 f213/

Created Jan 6, 2019
What would you like to do?
Fabfile example
from fabric.api import env, run as fabric_run
from fabric.contrib.project import rsync_project
env.app_path = '/home/backend'
env.user = 'circle'
env.use_ssh_config = True
env.disable_knodwn_hosts = True
env.colorize_errors = True
def run(cmd, *args, **kwargs):
fabric_run('cd %s && %s' % (env.app_path, cmd), *args, **kwargs)
def run_in_venv(cmd):
run('cd %s && . venv/bin/activate && %s' % (env.app_path, cmd))
def manage_py(*args):
run_in_venv('cd src && ./ %s' % ' '.join(args))
def upload():
return rsync_project(
remote_dir=env.app_path + '/src/',
extra_opts='--links --omit-dir-times',
def deploy():
run_in_venv('pip install -r src/requirements.txt') # install new requirements
manage_py('migrate', '--noinput')
manage_py('remove_stale_contenttypes', '--noinput')
manage_py('collectstatic', '--noinput', '--clear')
run('touch reload') # tell uwsgi to reload application code
# restart background celery workers
run('sudo /usr/bin/supervisorctl restart default-worker')
run('sudo /usr/bin/supervisorctl restart beat')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.