Ejemplo n.º 1
0
def get_git_shas_for_service(service, deploy_groups, soa_dir):
    """Returns a list of 2-tuples of the form (sha, timestamp) for each deploy tag in a service's git
    repository"""
    if service is None:
        return []
    git_url = get_git_url(service=service, soa_dir=soa_dir)
    all_deploy_groups = {
        config.get_deploy_group()
        for config in get_instance_config_for_service(
            service=service,
            soa_dir=soa_dir,
        )
    }
    deploy_groups, _ = validate_given_deploy_groups(all_deploy_groups,
                                                    deploy_groups)
    previously_deployed_shas = {}
    for ref, sha in list_remote_refs(git_url).items():
        regex_match = extract_tags(ref)
        try:
            deploy_group = regex_match['deploy_group']
            tstamp = regex_match['tstamp']
        except KeyError:
            pass
        else:
            # note that all strings are greater than ''
            if deploy_group in deploy_groups and tstamp > previously_deployed_shas.get(
                    sha, ''):
                previously_deployed_shas[sha] = tstamp
    return previously_deployed_shas.items()
Ejemplo n.º 2
0
def paasta_rollback(args):
    """Call mark_for_deployment with rollback parameters
    :param args: contains all the arguments passed onto the script: service,
    deploy groups and sha. These arguments will be verified and passed onto
    mark_for_deployment.
    """
    service = figure_out_service_name(args)
    git_url = get_git_url(service)
    commit = args.commit
    given_deploy_groups = [deploy_group for deploy_group in args.deploy_groups.split(",") if deploy_group]

    service_deploy_groups = set(config.get_deploy_group() for config in get_instance_config_for_service(
        soa_dir=DEFAULT_SOA_DIR,
        service=service,
    ))
    deploy_groups, invalid = validate_given_deploy_groups(service_deploy_groups, given_deploy_groups)
    if len(invalid) > 0:
        print PaastaColors.yellow("These deploy groups are not valid and will be skipped: %s.\n" % (",").join(invalid))

    if len(deploy_groups) == 0:
        print PaastaColors.red("ERROR: No valid deploy groups specified for %s.\n" % (service))
        returncode = 1

    for deploy_group in deploy_groups:
        returncode = mark_for_deployment(
            git_url=git_url,
            service=service,
            deploy_group=deploy_group,
            commit=commit,
        )

    sys.exit(returncode)
def get_branches(service, soa_dir):
    paasta_control_branches = set(('paasta-%s' % config.get_branch()
                                   for config in get_instance_config_for_service(soa_dir, service)))
    remote_refs = remote_git.list_remote_refs(utils.get_git_url(service))

    for branch in paasta_control_branches:
        if 'refs/heads/%s' % branch in remote_refs:
            yield branch
Ejemplo n.º 4
0
def paasta_rollback(args):
    """Call mark_for_deployment with rollback parameters
    :param args: contains all the arguments passed onto the script: service,
    deploy groups and sha. These arguments will be verified and passed onto
    mark_for_deployment.
    """
    soa_dir = args.soa_dir
    service = figure_out_service_name(args, soa_dir)

    git_url = get_git_url(service, soa_dir)
    given_deploy_groups = {
        deploy_group
        for deploy_group in args.deploy_groups.split(",") if deploy_group
    }

    service_deploy_groups = {
        config.get_deploy_group()
        for config in get_instance_config_for_service(
            service=service,
            soa_dir=soa_dir,
        )
    }
    deploy_groups, invalid = validate_given_deploy_groups(
        service_deploy_groups, given_deploy_groups)

    if len(invalid) > 0:
        print PaastaColors.yellow(
            "These deploy groups are not valid and will be skipped: %s.\n" %
            (",").join(invalid))

    if len(deploy_groups) == 0:
        print PaastaColors.red(
            "ERROR: No valid deploy groups specified for %s.\n" % (service))
        return 1

    commit = args.commit
    if not commit:
        list_previous_commits(service, deploy_groups,
                              bool(given_deploy_groups), soa_dir)
        return 1

    returncode = 0

    for deploy_group in deploy_groups:
        returncode = max(
            mark_for_deployment(
                git_url=git_url,
                service=service,
                deploy_group=deploy_group,
                commit=commit,
            ),
            returncode,
        )

    return returncode
Ejemplo n.º 5
0
def paasta_rollback(args):
    """Call mark_for_deployment with rollback parameters
    :param args: contains all the arguments passed onto the script: service,
    deploy groups and sha. These arguments will be verified and passed onto
    mark_for_deployment.
    """
    soa_dir = args.soa_dir
    service = figure_out_service_name(args, soa_dir)

    git_url = get_git_url(service, soa_dir)
    given_deploy_groups = {deploy_group for deploy_group in args.deploy_groups.split(",") if deploy_group}

    service_deploy_groups = {config.get_deploy_group() for config in get_instance_config_for_service(
        service=service,
        soa_dir=soa_dir,
    )}
    deploy_groups, invalid = validate_given_deploy_groups(service_deploy_groups, given_deploy_groups)

    if len(invalid) > 0:
        print PaastaColors.yellow("These deploy groups are not valid and will be skipped: %s.\n" % (",").join(invalid))

    if len(deploy_groups) == 0:
        print PaastaColors.red("ERROR: No valid deploy groups specified for %s.\n" % (service))
        return 1

    commit = args.commit
    if not commit:
        list_previous_commits(service, deploy_groups, bool(given_deploy_groups), soa_dir)
        return 1

    returncode = 0

    for deploy_group in deploy_groups:
        returncode = max(
            mark_for_deployment(
                git_url=git_url,
                service=service,
                deploy_group=deploy_group,
                commit=commit,
            ),
            returncode,
        )

    return returncode
