From f6b389233e2d8ac3b4d29322d86fceb2e2de7a37 Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Thu, 20 Jan 2011 11:06:19 +0200 Subject: initial commit --- fabfile.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 fabfile.py (limited to 'fabfile.py') diff --git a/fabfile.py b/fabfile.py new file mode 100644 index 0000000..0a25331 --- /dev/null +++ b/fabfile.py @@ -0,0 +1,43 @@ +def bootstrap(): + """ initialize remote host environment (virtualenv, deploy, update) """ + require('root', provided_by=('staging', 'production')) + run('mkdir -p %(root)s' % env) + run('mkdir -p %s' % os.path.join(env.home, 'www', 'log')) + create_virtualenv() + deploy() + update_requirements() + + +def create_virtualenv(): + """ setup virtualenv on remote host """ + require('virtualenv_root', provided_by=('staging', 'production')) + args = '--clear --distribute' + run('virtualenv %s %s' % (args, env.virtualenv_root)) + + +def deploy(): + """ rsync code to remote host """ + require('root', provided_by=('staging', 'production')) + if env.environment == 'production': + if not console.confirm('Are you sure you want to deploy production?', + default=False): + utils.abort('Production deployment aborted.') + extra_opts = '--omit-dir-times' + rsync_project( + env.root, + exclude=RSYNC_EXCLUDE, + delete=True, + extra_opts=extra_opts, + ) + touch() + + +def update_requirements(): + """ update external dependencies on remote host """ + require('code_root', provided_by=('staging', 'production')) + requirements = os.path.join(env.code_root, 'requirements') + with cd(requirements): + cmd = ['pip install'] + cmd += ['-E %(virtualenv_root)s' % env] + cmd += ['--requirement %s' % os.path.join(requirements, 'apps.txt')] + run(' '.join(cmd)) \ No newline at end of file -- cgit v1.3.1