def get_build_configuration():
    # Values expected in the eb config section in BuildSpec
    service_role_key = 'CodeBuildServiceRole'
    image_key = 'Image'
    compute_key = 'ComputeType'
    timeout_key = 'Timeout'

    # get setting from global if it exists
    cwd = os.getcwd()  # save working directory

    try:
        _traverse_to_project_root()

        build_spec = _get_yaml_dict(buildspec_name)

        # Assert that special beanstalk section exists
        if build_spec is None or buildspec_config_header not in build_spec.keys(
        ):
            LOG.debug("Buildspec Keys: {0}".format(build_spec.keys()))
            io.log_warning(strings['codebuild.noheader'].replace(
                '{header}', buildspec_config_header))
            return None

        build_configuration = BuildConfiguration()
        beanstalk_build_configs = build_spec[buildspec_config_header]

        if beanstalk_build_configs is None:
            LOG.debug("No values for EB header in buildspec file")
            return build_configuration

        LOG.debug("EB Config Keys: {0}".format(beanstalk_build_configs.keys()))

        if service_role_key in beanstalk_build_configs.keys():
            build_configuration.service_role = beanstalk_build_configs[
                service_role_key]

        if image_key in beanstalk_build_configs.keys():
            build_configuration.image = beanstalk_build_configs[image_key]

        if compute_key in beanstalk_build_configs.keys():
            build_configuration.compute_type = beanstalk_build_configs[
                compute_key]

        if timeout_key in beanstalk_build_configs.keys():
            build_configuration.timeout = beanstalk_build_configs[timeout_key]

    finally:
        os.chdir(cwd)  # move back to working directory

    return build_configuration
Exemple #2
0
def get_build_configuration():
    # TODO: Verify this is correct.
    # Values expected in the eb config section in BuildSpec
    service_role_key = 'CodeBuildServiceRole'
    image_key = 'Image'
    compute_key = 'ComputeType'
    timeout_key = 'Timeout'

    # get setting from global if it exists
    cwd = os.getcwd()  # save working directory

    try:
        _traverse_to_project_root()

        build_spec = _get_yaml_dict(buildspec_name)

        # Assert that special beanstalk section exists
        if buildspec_config_header not in build_spec.keys():
            LOG.debug("Buildspec Keys: {0}".format(build_spec.keys()))
            raise ValidationError("Beanstalk configuration header '{0}' is missing from Buildspec file".format(buildspec_config_header))

        build_configuration = BuildConfiguration()
        beanstalk_build_configs = build_spec[buildspec_config_header]
        LOG.debug("EB Config Keys: {0}".format(beanstalk_build_configs.keys()))

        if service_role_key in beanstalk_build_configs.keys():
            build_configuration.service_role = beanstalk_build_configs[service_role_key]

        if image_key in beanstalk_build_configs.keys():
            build_configuration.image = beanstalk_build_configs[image_key]

        if compute_key in beanstalk_build_configs.keys():
            build_configuration.compute_type = beanstalk_build_configs[compute_key]

        if timeout_key in beanstalk_build_configs.keys():
            build_configuration.timeout = beanstalk_build_configs[timeout_key]

    finally:
        os.chdir(cwd)  # move back to working directory

    return build_configuration