Ejemplo n.º 6
0
def paasta_rollback(args):
    """Call mark_for_deployment with rollback parameters
    :param args: contains all the arguments passed onto the script: service,
    deploy groups and sha. These arguments will be verified and passed onto
    mark_for_deployment.
    """
    service = figure_out_service_name(args)
    git_url = get_git_url(service)
    commit = args.commit
    given_deploy_groups = [
        deploy_group for deploy_group in args.deploy_groups.split(",")
        if deploy_group
    ]

    service_deploy_groups = set(config.get_deploy_group()
                                for config in get_instance_config_for_service(
                                    soa_dir=DEFAULT_SOA_DIR,
                                    service=service,
                                ))
    deploy_groups, invalid = validate_given_deploy_groups(
        service_deploy_groups, given_deploy_groups)
    if len(invalid) > 0:
        print PaastaColors.yellow(
            "These deploy groups are not valid and will be skipped: %s.\n" %
            (",").join(invalid))

    if len(deploy_groups) == 0:
        print PaastaColors.red(
            "ERROR: No valid deploy groups specified for %s.\n" % (service))
        returncode = 1

    for deploy_group in deploy_groups:
        returncode = mark_for_deployment(
            git_url=git_url,
            service=service,
            deploy_group=deploy_group,
            commit=commit,
        )

    sys.exit(returncode)
Ejemplo n.º 7
0
def get_git_shas_for_service(service, deploy_groups, soa_dir):
    """Returns a list of 2-tuples of the form (sha, timestamp) for each deploy tag in a service's git
    repository"""
    if service is None:
        return []
    git_url = get_git_url(service=service, soa_dir=soa_dir)
    all_deploy_groups = {config.get_deploy_group() for config in get_instance_config_for_service(
        service=service,
        soa_dir=soa_dir,
    )}
    deploy_groups, _ = validate_given_deploy_groups(all_deploy_groups, deploy_groups)
    previously_deployed_shas = {}
    for ref, sha in list_remote_refs(git_url).items():
        regex_match = extract_tags(ref)
        try:
            deploy_group = regex_match['deploy_group']
            tstamp = regex_match['tstamp']
        except KeyError:
            pass
        else:
            # note that all strings are greater than ''
            if deploy_group in deploy_groups and tstamp > previously_deployed_shas.get(sha, ''):
                previously_deployed_shas[sha] = tstamp
    return previously_deployed_shas.items()
Ejemplo n.º 8
0
def paasta_mark_for_deployment(args):
    """Wrapping mark_for_deployment"""
    if args.verbose:
        log.setLevel(level=logging.DEBUG)
    else:
        log.setLevel(level=logging.INFO)
    service = args.service
    if service and service.startswith('services-'):
        service = service.split('services-', 1)[1]

    validate_service_name(service, soa_dir=args.soa_dir)
    in_use_deploy_groups = {
        config.get_deploy_group()
        for config in get_instance_config_for_service(
            service=service,
            soa_dir=args.soa_dir,
        )
    }
    _, invalid_deploy_groups = validate_given_deploy_groups(
        in_use_deploy_groups, [args.deploy_group])

    if len(invalid_deploy_groups) == 1:
        print PaastaColors.red(
            "ERROR: These deploy groups are not currently used anywhere: %s.\n"
            % (",").join(invalid_deploy_groups))
        print PaastaColors.red(
            "This isn't technically wrong because you can mark-for-deployment before deploying there"
        )
        print PaastaColors.red(
            "but this is probably a typo. Did you mean one of these in-use deploy groups?:"
        )
        print PaastaColors.red("   %s" % (",").join(in_use_deploy_groups))
        print ""
        print PaastaColors.red("Continuing regardless...")

    ret = mark_for_deployment(
        git_url=args.git_url,
        deploy_group=args.deploy_group,
        service=service,
        commit=args.commit,
    )
    if args.block:
        try:
            line = "Waiting for deployment of {0} to {1} complete".format(
                args.commit, args.deploy_group)
            log.info(line)
            wait_for_deployment(service=service,
                                deploy_group=args.deploy_group,
                                git_sha=args.commit,
                                soa_dir=args.soa_dir,
                                timeout=args.timeout)
            line = "Deployment of {0} to {1} complete".format(
                args.commit, args.deploy_group)
            _log(service=service, component='deploy', line=line, level='event')
        except KeyboardInterrupt:
            print "Waiting for deployment aborted. PaaSTA will continue to try to deploy this code."
            print "If you wish to see the status, run:"
            print ""
            print "    paasta status -s %s -v" % service
            print ""
            print "Or if you wish to rollback:"
            print ""
            print "    paasta rollback -s %s -d %s" % (service,
                                                       args.deploy_group)
            sys.exit(1)
        except TimeoutError:
            sys.exit(1)
    return ret