lib/r10k/action/deploy/module.rb in r10k-3.9.0 vs lib/r10k/action/deploy/module.rb in r10k-3.9.1

- old
+ new

@@ -8,29 +8,57 @@ module Deploy class Module < R10K::Action::Base include R10K::Action::Deploy::DeployHelpers + # Deprecated attr_reader :force - def initialize(opts, argv, settings = nil) - settings ||= {} + attr_reader :settings + # @param opts [Hash] A hash of options defined in #allowed_initialized_opts + # and managed by the SetOps mixin within the Action::Base class. + # Corresponds to the CLI flags and options. + # @param argv [CRI::ArgumentList] A list-like collection of the remaining + # arguments to the CLI invocation (after removing flags and options). + # @param settings [Hash] A hash of configuration loaded from the relevant + # config (r10k.yaml). + def initialize(opts, argv, settings) super - # @force here is used to make it easier to reason about - @force = !@no_force + requested_env = @opts[:environment] ? [@opts[:environment].gsub(/\W/, '_')] : [] + + @settings = @settings.merge({ + overrides: { + environments: { + requested_environments: requested_env, + generate_types: @generate_types + }, + modules: { + requested_modules: @argv.map.to_a, + # force here is used to make it easier to reason about + force: !@no_force + }, + purging: {}, + output: {} + } + }) end def call @visit_ok = true + begin + expect_config! + deployment = R10K::Deployment.new(@settings) + check_write_lock!(@settings) - expect_config! - deployment = R10K::Deployment.new(@settings) - check_write_lock!(@settings) + deployment.accept(self) + rescue => e + @visit_ok = false + logger.error R10K::Errors::Formatting.format_exception(e, @trace) + end - deployment.accept(self) @visit_ok end include R10K::Action::Visitor @@ -43,32 +71,23 @@ def visit_source(source) yield end def visit_environment(environment) - if @opts[:environment] && (@opts[:environment] != environment.dirname) - logger.debug1(_("Only updating modules in environment %{opt_env} skipping environment %{env_path}") % {opt_env: @opts[:environment], env_path: environment.path}) + requested_envs = @settings.dig(:overrides, :environments, :requested_environments) + if !requested_envs.empty? && !requested_envs.include?(environment.dirname) + logger.debug1(_("Only updating modules in environment(s) %{opt_env} skipping environment %{env_path}") % {opt_env: requested_envs.inspect, env_path: environment.path}) else - logger.debug1(_("Updating modules %{modules} in environment %{env_path}") % {modules: @argv.inspect, env_path: environment.path}) - yield - end - end + logger.debug1(_("Updating modules %{modules} in environment %{env_path}") % {modules: @settings.dig(:overrides, :modules, :requested_modules).inspect, env_path: environment.path}) - def visit_puppetfile(puppetfile) - puppetfile.load - yield - end + environment.deploy - def visit_module(mod) - if @argv.include?(mod.name) - logger.info _("Deploying module %{mod_path}") % {mod_path: mod.path} - mod.sync(force: @force) - if mod.environment && @generate_types - logger.debug("Generating puppet types for environment '#{mod.environment.dirname}'...") - mod.environment.generate_types! + requested_mods = @settings.dig(:overrides, :modules, :requested_modules) || [] + generate_types = @settings.dig(:overrides, :environments, :generate_types) + if generate_types && !((environment.modules.map(&:name) & requested_mods).empty?) + logger.debug("Generating puppet types for environment '#{environment.dirname}'...") + environment.generate_types! end - else - logger.debug1(_("Only updating modules %{modules}, skipping module %{mod_name}") % {modules: @argv.inspect, mod_name: mod.name}) end end def allowed_initialize_opts super.merge(environment: true,