r10k 3.11.0 → 3.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/docker.yml +1 -1
  3. data/.github/workflows/rspec_tests.yml +2 -2
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG.mkd +34 -0
  6. data/doc/dynamic-environments/configuration.mkd +35 -7
  7. data/doc/dynamic-environments/usage.mkd +26 -0
  8. data/doc/puppetfile.mkd +16 -4
  9. data/integration/tests/basic_functionality/basic_deployment.rb +176 -0
  10. data/lib/r10k/action/base.rb +1 -1
  11. data/lib/r10k/action/deploy/deploy_helpers.rb +4 -0
  12. data/lib/r10k/action/deploy/display.rb +1 -1
  13. data/lib/r10k/action/deploy/environment.rb +13 -8
  14. data/lib/r10k/action/deploy/module.rb +14 -10
  15. data/lib/r10k/action/puppetfile/check.rb +7 -5
  16. data/lib/r10k/action/puppetfile/install.rb +22 -16
  17. data/lib/r10k/action/puppetfile/purge.rb +12 -9
  18. data/lib/r10k/action/runner.rb +6 -0
  19. data/lib/r10k/action/visitor.rb +3 -0
  20. data/lib/r10k/cli/deploy.rb +1 -0
  21. data/lib/r10k/cli/puppetfile.rb +0 -1
  22. data/lib/r10k/content_synchronizer.rb +16 -4
  23. data/lib/r10k/environment/bare.rb +4 -7
  24. data/lib/r10k/environment/base.rb +64 -11
  25. data/lib/r10k/environment/name.rb +14 -9
  26. data/lib/r10k/environment/plain.rb +16 -0
  27. data/lib/r10k/environment/tarball.rb +78 -0
  28. data/lib/r10k/environment/with_modules.rb +6 -10
  29. data/lib/r10k/environment.rb +2 -0
  30. data/lib/r10k/errors.rb +5 -0
  31. data/lib/r10k/forge/module_release.rb +2 -1
  32. data/lib/r10k/git/cache.rb +4 -13
  33. data/lib/r10k/git/rugged/base_repository.rb +12 -1
  34. data/lib/r10k/git/rugged/cache.rb +8 -0
  35. data/lib/r10k/git/stateful_repository.rb +9 -0
  36. data/lib/r10k/initializers.rb +21 -7
  37. data/lib/r10k/logging.rb +78 -1
  38. data/lib/r10k/module/base.rb +5 -1
  39. data/lib/r10k/module/definition.rb +64 -0
  40. data/lib/r10k/module/forge.rb +10 -2
  41. data/lib/r10k/module/git.rb +22 -1
  42. data/lib/r10k/module/local.rb +6 -3
  43. data/lib/r10k/module/svn.rb +10 -0
  44. data/lib/r10k/module/tarball.rb +101 -0
  45. data/lib/r10k/module.rb +21 -2
  46. data/lib/r10k/module_loader/puppetfile/dsl.rb +8 -3
  47. data/lib/r10k/module_loader/puppetfile.rb +109 -30
  48. data/lib/r10k/puppetfile.rb +1 -2
  49. data/lib/r10k/settings.rb +46 -0
  50. data/lib/r10k/source/git.rb +18 -18
  51. data/lib/r10k/source/yaml.rb +1 -1
  52. data/lib/r10k/tarball.rb +183 -0
  53. data/lib/r10k/util/cacheable.rb +31 -0
  54. data/lib/r10k/util/downloader.rb +134 -0
  55. data/lib/r10k/util/purgeable.rb +6 -2
  56. data/lib/r10k/util/setopts.rb +2 -0
  57. data/lib/r10k/util/subprocess.rb +1 -0
  58. data/lib/r10k/version.rb +1 -1
  59. data/locales/r10k.pot +119 -71
  60. data/r10k.gemspec +2 -2
  61. data/r10k.yaml.example +28 -0
  62. data/spec/fixtures/tarball/tarball.tar.gz +0 -0
  63. data/spec/fixtures/unit/action/r10k_logging.yaml +12 -0
  64. data/spec/fixtures/unit/puppetfile/forge-override/Puppetfile +8 -0
  65. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile +10 -0
  66. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile.new +10 -0
  67. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/managed_symlink_file +1 -0
  68. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/{managed_subdir_2 → subdir_allowlisted_2}/ignored_1 +0 -0
  69. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/unmanaged_symlink_dir +1 -0
  70. data/spec/fixtures/unit/util/purgeable/managed_one/managed_symlink_dir +1 -0
  71. data/spec/fixtures/unit/util/purgeable/managed_one/unmanaged_symlink_file +1 -0
  72. data/spec/integration/git/rugged/cache_spec.rb +33 -0
  73. data/spec/integration/util/purageable_spec.rb +41 -0
  74. data/spec/r10k-mocks/mock_env.rb +3 -0
  75. data/spec/r10k-mocks/mock_source.rb +7 -3
  76. data/spec/shared-contexts/tarball.rb +32 -0
  77. data/spec/spec_helper.rb +1 -0
  78. data/spec/unit/action/deploy/environment_spec.rb +80 -30
  79. data/spec/unit/action/deploy/module_spec.rb +52 -64
  80. data/spec/unit/action/puppetfile/check_spec.rb +17 -5
  81. data/spec/unit/action/puppetfile/install_spec.rb +42 -36
  82. data/spec/unit/action/puppetfile/purge_spec.rb +15 -17
  83. data/spec/unit/action/runner_spec.rb +52 -9
  84. data/spec/unit/environment/bare_spec.rb +13 -0
  85. data/spec/unit/environment/base_spec.rb +30 -17
  86. data/spec/unit/environment/git_spec.rb +2 -2
  87. data/spec/unit/environment/name_spec.rb +18 -0
  88. data/spec/unit/environment/plain_spec.rb +8 -0
  89. data/spec/unit/environment/svn_spec.rb +4 -3
  90. data/spec/unit/environment/tarball_spec.rb +45 -0
  91. data/spec/unit/environment/with_modules_spec.rb +3 -2
  92. data/spec/unit/git/cache_spec.rb +2 -15
  93. data/spec/unit/git/rugged/cache_spec.rb +19 -0
  94. data/spec/unit/module/base_spec.rb +8 -8
  95. data/spec/unit/module/forge_spec.rb +32 -4
  96. data/spec/unit/module/git_spec.rb +51 -10
  97. data/spec/unit/module/svn_spec.rb +18 -6
  98. data/spec/unit/module/tarball_spec.rb +70 -0
  99. data/spec/unit/module_loader/puppetfile_spec.rb +96 -31
  100. data/spec/unit/puppetfile_spec.rb +2 -2
  101. data/spec/unit/settings_spec.rb +25 -2
  102. data/spec/unit/tarball_spec.rb +57 -0
  103. data/spec/unit/util/cacheable_spec.rb +23 -0
  104. data/spec/unit/util/downloader_spec.rb +98 -0
  105. data/spec/unit/util/purgeable_spec.rb +22 -11
  106. metadata +44 -17
@@ -1,7 +1,7 @@
1
- require 'r10k/puppetfile'
2
- require 'r10k/errors/formatting'
3
- require 'r10k/action/visitor'
4
1
  require 'r10k/action/base'
2
+ require 'r10k/content_synchronizer'
3
+ require 'r10k/errors/formatting'
4
+ require 'r10k/module_loader/puppetfile'
5
5
  require 'r10k/util/cleaner'
6
6
 
7
7
  module R10K
@@ -10,25 +10,31 @@ module R10K
10
10
  class Install < R10K::Action::Base
11
11
 
12
12
  def call
13
- @ok = true
14
13
  begin
15
- pf = R10K::Puppetfile.new(@root,
16
- {moduledir: @moduledir,
17
- puppetfile_path: @puppetfile,
18
- force: @force || false})
19
- pf.load!
20
- pf.sync
14
+ options = { basedir: @root, overrides: { force: @force || false } }
15
+ options[:moduledir] = @moduledir if @moduledir
16
+ options[:puppetfile] = @puppetfile if @puppetfile
17
+
18
+ loader = R10K::ModuleLoader::Puppetfile.new(**options)
19
+ loaded_content = loader.load!
21
20
 
22
- R10K::Util::Cleaner.new(pf.managed_directories,
23
- pf.desired_contents,
24
- pf.purge_exclusions).purge!
21
+ pool_size = @settings[:pool_size] || 4
22
+ modules = loaded_content[:modules]
23
+ if pool_size > 1
24
+ R10K::ContentSynchronizer.concurrent_sync(modules, pool_size, logger)
25
+ else
26
+ R10K::ContentSynchronizer.serial_sync(modules, logger)
27
+ end
25
28
 
