def launch_webserver_bcpp_task(**kwargs):
    """Add missing DB column.

    fab -P -R mmathethe utils.launch_webserver_bcpp_task:target_os=Darwin --user=django

    """
    prepare_env(**kwargs)
    launch_webserver()
def r0135(**kwargs):
    """Release 0.1.35.
    """

    release = '0.1.34'
    packages = [
        'git+https://github.com/botswana-harvard/bcpp-subject.git@master#egg=bcpp_subject',
        'git+https://github.com/botswana-harvard/plot.git@master#egg=plot'
    ]

    bootstrap_filename = 'bootstrap_client.conf'

    prepare_env(bootstrap_filename=bootstrap_filename, **kwargs)

    venv_name = env.venv_name

    rsync_deployment_root()

    venv_name = venv_name or env.venv_name
    # copy new pip tarballs to deployment root
    for package in packages:
        pip_download(package)

    with cd('/Users/django/source/bcpp'):
        run('git stash')
        run('git pull')
        run('git stash pop')

#     for package in packages:
    uninstall_package = package.split('=')[1]
    run('workon {venv_name} && pip3 uninstall {package_name}'.format(
        venv_name=venv_name, package_name=uninstall_package))
    pip_install_from_cache(package_name=package, venv_name=venv_name)

    mount_dmg(dmg_path=env.etc_dir,
              dmg_filename=env.dmg_filename,
              dmg_passphrase=env.crypto_keys_passphrase)

    with cd(os.path.join(env.remote_source_root, env.project_repo_name)):
        run('git checkout master')
        result = run(
            'git diff --name-status master..{release}'.format(release=release))
        if result:
            warn('master is not at {release}'.format(release=release))

    update_settings()

    install_protocol_database()

    launch_webserver()
def r0134(bootstrap_filename=None,
          skip_update_project_repo=None,
          skip_venv=None,
          map_area=None,
          **kwargs):
    """Release 0.1.34.
    """
    release = '0.1.34'
    bootstrap_filename = bootstrap_filename or 'bootstrap_client.conf'
    if not map_area:
        abort('Specify the map_area')

    prepare_env(release=release,
                bootstrap_filename=bootstrap_filename,
                map_area=map_area,
                **kwargs)

    rsync_deployment_root()

    if not skip_update_project_repo:
        print('rsync -pthrvz --delete {source} {destination}'.format(
            source=os.path.join(env.deployment_root, env.project_appname),
            destination=env.remote_source_root))
        run('rsync -pthrvz --delete {source} {destination}'.format(
            source=os.path.join(env.deployment_root, env.project_appname),
            destination=env.remote_source_root))

    with cd(os.path.join(env.project_repo_root)):
        run('git checkout master')

    if not skip_venv:
        create_venv()
    install_gunicorn()

    # copy bcpp.conf into etc/{project_app_name}/
    mount_dmg(dmg_path=env.etc_dir,
              dmg_filename=env.dmg_filename,
              dmg_passphrase=env.crypto_keys_passphrase)
    put_mysql_conf()
    put_my_cnf()
    put_project_conf()
    update_bcpp_conf()
    update_settings()

    install_protocol_database(skip_backup=True)

    get_pip_list()

    launch_webserver()
Пример #4
0
def update_temp_task(map_area=None, bootstrap_filename=None, **kwargs):
    release = '0.1.34'
    if not map_area:
        abort('Specify the map_area')
    bootstrap_filename = bootstrap_filename or 'bootstrap_client.conf'
    prepare_env(release=release,
                bootstrap_filename=bootstrap_filename,
                map_area=map_area,
                **kwargs)
    run(f'rm ~/deployment/bcpp/database/{release}/{map_area}/edc_mmathethe_deployment_201704260014.sql', warn_only=True)
    local_path = os.path.expanduser(
        f'~/deployment/{release}/{map_area}/edc_mmathethe_deployment_201704260454.sql')
    remote_path = f'~/deployment/bcpp/database/{release}/{map_area}/edc_mmathethe_deployment_201704260454.sql'
    rsync_project(local_dir=local_path, remote_dir=remote_path)
    install_protocol_database(skip_backup=True)
    launch_webserver()
