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))