29
+ R10K::Util::Cleaner.new(loaded_content[:managed_directories],
30
+ loaded_content[:desired_contents],
31
+ loaded_content[:purge_exclusions]).purge!
32
+
33
+ true
26
34
  rescue => e
27
- @ok = false
28
35
  logger.error R10K::Errors::Formatting.format_exception(e, @trace)
36
+ false
29
37
  end
30
-
31
- @ok
32
38
  end
33
39
 
34
40
  private
@@ -1,7 +1,7 @@
1
- require 'r10k/puppetfile'
2
- require 'r10k/util/cleaner'
3
1
  require 'r10k/action/base'
4
2
  require 'r10k/errors/formatting'
3
+ require 'r10k/module_loader/puppetfile'
4
+ require 'r10k/util/cleaner'
5
5
 
6
6
  module R10K
7
7
  module Action
@@ -9,13 +9,16 @@ module R10K
9
9
  class Purge < R10K::Action::Base
10
10
 
11
11
  def call
12
- pf = R10K::Puppetfile.new(@root,
13
- {moduledir: @moduledir,
14
- puppetfile_path: @puppetfile})
15
- pf.load!
16
- R10K::Util::Cleaner.new(pf.managed_directories,
17
- pf.desired_contents,
18
- pf.purge_exclusions).purge!
12
+ options = { basedir: @root }
13
+
14
+ options[:moduledir] = @moduledir if @moduledir
15
+ options[:puppetfile] = @puppetfile if @puppetfile
16
+
17
+ loader = R10K::ModuleLoader::Puppetfile.new(**options)
18
+ loaded_content = loader.load!
19
+ R10K::Util::Cleaner.new(loaded_content[:managed_directories],
20
+ loaded_content[:desired_contents],
21
+ loaded_content[:purge_exclusions]).purge!
19
22
 
20
23
  true
21
24
  rescue => e
@@ -51,6 +51,12 @@ module R10K
51
51
  overrides[:deploy][:generate_types] = @opts[:'generate-types'] if @opts.key?(:'generate-types')
52
52
  overrides[:deploy][:exclude_spec] = @opts[:'exclude-spec'] if @opts.key?(:'exclude-spec')
53
53
  end
54
+ # If the log level has been given as an argument, ensure that output happens on stderr
55
+ if @opts.key?(:loglevel)
56
+ overrides[:logging] = {}
57
+ overrides[:logging][:level] = @opts[:loglevel]
58
+ overrides[:logging][:disable_default_stderr] = false
59
+ end
54
60
 
55
61
  with_overrides = config_settings.merge(overrides) do |key, oldval, newval|
56
62
  newval = oldval.merge(newval) if oldval.is_a? Hash
@@ -1,4 +1,5 @@
1
1
  require 'r10k/errors/formatting'
2
+ require 'r10k/logging'
2
3
 
3
4
  module R10K
4
5
  module Action
@@ -13,6 +14,8 @@ module R10K
13
14
  # @api private
14
15
  module Visitor
15
16
 
17
+ include R10K::Logging
18
+
16
19
  # Dispatch to the type specific visitor method
17
20
  #
18
21
  # @param type [Symbol] The object type to dispatch for
@@ -69,6 +69,7 @@ scheduled. On subsequent deployments, Puppetfile deployment will default to off.
69
69
 
70
70
  flag :p, :puppetfile, 'Deploy modules (deprecated, use -m)'
71
71
  flag :m, :modules, 'Deploy modules'