Пример #5
0
def r01341(skip_db=None,
           bootstrap_filename=None,
           venv_name=None,
           map_area=None,
           **kwargs):
    """Release 0.1.34.1
    """

    release = '0.1.34'
    packages = [
        'git+https://github.com/botswana-harvard/bcpp-subject.git@master#egg=bcpp_subject',
        'git+https://github.com/botswana-harvard/plot.git@master#egg=plot'
    ]
    bootstrap_filename = bootstrap_filename or 'bootstrap_client.conf'

    if not map_area:
        abort('Specify the map_area')

    prepare_env(release=release,
                bootstrap_filename=bootstrap_filename,
                map_area=map_area,
                **kwargs)

    venv_name = venv_name or env.venv_name

    rsync_deployment_root()

    # copy new pip tarballs to deployment root
    for package in packages:
        pip_download(package)

    for package in packages:
        uninstall_package = package.split('=')[1]
        run('workon {venv_name} && pip3 uninstall {package_name}'.format(
            venv_name=venv_name, package_name=uninstall_package))
        pip_install_from_cache(package_name=package, venv_name=venv_name)

    with cd('/Users/django/source/bcpp'):
        with prefix('source /Users/django/.venvs/bcpp/bin/activate'):
            run('python manage.py update_anonymous_sectioning')

    mount_dmg(dmg_path=env.etc_dir,
              dmg_filename=env.dmg_filename,
              dmg_passphrase=env.crypto_keys_passphrase)

    launch_webserver()
def change_map_area_task(map_area=None,
                         bootstrap_path=None,
                         bootstrap_branch=None):
    """Change a remote host's map area and restart web.

    For example:

        fab -H bcpp057 utils.change_map_area_task:bootstrap_path=/Users/erikvw/source/bcpp/fabfile/conf/,bootstrap_branch=develop,map_area=mmankgodi --user=django

    """
    bootstrap_env(path=bootstrap_path,
                  filename='bootstrap_client.conf',
                  bootstrap_branch=bootstrap_branch)

    update_fabric_env()

    update_bcpp_conf(map_area=map_area)

    launch_webserver()
def deploy_client(conf_filename=None, bootstrap_path=None, map_area=None, user=None,
                  bootstrap_branch=None, skip_mysql=None, skip_python=None,
                  work_online=True, deployment_root=None, release=None, **kwargs):

    #  Install Mysql,

    #  Create a venv with installed requirements.
    conf_filename = 'bootstrap_client.conf'
    env.deployment_root = deployment_root
    env.etc_dir = '/etc/'
    env.project_conf = 'bcpp-clinic.conf'
    env.dbname = 'edc'
    env.device_id = 78
    env.python_version = 3.6
    env.venv_name = 'bcpp-clinic'
    env.venv_dir = '/Users/django/.venvs/'
    clone_clinic_repo()
    bootstrap_env(
        path=bootstrap_path,
        filename=conf_filename,
        bootstrap_branch=None)
    env.bootstrap_path = bootstrap_path or env.bootstrap_path

    if not release:
        abort('Specify the release')
    if not map_area:
        abort('Specify the map_area')

    env.project_release = release
    env.map_area = map_area

    env.project_repo_name = get_repo_name(env.project_repo_url)
    env.project_repo_root = os.path.join(
        env.deployment_root, env.project_repo_name)
    env.fabric_config_root = os.path.join(env.project_repo_root, 'fabfile')
    env.fabric_config_path = os.path.join(
        env.fabric_config_root, 'conf', env.fabric_conf)

    rsync_deployment_root()
    project_conf = 'bcpp-clinic.conf'
    local_copy = os.path.expanduser(os.path.join(
        env.fabric_config_root, 'conf', project_conf))
    remote_copy = os.path.join(
        env.etc_dir, 'bcpp-clinic')
    path1 = os.path.join(env.etc_dir, 'bcpp-clinic')
    if exists(path1):
        sudo('rm -rf {path1}')
    if not exists(env.etc_dir):
        sudo('mkdir {etc_dir}'.format(etc_dir=env.etc_dir))
    if not exists(remote_copy):
        sudo(f'mkdir {remote_copy}')
    put(local_copy, remote_copy, use_sudo=True)
    update_bcpp_clinic_conf()

    update_fabric_env()
    if not skip_mysql:
        install_mysql()

    if not skip_python:
        install_python3()
    run('mysql -uroot -pcc3721b drop database edc;', warn_only=True)
    run('mysql -uroot -pcc3721b create database edc character set utf8;',
        warn_only=True)
    create_venv(env.venv_name, env.requirements_file)
    install_nginx(skip_bootstrap=True)
    install_gunicorn(work_online=True)
    launch_webserver()
