def install_geotaxi(): require.deb.packages(['libhiredis-dev']) git.checkout('GeoTaxi') git.pull('GeoTaxi') with cd('GeoTaxi'): require.files.directory('obj') run('make')
def install_swagger_ui(): with cd('~'): if not files.exists('APITaxi_swagger'): git.clone('https://github.com/openmaraude/APITaxi_swagger') git.checkout('APITaxi_swagger') git.pull('APITaxi_swagger') return path.join(run('pwd'), 'APITaxi_swagger')
def install(): sudo('rm -rf {}'.format(SETTINGS['proj']['remote-root'])) sudo('rm -rf {}'.format(SETTINGS['proj']['remote-venv'])) git.clone('https://github.com/ccortezia/featuring.git', path=SETTINGS['proj']['remote-root'], use_sudo=False) git.checkout(SETTINGS['proj']['remote-root'], branch='api-revamp') require.python.virtualenv(SETTINGS['proj']['remote-venv'], venv_python='/usr/bin/python3.7') require.python.pip() with python.virtualenv(SETTINGS['proj']['remote-venv']): python.install_requirements(os.path.join(COMPROOT, 'requirements.txt')) upload_template( filename=SETTINGS['supervisor']['proj-local'], destination=SETTINGS['supervisor']['proj-remote'], context={}, use_sudo=True) sudo('mkdir -p {}'.format(os.path.dirname(SETTINGS['gunicorn']['proj-remote']))) put(SETTINGS['gunicorn']['proj-local'], SETTINGS['gunicorn']['proj-remote'], use_sudo=True) with python.virtualenv(SETTINGS['proj']['remote-venv']): require.python.package('gunicorn')
def working_copy(remote_url, path=None, branch="master", update=True, use_sudo=False, user=None): """ Require a working copy of the repository from the ``remote_url``. Clones or pulls from the repository under ``remote_url`` and checks out ``branch``. :param remote_url: URL of the remote repository (e.g. https://github.com/ronnix/fabtools.git). The given URL will be the ``origin`` remote of the working copy. :type remote_url: str :param path: Absolute or relative path of the working copy on the filesystem. If this directory doesn't exist yet, a new working copy is created through ``git clone``. If the directory does exist *and* ``update == True``, a ``git pull`` is issued. If ``path is None`` the ``git clone`` is issued in the current working directory and the directory name of the working copy is created by ``git``. :type path: str :param branch: Branch to switch to after cloning or pulling. :type branch: str :param update: Whether or not to update an existing working copy via ``git pull``. :type update: bool :param use_sudo: If ``True`` execute ``git`` with :func:`fabric.operations.sudo`, else with :func:`fabric.operations.run`. :type use_sudo: bool :param user: If ``use_sudo is True``, run :func:`fabric.operations.sudo` with the given user. If ``use_sudo is False`` this parameter has no effect. :type user: str """ if is_dir(path, use_sudo=use_sudo) and update: # git pull git.pull(path=path, use_sudo=use_sudo, user=user) elif is_dir(path, use_sudo=use_sudo) and not update: # do nothing return elif not is_dir(path, use_sudo=use_sudo): # git clone git.clone(remote_url, path=path, use_sudo=use_sudo, user=user) if path is None: path = remote_url.split('/')[-1].replace('.git', '') else: raise ValueError("Invalid combination of parameters.") git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user)
def setup_server(): """ Setup project on clean Ubuntu server """ sudo('apt-get update') require.deb.packages([ 'sudo', 'mc', 'git', 'nginx', 'supervisor', 'uwsgi', 'uwsgi-plugin-python', 'libpq-dev', ]) # Creating project paths sudo('mkdir {env.project_path:s} -p'.format(env=env)) sudo('chown {env.project_user:s} {env.project_path:s}'.format(env=env)) sudo('mkdir {env.venv_path:s} -p'.format(env=env)) sudo('chown {env.project_user:s} {env.venv_path:s}'.format(env=env)) git.clone(env.repository_url, path=env.project_path, use_sudo=False, user=env.project_user) git.checkout(path=env.project_path, branch=env.branch, use_sudo=False, user=env.project_user) require.python.virtualenv(env.venv_path, use_sudo=False) with virtualenv(env.venv_path): require.python.requirements(os.path.join(env.project_path, 'requirements.txt')) require.postgres.server() require.postgres.user(env.db_user, password=env.db_pass, createdb=False, createrole=True) require.postgres.database(env.db_name, env.db_user) upload_template( filename='conf/server_local.py', destination='%(settings_path)s/local.py' % env, context={ 'db_name': env.db_name, 'db_pass': env.db_pass, 'db_user': env.db_user, }, use_jinja=True ) with cd(env.manage_path): run('chmod ogu+x manage.py') uwsgi_setup() supervisor_setup() sudo('rm /etc/nginx/sites-enabled/default') nginx_setup() manage('syncdb') manage('migrate') manage('collectstatic --noinput')
def run_tests(): """Run all tests for the project""" with virtualenv(env.virtualenv_path): if env.has_key("deploy_branch"): checkout(env.app_path, env.deploy_branch) with cd(env.source_root): sudo("./manage.py test")
def deploy_code(repo_url='', app_dir='', user='', remote='origin', branch='master'): raw_branch = '' if '/' in branch: remote, raw_branch = branch.split('/') print(green('Fetching {}'.format(remote))) git.fetch(app_dir, remote=remote) print(green('Checking out {}'.format(branch))) git.checkout(app_dir, branch=branch) print(green('Pulling updates from {}'.format(branch))) if raw_branch: git.pull(app_dir, remote=remote, branch=raw_branch) else: git.pull(app_dir, remote=remote, branch=branch)
def clone_repository(): if not exists(os.path.join(env.app_root, "requirements.txt")): clone(env.git_url, env.app_root, use_sudo=True) if env.has_key("deploy_branch"): checkout(env.app_root, env.deploy_branch, use_sudo=True)
def working_copy(remote_url, path=None, branch="master", update=True, use_sudo=False, user=None): """ Require a working copy of the repository from the ``remote_url``. The ``path`` is optional, and defaults to the last segment of the remote repository URL, without its ``.git`` suffix. If the ``path`` does not exist, this will clone the remote repository and check out the specified branch. If the ``path`` exists and ``update`` is ``True``, it will fetch changes from the remote repository, check out the specified branch, then merge the remote changes into the working copy. If the ``path`` exists and ``update`` is ``False``, it will only check out the specified branch, without fetching remote changesets. :param remote_url: URL of the remote repository (e.g. https://github.com/ronnix/fabtools.git). The given URL will be the ``origin`` remote of the working copy. :type remote_url: str :param path: Absolute or relative path of the working copy on the filesystem. If this directory doesn't exist yet, a new working copy is created through ``git clone``. If the directory does exist *and* ``update == True``, a ``git fetch`` is issued. If ``path is None`` the ``git clone`` is issued in the current working directory and the directory name of the working copy is created by ``git``. :type path: str :param branch: Branch to check out. :type branch: str :param update: Whether or not to fetch and merge remote changesets. :type update: bool :param use_sudo: If ``True`` execute ``git`` with :func:`fabric.operations.sudo`, else with :func:`fabric.operations.run`. :type use_sudo: bool :param user: If ``use_sudo is True``, run :func:`fabric.operations.sudo` with the given user. If ``use_sudo is False`` this parameter has no effect. :type user: str """ command() if path is None: path = remote_url.split('/')[-1].rstrip('.git') if is_dir(path, use_sudo=use_sudo) and update: git.fetch(path=path, use_sudo=use_sudo, user=user) git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user) git.pull(path=path, use_sudo=use_sudo, user=user) elif is_dir(path, use_sudo=use_sudo) and not update: git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user) elif not is_dir(path, use_sudo=use_sudo): git.clone(remote_url, path=path, use_sudo=use_sudo, user=user) git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user) else: raise ValueError("Invalid combination of parameters.")
def working_copy(remote_url, path=None, branch="master", update=True, stash=True, use_sudo=False, user=None): """ Require a working copy of the repository from the ``remote_url``. Clones or pulls from the repository under ``remote_url`` and checks out ``branch``. :param remote_url: URL of the remote repository (e.g. https://github.com/ronnix/fabtools.git). The given URL will be the ``origin`` remote of the working copy. :type remote_url: str :param path: Absolute or relative path of the working copy on the filesystem. If this directory doesn't exist yet, a new working copy is created through ``git clone``. If the directory does exist *and* ``update == True``, a ``git pull`` is issued. If ``path is None`` the ``git clone`` is issued in the current working directory and the directory name of the working copy is created by ``git``. :type path: str :param branch: Branch to switch to after cloning or pulling. :type branch: str :param update: Whether or not to update an existing working copy via ``git pull``. :type update: bool :param use_sudo: If ``True`` execute ``git`` with :func:`fabric.operations.sudo`, else with :func:`fabric.operations.run`. :type use_sudo: bool :param user: If ``use_sudo is True``, run :func:`fabric.operations.sudo` with the given user. If ``use_sudo is False`` this parameter has no effect. :type user: str """ if is_dir(path, use_sudo=use_sudo) and update: # git pull git.pull(path=path, use_sudo=use_sudo, user=user, stash=stash) elif is_dir(path, use_sudo=use_sudo) and not update: # do nothing return elif not is_dir(path, use_sudo=use_sudo): # git clone git.clone(remote_url, path=path, use_sudo=use_sudo, user=user) if path is None: path = remote_url.split('/')[-1].replace('.git', '') else: raise ValueError("Invalid combination of parameters.") git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user)
def working_copy(remote_url, path=None, branch="master", update=True, use_sudo=False, user=None): """ Require a working copy of the repository from the ``remote_url``. The ``path`` is optional, and defaults to the last segment of the remote repository URL, without its ``.git`` suffix. If the ``path`` does not exist, this will clone the remote repository and check out the specified branch. If the ``path`` exists and ``update`` is ``True``, it will fetch changes from the remote repository, check out the specified branch, then merge the remote changes into the working copy. If the ``path`` exists and ``update`` is ``False``, it will only check out the specified branch, without fetching remote changesets. :param remote_url: URL of the remote repository (e.g. https://github.com/ronnix/fabtools.git). The given URL will be the ``origin`` remote of the working copy. :type remote_url: str :param path: Absolute or relative path of the working copy on the filesystem. If this directory doesn't exist yet, a new working copy is created through ``git clone``. If the directory does exist *and* ``update == True``, a ``git fetch`` is issued. If ``path is None`` the ``git clone`` is issued in the current working directory and the directory name of the working copy is created by ``git``. :type path: str :param branch: Branch to check out. :type branch: str :param update: Whether or not to fetch and merge remote changesets. :type update: bool :param use_sudo: If ``True`` execute ``git`` with :func:`fabric.operations.sudo`, else with :func:`fabric.operations.run`. :type use_sudo: bool :param user: If ``use_sudo is True``, run :func:`fabric.operations.sudo` with the given user. If ``use_sudo is False`` this parameter has no effect. :type user: str """ if path is None: path = remote_url.split('/')[-1].rstrip('.git') if is_dir(path, use_sudo=use_sudo) and update: git.fetch(path=path, use_sudo=use_sudo, user=user) git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user) git.pull(path=path, use_sudo=use_sudo, user=user) elif is_dir(path, use_sudo=use_sudo) and not update: git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user) elif not is_dir(path, use_sudo=use_sudo): git.clone(remote_url, path=path, use_sudo=use_sudo, user=user) git.checkout(path=path, branch=branch, use_sudo=use_sudo, user=user) else: raise ValueError("Invalid combination of parameters.")