Class: R10K::Action::Deploy::Environment

Inherits:
Base
  • Object
show all
Includes:
DeployHelpers, Visitor
Defined in:
lib/r10k/action/deploy/environment.rb

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Visitor

#visit

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Methods included from DeployHelpers

#check_write_lock!, #expect_config!

Constructor Details

#initialize(opts, argv, settings = {}) ⇒ Environment

Note:

All arguments will be required in the next major version

Returns a new instance of Environment.

Parameters:

  • 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.

  • argv (Enumerable)

    Typically CRI::ArgumentList or Array. A list-like collection of the remaining arguments to the CLI invocation (after removing flags and options).

  • settings (Hash) (defaults to: {})

    A hash of configuration loaded from the relevant config (r10k.yaml).



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/r10k/action/deploy/environment.rb', line 32

def initialize(opts, argv, settings = {})
  super

  # instance variables below are set by the super class based on the
  # spec of #allowed_initialize_opts and any command line flags. This
  # gives a preference order of cli flags > config files > defaults.
  @settings = @settings.merge({
    overrides: {
      environments: {
        requested_environments: @argv.map { |arg| arg.gsub(/\W/,'_') },
        default_branch_override: @default_branch_override,
        generate_types: @generate_types || settings.dig(:deploy, :generate_types) || false,
        preload_environments: true,
        incremental: @incremental
      },
      modules: {
        exclude_spec: settings.dig(:deploy, :exclude_spec),
        requested_modules: [],
        deploy_modules: @modules,
        pool_size: @settings[:pool_size] || 4,
        force: !@no_force, # force here is used to make it easier to reason about
      },
      purging: {
        purge_levels: settings.dig(:deploy, :purge_levels) || [],
        purge_allowlist: read_purge_allowlist(settings.dig(:deploy, :purge_whitelist) || [],
                                              settings.dig(:deploy, :purge_allowlist) || [])
      },
      forge: {
        allow_puppetfile_override: settings.dig(:forge, :allow_puppetfile_override) || false
      },
      output: {}
    }
  })
end

Instance Attribute Details

#forceObject (readonly)

Deprecated



18
19
20
# File 'lib/r10k/action/deploy/environment.rb', line 18

def force
  @force
end

#settingsObject (readonly)

Returns the value of attribute settings.



20
21
22
# File 'lib/r10k/action/deploy/environment.rb', line 20

def settings
  @settings
end

Instance Method Details

#callObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/r10k/action/deploy/environment.rb', line 67

def call
  @visit_ok = true

  begin
    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

  @visit_ok
end