Пример #8
0
def launch_webserver_bcpp(**kwargs):
    prepare_env(**kwargs)
    mount_dmg(dmg_path=env.etc_dir,
              dmg_filename=env.dmg_filename,
              dmg_passphrase=env.crypto_keys_passphrase)
    launch_webserver()
Пример #9
0
def deploy(requirements_list=None,
           conf_filename=None,
           bootstrap_path=None,
           release=None,
           map_area=None,
           user=None,
           bootstrap_branch=None,
           skip_update_os=None,
           skip_db=None,
           skip_restore_db=None,
           skip_repo=None,
           skip_venv=None,
           skip_mysql=None,
           skip_python=None,
           skip_web=None,
           update=None,
           current_tag=None,
           skip_collectstatic=None,
           skip_bash_config=None,
           skip_keys=None,
           work_online=None,
           specific_tag=None):

    bootstrap_env(path=bootstrap_path,
                  filename=conf_filename,
                  bootstrap_branch=bootstrap_branch)
    if not release:
        abort('Specify the release')
    if not map_area:
        abort('Specify the map_area')

    env.project_release = release
    env.map_area = map_area

    env.project_repo_name = get_repo_name(env.project_repo_url)
    env.project_repo_root = os.path.join(env.deployment_root,
                                         env.project_repo_name)
    env.fabric_config_root = os.path.join(env.project_repo_root, 'fabfile')
    env.fabric_config_path = os.path.join(env.fabric_config_root, 'conf',
                                          env.fabric_conf)

    rsync_deployment_root()

    if update:
        env.fabric_config_path = os.path.expanduser(
            os.path.join('/Users/django/source', env.project_repo_name,
                         'fabfile/conf', env.fabric_conf))
        update_fabric_env()

        for package in requirements_list:
            run(f'source {activate_venv()} && pip3 uninstall {package}',
                warn_only=True)
            pip_install_from_cache(package_name=package,
                                   venv_name=env.venv_name)

        if not skip_repo:
            put_ambition_repo()

    else:
        update_fabric_env()
        if not skip_update_os:
            if env.target_os == MACOSX:
                update_brew_cache(no_auto_update=True)
            elif env.target_os == LINUX:
                sudo('apt-get update')

        if not skip_bash_config:
            put_bash_config()

        if not exists(
                os.path.join(env.remote_source_root, env.project_repo_name)):
            run('mkdir -p {remote_source_root}'.format(
                remote_source_root=env.remote_source_root),
                warn_only=True)

        if not skip_repo:
            put_ambition_repo()

        # make static and media
        if not exists(env.static_root):
            run('mkdir {static_root}'.format(static_root=env.static_root),
                warn_only=True)
        if not exists(env.media_root):
            run('mkdir {media_root}'.format(media_root=env.media_root),
                warn_only=True)

        if not skip_mysql:
            install_mysql()

        if not skip_python:
            install_python3()

        if not skip_venv:
            with cd(os.path.join(env.project_repo_root)):
                if specific_tag:
                    run(f'git checkout {release}')
            create_venv(work_online=work_online)

        if not skip_web:
            if env.log_root and exists(env.log_root):
                sudo('rm -rf {log_root}'.format(log_root=env.log_root),
                     warn_only=True)
            run('mkdir -p {log_root}'.format(log_root=env.log_root))
            install_nginx(skip_bootstrap=True)
            install_gunicorn(work_online=work_online)

        if not skip_keys:
            # crypto_keys DMG into etc/{project_app_name}/
            put(os.path.expanduser(
                os.path.join(env.fabric_config_root, 'etc', env.dmg_filename)),
                env.etc_dir,
                use_sudo=True)

    # copy ambition.conf into etc/{project_app_name}/
    put_project_conf()
    update_ambition_conf

    with cd(os.path.join(env.project_repo_root)):
        if specific_tag:
            run(f'git checkout {release}')
        else:
            run('git checkout master')

    # mount dmg
    if env.device_role == CENTRAL_SERVER:
        mount_dmg_locally(dmg_path=env.etc_dir,
                          dmg_filename=env.dmg_filename,
                          dmg_passphrase=env.crypto_keys_passphrase)
        if not exists(env.key_path):
            sudo(f'mkdir -p {env.key_path}')
        with lcd(env.key_volume):
            put(local_path='user*',
                remote_path=f'{env.key_path}/',
                use_sudo=True)
        dismount_dmg_locally(volume_name=env.key_volume)
    else:
        mount_dmg(dmg_path=env.etc_dir,
                  dmg_filename=env.dmg_filename,
                  dmg_passphrase=env.crypto_keys_passphrase)

    with cd(os.path.join(env.remote_source_root, env.project_repo_name)):
        if specific_tag:
            run(f'git checkout {release}')
        else:
            run('git checkout master')
            result = run('git diff --name-status master..{release}'.format(
                release=release))
            if result:
                warn('master is not at {release}'.format(release=release))

    update_settings()

    if not skip_db:
        run('brew services stop mysql', warn_only=True)
        run('brew services start mysql')
    if not skip_restore_db:
        install_protocol_database(skip_backup=True)

    if not skip_collectstatic:
        with cd(os.path.join(env.remote_source_root, env.project_repo_name)):
            with prefix(f'source {activate_venv()}'.format(
                    venv_name=env.venv_name)):
                run('python manage.py collectstatic')
                run('python manage.py collectstatic_js_reverse')

    launch_webserver()
