def _get_diff(environment, deploy_revs):
    global DEPLOY_DIFF
    if DEPLOY_DIFF is not None:
        return DEPLOY_DIFF

    tag_commits = environment.fab_settings_config.tag_deploy_commits
    repo = github_repo('dimagi/commcare-hq',
                       require_write_permissions=tag_commits)

    deployed_version = _get_deployed_version(environment)
    latest_version = repo.get_commit(
        deploy_revs['commcare']).sha if repo else None

    new_version_details = {
        'Branch deployed':
        ', '.join([f'{repo}: {ref}' for repo, ref in deploy_revs.items()])
    }
    if environment.fab_settings_config.custom_deploy_details:
        new_version_details.update(
            environment.fab_settings_config.custom_deploy_details)
    DEPLOY_DIFF = DeployDiff(
        repo,
        deployed_version,
        latest_version,
        new_version_details=new_version_details,
        generate_diff=environment.fab_settings_config.generate_deploy_diffs)
    return DEPLOY_DIFF
 def repo(self):
     match = re.match(r"[email protected]:(.*?).git", self.url)
     if not match:
         raise EnvironmentException(
             "Unable to parse repository URL: {}".format(self.url))
     repo = match.group(1)
     return github_repo(repo, repo_is_private=self.is_private)
Exemple #3
0
def env_common():
    servers = env.ccc_environment.sshable_hostnames_by_group

    env.is_monolith = len(set(servers['all']) - set(servers['control'])) < 2

    # turn whatever `code_branch` is into a commit hash
    env.deploy_ref = github_repo('dimagi/commcare-hq').get_commit(
        env.code_branch).sha

    _setup_path()

    all = servers['all']
    staticfiles = servers.get('staticfiles', servers['proxy'])
    webworkers = servers['webworkers']
    django_manage = servers.get('django_manage', [webworkers[0]])
    postgresql = servers['postgresql']
    pg_standby = servers.get('pg_standby', [])
    formplayer = servers['formplayer']
    elasticsearch = servers['elasticsearch']
    celery = servers['celery']
    # if no server specified, just don't run pillowtop
    pillowtop = servers.get('pillowtop', [])
    airflow = servers.get('airflow', [])

    deploy = servers.get('deploy', servers['webworkers'])[:1]

    if len(staticfiles) > 1 and not env.use_shared_dir_for_staticfiles:
        utils.abort(
            "There should be only one 'staticfiles' host. "
            "Ensure that only one host is assigned to the 'staticfiles' group, "
            "or enable use_shared_dir_for_staticfiles.")

    env.roledefs = {
        'all': all,
        'pg': postgresql,
        'pgstandby': pg_standby,
        'elasticsearch': elasticsearch,
        'django_celery': celery,
        'django_app': webworkers,
        'django_manage': django_manage,
        'django_pillowtop': pillowtop,
        'formplayer': formplayer,
        'staticfiles': staticfiles,
        'staticfiles_primary': [staticfiles[0]],
        'lb': [],
        # having deploy here makes it so that
        # we don't get prompted for a host or run deploy too many times
        'deploy': deploy,
        # fab complains if this doesn't exist
        'django_monolith': [],
        'control': servers.get('control')[:1],
        'airflow': airflow
    }
    env.roles = ['deploy']
    env.hosts = env.roledefs['deploy']
    env.resume = False
    env.full_deploy = False
    env.supervisor_roles = ROLES_ALL_SERVICES
Exemple #4
0
def _get_diff(environment, deploy_revs):
    global DEPLOY_DIFF
    if DEPLOY_DIFF is not None:
        return DEPLOY_DIFF

    tag_commits = environment.fab_settings_config.tag_deploy_commits
    repo = github_repo('dimagi/commcare-hq', require_write_permissions=tag_commits)

    deployed_version = _get_deployed_version(environment)
    latest_version = repo.get_commit(deploy_revs['commcare']).sha if repo else None

    DEPLOY_DIFF = DeployDiff(repo, deployed_version, latest_version, new_version_details=deploy_revs)
    return DEPLOY_DIFF
Exemple #5
0
def deploy_formplayer(environment, args):
    print(color_notice("\nPreparing to deploy Formplayer to: "), end="")
    print(f"{environment.name}\n")

    tag_commits = environment.fab_settings_config.tag_deploy_commits
    repo = github_repo('dimagi/formplayer',
                       require_write_permissions=tag_commits)

    diff = get_deploy_diff(environment, repo)
    diff.print_deployer_diff()

    context = DeployContext(service_name="Formplayer",
                            revision=args.commcare_rev,
                            diff=diff,
                            start_time=datetime.utcnow())

    if not ask('Continue with deploy?', quiet=args.quiet):
        return 1

    record_deploy_start(environment, context)

    rc = run_ansible_playbook_command(environment, args)
    if rc != 0:
        record_deploy_failed(environment, context)
        return rc

    rc = commcare_cloud(
        args.env_name,
        'run-shell-command',
        'formplayer',
        ('supervisorctl reread; '
         'supervisorctl update {project}-{deploy_env}-formsplayer-spring; '
         'supervisorctl restart {project}-{deploy_env}-formsplayer-spring'
         ).format(
             project='commcare-hq',
             deploy_env=environment.meta_config.deploy_env,
         ),
        '-b',
    )
    if rc != 0:
        record_deploy_failed(environment, context)
        return rc

    record_deploy_success(environment, context)
    return 0
Exemple #6
0
 def repo(self):
     tag_commits = getattr(env, "tag_deploy_commits", None)
     return github_repo('dimagi/commcare-hq',
                        require_write_permissions=tag_commits)