How to use the runway.util.merge_dicts function in runway

To help you get started, we’ve selected a few runway examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github onicagroup / runway / runway / commands / modules_command.py View on Github external
# this is not necessarily a cause for concern so continue
                # to the next deployment rather than exiting
                continue

            # check should be obsolete, checked when the config is parsed
            if deployment.regions or deployment.parallel_regions:
                if deployment.env_vars:
                    deployment_env_vars = merge_nested_environment_dicts(
                        deployment.env_vars, env_name=context.env_name,
                        env_root=self.env_root
                    )
                    if deployment_env_vars:
                        LOGGER.info("OS environment variable overrides being "
                                    "applied this deployment: %s",
                                    str(deployment_env_vars))
                    context.env_vars = merge_dicts(context.env_vars,
                                                   deployment_env_vars)

                LOGGER.info("")

                if deployment.parallel_regions and context.use_concurrent:
                    LOGGER.info("Processing parallel regions %s",
                                deployment.parallel_regions)
                    LOGGER.info('(output will be interwoven)')
                    executor = concurrent.futures.ProcessPoolExecutor(
                        max_workers=context.max_concurrent_regions
                    )
                    futures = [executor.submit(self._execute_deployment,
                                               *[deployment, context,
                                                 region, True])
                               for region in deployment.parallel_regions]
                    concurrent.futures.wait(futures)
github onicagroup / runway / runway / commands / modules_command.py View on Github external
def load_module_opts_from_file(path, module_options):
    """Update module_options with any options defined in module path."""
    module_options_file = os.path.join(path,
                                       'runway.module.yml')
    if os.path.isfile(module_options_file):
        with open(module_options_file, 'r') as stream:
            module_options = merge_dicts(module_options,
                                         yaml.safe_load(stream))
    return module_options
