Exemplo n.º 1
0
    def __init__(self):
        """Setup the Runner for all Foremast modules."""
        debug_flag()

        self.email = os.getenv("EMAIL")
        self.env = os.getenv("ENV")
        self.group = os.getenv("PROJECT")
        self.region = os.getenv("REGION")
        self.repo = os.getenv("GIT_REPO")
        self.runway_dir = os.getenv("RUNWAY_DIR")
        self.artifact_path = os.getenv("ARTIFACT_PATH")
        self.artifact_version = os.getenv("ARTIFACT_VERSION")
        self.promote_stage = os.getenv("PROMOTE_STAGE", "latest")
        self.provider = os.getenv("PROVIDER", "aws")

        self.git_project = "{}/{}".format(self.group, self.repo)
        parsed = gogoutils.Parser(self.git_project)
        generated = gogoutils.Generator(*parsed.parse_url(), formats=consts.APP_FORMATS)

        self.app = generated.app_name()
        self.trigger_job = generated.jenkins()['name']
        self.git_short = generated.gitlab()['main']

        self.raw_path = "./raw.properties"
        self.json_path = self.raw_path + ".json"
        self.configs = None
Exemplo n.º 2
0
def main():
    """Entry point for creating a Spinnaker application."""
    # Setup parser
    parser = argparse.ArgumentParser()
    add_debug(parser)
    add_app(parser)
    parser.add_argument('--email',
                        help='Email address to associate with application',
                        default='*****@*****.**')
    parser.add_argument('--project',
                        help='Git project to associate with application',
                        default='None')
    parser.add_argument('--repo',
                        help='Git repo to associate with application',
                        default='None')
    parser.add_argument('--git', help='Git URI', default=None)
    args = parser.parse_args()

    logging.basicConfig(format=LOGGING_FORMAT)
    logging.getLogger(__package__.split('.')[0]).setLevel(args.debug)

    if args.git and args.git != 'None':
        parsed = gogoutils.Parser(args.git).parse_url()
        generated = gogoutils.Generator(*parsed, formats=APP_FORMATS)
        project = generated.project
        repo = generated.repo
    else:
        project = args.project
        repo = args.repo

    spinnakerapps = SpinnakerApp(app=args.app,
                                 email=args.email,
                                 project=project,
                                 repo=repo)
    spinnakerapps.create_app()
Exemplo n.º 3
0
def get_details(app='groupproject', env='dev'):
    """Extract details for Application.

    Args:
        app (str): Application Name
        env (str): Environment/account to get details from

    Returns:
        collections.namedtuple with _group_, _policy_, _profile_, _role_,
            _user_.
    """
    api = murl.Url(API_URL)
    api.path = 'applications/{app}'.format(app=app)

    request = requests.get(api.url,
                           verify=GATE_CA_BUNDLE,
                           cert=GATE_CLIENT_CERT)

    if not request.ok:
        raise SpinnakerAppNotFound('"{0}" not found.'.format(app))

    app_details = request.json()

    LOG.debug('App details: %s', app_details)
    group = app_details['attributes'].get('repoProjectKey')
    project = app_details['attributes'].get('repoSlug')
    generated = gogoutils.Generator(group,
                                    project,
                                    env=env,
                                    formats=APP_FORMATS)

    LOG.debug('Application details: %s', generated)
    return generated
Exemplo n.º 4
0
def get_details(app='groupproject', env='dev', region='us-east-1'):
    """Extract details for Application.

    Args:
        app (str): Application Name
        env (str): Environment/account to get details from

    Returns:
        collections.namedtuple with _group_, _policy_, _profile_, _role_,
            _user_.

    """
    uri = '/applications/{app}'.format(app=app)
    request = gate_request(uri=uri)

    if not request.ok:
        raise SpinnakerAppNotFound('"{0}" not found.'.format(app))

    app_details = request.json()

    LOG.debug('App details: %s', app_details)
    group = app_details['attributes'].get('repoProjectKey')
    project = app_details['attributes'].get('repoSlug')
    generated = gogoutils.Generator(group,
                                    project,
                                    env=env,
                                    region=region,
                                    formats=APP_FORMATS)

    LOG.debug('Application details: %s', generated)
    return generated
