r10k 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGELOG.mkd +150 -0
  3. data/README.mkd +10 -1
  4. data/doc/dynamic-environments/configuration.mkd +31 -0
  5. data/doc/dynamic-environments/quickstart.mkd +33 -79
  6. data/doc/faq.mkd +67 -0
  7. data/doc/git/providers.mkd +37 -0
  8. data/doc/puppetfile.mkd +73 -0
  9. data/integration/lib/r10k_utils.rb +47 -2
  10. data/integration/pre-suite/01_git_config.rb +9 -8
  11. data/integration/pre-suite/02_pe_r10k.rb +5 -8
  12. data/integration/scripts/setup_r10k_env_centos5.sh +1 -1
  13. data/integration/scripts/setup_r10k_env_centos6.sh +1 -1
  14. data/integration/scripts/setup_r10k_env_rhel7.sh +1 -1
  15. data/integration/scripts/setup_r10k_env_sles11.sh +1 -1
  16. data/integration/scripts/setup_r10k_env_sles12.sh +1 -1
  17. data/integration/scripts/setup_r10k_env_ubuntu1004.sh +1 -1
  18. data/integration/scripts/setup_r10k_env_ubuntu1204.sh +1 -1
  19. data/integration/scripts/setup_r10k_env_ubuntu1404.sh +1 -1
  20. data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +1 -1
  21. data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +1 -1
  22. data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +1 -1
  23. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +1 -1
  24. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +1 -1
  25. data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +1 -1
  26. data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +1 -1
  27. data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +1 -1
  28. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +1 -1
  29. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +1 -1
  30. data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +1 -1
  31. data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +1 -1
  32. data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +1 -1
  33. data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +1 -1
  34. data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +1 -1
  35. data/integration/tests/basic_functionality/install_pe_only_module_with_puppetfile.rb +83 -0
  36. data/integration/tests/basic_functionality/negative/attempt_to_install_peonly_module_without_license.rb +71 -0
  37. data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +7 -2
  38. data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +3 -2
  39. data/integration/tests/basic_functionality/negative/neg_invalid_git_provider.rb +3 -2
  40. data/integration/tests/basic_functionality/negative/negative_bad_proxy.rb +56 -0
  41. data/integration/tests/basic_functionality/proxy_specified_in_configuration.rb +103 -0
  42. data/integration/tests/basic_functionality/proxy_with_puppetfile.rb +61 -0
  43. data/integration/tests/basic_functionality/rugged_git_provider_with_ssh.rb +2 -1
  44. data/integration/tests/basic_functionality/rugged_git_provider_without_ssh.rb +2 -1
  45. data/integration/tests/command_line/deploy_env_without_mod_update.rb +3 -2
  46. data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +3 -2
  47. data/integration/tests/command_line/negative/neg_invalid_cli_dep_flag.rb +2 -1
  48. data/integration/tests/command_line/negative/neg_invalid_cli_env_flag.rb +2 -1
  49. data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +3 -4
  50. data/integration/tests/git_source/git_source_git.rb +7 -2
  51. data/integration/tests/git_source/git_source_ssh.rb +3 -2
  52. data/integration/tests/git_source/git_source_submodule.rb +2 -1
  53. data/integration/tests/git_source/negative/neg_git_broken_remote.rb +2 -1
  54. data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +2 -1
  55. data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +2 -1
  56. data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +2 -1
  57. data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +3 -3
  58. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +2 -1
  59. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +9 -5
  60. data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +9 -2
  61. data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +2 -1
  62. data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +2 -1
  63. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +2 -1
  64. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +7 -2
  65. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +3 -4
  66. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +2 -1
  67. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +2 -1
  68. data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +2 -1
  69. data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +2 -1
  70. data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +10 -4
  71. data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +9 -2
  72. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +2 -1
  73. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +2 -1
  74. data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +7 -2
  75. data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +2 -1
  76. data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +9 -2
  77. data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +2 -1
  78. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +2 -1
  79. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +2 -1
  80. data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +2 -1
  81. data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +2 -1
  82. data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +2 -1
  83. data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +2 -1
  84. data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +2 -1
  85. data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +3 -2
  86. data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +3 -2
  87. data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +2 -1
  88. data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +4 -3
  89. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +3 -2
  90. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +4 -3
  91. data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +3 -2
  92. data/integration/tests/user_scenario/complex_workflow/single_env_git_module_update.rb +3 -2
  93. data/lib/r10k/action/base.rb +31 -0
  94. data/lib/r10k/action/deploy/deploy_helpers.rb +34 -0
  95. data/lib/r10k/action/deploy/display.rb +57 -75
  96. data/lib/r10k/action/deploy/environment.rb +52 -15
  97. data/lib/r10k/action/deploy/module.rb +13 -18
  98. data/lib/r10k/action/puppetfile/check.rb +8 -18
  99. data/lib/r10k/action/puppetfile/install.rb +13 -27
  100. data/lib/r10k/action/puppetfile/purge.rb +8 -17
  101. data/lib/r10k/action/runner.rb +39 -3
  102. data/lib/r10k/cli.rb +1 -3
  103. data/lib/r10k/cli/deploy.rb +3 -1
  104. data/lib/r10k/cli/puppetfile.rb +2 -2
  105. data/lib/r10k/deployment.rb +8 -6
  106. data/lib/r10k/deployment/config.rb +18 -65
  107. data/lib/r10k/environment/base.rb +19 -0
  108. data/lib/r10k/environment/git.rb +9 -0
  109. data/lib/r10k/environment/svn.rb +9 -0
  110. data/lib/r10k/forge/module_release.rb +21 -14
  111. data/lib/r10k/git.rb +6 -0
  112. data/lib/r10k/git/alternates.rb +20 -6
  113. data/lib/r10k/git/cache.rb +1 -1
  114. data/lib/r10k/git/rugged/bare_repository.rb +5 -0
  115. data/lib/r10k/git/rugged/base_repository.rb +6 -20
  116. data/lib/r10k/git/rugged/credentials.rb +66 -0
  117. data/lib/r10k/git/rugged/thin_repository.rb +16 -11
  118. data/lib/r10k/git/rugged/working_repository.rb +15 -7
  119. data/lib/r10k/git/shellgit/bare_repository.rb +9 -4
  120. data/lib/r10k/git/shellgit/thin_repository.rb +8 -10
  121. data/lib/r10k/git/stateful_repository.rb +1 -1
  122. data/lib/r10k/initializers.rb +55 -0
  123. data/lib/r10k/module.rb +1 -0
  124. data/lib/r10k/module/base.rb +3 -2
  125. data/lib/r10k/module/forge.rb +14 -6
  126. data/lib/r10k/module/local.rb +36 -0
  127. data/lib/r10k/module/metadata_file.rb +2 -2
  128. data/lib/r10k/puppetfile.rb +1 -1
  129. data/lib/r10k/settings.rb +86 -0
  130. data/lib/r10k/settings/collection.rb +118 -0
  131. data/lib/r10k/settings/definition.rb +112 -0
  132. data/lib/r10k/settings/enum_definition.rb +22 -0
  133. data/lib/r10k/settings/loader.rb +96 -0
  134. data/lib/r10k/settings/uri_definition.rb +19 -0
  135. data/lib/r10k/util/subprocess/runner/windows.rb +4 -4
  136. data/lib/r10k/version.rb +1 -1
  137. data/r10k.gemspec +2 -3
  138. data/spec/fixtures/unit/puppetfile/argument-error/Puppetfile +1 -0
  139. data/spec/fixtures/unit/util/subprocess/{posix/runner → runner}/no-execute.sh +0 -0
  140. data/spec/integration/git/rugged/thin_repository_spec.rb +2 -2
  141. data/spec/integration/git/rugged/working_repository_spec.rb +9 -0
  142. data/spec/integration/git/shellgit/thin_repository_spec.rb +2 -2
  143. data/spec/integration/git/stateful_repository_spec.rb +1 -1
  144. data/spec/r10k-mocks/mock_config.rb +10 -13
  145. data/spec/r10k-mocks/mock_env.rb +8 -0
  146. data/spec/shared-examples/deploy-actions.rb +69 -0
  147. data/spec/shared-examples/puppetfile-action.rb +17 -0
  148. data/spec/unit/action/cri_runner_spec.rb +3 -1
  149. data/spec/unit/action/deploy/deploy_helpers_spec.rb +38 -0
  150. data/spec/unit/action/deploy/display_spec.rb +31 -0
  151. data/spec/unit/action/deploy/environment_spec.rb +56 -0
  152. data/spec/unit/action/deploy/module_spec.rb +17 -0
  153. data/spec/unit/action/puppetfile/check_spec.rb +26 -0
  154. data/spec/unit/action/puppetfile/install_spec.rb +68 -0
  155. data/spec/unit/action/puppetfile/purge_spec.rb +19 -0
  156. data/spec/unit/action/runner_spec.rb +10 -9
  157. data/spec/unit/deployment/config_spec.rb +20 -44
  158. data/spec/unit/deployment_spec.rb +1 -1
  159. data/spec/unit/environment/git_spec.rb +20 -0
  160. data/spec/unit/environment/svn_spec.rb +20 -0
  161. data/spec/unit/forge/module_release_spec.rb +6 -3
  162. data/spec/unit/git/alternates_spec.rb +38 -12
  163. data/spec/unit/git/cache_spec.rb +4 -0
  164. data/spec/unit/git/rugged/credentials_spec.rb +74 -0
  165. data/spec/unit/initializers_spec.rb +68 -0
  166. data/spec/unit/module/base_spec.rb +2 -2
  167. data/spec/unit/module/forge_spec.rb +11 -3
  168. data/spec/unit/module/metadata_file_spec.rb +0 -1
  169. data/spec/unit/puppetfile_spec.rb +11 -0
  170. data/spec/unit/settings/collection_spec.rb +122 -0
  171. data/spec/unit/settings/definition_spec.rb +78 -0
  172. data/spec/unit/settings/enum_definition_spec.rb +20 -0
  173. data/spec/unit/{deployment/config → settings}/loader_spec.rb +50 -2
  174. data/spec/unit/settings/uri_definition_spec.rb +23 -0
  175. data/spec/unit/settings_spec.rb +151 -0
  176. data/spec/unit/util/subprocess/runner/posix_spec.rb +1 -1
  177. data/spec/unit/util/subprocess/runner/windows_spec.rb +7 -0
  178. metadata +53 -90
  179. data/lib/r10k/deployment/config/loader.rb +0 -59
  180. data/lib/shared/puppet/module_tool/metadata.rb +0 -197
  181. data/lib/shared/puppet_forge/connection.rb +0 -64
  182. data/lib/shared/puppet_forge/connection/connection_failure.rb +0 -26
  183. data/lib/shared/puppet_forge/error.rb +0 -41
  184. data/lib/shared/puppet_forge/tar.rb +0 -10
  185. data/lib/shared/puppet_forge/tar/mini.rb +0 -81
  186. data/lib/shared/puppet_forge/unpacker.rb +0 -68
  187. data/lib/shared/puppet_forge/v3.rb +0 -13
  188. data/lib/shared/puppet_forge/v3/module.rb +0 -69
  189. data/lib/shared/puppet_forge/v3/module_release.rb +0 -85
  190. data/lib/shared/puppet_forge/version.rb +0 -3
  191. data/spec/unit/puppet/module_tool/metadata_spec.rb +0 -301
  192. data/spec/unit/puppet_forge/connection/connection_failure_spec.rb +0 -28
  193. data/spec/unit/puppet_forge/connection_spec.rb +0 -41
  194. data/spec/unit/puppet_forge/tar/mini_spec.rb +0 -87
  195. data/spec/unit/puppet_forge/tar_spec.rb +0 -9
  196. data/spec/unit/puppet_forge/unpacker_spec.rb +0 -59
  197. data/spec/unit/puppet_forge/v3/module_release_spec.rb +0 -83
  198. data/spec/unit/puppet_forge/v3/module_spec.rb +0 -75
@@ -4,15 +4,20 @@ require 'r10k/git/shellgit/base_repository'
4
4
  # Create and manage Git bare repositories.
5
5
  class R10K::Git::ShellGit::BareRepository < R10K::Git::ShellGit::BaseRepository
6
6
 
7
+ # @param basedir [String] The base directory of the Git repository
8
+ # @param dirname [String] The directory name of the Git repository
9
+ def initialize(basedir, dirname)
10
+ @path = Pathname.new(File.join(basedir, dirname))
11
+ end
12
+
7
13
  # @return [Pathname] The path to this Git repository
8
14
  def git_dir
9
15
  @path
10
16
  end
11
17
 
12
- # @param basedir [String] The base directory of the Git repository
13
- # @param dirname [String] The directory name of the Git repository
14
- def initialize(basedir, dirname)
15
- @path = Pathname.new(File.join(basedir, dirname))
18
+ # @return [Pathname] The path to the objects directory in this Git repository
19
+ def objects_dir
20
+ @path + "objects"
16
21
  end
17
22
 
18
23
  def clone(remote)
@@ -8,11 +8,14 @@ require 'r10k/git/shellgit/working_repository'
8
8
  # making new clones very lightweight.
9
9
  class R10K::Git::ShellGit::ThinRepository < R10K::Git::ShellGit::WorkingRepository
10
10
 
11
- def initialize(basedir, dirname)
12
- super
13
-
14
- if exist? && origin
15
- set_cache(origin)
11
+ def initialize(basedir, dirname, cache_repo)
12
+ @cache_repo = cache_repo
13
+ super(basedir, dirname)
14
+ if git_dir.exist?
15
+ entry_added = alternates.add?(@cache_repo.objects_dir.to_s)
16
+ if entry_added
17
+ logger.debug2 { "Updated repo #{@path} to include alternate object db path #{@cache_repo.objects_dir}" }
18
+ end
16
19
  end
17
20
  end
18
21
 
@@ -26,7 +29,6 @@ class R10K::Git::ShellGit::ThinRepository < R10K::Git::ShellGit::WorkingReposito
26
29
  # @return [void]
27
30
  def clone(remote, opts = {})
28
31
  # todo check if opts[:reference] is set
29
- set_cache(remote)
30
32
  @cache_repo.sync
31
33
 
32
34
  super(remote, opts.merge(:reference => @cache_repo.git_dir.to_s))
@@ -45,10 +47,6 @@ class R10K::Git::ShellGit::ThinRepository < R10K::Git::ShellGit::WorkingReposito
45
47
 
46
48
  private
47
49
 
48
- def set_cache(remote)
49
- @cache_repo = R10K::Git::ShellGit::Cache.generate(remote)
50
- end
51
-
52
50
  def setup_cache_remote
53
51
  git ["remote", "add", "cache", @cache_repo.git_dir.to_s], :path => @path.to_s
54
52
  fetch
@@ -25,8 +25,8 @@ class R10K::Git::StatefulRepository
25
25
  @ref = ref
26
26
  @remote = remote
27
27
 
28
- @repo = R10K::Git.thin_repository.new(basedir, dirname)
29
28
  @cache = R10K::Git.cache.generate(remote)
29
+ @repo = R10K::Git.thin_repository.new(basedir, dirname, @cache)
30
30
  end
31
31
 
32
32
  def sync
@@ -0,0 +1,55 @@
1
+ require 'r10k/logging'
2
+
3
+ require 'r10k/git'
4
+ require 'r10k/git/cache'
5
+
6
+ require 'r10k/forge/module_release'
7
+
8
+ module R10K
9
+ module Initializers
10
+ class BaseInitializer
11
+
12
+ include R10K::Logging
13
+
14
+ def initialize(settings)
15
+ @settings = settings
16
+ end
17
+
18
+ private
19
+
20
+ def with_setting(key)
21
+ if !@settings[key].nil?
22
+ yield @settings[key]
23
+ end
24
+ end
25
+ end
26
+
27
+ class GlobalInitializer < BaseInitializer
28
+ def call
29
+ with_setting(:purgedirs) do |_|
30
+ logger.warn("the purgedirs key in r10k.yaml is deprecated. it is currently ignored.")
31
+ end
32
+
33
+ with_setting(:cachedir) { |value| R10K::Git::Cache.settings[:cache_root] = value }
34
+
35
+ with_setting(:git) { |value| GitInitializer.new(value).call }
36
+ with_setting(:forge) { |value| ForgeInitializer.new(value).call }
37
+ end
38
+ end
39
+
40
+ class GitInitializer < BaseInitializer
41
+ def call
42
+ with_setting(:provider) { |value| R10K::Git.provider = value }
43
+ with_setting(:username) { |value| R10K::Git.settings[:username] = value }
44
+ with_setting(:private_key) { |value| R10K::Git.settings[:private_key] = value }
45
+ end
46
+ end
47
+
48
+ class ForgeInitializer < BaseInitializer
49
+ def call
50
+ with_setting(:proxy) { |value| R10K::Forge::ModuleRelease.settings[:proxy] = value }
51
+ with_setting(:baseurl) { |value| R10K::Forge::ModuleRelease.settings[:baseurl] = value }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -32,5 +32,6 @@ module R10K::Module
32
32
  require 'r10k/module/base'
33
33
  require 'r10k/module/git'
34
34
  require 'r10k/module/svn'
35
+ require 'r10k/module/local'
35
36
  require 'r10k/module/forge'
36
37
  end
@@ -1,4 +1,5 @@
1
1
  require 'r10k/module'
2
+ require 'puppet_forge'
2
3
 
3
4
  # This class defines a common interface for module implementations.
4
5
  class R10K::Module::Base
@@ -36,10 +37,10 @@ class R10K::Module::Base
36
37
  # @param dirname [String]
37
38
  # @param args [Array]
38
39
  def initialize(title, dirname, args)
39
- @title = title
40
+ @title = PuppetForge::V3.normalize_name(title)
40
41
  @dirname = dirname
41
42
  @args = args
42
- @owner, @name = parse_title(title)
43
+ @owner, @name = parse_title(@title)
43
44
  @path = Pathname.new(File.join(@dirname, @name))
44
45
  end
45
46
 
@@ -1,13 +1,12 @@
1
1
  require 'r10k/module'
2
2
  require 'r10k/errors'
3
- require 'shared/puppet/module_tool/metadata'
4
3
  require 'r10k/module/metadata_file'
5
4
 
6
5
  require 'r10k/forge/module_release'
7
- require 'shared/puppet_forge/v3/module'
8
6
 
9
7
  require 'pathname'
10
8
  require 'fileutils'
9
+ require 'puppet_forge'
11
10
 
12
11
  class R10K::Module::Forge < R10K::Module::Base
13
12
 
@@ -19,7 +18,7 @@ class R10K::Module::Forge < R10K::Module::Base
19
18
 
20
19
  # @!attribute [r] metadata
21
20
  # @api private
22
- # @return [Puppet::ModuleTool::Metadata]
21
+ # @return [PuppetForge::Metadata]
23
22
  attr_reader :metadata
24
23
 
25
24
  # @!attribute [r] v3_module
@@ -35,7 +34,7 @@ class R10K::Module::Forge < R10K::Module::Base
35
34
  @metadata = @metadata_file.read
36
35
 
37
36
  @expected_version = expected_version || current_version || :latest
38
- @v3_module = PuppetForge::V3::Module.new(@title)
37
+ @v3_module = PuppetForge::V3::Module.new(:slug => @title)
39
38
  end
40
39
 
41
40
  def sync(options = {})
@@ -60,7 +59,11 @@ class R10K::Module::Forge < R10K::Module::Base
60
59
  # @return [String] The expected version that the module
61
60
  def expected_version
62
61
  if @expected_version == :latest
63
- @expected_version = @v3_module.latest_version
62
+ begin
63
+ @expected_version = @v3_module.current_release.version
64
+ rescue Faraday::ResourceNotFound => e
65
+ raise PuppetForge::ReleaseNotFound, "The module #{@title} does not exist on #{PuppetForge::V3::Release.conn.url_prefix}.", e.backtrace
66
+ end
64
67
  end
65
68
  @expected_version
66
69
  end
@@ -85,6 +88,7 @@ class R10K::Module::Forge < R10K::Module::Base
85
88
  # @return [Symbol] :absent If the directory doesn't exist
86
89
  # @return [Symbol] :mismatched If the module is not a forge module, or
87
90
  # isn't the right forge module
91
+ # @return [Symbol] :mismatched If the module was previously a git checkout
88
92
  # @return [Symbol] :outdated If the installed module is older than expected
89
93
  # @return [Symbol] :insync If the module is in the desired state
90
94
  def status
@@ -97,9 +101,13 @@ class R10K::Module::Forge < R10K::Module::Base
97
101
  return :mismatched
98
102
  end
99
103
 
104
+ if File.directory?(@path + '.git')
105
+ return :mismatched
106
+ end
107
+
100
108
  # The module is present and has a metadata file, read the metadata to
101
109
  # determine the state of the module.
102
- @metadata_file.read(@path + 'metadata.json')
110
+ @metadata = @metadata_file.read(@path + 'metadata.json')
103
111
 
104
112
  if not @title.tr('/','-') == @metadata.full_module_name.tr('/','-')
105
113
 
@@ -0,0 +1,36 @@
1
+ require 'r10k/module'
2
+ require 'r10k/logging'
3
+
4
+ # A dummy module type that can be used to "protect" Puppet modules that exist
5
+ # inside of the Puppetfile "moduledir" location. Local modules will not be
6
+ # modified, and will not be purged when r10k removes unmanaged modules.
7
+ class R10K::Module::Local < R10K::Module::Base
8
+
9
+ R10K::Module.register(self)
10
+
11
+ def self.implement?(name, args)
12
+ args.is_a?(Hash) && args[:local]
13
+ end
14
+
15
+ include R10K::Logging
16
+
17
+ def version
18
+ "0.0.0"
19
+ end
20
+
21
+ def properties
22
+ {
23
+ :expected => "0.0.0 (local)",
24
+ :actual => "0.0.0 (local)",
25
+ :type => :forge,
26
+ }
27
+ end
28
+
29
+ def status
30
+ :insync
31
+ end
32
+
33
+ def sync
34
+ logger.debug1 "Module #{title} is a local module, always indicating synced."
35
+ end
36
+ end
@@ -1,6 +1,6 @@
1
1
  require 'r10k/module'
2
2
  require 'r10k/errors'
3
- require 'shared/puppet/module_tool/metadata'
3
+ require 'puppet_forge'
4
4
 
5
5
  class R10K::Module::MetadataFile
6
6
 
@@ -19,7 +19,7 @@ class R10K::Module::MetadataFile
19
19
  if self.exist?
20
20
  metadata_file_path.open do |f|
21
21
  begin