github onicagroup / runway / runway / commands / modules_command.py View on Github external
deployment the module belongs to. Used to get options,
                environments, parameters, and env_vars from the deployment level.
            context: (:class:`runway.context.Context`): Current context instance.

        """
        deployment.resolve(context, self.runway_vars)
        module.resolve(context, self.runway_vars)
        module_opts = {
            'environments': deployment.environments.copy(),
            'options': deployment.module_options.copy(),
            'parameters': deployment.parameters.copy()
        }

        path = Path(module, self.env_root, os.path.join(self.env_root, '.runway_cache'))

        module_opts = merge_dicts(module_opts, module.data)
        module_opts = load_module_opts_from_file(path.module_root, module_opts)

        module_opts['environment'] = module_opts['environments'].get(
            context.env_name, {}
        )
        if isinstance(module_opts['environment'], dict) and \
                not self.runway_config.future.strict_environments:
            module_opts['parameters'].update(module_opts['environment'])
            if module_opts['parameters']:
                # deploy if env is empty but params are provided
                module_opts['environment'] = True
        else:
            module_opts['environment'] = validate_environment(
                context=context,
                module=module,
                env_def=module_opts['environments'],
github onicagroup / runway / runway / commands / env.py View on Github external
else:
                deployments_to_run = self.select_deployment_to_run(
                    deployments
                )
        for deployment in deployments_to_run:
            if deployment.get('regions'):
                if deployment.get('env_vars'):
                    context.env_vars = merge_dicts(
                        context.env_vars,
                        get_deployment_env_vars(context.env_name,
                                                deployment['env_vars'],
                                                self.env_root)
                    )
                for region in deployment['regions']:
                    context.env_region = region
                    context.env_vars = merge_dicts(
                        context.env_vars,
                        {'AWS_DEFAULT_REGION': context.env_region,
                         'AWS_REGION': context.env_region}
                    )
                    if deployment.get('assume-role'):
                        pre_deploy_assume_role(deployment['assume-role'],
                                               context)
                    if deployment.get('account-id') or (
                            deployment.get('account-alias')):
                        validate_account_credentials(deployment, context)
                    modules = deployment.get('modules', [])
                    if deployment.get('current_dir'):
                        modules.append('.' + os.sep)
                    for module in modules:
                        module_opts = {}
                        if deployment.get('environments'):
github onicagroup / runway / runway / commands / env.py View on Github external
'environment %s...',
                        context.env_name)

        if assume_role_arn:
            context.env_vars = merge_dicts(
                context.env_vars,
                assume_role(
                    role_arn=assume_role_arn,
                    session_name=assume_role_config.get('session_name', None),
                    duration_seconds=assume_role_duration,
                    region=context.env_region,
                    env_vars=context.env_vars
                )
            )
    else:
        context.env_vars = merge_dicts(
            context.env_vars,
            assume_role(role_arn=assume_role_config,
                        region=context.env_region,
                        env_vars=context.env_vars)
        )
github onicagroup / runway / runway / commands / env.py View on Github external
LOGGER.info('Any/all deployment(s) selected will be '
                            'irrecoverably DESTROYED.')
                deployments_to_run = self.reverse_deployments(
                    self.select_deployment_to_run(
                        deployments,
                        command=command
                    )
                )
            else:
                deployments_to_run = self.select_deployment_to_run(
                    deployments
                )
        for deployment in deployments_to_run:
            if deployment.get('regions'):
                if deployment.get('env_vars'):
                    context.env_vars = merge_dicts(
                        context.env_vars,
                        get_deployment_env_vars(context.env_name,
                                                deployment['env_vars'],
                                                self.env_root)
                    )
                for region in deployment['regions']:
                    context.env_region = region
                    context.env_vars = merge_dicts(
                        context.env_vars,
                        {'AWS_DEFAULT_REGION': context.env_region,
                         'AWS_REGION': context.env_region}
                    )
                    if deployment.get('assume-role'):
                        pre_deploy_assume_role(deployment['assume-role'],
                                               context)
                    if deployment.get('account-id') or (
github onicagroup / runway / runway / commands / env.py View on Github external
if deployment.get('current_dir'):
                        modules.append('.' + os.sep)
                    for module in modules:
                        module_opts = {}
                        if deployment.get('environments'):
                            module_opts['environments'] = deployment['environments'].copy()  # noqa
                        if deployment.get('module_options'):
                            module_opts['options'] = deployment['module_options'].copy()  # noqa
                        if isinstance(module, six.string_types):
                            module = {'path': module}
                        if path_is_current_dir(module['path']):
                            module_root = self.env_root
                        else:
                            module_root = os.path.join(self.env_root,
                                                       module['path'])
                        module_opts = merge_dicts(module_opts, module)
                        module_opts = load_module_opts_from_file(module_root,
                                                                 module_opts)
                        if deployment.get('skip-npm-ci'):
                            module_opts['skip_npm_ci'] = True
                        LOGGER.info("Processing module %s...\n",
                                    module['path'])
                        LOGGER.debug("Module options are: %s", module_opts)
                        with change_dir(module_root):
                            getattr(
                                determine_module_class(module_root, module_opts)(  # noqa
                                    context=context,
                                    path=module_root,
                                    options=module_opts
                                ),
                                command)()
                if deployment.get('assume-role'):
github onicagroup / runway / runway / commands / env.py View on Github external
def load_module_opts_from_file(path, module_options):
    """Update module_options with any options defined in module path."""
    module_options_file = os.path.join(path,
                                       'runway.module.yml')
    if os.path.isfile(module_options_file):
        with open(module_options_file, 'r') as stream:
            module_options = merge_dicts(module_options,
                                         yaml.safe_load(stream))
    return module_options
github onicagroup / runway / runway / commands / runway / envvars.py View on Github external
env_region=None,
                env_root=self.env_root,
                env_vars=os.environ.copy()
            )
            env_vars = {}
            for deployment in self.runway_config.deployments:
                try:
                    deployment.resolve(context, self.runway_vars)
                except FailedVariableLookup as err:
                    if any(var in str(err.lookup)
                           for var in ['AWS_REGION', 'AWS_DEFAULT_REGION']):
                        select_region(context, deployment.regions)
                        deployment.resolve(context, self.runway_vars)
                    else:
                        raise
                env_vars = merge_dicts(env_vars, deployment.env_vars)
            if env_vars:
                env_vars = merge_nested_environment_dicts(
                    env_vars,
                    env_name=context.env_name,
                    env_root=context.env_root
                )

            if 'MSYSTEM' in os.environ and (
                    os.environ['MSYSTEM'].startswith('MINGW') and (
                        platform.system() == 'Windows')):  # type: ignore
                print_env_vars_posix(env_vars)  # git bash
            elif platform.system() == 'Windows':  # type: ignore
                print_env_vars_psh(env_vars)
            else:
                print_env_vars_posix(env_vars)
        else: