r10k 3.6.0 → 3.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/docker.yml +4 -1
- data/.github/workflows/release.yml +3 -2
- data/.github/workflows/rspec_tests.yml +81 -0
- data/.github/workflows/stale.yml +19 -0
- data/.travis.yml +8 -1
- data/CHANGELOG.mkd +33 -0
- data/CODEOWNERS +2 -2
- data/README.mkd +2 -2
- data/doc/common-patterns.mkd +1 -0
- data/doc/dynamic-environments/configuration.mkd +123 -42
- data/doc/dynamic-environments/usage.mkd +12 -11
- data/doc/puppetfile.mkd +23 -3
- data/docker/Gemfile +1 -1
- data/docker/Makefile +4 -3
- data/docker/docker-compose.yml +18 -0
- data/docker/r10k/Dockerfile +1 -1
- data/docker/r10k/docker-entrypoint.sh +0 -1
- data/docker/r10k/release.Dockerfile +1 -1
- data/docker/spec/dockerfile_spec.rb +26 -32
- data/integration/tests/git_source/git_source_repeated_remote.rb +2 -2
- data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +2 -1
- data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +2 -1
- data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +1 -1
- data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +2 -1
- data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +1 -1
- data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +1 -1
- data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +1 -1
- data/lib/r10k/action/base.rb +10 -0
- data/lib/r10k/action/deploy/display.rb +49 -10
- data/lib/r10k/action/deploy/environment.rb +102 -51
- data/lib/r10k/action/deploy/module.rb +55 -30
- data/lib/r10k/action/puppetfile/check.rb +3 -1
- data/lib/r10k/action/puppetfile/install.rb +20 -23
- data/lib/r10k/action/puppetfile/purge.rb +8 -2
- data/lib/r10k/action/runner.rb +34 -0
- data/lib/r10k/cli/deploy.rb +14 -7
- data/lib/r10k/cli/puppetfile.rb +5 -5
- data/lib/r10k/content_synchronizer.rb +83 -0
- data/lib/r10k/deployment.rb +1 -1
- data/lib/r10k/environment/base.rb +30 -3
- data/lib/r10k/environment/git.rb +17 -5
- data/lib/r10k/environment/name.rb +22 -4
- data/lib/r10k/environment/svn.rb +11 -4
- data/lib/r10k/environment/with_modules.rb +46 -30
- data/lib/r10k/git.rb +1 -0
- data/lib/r10k/git/cache.rb +11 -1
- data/lib/r10k/git/rugged/credentials.rb +39 -2
- data/lib/r10k/initializers.rb +2 -0
- data/lib/r10k/module.rb +1 -1
- data/lib/r10k/module/base.rb +17 -1
- data/lib/r10k/module/forge.rb +29 -11
- data/lib/r10k/module/git.rb +50 -27
- data/lib/r10k/module/local.rb +2 -1
- data/lib/r10k/module/svn.rb +24 -18
- data/lib/r10k/puppetfile.rb +66 -83
- data/lib/r10k/settings.rb +29 -2
- data/lib/r10k/source/base.rb +9 -0
- data/lib/r10k/source/git.rb +18 -7
- data/lib/r10k/source/hash.rb +5 -5
- data/lib/r10k/source/svn.rb +5 -3
- data/lib/r10k/util/cleaner.rb +21 -0
- data/lib/r10k/util/setopts.rb +33 -12
- data/lib/r10k/version.rb +1 -1
- data/locales/r10k.pot +98 -82
- data/r10k.gemspec +1 -1
- data/spec/fixtures/unit/action/r10k_creds.yaml +9 -0
- data/spec/r10k-mocks/mock_source.rb +1 -1
- data/spec/shared-examples/puppetfile-action.rb +7 -7
- data/spec/shared-examples/subprocess-runner.rb +11 -5
- data/spec/unit/action/deploy/display_spec.rb +35 -5
- data/spec/unit/action/deploy/environment_spec.rb +207 -37
- data/spec/unit/action/deploy/module_spec.rb +173 -26
- data/spec/unit/action/puppetfile/check_spec.rb +2 -2
- data/spec/unit/action/puppetfile/install_spec.rb +31 -10
- data/spec/unit/action/puppetfile/purge_spec.rb +25 -5
- data/spec/unit/action/runner_spec.rb +48 -1
- data/spec/unit/environment/git_spec.rb +19 -2
- data/spec/unit/environment/name_spec.rb +28 -0
- data/spec/unit/environment/svn_spec.rb +12 -0
- data/spec/unit/environment/with_modules_spec.rb +74 -0
- data/spec/unit/git/cache_spec.rb +10 -0
- data/spec/unit/git/rugged/credentials_spec.rb +79 -2
- data/spec/unit/git_spec.rb +3 -3
- data/spec/unit/module/forge_spec.rb +21 -13
- data/spec/unit/module/git_spec.rb +64 -1
- data/spec/unit/module_spec.rb +60 -10
- data/spec/unit/puppetfile_spec.rb +63 -60
- data/spec/unit/settings_spec.rb +12 -0
- data/spec/unit/source/git_spec.rb +15 -3
- data/spec/unit/util/purgeable_spec.rb +2 -8
- data/spec/unit/util/setopts_spec.rb +25 -1
- metadata +11 -11
- data/azure-pipelines.yml +0 -87
data/lib/r10k/action/runner.rb
CHANGED
@@ -46,6 +46,7 @@ module R10K
|
|
46
46
|
overrides[:cachedir] = @opts[:cachedir] if @opts.key?(:cachedir)
|
47
47
|
overrides[:deploy] = {} if @opts.key?(:'puppet-path') || @opts.key?(:'generate-types')
|
48
48
|
overrides[:deploy][:puppet_path] = @opts[:'puppet-path'] if @opts.key?(:'puppet-path')
|
49
|
+
overrides[:deploy][:puppet_conf] = @opts[:'puppet-conf'] unless @opts[:'puppet-conf'].nil?
|
49
50
|
overrides[:deploy][:generate_types] = @opts[:'generate-types'] if @opts.key?(:'generate-types')
|
50
51
|
|
51
52
|
with_overrides = config_settings.merge(overrides) do |key, oldval, newval|
|
@@ -54,6 +55,10 @@ module R10K
|
|
54
55
|
newval
|
55
56
|
end
|
56
57
|
|
58
|
+
# Credentials from the CLI override both the global and per-repo
|
59
|
+
# credentials from the config, and so need to be handled specially
|
60
|
+
with_overrides = add_credential_overrides(with_overrides)
|
61
|
+
|
57
62
|
@settings = R10K::Settings.global_settings.evaluate(with_overrides)
|
58
63
|
|
59
64
|
R10K::Initializers::GlobalInitializer.new(@settings).call
|
@@ -91,6 +96,35 @@ module R10K
|
|
91
96
|
|
92
97
|
results
|
93
98
|
end
|
99
|
+
|
100
|
+
def add_credential_overrides(overrides)
|
101
|
+
sshkey_path = @opts[:'private-key']
|
102
|
+
token_path = @opts[:'oauth-token']
|
103
|
+
|
104
|
+
if sshkey_path && token_path
|
105
|
+
raise R10K::Error, "Cannot specify both an SSH key and a token to use with this deploy."
|
106
|
+
end
|
107
|
+
|
108
|
+
if sshkey_path
|
109
|
+
overrides[:git] ||= {}
|
110
|
+
overrides[:git][:private_key] = sshkey_path
|
111
|
+
if repo_settings = overrides[:git][:repositories]
|
112
|
+
repo_settings.each do |repo|
|
113
|
+
repo[:private_key] = sshkey_path
|
114
|
+
end
|
115
|
+
end
|
116
|
+
elsif token_path
|
117
|
+
overrides[:git] ||= {}
|
118
|
+
overrides[:git][:oauth_token] = token_path
|
119
|
+
if repo_settings = overrides[:git][:repositories]
|
120
|
+
repo_settings.each do |repo|
|
121
|
+
repo[:oauth_token] = token_path
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
overrides
|
127
|
+
end
|
94
128
|
end
|
95
129
|
end
|
96
130
|
end
|
data/lib/r10k/cli/deploy.rb
CHANGED
@@ -21,7 +21,7 @@ module R10K::CLI
|
|
21
21
|
(https://puppet.com/docs/puppet/latest/environments_about.html).
|
22
22
|
DESCRIPTION
|
23
23
|
|
24
|
-
|
24
|
+
option nil, :cachedir, 'Specify a cachedir, overriding the value in config', argument: :required
|
25
25
|
flag nil, :'no-force', 'Prevent the overwriting of local module modifications'
|
26
26
|
flag nil, :'generate-types', 'Run `puppet generate types` after updating an environment'
|
27
27
|
option nil, :'puppet-path', 'Path to puppet executable', argument: :required do |value, cmd|
|
@@ -31,6 +31,9 @@ module R10K::CLI
|
|
31
31
|
exit 1
|
32
32
|
end
|
33
33
|
end
|
34
|
+
option nil, :'puppet-conf', 'Path to puppet.conf', argument: :required
|
35
|
+
option nil, :'private-key', 'Path to SSH key to use when cloning. Only valid with rugged provider', argument: :required
|
36
|
+
option nil, :'oauth-token', 'Path to OAuth token to use when cloning. Only valid with rugged provider', argument: :required
|
34
37
|
|
35
38
|
run do |opts, args, cmd|
|
36
39
|
puts cmd.help(:verbose => opts[:verbose])
|
@@ -52,7 +55,7 @@ branches.
|
|
52
55
|
|
53
56
|
Environments can provide a Puppetfile at the root of the directory to deploy
|
54
57
|
independent Puppet modules. To recursively deploy an environment, pass the
|
55
|
-
`--
|
58
|
+
`--modules` flag to the command.
|
56
59
|
|
57
60
|
**NOTE**: If an environment has a Puppetfile when it is instantiated a
|
58
61
|
recursive update will be forced. It is assumed that environments are dependent
|
@@ -60,8 +63,10 @@ on modules specified in the Puppetfile and an update will be automatically
|
|
60
63
|
scheduled. On subsequent deployments, Puppetfile deployment will default to off.
|
61
64
|
DESCRIPTION
|
62
65
|
|
63
|
-
flag :p, :puppetfile, 'Deploy modules
|
64
|
-
|
66
|
+
flag :p, :puppetfile, 'Deploy modules (deprecated, use -m)'
|
67
|
+
flag :m, :modules, 'Deploy modules'
|
68
|
+
option nil, :'default-branch-override', 'Specify a branchname to override the default branch in the puppetfile',
|
69
|
+
argument: :required
|
65
70
|
|
66
71
|
runner R10K::Action::CriRunner.wrap(R10K::Action::Deploy::Environment)
|
67
72
|
end
|
@@ -81,7 +86,7 @@ It will load the Puppetfile configurations out of all environments, and will
|
|
81
86
|
try to deploy the given module names in all environments.
|
82
87
|
DESCRIPTION
|
83
88
|
|
84
|
-
|
89
|
+
option :e, :environment, 'Update the modules in the given environment', argument: :required
|
85
90
|
|
86
91
|
runner R10K::Action::CriRunner.wrap(R10K::Action::Deploy::Module)
|
87
92
|
end
|
@@ -96,10 +101,12 @@ try to deploy the given module names in all environments.
|
|
96
101
|
usage 'display'
|
97
102
|
summary 'Display environments and modules in the deployment'
|
98
103
|
|
99
|
-
flag :p, :puppetfile, 'Display
|
104
|
+
flag :p, :puppetfile, 'Display modules (deprecated, use -m)'
|
105
|
+
flag :m, :modules, 'Display modules'
|
100
106
|
flag nil, :detail, 'Display detailed information'
|
101
107
|
flag nil, :fetch, 'Update available environment lists from all remote sources'
|
102
|
-
|
108
|
+
option nil, :format, 'Display output in a specific format. Valid values: json, yaml. Default: yaml',
|
109
|
+
argument: :required
|
103
110
|
|
104
111
|
runner R10K::Action::CriRunner.wrap(R10K::Action::Deploy::Display)
|
105
112
|
end
|
data/lib/r10k/cli/puppetfile.rb
CHANGED
@@ -30,8 +30,8 @@ Puppetfile (http://bombasticmonkey.com/librarian-puppet/).
|
|
30
30
|
name 'install'
|
31
31
|
usage 'install'
|
32
32
|
summary 'Install all modules from a Puppetfile'
|
33
|
-
|
34
|
-
|
33
|
+
option nil, :moduledir, 'Path to install modules to', argument: :required
|
34
|
+
option nil, :puppetfile, 'Path to puppetfile', argument: :required
|
35
35
|
flag nil, :force, 'Force locally changed files to be overwritten'
|
36
36
|
runner R10K::Action::Puppetfile::CriRunner.wrap(R10K::Action::Puppetfile::Install)
|
37
37
|
end
|
@@ -45,7 +45,7 @@ Puppetfile (http://bombasticmonkey.com/librarian-puppet/).
|
|
45
45
|
usage 'check'
|
46
46
|
summary 'Try and load the Puppetfile to verify the syntax is correct.'
|
47
47
|
|
48
|
-
|
48
|
+
option nil, :puppetfile, 'Path to Puppetfile', argument: :required
|
49
49
|
runner R10K::Action::Puppetfile::CriRunner.wrap(R10K::Action::Puppetfile::Check)
|
50
50
|
end
|
51
51
|
end
|
@@ -58,8 +58,8 @@ Puppetfile (http://bombasticmonkey.com/librarian-puppet/).
|
|
58
58
|
usage 'purge'
|
59
59
|
summary 'Purge unmanaged modules from a Puppetfile managed directory'
|
60
60
|
|
61
|
-
|
62
|
-
|
61
|
+
option nil, :moduledir, 'Path to install modules to', argument: :required
|
62
|
+
option nil, :puppetfile, 'Path to Puppetfile', argument: :required
|
63
63
|
runner R10K::Action::Puppetfile::CriRunner.wrap(R10K::Action::Puppetfile::Purge)
|
64
64
|
end
|
65
65
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module R10K
|
2
|
+
module ContentSynchronizer
|
3
|
+
|
4
|
+
def self.serial_accept(modules, visitor, loader)
|
5
|
+
visitor.visit(:puppetfile, loader) do
|
6
|
+
serial_sync(modules)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.serial_sync(modules)
|
11
|
+
modules.each do |mod|
|
12
|
+
mod.sync
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.concurrent_accept(modules, visitor, loader, pool_size, logger)
|
17
|
+
mods_queue = modules_visit_queue(modules, visitor, loader)
|
18
|
+
sync_queue(mods_queue, pool_size, logger)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.concurrent_sync(modules, pool_size, logger)
|
22
|
+
mods_queue = modules_sync_queue(modules)
|
23
|
+
sync_queue(mods_queue, pool_size, logger)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.sync_queue(mods_queue, pool_size, logger)
|
27
|
+
logger.debug _("Updating modules with %{pool_size} threads") % {pool_size: pool_size}
|
28
|
+
thread_pool = pool_size.times.map { sync_thread(mods_queue, logger) }
|
29
|
+
thread_exception = nil
|
30
|
+
|
31
|
+
# If any threads raise an exception the deployment is considered a failure.
|
32
|
+
# In that event clear the queue, wait for other threads to finish their
|
33
|
+
# current work, then re-raise the first exception caught.
|
34
|
+
begin
|
35
|
+
thread_pool.each(&:join)
|
36
|
+
rescue => e
|
37
|
+
logger.error _("Error during concurrent deploy of a module: %{message}") % {message: e.message}
|
38
|
+
mods_queue.clear
|
39
|
+
thread_exception ||= e
|
40
|
+
retry
|
41
|
+
ensure
|
42
|
+
raise thread_exception unless thread_exception.nil?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.modules_visit_queue(modules, visitor, loader)
|
47
|
+
Queue.new.tap do |queue|
|
48
|
+
visitor.visit(:puppetfile, loader) do
|
49
|
+
enqueue_modules(queue, modules)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.modules_sync_queue(modules)
|
55
|
+
Queue.new.tap do |queue|
|
56
|
+
enqueue_modules(queue, modules)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.enqueue_modules(queue, modules)
|
61
|
+
modules_by_cachedir = modules.group_by { |mod| mod.cachedir }
|
62
|
+
modules_without_vcs_cachedir = modules_by_cachedir.delete(:none) || []
|
63
|
+
|
64
|
+
modules_without_vcs_cachedir.each {|mod| queue << Array(mod) }
|
65
|
+
modules_by_cachedir.values.each {|mods| queue << mods }
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.sync_thread(mods_queue, logger)
|
69
|
+
Thread.new do
|
70
|
+
begin
|
71
|
+
while mods = mods_queue.pop(true) do
|
72
|
+
mods.each { |mod| mod.sync }
|
73
|
+
end
|
74
|
+
rescue ThreadError => e
|
75
|
+
logger.debug _("Module thread %{id} exiting: %{message}") % {message: e.message, id: Thread.current.object_id}
|
76
|
+
Thread.exit
|
77
|
+
rescue => e
|
78
|
+
Thread.main.raise(e)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/r10k/deployment.rb
CHANGED
@@ -118,7 +118,7 @@ module R10K
|
|
118
118
|
raise R10K::Error, _("Unable to load sources; the supplied configuration does not define the 'sources' key")
|
119
119
|
end
|
120
120
|
@_sources = sources.map do |(name, hash)|
|
121
|
-
R10K::Source.from_hash(name, hash)
|
121
|
+
R10K::Source.from_hash(name, hash.merge({overrides: @config[:overrides]}))
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'r10k/util/subprocess'
|
2
|
+
require 'r10k/logging'
|
2
3
|
|
3
4
|
# This class defines a common interface for environment implementations.
|
4
5
|
#
|
5
6
|
# @since 1.3.0
|
6
7
|
class R10K::Environment::Base
|
7
8
|
|
9
|
+
include R10K::Logging
|
10
|
+
|
8
11
|
# @!attribute [r] name
|
9
12
|
# @return [String] A name for this environment that is unique to the given source
|
10
13
|
attr_reader :name
|
@@ -43,12 +46,16 @@ class R10K::Environment::Base
|
|
43
46
|
@basedir = basedir
|
44
47
|
@dirname = dirname
|
45
48
|
@options = options
|
46
|
-
@puppetfile_name = options
|
49
|
+
@puppetfile_name = options.delete(:puppetfile_name)
|
50
|
+
@overrides = options.delete(:overrides) || {}
|
47
51
|
|
48
52
|
@full_path = File.join(@basedir, @dirname)
|
49
53
|
@path = Pathname.new(File.join(@basedir, @dirname))
|
50
54
|
|
51
|
-
@puppetfile = R10K::Puppetfile.new(@full_path,
|
55
|
+
@puppetfile = R10K::Puppetfile.new(@full_path,
|
56
|
+
{overrides: @overrides,
|
57
|
+
force: @overrides.dig(:modules, :force),
|
58
|
+
puppetfile_name: @puppetfile_name})
|
52
59
|
@puppetfile.environment = self
|
53
60
|
end
|
54
61
|
|
@@ -103,12 +110,32 @@ class R10K::Environment::Base
|
|
103
110
|
@puppetfile.modules
|
104
111
|
end
|
105
112
|
|
113
|
+
# @return [Array<R10K::Module::Base>] Whether or not the given module
|
114
|
+
# conflicts with any modules already defined in the r10k environment
|
115
|
+
# object.
|
116
|
+
def module_conflicts?(mod)
|
117
|
+
false
|
118
|
+
end
|
119
|
+
|
106
120
|
def accept(visitor)
|
107
121
|
visitor.visit(:environment, self) do
|
108
122
|
puppetfile.accept(visitor)
|
109
123
|
end
|
110
124
|
end
|
111
125
|
|
126
|
+
def deploy
|
127
|
+
puppetfile.load(@overrides.dig(:environments, :default_branch_override))
|
128
|
+
|
129
|
+
puppetfile.sync
|
130
|
+
|
131
|
+
if (@overrides.dig(:purging, :purge_levels) || []).include?(:puppetfile)
|
132
|
+
logger.debug("Purging unmanaged Puppetfile content for environment '#{dirname}'...")
|
133
|
+
R10K::Util::Cleaner.new(puppetfile.managed_directories,
|
134
|
+
puppetfile.desired_contents,
|
135
|
+
puppetfile.purge_exclusions).purge!
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
112
139
|
def whitelist(user_whitelist=[])
|
113
140
|
user_whitelist.collect { |pattern| File.join(@full_path, pattern) }
|
114
141
|
end
|
@@ -137,7 +164,7 @@ class R10K::Environment::Base
|
|
137
164
|
end
|
138
165
|
|
139
166
|
def generate_types!
|
140
|
-
argv = [R10K::Settings.puppet_path, 'generate', 'types', '--environment', dirname, '--environmentpath', basedir]
|
167
|
+
argv = [R10K::Settings.puppet_path, 'generate', 'types', '--environment', dirname, '--environmentpath', basedir, '--config', R10K::Settings.puppet_conf]
|
141
168
|
subproc = R10K::Util::Subprocess.new(argv)
|
142
169
|
subproc.raise_on_fail = true
|
143
170
|
subproc.logger = logger
|
data/lib/r10k/environment/git.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'r10k/logging'
|
2
1
|
require 'r10k/puppetfile'
|
3
2
|
require 'r10k/git/stateful_repository'
|
4
3
|
require 'forwardable'
|
@@ -8,8 +7,6 @@ require 'forwardable'
|
|
8
7
|
# @since 1.3.0
|
9
8
|
class R10K::Environment::Git < R10K::Environment::WithModules
|
10
9
|
|
11
|
-
include R10K::Logging
|
12
|
-
|
13
10
|
R10K::Environment.register(:git, self)
|
14
11
|
# Register git as the default environment type
|
15
12
|
R10K::Environment.register(nil, self)
|
@@ -27,6 +24,8 @@ class R10K::Environment::Git < R10K::Environment::WithModules
|
|
27
24
|
# @return [R10K::Git::StatefulRepository] The git repo backing this environment
|
28
25
|
attr_reader :repo
|
29
26
|
|
27
|
+
include R10K::Util::Setopts
|
28
|
+
|
30
29
|
# Initialize the given Git environment.
|
31
30
|
#
|
32
31
|
# @param name [String] The unique name describing this environment.
|
@@ -38,8 +37,21 @@ class R10K::Environment::Git < R10K::Environment::WithModules
|
|
38
37
|
# @param options [String] :ref The git reference to use for this environment
|
39
38
|
def initialize(name, basedir, dirname, options = {})
|
40
39
|
super
|
41
|
-
|
42
|
-
|
40
|
+
setopts(options, {
|
41
|
+
# Standard option interface
|
42
|
+
:version => :ref,
|
43
|
+
:source => :remote,
|
44
|
+
:type => ::R10K::Util::Setopts::Ignore,
|
45
|
+
|
46
|
+
# Type-specific options
|
47
|
+
:ref => :self,
|
48
|
+
:remote => :self,
|
49
|
+
|
50
|
+
}, raise_on_unhandled: false)
|
51
|
+
# TODO: in r10k 4.0.0, a major version bump, stop allowing garbage options.
|
52
|
+
# We only allow them now, here, on this object, because prior to adopting
|
53
|
+
# setopts in the constructor, this object type didn't do any validation
|
54
|
+
# checking of options passed, and would permit garbage parameters.
|
43
55
|
|
44
56
|
@repo = R10K::Git::StatefulRepository.new(@remote, @basedir, @dirname)
|
45
57
|
end
|
@@ -12,13 +12,13 @@ module R10K
|
|
12
12
|
INVALID_CHARACTERS = %r[\W]
|
13
13
|
|
14
14
|
def initialize(name, opts)
|
15
|
-
@name = name
|
16
|
-
@opts = opts
|
17
|
-
|
18
15
|
@source = opts[:source]
|
19
16
|
@prefix = opts[:prefix]
|
20
17
|
@invalid = opts[:invalid]
|
21
18
|
|
19
|
+
@name = derive_name(name, opts[:strip_component])
|
20
|
+
@opts = opts
|
21
|
+
|
22
22
|
case @invalid
|
23
23
|
when 'correct_and_warn'
|
24
24
|
@validate = true
|
@@ -71,8 +71,26 @@ module R10K
|
|
71
71
|
|
72
72
|
private
|
73
73
|
|
74
|
-
def
|
74
|
+
def derive_name(name, strip_component)
|
75
|
+
return name unless strip_component
|
76
|
+
|
77
|
+
unless strip_component.is_a?(String)
|
78
|
+
raise _('Improper configuration value given for strip_component setting in %{src} source. ' \
|
79
|
+
'Value must be a string, a /regex/, false, or omitted. Got "%{val}" (%{type})' \
|
80
|
+
% {src: @source, val: strip_component, type: strip_component.class})
|
81
|
+
end
|
75
82
|
|
83
|
+
if %r{^/.*/$}.match(strip_component)
|
84
|
+
regex = Regexp.new(strip_component[1..-2])
|
85
|
+
name.gsub(regex, '')
|
86
|
+
elsif name.start_with?(strip_component)
|
87
|
+
name[strip_component.size..-1]
|
88
|
+
else
|
89
|
+
name
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def derive_prefix(source,prefix)
|
76
94
|
if prefix == true
|
77
95
|
"#{source}_"
|
78
96
|
elsif prefix.is_a? String
|
data/lib/r10k/environment/svn.rb
CHANGED
@@ -7,8 +7,6 @@ require 'r10k/util/setopts'
|
|
7
7
|
# @since 1.3.0
|
8
8
|
class R10K::Environment::SVN < R10K::Environment::Base
|
9
9
|
|
10
|
-
include R10K::Logging
|
11
|
-
|
12
10
|
R10K::Environment.register(:svn, self)
|
13
11
|
|
14
12
|
# @!attribute [r] remote
|
@@ -44,8 +42,17 @@ class R10K::Environment::SVN < R10K::Environment::Base
|
|
44
42
|
# @option options [String] :password The SVN password
|
45
43
|
def initialize(name, basedir, dirname, options = {})
|
46
44
|
super
|
45
|
+
setopts(options, {
|
46
|
+
# Standard option interface
|
47
|
+
:source => :remote,
|
48
|
+
:version => :expected_revision,
|
49
|
+
:type => ::R10K::Util::Setopts::Ignore,
|
47
50
|
|
48
|
-
|
51
|
+
# Type-specific options
|
52
|
+
:remote => :self,
|
53
|
+
:username => :self,
|
54
|
+
:password => :self,
|
55
|
+
})
|
49
56
|
|
50
57
|
@working_dir = R10K::SVN::WorkingDir.new(Pathname.new(@full_path), :username => @username, :password => @password)
|
51
58
|
end
|
@@ -61,7 +68,7 @@ class R10K::Environment::SVN < R10K::Environment::Base
|
|
61
68
|
if @working_dir.is_svn?
|
62
69
|
@working_dir.update
|
63
70
|
else
|
64
|
-
@working_dir.checkout(@remote)
|
71
|
+
@working_dir.checkout(@remote, @expected_revision)
|
65
72
|
end
|
66
73
|
@synced = true
|
67
74
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'r10k/logging'
|
2
1
|
require 'r10k/util/purgeable'
|
3
2
|
|
4
3
|
# This abstract base class implements an environment that can include module
|
@@ -7,8 +6,6 @@ require 'r10k/util/purgeable'
|
|
7
6
|
# @since 3.4.0
|
8
7
|
class R10K::Environment::WithModules < R10K::Environment::Base
|
9
8
|
|
10
|
-
include R10K::Logging
|
11
|
-
|
12
9
|
# @!attribute [r] moduledir
|
13
10
|
# @return [String] The directory to install environment-defined modules
|
14
11
|
# into (default: #{basedir}/modules)
|
@@ -24,7 +21,7 @@ class R10K::Environment::WithModules < R10K::Environment::Base
|
|
24
21
|
# @param options [String] :moduledir The path to install modules to
|
25
22
|
# @param options [Hash] :modules Modules to add to the environment
|
26
23
|
def initialize(name, basedir, dirname, options = {})
|
27
|
-
super
|
24
|
+
super
|
28
25
|
|
29
26
|
@managed_content = {}
|
30
27
|
@modules = []
|
@@ -46,38 +43,71 @@ class R10K::Environment::WithModules < R10K::Environment::Base
|
|
46
43
|
# - The r10k environment object
|
47
44
|
# - A Puppetfile in the environment's content
|
48
45
|
def modules
|
49
|
-
return @modules if
|
46
|
+
return @modules if puppetfile.nil?
|
47
|
+
|
48
|
+
puppetfile.load unless puppetfile.loaded?
|
49
|
+
@modules + puppetfile.modules
|
50
|
+
end
|
51
|
+
|
52
|
+
def module_conflicts?(mod_b)
|
53
|
+
conflict = @modules.any? { |mod_a| mod_a.name == mod_b.name }
|
54
|
+
return false unless conflict
|
55
|
+
|
56
|
+
msg_vars = {src: mod_b.origin, name: mod_b.name}
|
57
|
+
msg_error = _('Environment and %{src} both define the "%{name}" module' % msg_vars)
|
58
|
+
msg_continue = _("#{msg_error}. The %{src} definition will be ignored" % msg_vars)
|
59
|
+
|
60
|
+
case conflict_opt = @options[:module_conflicts]
|
61
|
+
when 'override_and_warn', nil
|
62
|
+
logger.warn msg_continue
|
63
|
+
when 'override'
|
64
|
+
logger.debug msg_continue
|
65
|
+
when 'error'
|
66
|
+
raise R10K::Error, msg_error
|
67
|
+
else
|
68
|
+
raise R10K::Error, _('Unexpected value for `module_conflicts` setting in %{env} ' \
|
69
|
+
'environment: %{val}' % {env: self.name, val: conflict_opt})
|
70
|
+
end
|
50
71
|
|
51
|
-
|
52
|
-
@modules + @puppetfile.modules
|
72
|
+
true
|
53
73
|
end
|
54
74
|
|
55
75
|
def accept(visitor)
|
56
76
|
visitor.visit(:environment, self) do
|
57
77
|
@modules.each do |mod|
|
58
|
-
mod.
|
78
|
+
mod.sync
|
59
79
|
end
|
60
80
|
|
61
81
|
puppetfile.accept(visitor)
|
62
|
-
validate_no_module_conflicts
|
63
82
|
end
|
64
83
|
end
|
65
84
|
|
85
|
+
def deploy
|
86
|
+
@modules.each do |mod|
|
87
|
+
mod.sync
|
88
|
+
end
|
89
|
+
|
90
|
+
super
|
91
|
+
end
|
92
|
+
|
66
93
|
def load_modules(module_hash)
|
67
94
|
module_hash.each do |name, args|
|
95
|
+
if !args.is_a?(Hash)
|
96
|
+
args = { version: args }
|
97
|
+
end
|
98
|
+
|
68
99
|
add_module(name, args)
|
69
100
|
end
|
70
101
|
end
|
71
102
|
|
72
103
|
# @param [String] name
|
73
|
-
# @param [
|
104
|
+
# @param [Hash] args
|
74
105
|
def add_module(name, args)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
106
|
+
# symbolize keys in the args hash
|
107
|
+
args = args.inject({}) { |memo,(k,v)| memo[k.to_sym] = v; memo }
|
108
|
+
args[:overrides] = @overrides
|
79
109
|
|
80
|
-
if
|
110
|
+
if install_path = args.delete(:install_path)
|
81
111
|
install_path = resolve_install_path(install_path)
|
82
112
|
validate_install_path(install_path, name)
|
83
113
|
else
|
@@ -88,26 +118,12 @@ class R10K::Environment::WithModules < R10K::Environment::Base
|
|
88
118
|
@managed_content[install_path] = Array.new unless @managed_content.has_key?(install_path)
|
89
119
|
|
90
120
|
mod = R10K::Module.new(name, install_path, args, self.name)
|
91
|
-
mod.origin =
|
121
|
+
mod.origin = :environment
|
92
122
|
|
93
123
|
@managed_content[install_path] << mod.name
|
94
124
|
@modules << mod
|
95
125
|
end
|
96
126
|
|
97
|
-
def validate_no_module_conflicts
|
98
|
-
@puppetfile.load unless @puppetfile.loaded?
|
99
|
-
conflicts = (@modules + @puppetfile.modules)
|
100
|
-
.group_by { |mod| mod.name }
|
101
|
-
.select { |_, v| v.size > 1 }
|
102
|
-
.map(&:first)
|
103
|
-
unless conflicts.empty?
|
104
|
-
msg = _('Puppetfile cannot contain module names defined by environment %{name}') % {name: self.name}
|
105
|
-
msg += ' '
|
106
|
-
msg += _("Remove the conflicting definitions of the following modules: %{conflicts}" % { conflicts: conflicts.join(' ') })
|
107
|
-
raise R10K::Error.new(msg)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
127
|
include R10K::Util::Purgeable
|
112
128
|
|
113
129
|
# Returns an array of the full paths that can be purged.
|