Skip to content

Instantly share code, notes, and snippets.

@notsobad
Created July 26, 2014 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notsobad/52530b890338f8fde1a2 to your computer and use it in GitHub Desktop.
Save notsobad/52530b890338f8fde1a2 to your computer and use it in GitHub Desktop.
Use fabric and svn to deploy code to multi servers.
import os
from fabric.api import task, run, env, cd
'''
* fab version
* fab deploy user:password:version
* fab reload_ui
'''
__author__ = 'notsobad'
env.key_filename = '~/.ssh/ui.rsa'
env.hosts = ['ui1', 'ui2']
def run_app(cmd):
if env.user == 'root':
cmd = 'sudo -u app %s' % cmd
return run(cmd)
@task
def version():
run_app('svnversion /home/notsobad/ui')
@task
def reload_ui():
run_app('touch /tmp/.ui-reload')
@task
def deploy(username, password, to_version):
with cd('/home/notsobad/ui'):
cmd = 'svn up -r {to_version} --username {username} --password "{password}" .'.format(username=username, password=password, to_version=to_version)
run_app(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment