lib/r10k/action/deploy/module.rb in r10k-3.10.0 vs lib/r10k/action/deploy/module.rb in r10k-3.11.0
- old
+ new
@@ -27,18 +27,20 @@
# @note All arguments will be required in the next major version
def initialize(opts, argv, settings = {})
super
requested_env = @opts[:environment] ? [@opts[:environment].gsub(/\W/, '_')] : []
+ @modified_envs = []
@settings = @settings.merge({
overrides: {
environments: {
requested_environments: requested_env,
generate_types: @generate_types
},
modules: {
+ exclude_spec: settings.dig(:deploy, :exclude_spec),
requested_modules: @argv.map.to_a,
# force here is used to make it easier to reason about
force: !@no_force
},
purging: {},
@@ -67,10 +69,25 @@
private
def visit_deployment(deployment)
yield
+ ensure
+ if (postcmd = @settings[:postrun])
+ if @modified_envs.any?
+ if postcmd.grep('$modifiedenvs').any?
+ envs_to_run = @modified_envs.join(' ')
+ logger.debug "Running postrun command for environments #{envs_to_run}."
+ postcmd = postcmd.map { |e| e.gsub('$modifiedenvs', envs_to_run) }
+ end
+ subproc = R10K::Util::Subprocess.new(postcmd)
+ subproc.logger = logger
+ subproc.execute
+ else
+ logger.debug "No environments were modified, not executing postrun command."
+ end
+ end
end
def visit_source(source)
yield
end
@@ -83,26 +100,35 @@
logger.debug1(_("Updating modules %{modules} in environment %{env_path}") % {modules: @settings.dig(:overrides, :modules, :requested_modules).inspect, env_path: environment.path})
environment.deploy
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!
+ # We actually synced a module in this env
+ if !((environment.modules.map(&:name) & requested_mods).empty?)
+ # Record modified environment for postrun command
+ @modified_envs << environment.dirname
+
+ if generate_types = @settings.dig(:overrides, :environments, :generate_types)
+ logger.debug("Generating puppet types for environment '#{environment.dirname}'...")
+ environment.generate_types!
+ end
end
end
end
def allowed_initialize_opts
super.merge(environment: true,
cachedir: :self,
+ 'exclude-spec': :self,
'no-force': :self,
'generate-types': :self,
'puppet-path': :self,
'puppet-conf': :self,
'private-key': :self,
- 'oauth-token': :self)
+ 'oauth-token': :self,
+ 'github-app-id': :self,
+ 'github-app-key': :self,
+ 'github-app-ttl': :self)
end
end
end
end
end