22
- metadata = Puppet::ModuleTool::Metadata.new
22
+ metadata = PuppetForge::Metadata.new
23
23
  metadata.update(JSON.load(f), false)
24
24
  rescue JSON::ParserError => e
25
25
  exception = R10K::Error.wrap(e, "Could not read metadata.json")
@@ -51,7 +51,7 @@ class Puppetfile
51
51
  def load!
52
52
  dsl = R10K::Puppetfile::DSL.new(self)
53
53
  dsl.instance_eval(puppetfile_contents, @puppetfile_path)
54
- rescue SyntaxError, LoadError => e
54
+ rescue SyntaxError, LoadError, ArgumentError => e
55
55
  raise R10K::Error.wrap(e, "Failed to evaluate #{@puppetfile_path}")
56
56
  end
57
57
 
@@ -1,6 +1,92 @@
1
+ require 'etc'
2
+
1
3
  module R10K
2
4
  module Settings
3
5
  require 'r10k/settings/container'
4
6
  require 'r10k/settings/mixin'
7
+
8
+ require 'r10k/settings/collection'
9
+ require 'r10k/settings/definition'
10
+
11
+ def self.git_settings
12
+ R10K::Settings::Collection.new(:git, [
13
+
14
+ EnumDefinition.new(:provider, {
15
+ :desc => "The Git provider to use. Valid values: 'shellgit', 'rugged'",
16
+ :normalize => lambda { |input| input.to_sym },
17
+ :enum => [:shellgit, :rugged],
18
+ }),
19
+
20
+ Definition.new(:username, {
21
+ :desc => "The username to use for Git SSH remotes that do not specify a user.
22
+ Only used by the 'rugged' Git provider.
23
+ Default: the current user",
24
+ :default => lambda { Etc.getlogin },
25
+ }),
26
+
27
+ Definition.new(:private_key, {
28
+ :desc => "The path to the SSH private key for Git SSH remotes.
29
+ Only used by the 'rugged' Git provider.",
30
+ })
31
+ ])
32
+ end
33
+
34
+ def self.forge_settings
35
+ R10K::Settings::Collection.new(:forge, [
36
+ URIDefinition.new(:proxy, {
37
+ :desc => "An optional proxy server to use when downloading modules from the forge.",
38
+ }),
39
+
40
+ URIDefinition.new(:baseurl, {
41
+ :desc => "The URL to the Puppet Forge to use for downloading modules."
42
+ }),
43
+ ])
44
+ end
45
+
46
+ def self.deploy_settings
47
+ R10K::Settings::Collection.new(:deploy, [
48
+ Definition.new(:write_lock, {
49
+ :desc => "Whether r10k deploy actions should be locked out in case r10k is being managed
50
+ by another application. The value should be a string containing the reason for the write lock.",
51
+ :validate => lambda do |value|
52
+ if value && !value.is_a?(String)
53
+ raise ArgumentError, "The write_lock setting should be a string containing the reason for the write lock, not a #{value.class}"
54
+ end
55
+ end
56
+ }),
57
+ ])
58
+ end
59
+
60
+ def self.global_settings
61
+ R10K::Settings::Collection.new(:global, [
62
+ Definition.new(:sources, {
63
+ :desc => "Where r10k should retrieve sources when deploying environments.
64
+ Only used for r10k environment deployment.",
65
+ }),
66
+
67
+ Definition.new(:purgedirs, {
68
+ :desc => "The purgedirs setting was deprecated in r10k 1.0.0 and is no longer respected.",
69
+ }),
70
+
71
+ Definition.new(:cachedir, {
72
+ :desc => "Where r10k should store cached Git repositories.",
73
+ }),
74
+
75
+ Definition.new(:postrun, {
76
+ :desc => "The command r10k should run after deploying environments.",
77
+ :validate => lambda do |value|
78
+ if !value.is_a?(Array)
79
+ raise ArgumentError, "The postrun setting should be an array of strings, not a #{value.class}"
80
+ end
81
+ end
82
+ }),
83
+
84
+ R10K::Settings.forge_settings,
85
+
86
+ R10K::Settings.git_settings,
87
+
88
+ R10K::Settings.deploy_settings,
89
+ ])
90
+ end
5
91
  end