Пример #10
0
def deploy_client(conf_filename=None,
                  bootstrap_path=None,
                  map_area=None,
                  user=None,
                  bootstrap_branch=None,
                  skip_mysql=None,
                  skip_python=None,
                  work_online=True,
                  deployment_root=None,
                  release=None,
                  **kwargs):

    #  Install Mysql,

    #  Create a venv with installed requirements.
    conf_filename = 'bootstrap_client.conf'
    env.deployment_root = deployment_root
    env.etc_dir = '/etc/'
    env.project_conf = 'bcpp-clinic.conf'
    env.dbname = 'edc'
    env.device_id = 78
    env.python_version = 3.6
    env.venv_name = 'bcpp-clinic'
    env.venv_dir = '/Users/django/.venvs/'
    clone_clinic_repo()
    bootstrap_env(path=bootstrap_path,
                  filename=conf_filename,
                  bootstrap_branch=None)
    env.bootstrap_path = bootstrap_path or env.bootstrap_path

    if not release:
        abort('Specify the release')
    if not map_area:
        abort('Specify the map_area')

    env.project_release = release
    env.map_area = map_area

    env.project_repo_name = get_repo_name(env.project_repo_url)
    env.project_repo_root = os.path.join(env.deployment_root,
                                         env.project_repo_name)
    env.fabric_config_root = os.path.join(env.project_repo_root, 'fabfile')
    env.fabric_config_path = os.path.join(env.fabric_config_root, 'conf',
                                          env.fabric_conf)

    rsync_deployment_root()
    project_conf = 'bcpp-clinic.conf'
    local_copy = os.path.expanduser(
        os.path.join(env.fabric_config_root, 'conf', project_conf))
    remote_copy = os.path.join(env.etc_dir, 'bcpp-clinic')
    path1 = os.path.join(env.etc_dir, 'bcpp-clinic')
    if exists(path1):
        sudo('rm -rf {path1}')
    if not exists(env.etc_dir):
        sudo('mkdir {etc_dir}'.format(etc_dir=env.etc_dir))
    if not exists(remote_copy):
        sudo(f'mkdir {remote_copy}')
    put(local_copy, remote_copy, use_sudo=True)
    update_bcpp_clinic_conf()

    update_fabric_env()
    if not skip_mysql:
        install_mysql()

    if not skip_python:
        install_python3()
    run('mysql -uroot -pcc3721b drop database edc;', warn_only=True)
    run('mysql -uroot -pcc3721b create database edc character set utf8;',
        warn_only=True)
    create_venv(env.venv_name, env.requirements_file)
    install_nginx(skip_bootstrap=True)
    install_gunicorn(work_online=True)
    launch_webserver()