72
+ flag nil, :incremental, 'Used with the --modules flag, only update those modules whose definition has changed or whose definition allows the version to float'
72
73
  option nil, :'default-branch-override', 'Specify a branchname to override the default branch in the puppetfile',
73
74
  argument: :required
74
75
 
@@ -1,5 +1,4 @@
1
1
  require 'r10k/cli'
2
- require 'r10k/puppetfile'
3
2
  require 'r10k/action/puppetfile'
4
3
 
5
4
  require 'cri'
@@ -8,24 +8,31 @@ module R10K
8
8
  end
9
9
 
10
10
  def self.serial_sync(modules)
11
+ updated_modules = []
11
12
  modules.each do |mod|
12
- mod.sync
13
+ updated = mod.sync
14
+ updated_modules << mod.name if updated
13
15
  end
16
+ updated_modules
14
17
  end
15
18
 
19
+ # Returns a Queue of the names of modules actually updated
16
20
  def self.concurrent_accept(modules, visitor, loader, pool_size, logger)
17
21
  mods_queue = modules_visit_queue(modules, visitor, loader)
18
22
  sync_queue(mods_queue, pool_size, logger)
19
23
  end
20
24
 
25
+ # Returns a Queue of the names of modules actually updated
21
26
  def self.concurrent_sync(modules, pool_size, logger)
22
27
  mods_queue = modules_sync_queue(modules)
23
28
  sync_queue(mods_queue, pool_size, logger)
24
29
  end
25
30
 
31
+ # Returns a Queue of the names of modules actually updated
26
32
  def self.sync_queue(mods_queue, pool_size, logger)
27
33
  logger.debug _("Updating modules with %{pool_size} threads") % {pool_size: pool_size}
28
- thread_pool = pool_size.times.map { sync_thread(mods_queue, logger) }
34
+ updated_modules = Queue.new
35
+ thread_pool = pool_size.times.map { sync_thread(mods_queue, logger, updated_modules) }
29
36
  thread_exception = nil
30
37
 
31
38
  # If any threads raise an exception the deployment is considered a failure.
@@ -33,6 +40,8 @@ module R10K
33
40
  # current work, then re-raise the first exception caught.
34
41
  begin
35
42
  thread_pool.each(&:join)
43
+ # Return the list of all modules that were actually updated
44
+ updated_modules
36
45
  rescue => e
37
46
  logger.error _("Error during concurrent deploy of a module: %{message}") % {message: e.message}
38
47
  mods_queue.clear
@@ -65,11 +74,14 @@ module R10K
65
74
  modules_by_cachedir.values.each {|mods| queue << mods }
66
75
  end
67
76
 
68
- def self.sync_thread(mods_queue, logger)
77
+ def self.sync_thread(mods_queue, logger, updated_modules)
69
78
  Thread.new do
70
79
  begin
71
80
  while mods = mods_queue.pop(true) do
72
- mods.each { |mod| mod.sync }
81
+ mods.each do |mod|
82
+ updated = mod.sync
83
+ updated_modules << mod.name if updated
84
+ end
73
85
  end
74
86
  rescue ThreadError => e
75
87
  logger.debug _("Module thread %{id} exiting: %{message}") % {message: e.message, id: Thread.current.object_id}
@@ -1,13 +1,10 @@
1
- class R10K::Environment::Bare < R10K::Environment::WithModules
1
+ class R10K::Environment::Bare < R10K::Environment::Plain
2
2
 
3
3
  R10K::Environment.register(:bare, self)
4
4
 
5
- def sync
6
- path.mkpath
7
- end
8
-
9
- def status
10
- :not_applicable
5
+ def initialize(name, basedir, dirname, options = {})
6
+ logger.warn _('"bare" environment type is deprecated; please use "plain" instead (environment: %{name})') % {name: name}
7
+ super
11
8
  end
12
9
 
13
10
  def signature
@@ -1,5 +1,8 @@
1
- require 'r10k/util/subprocess'
1
+ require 'r10k/content_synchronizer'
2
2
  require 'r10k/logging'
3
+ require 'r10k/module_loader/puppetfile'
4
+ require 'r10k/util/cleaner'
5
+ require 'r10k/util/subprocess'
3
6
 
4
7
  # This class defines a common interface for environment implementations.
5
8
  #
@@ -34,6 +37,10 @@ class R10K::Environment::Base
34
37
  # @return [String] The puppetfile name (relative)
35
38
  attr_reader :puppetfile_name
36
39
 
40
+ attr_reader :managed_directories, :desired_contents
41
+
42
+ attr_reader :loader
43
+
37
44
  # Initialize the given environment.
38
45
  #
39
46
  # @param name [String] The unique name describing this environment.
@@ -57,6 +64,20 @@ class R10K::Environment::Base
57
64
  force: @overrides.dig(:modules, :force),
58
65
  puppetfile_name: @puppetfile_name})
59
66
  @puppetfile.environment = self
67
+
68
+ loader_options = { basedir: @full_path, overrides: @overrides, environment: self }
69
+ loader_options[:puppetfile] = @puppetfile_name if @puppetfile_name
70
+
71
+ @loader = R10K::ModuleLoader::Puppetfile.new(**loader_options)
72
+
73
+ if @overrides.dig(:environments, :incremental)
74
+ @loader.load_metadata
75
+ end
76
+
77
+ @base_modules = nil
78
+ @purge_exclusions = nil
79
+ @managed_directories = [ @full_path ]
80
+ @desired_contents = []
60
81
  end
61
82
 
62
83
  # Synchronize the given environment.
@@ -106,8 +127,11 @@ class R10K::Environment::Base
106
127
  # @return [Array<R10K::Module::Base>] All modules defined in the Puppetfile
107
128
  # associated with this environment.
108
129
  def modules
109
- @puppetfile.load
110
- @puppetfile.modules
130
+ if @base_modules.nil?
131
+ load_puppetfile_modules
132
+ end
133
+
134
+ @base_modules
111
135
  end
112
136
 
113
137
  # @return [Array<R10K::Module::Base>] Whether or not the given module
@@ -123,29 +147,50 @@ class R10K::Environment::Base
123
147
  end
124
148
  end
125
149
 
150
+
151
+ # Returns a Queue of the names of modules actually updated
126
152
  def deploy
127
- puppetfile.load(@overrides.dig(:environments, :default_branch_override))
153
+ if @base_modules.nil?
154
+ load_puppetfile_modules
155
+ end
128
156
 
129
- puppetfile.sync
157
+ if ! @base_modules.empty?
158
+ pool_size = @overrides.dig(:modules, :pool_size)
159
+ updated_modules = R10K::ContentSynchronizer.concurrent_sync(@base_modules, pool_size, logger)
160
+ end
130
161
 
131
162
  if (@overrides.dig(:purging, :purge_levels) || []).include?(:puppetfile)
132
163
  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!
164
+ @puppetfile_cleaner.purge!
136
165
  end
166
+
167
+ updated_modules
168
+ end
169
+
170
+ def load_puppetfile_modules
171
+ loaded_content = @loader.load
172
+ @base_modules = loaded_content[:modules]
173
+
174
+ @purge_exclusions = determine_purge_exclusions(loaded_content[:managed_directories],
175
+ loaded_content[:desired_contents])
176
+
177
+ @puppetfile_cleaner = R10K::Util::Cleaner.new(loaded_content[:managed_directories],
178
+ loaded_content[:desired_contents],
179
+ loaded_content[:purge_exclusions])
137
180
  end
138
181
 
139
182
  def whitelist(user_whitelist=[])
140
183
  user_whitelist.collect { |pattern| File.join(@full_path, pattern) }
141
184
  end
142
185
 
143
- def purge_exclusions
186
+ def determine_purge_exclusions(pf_managed_dirs = @puppetfile.managed_directories,
187
+ pf_desired_contents = @puppetfile.desired_contents)
188
+
144
189
  list = [File.join(@full_path, '.r10k-deploy.json')].to_set
145
190
 
146
- list += @puppetfile.managed_directories
191
+ list += pf_managed_dirs
147
192
 
148
- list += @puppetfile.desired_contents.flat_map do |item|
193
+ list += pf_desired_contents.flat_map do |item|
149
194
  desired_tree = []
150
195
 
151
196
  if File.directory?(item)
@@ -163,6 +208,14 @@ class R10K::Environment::Base
163
208
  list.to_a
164
209
  end
165
210
 
211
+ def purge_exclusions
212
+ if @purge_exclusions.nil?
213
+ load_puppetfile_modules
214
+ end
215
+
216
+ @purge_exclusions
217
+ end
218
+
166
219
  def generate_types!
167
220
  argv = [R10K::Settings.puppet_path, 'generate', 'types', '--environment', dirname, '--environmentpath', basedir, '--config', R10K::Settings.puppet_conf]
168
221
  subproc = R10K::Util::Subprocess.new(argv)
@@ -6,17 +6,22 @@ module R10K
6
6
  class Name
7
7
 
8
8
  # @!attribute [r] name
9
- # @return [String] The unmodified name of the environment
9
+ # @return [String] The functional name of the environment derived from inputs and options.
10
10
  attr_reader :name
11
11
 
12
+ # @!attribute [r] original_name
13
+ # @return [String] The unmodified name originally given to create the object.
14
+ attr_reader :original_name
15
+
12
16
  INVALID_CHARACTERS = %r[\W]
13
17
 
14
- def initialize(name, opts)
18
+ def initialize(original_name, opts)
15
19
  @source = opts[:source]
16
20
  @prefix = opts[:prefix]
17
21
  @invalid = opts[:invalid]
18
22
 
19
- @name = derive_name(name, opts[:strip_component])
23
+ @name = derive_name(original_name, opts[:strip_component])
24
+ @original_name = original_name
20
25
  @opts = opts
21
26
 
22
27
  case @invalid
@@ -71,8 +76,8 @@ module R10K
71
76
 
72
77
  private
73
78
 
74
- def derive_name(name, strip_component)
75
- return name unless strip_component
79
+ def derive_name(original_name, strip_component)
80
+ return original_name unless strip_component
76
81
 
77
82
  unless strip_component.is_a?(String)