6
92
  end
@@ -0,0 +1,118 @@
1
+ require 'r10k/settings/definition'
2
+ require 'r10k/util/setopts'
3
+ require 'r10k/util/symbolize_keys'
4
+ require 'r10k/errors'
5
+
6
+ module R10K
7
+ module Settings
8
+
9
+ # Define a group of settings, which can be single definitions or nested
10
+ # collections.
11
+ class Collection
12
+
13
+ # @!attribute [r] name
14
+ # @return [String] The name of this collection
15
+ attr_reader :name
16
+
17
+ # @param name [Symbol] The name of the collection
18
+ # @param settings [Array] All settings in this collection
19
+ def initialize(name, settings)
20
+ @name = name
21
+ @settings = Hash[settings.map { |s| [s.name, s] }]
22
+ end
23
+
24
+ # Assign new values, perform validation checks, and return the final
25
+ # values for this collection
26
+ def evaluate(newvalues)
27
+ assign(newvalues)
28
+ validate
29
+ resolve
30
+ end
31
+
32
+ # Assign a hash of values to the settings in this collection.
33
+ #
34
+ # If the passed hash contains any invalid settings values, the names
35
+ # of those settings are stored for use in the {#validate} method.
36
+ #
37
+ # @param newvalues [Hash]
38
+ # @return [void]
39
+ def assign(newvalues)
40
+ return if newvalues.nil?
41
+
42
+ R10K::Util::SymbolizeKeys.symbolize_keys!(newvalues)
43
+ @settings.each_pair do |name, setting|
44
+ if newvalues.key?(name)
45
+ setting.assign(newvalues[name])
46
+ end
47
+ end
48
+ end
49
+
50
+ # Validate all settings and return validation errors
51
+ #
52
+ # @return [nil, Hash] If all validation passed nil will be returned; if
53
+ # validation failed then a hash of those errors will be returned.
54
+ def validate
55
+ errors = {}
56
+
57
+ @settings.each_pair do |name, setting|
58
+ begin
59
+ setting.validate
60
+ rescue => error
61
+ errors[name] = error
62
+ end
63
+ end
64
+
65
+ if !errors.empty?
66
+ raise ValidationError.new("Validation failed for #{@name} settings group", :errors => errors)
67
+ end
68
+ end
69
+
70
+ # Evaluate all settings and return a frozen hash of the final values.
71
+ # @return [Hash]
72
+ def resolve
73
+ rv = {}
74
+ @settings.each_pair do |name, setting|
75
+ rv[name] = setting.resolve
76
+ end
77
+ rv.freeze
78
+ end
79
+
80
+ class ValidationError < R10K::Error
81
+
82
+ attr_reader :errors
83
+
84
+ def initialize(mesg, options = {})
85
+ super
86
+ @errors = options[:errors]
87
+ end
88
+
89
+ def format
90
+ struct = []
91
+ struct << "#{message}:"
92
+ @errors.each_pair do |name, nested|
93
+ struct << indent(structure_exception(name, nested))
94
+ end
95
+ struct.join("\n")
96
+ end
97
+
98
+ private
99
+
100
+ def structure_exception(name, exc)
101
+ struct = []
102
+ struct << "#{name}:"
103
+ if exc.is_a? ValidationError
104
+ struct << indent(exc.format)
105
+ else
106
+ struct << indent(exc.message)
107
+ end
108
+ struct.join("\n")
109
+ end
110
+
111
+ def indent(str, level = 4)
112
+ prefix = ' ' * level
113
+ str.gsub(/^/, prefix)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end