Exemplo n.º 5
0
def write_variables(app_configs=None, out_file='', git_short=''):
    """Append _application.json_ configs to _out_file_, .exports, and .json.

    Variables are written in INI style, e.g. UPPER_CASE=value. The .exports file
    contains 'export' prepended to each line for easy sourcing. The .json file
    is a minified representation of the combined configurations.

    Args:
        app_configs (dict): Environment configurations from _application.json_
            files, e.g. {'dev': {'elb': {'subnet_purpose': 'internal'}}}.
        out_file (str): Name of INI file to append to.
        git_short (str): Short name of Git repository, e.g. forrest/core.

    Returns:
        dict: Configuration equivalent to the JSON output.
    """
    generated = gogoutils.Generator(*gogoutils.Parser(git_short).parse_url(), formats=APP_FORMATS)

    json_configs = {}
    for env, configs in app_configs.items():
        if env != 'pipeline':
            instance_profile = generated.iam()['profile']
            rendered_configs = json.loads(
                get_template(
                    'configs/configs.json.j2',
                    env=env,
                    app=generated.app_name(),
                    profile=instance_profile,
                    formats=generated))
            json_configs[env] = dict(DeepChainMap(configs, rendered_configs))
            region_list = configs.get('regions', rendered_configs['regions'])
            json_configs[env]['regions'] = region_list  # removes regions defined in templates but not configs.
            for region in region_list:
                region_config = json_configs[env][region]
                json_configs[env][region] = dict(DeepChainMap(region_config, rendered_configs))
        else:
            default_pipeline_json = json.loads(get_template('configs/pipeline.json.j2', formats=generated))
            json_configs['pipeline'] = dict(DeepChainMap(configs, default_pipeline_json))

    LOG.debug('Compiled configs:\n%s', pformat(json_configs))

    config_lines = convert_ini(json_configs)

    with open(out_file, 'at') as jenkins_vars:
        LOG.info('Appending variables to %s.', out_file)
        jenkins_vars.write('\n'.join(config_lines))

    with open(out_file + '.exports', 'wt') as export_vars:
        LOG.info('Writing sourceable variables to %s.', export_vars.name)
        export_vars.write('\n'.join('export {0}'.format(line) for line in config_lines))

    with open(out_file + '.json', 'wt') as json_handle:
        LOG.info('Writing JSON to %s.', json_handle.name)
        LOG.debug('Total JSON dict:\n%s', json_configs)
        json.dump(json_configs, json_handle)

    return json_configs
Exemplo n.º 6
0
def main():
    """Append Application Configurations to a given file in multiple formats."""
    logging.basicConfig(format=LOGGING_FORMAT)

    parser = argparse.ArgumentParser(description=main.__doc__)
    add_debug(parser)
    parser.add_argument('-o',
                        '--output',
                        required=True,
                        help='Name of environment file to append to')
    parser.add_argument('-g',
                        '--git-short',
                        metavar='GROUP/PROJECT',
                        required=True,
                        help='Short name for Git, e.g. forrest/core')
    parser.add_argument(
        '-r',
        '--runway-dir',
        help='Runway directory with app.json files, requires --git-short')
    args = parser.parse_args()

    LOG.setLevel(args.debug)
    logging.getLogger(__package__.split('.')[0]).setLevel(args.debug)

    generated = gogoutils.Generator(*gogoutils.Parser(
        args.git_short).parse_url(),
                                    formats=APP_FORMATS)
    git_short = generated.gitlab()['main']

    if args.runway_dir:
        configs = process_runway_configs(runway_dir=args.runway_dir)
    else:
        configs = process_git_configs(git_short=git_short)

    write_variables(app_configs=configs,
                    out_file=args.output,
                    git_short=git_short)