78
83
  raise _('Improper configuration value given for strip_component setting in %{src} source. ' \
@@ -82,11 +87,11 @@ module R10K
82
87
 
83
88
  if %r{^/.*/$}.match(strip_component)
84
89
  regex = Regexp.new(strip_component[1..-2])
85
- name.gsub(regex, '')
86
- elsif name.start_with?(strip_component)
87
- name[strip_component.size..-1]
90
+ original_name.gsub(regex, '')
91
+ elsif original_name.start_with?(strip_component)
92
+ original_name[strip_component.size..-1]
88
93
  else
89
- name
94
+ original_name
90
95
  end
91
96
  end
92
97
 
@@ -0,0 +1,16 @@
1
+ class R10K::Environment::Plain < R10K::Environment::WithModules
2
+
3
+ R10K::Environment.register(:plain, self)
4
+
5
+ def sync
6
+ path.mkpath
7
+ end
8
+
9
+ def status
10
+ :not_applicable
11
+ end
12
+
13
+ def signature
14
+ 'plain-default'
15
+ end
16
+ end
@@ -0,0 +1,78 @@
1
+ require 'r10k/util/setopts'
2
+ require 'r10k/tarball'
3
+ require 'r10k/environment'
4
+
5
+ class R10K::Environment::Tarball < R10K::Environment::WithModules
6
+
7
+ R10K::Environment.register(:tarball, self)
8
+
9
+ # @!attribute [r] tarball
10
+ # @api private
11
+ # @return [R10K::Tarball]
12
+ attr_reader :tarball
13
+
14
+ include R10K::Util::Setopts
15
+
16
+ # Initialize the given tarball environment.
17
+ #
18
+ # @param name [String] The unique name describing this environment.
19
+ # @param basedir [String] The base directory where this environment will be created.
20
+ # @param dirname [String] The directory name for this environment.
21
+ # @param options [Hash] An additional set of options for this environment.
22
+ #
23
+ # @param options [String] :source Where to get the tarball from
24
+ # @param options [String] :version The sha256 digest of the tarball
25
+ def initialize(name, basedir, dirname, options = {})
26
+ super
27
+ setopts(options, {
28
+ # Standard option interface
29
+ :type => ::R10K::Util::Setopts::Ignore,
30
+ :source => :self,
31
+ :version => :checksum,
32
+
33
+ # Type-specific options
34
+ :checksum => :self,
35
+ })
36
+
37
+ @tarball = R10K::Tarball.new(name, @source, checksum: @checksum)
38
+ end
39
+
40
+ def path
41
+ @path ||= Pathname.new(File.join(@basedir, @dirname))
42
+ end
43
+
44
+ def sync
45
+ tarball.get unless tarball.cache_valid?
46
+ case status
47
+ when :absent, :mismatched
48
+ tarball.unpack(path.to_s)
49
+ # Untracked files left behind from previous extractions are expected to
50
+ # be deleted by r10k's purge facility.
51
+ end
52
+ end
53
+
54
+ def status
55
+ if not path.exist?
56
+ :absent
57
+ elsif not (tarball.cache_valid? && tarball.insync?(path.to_s, ignore_untracked_files: true))
58
+ :mismatched
59
+ else
60
+ :insync
61
+ end
62
+ end
63
+
64
+ def signature
65
+ @checksum || @tarball.cache_checksum
66
+ end
67
+
68
+ include R10K::Util::Purgeable
69
+
70
+ # Returns an array of the full paths to all the content being managed.
71
+ # @note This implements a required method for the Purgeable mixin
72
+ # @return [Array<String>]
73
+ def desired_contents
74
+ desired = []
75
+ desired += @tarball.paths.map { |entry| File.join(@full_path, entry) }
76
+ desired += super
77
+ end
78
+ end
@@ -23,6 +23,7 @@ class R10K::Environment::WithModules < R10K::Environment::Base
23
23
  def initialize(name, basedir, dirname, options = {})
24
24
  super
25
25
 
26
+ @all_modules = nil
26
27
  @managed_content = {}
27
28
  @modules = []
28
29
  @moduledir = case options[:moduledir]
@@ -43,10 +44,12 @@ class R10K::Environment::WithModules < R10K::Environment::Base
43
44
  # - The r10k environment object
44
45
  # - A Puppetfile in the environment's content
45
46
  def modules
46
- return @modules if puppetfile.nil?
47
+ if @all_modules.nil?
48
+ puppetfile_modules = super()
49
+ @all_modules = @modules + puppetfile_modules
50
+ end
47
51
 
48
- puppetfile.load unless puppetfile.loaded?
49
- @modules + puppetfile.modules
52
+ @all_modules
50
53
  end
51
54
 
52
55
  def module_conflicts?(mod_b)
@@ -126,13 +129,6 @@ class R10K::Environment::WithModules < R10K::Environment::Base
126
129
 
127
130
  include R10K::Util::Purgeable
128
131
 
129
- # Returns an array of the full paths that can be purged.
130
- # @note This implements a required method for the Purgeable mixin
131
- # @return [Array<String>]
132
- def managed_directories
133
- [@full_path]
134
- end
135
-
136
132
  # Returns an array of the full paths of filenames that should exist. Files
137
133
  # inside managed_directories that are not listed in desired_contents will
138
134
  # be purged.
@@ -30,8 +30,10 @@ module R10K
30
30
 
31
31
  require 'r10k/environment/base'
32
32
  require 'r10k/environment/with_modules'
33
+ require 'r10k/environment/plain'
33
34
  require 'r10k/environment/bare'
34
35
  require 'r10k/environment/git'
35
36
  require 'r10k/environment/svn'
37
+ require 'r10k/environment/tarball'
36
38
  end
37
39
  end
data/lib/r10k/errors.rb CHANGED
@@ -58,4 +58,9 @@ module R10K
58
58
  str.gsub(/^/, prefix)
59
59
  end
60
60
  end
61
+
62
+ # An error class for configuration errors
63
+ #
64
+ class ConfigError < Error
65
+ end
61
66
  end
@@ -1,5 +1,6 @@
1
1
  require 'r10k/logging'
2
2
  require 'r10k/settings/mixin'
3
+ require 'r10k/util/cacheable'
3
4
  require 'fileutils'
4
5
  require 'tmpdir'
5
6
  require 'puppet_forge'
@@ -13,7 +14,7 @@ module R10K
13
14
 
14
15
  def_setting_attr :proxy
15
16
  def_setting_attr :baseurl
16
- def_setting_attr :cache_root, File.expand_path(ENV['HOME'] ? '~/.r10k/cache': '/root/.r10k/cache')
17
+ def_setting_attr :cache_root, R10K::Util::Cacheable.default_cachedir
17
18
 
18
19
  include R10K::Logging
19
20
 
@@ -3,6 +3,7 @@ require 'r10k/git'
3
3
  require 'r10k/settings'
4
4
  require 'r10k/instance_cache'
5
5
  require 'forwardable'
6
+ require 'r10k/util/cacheable'
6
7
 
7
8
  # Cache Git repository mirrors for object database reuse.
8
9
  #
@@ -15,18 +16,9 @@ require 'forwardable'
15
16
  class R10K::Git::Cache
16
17
 
17
18
  include R10K::Settings::Mixin
19
+ include R10K::Util::Cacheable
18
20
 
19
- #@api private
20
- def self.determine_cache_root
21
- if R10K::Util::Platform.windows?
22
- File.join(ENV['LOCALAPPDATA'], 'r10k', 'git')
23
- else
24
- File.expand_path(ENV['HOME'] ? '~/.r10k/git': '/root/.r10k/git')
25
- end
26
- end
27
- private_class_method :determine_cache_root
28
-
29
- def_setting_attr :cache_root, determine_cache_root
21
+ def_setting_attr :cache_root, R10K::Util::Cacheable.default_cachedir('git')
30
22
 
31
23
  @instance_cache = R10K::InstanceCache.new(self)
32
24
 
@@ -109,8 +101,7 @@ class R10K::Git::Cache
109
101
 
110
102
  alias cached? exist?
111
103
 
112
- # Reformat the remote name into something that can be used as a directory
113
104
  def sanitized_dirname
114
- @sanitized_dirname ||= @remote.gsub(/(\w+:\/\/)(.*)(@)/, '\1').gsub(/[^@\w\.-]/, '-')
105
+ @sanitized_dirname ||= super(@remote)
115
106
  end
116
107
  end
@@ -20,7 +20,8 @@ class R10K::Git::Rugged::BaseRepository
20
20
  else
21
21
  object.oid
22
22
  end
23
- rescue ::Rugged::ReferenceError
23
+ rescue ::Rugged::ReferenceError, ::Rugged::OdbError => e
24
+ logger.debug2(_("Unable to resolve %{pattern}: %{e} ") % {pattern: pattern, e: e })
24
25
  nil
25
26
  end
26
27
 
@@ -60,6 +61,16 @@ class R10K::Git::Rugged::BaseRepository
60
61
  remotes_hash
61
62
  end
62
63
 
64
+ # Update a remote URL
65
+ # @param [String] The remote URL of the git repository
66
+ # @param [String] An optional remote name for the git repository
67
+ def update_remote(remote, remote_name='origin')
68
+ if @_rugged_repo
69
+ logger.debug2(_("Remote URL is different from cache, updating %{orig} to %{update}") % {orig: remotes[remote_name], update: remote})
70
+ @_rugged_repo.remotes.set_url(remote_name, remote)
71
+ end
72
+ end
73
+
63
74
  private
64
75
 
65
76
  def with_repo(opts={})
@@ -8,4 +8,12 @@ class R10K::Git::Rugged::Cache < R10K::Git::Cache
8
8
  def self.bare_repository
9
9
  R10K::Git::Rugged::BareRepository
10
10
  end
11
+
12
+ # Update the remote URL if the cache differs from the current configuration
13
+ def sync!
14
+ if cached? && @repo.remotes['origin'] != @remote
15
+ @repo.update_remote(@remote)
16
+ end
17
+ super
18
+ end
11
19
  end