r10k 1.4.2 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/CHANGELOG.mkd +192 -0
- data/CONTRIBUTING.mkd +3 -3
- data/Gemfile +4 -0
- data/README.mkd +13 -6
- data/doc/dynamic-environments/configuration.mkd +77 -8
- data/doc/dynamic-environments/git-environments.mkd +12 -2
- data/doc/dynamic-environments/quickstart.mkd +6 -0
- data/doc/faq.mkd +6 -6
- data/doc/git/cloning-and-mirroring.mkd +60 -0
- data/doc/git/providers.mkd +68 -0
- data/integration/Gemfile +3 -0
- data/integration/README.mkd +29 -0
- data/integration/configs/README.mkd +7 -0
- data/integration/configs/pe/centos-6-64mda +25 -0
- data/integration/configs/pe/centos-7-64mda +25 -0
- data/integration/configs/pe/debian-6-64mda +25 -0
- data/integration/configs/pe/debian-7-64mda +25 -0
- data/integration/configs/pe/redhat-6-64mda +25 -0
- data/integration/configs/pe/redhat-7-64mda +25 -0
- data/integration/configs/pe/sles-11-64mda +25 -0
- data/integration/configs/pe/ubuntu-1004-64mda +25 -0
- data/integration/configs/pe/ubuntu-1204-64mda +25 -0
- data/integration/configs/pe/ubuntu-1404-64mda +25 -0
- data/integration/files/README.mkd +4 -0
- data/integration/files/hiera.yaml +8 -0
- data/integration/files/modules/helloworld/manifests/init.pp +3 -0
- data/integration/files/modules/hieratest/manifests/init.pp +3 -0
- data/integration/files/modules/unicode/files/pretend_unicode +1 -0
- data/integration/files/modules/unicode/manifests/init.pp +6 -0
- data/integration/files/pre-suite/prod_env.config +3 -0
- data/integration/files/r10k_conf.yaml.erb +9 -0
- data/integration/lib/README.mkd +4 -0
- data/integration/lib/git_utils.rb +205 -0
- data/integration/lib/master_manipulator.rb +205 -0
- data/integration/lib/r10k_utils.rb +166 -0
- data/integration/manifests/README.mkd +4 -0
- data/integration/pre-suite/00_pe_install.rb +4 -0
- data/integration/pre-suite/01_git_config.rb +59 -0
- data/integration/pre-suite/02_pe_r10k.rb +60 -0
- data/integration/pre-suite/03_test_utils.rb +17 -0
- data/integration/pre-suite/README.mkd +5 -0
- data/integration/test_run_scripts/README.mkd +5 -0
- data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +20 -0
- data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +20 -0
- data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +20 -0
- data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +20 -0
- data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +20 -0
- data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +20 -0
- data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +20 -0
- data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +20 -0
- data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +20 -0
- data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +20 -0
- data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +20 -0
- data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +20 -0
- data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +20 -0
- data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +20 -0
- data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +20 -0
- data/integration/tests/README.mkd +4 -0
- data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +46 -0
- data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +27 -0
- data/integration/tests/command_line/deploy_env_without_mod_update.rb +75 -0
- data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +76 -0
- data/integration/tests/command_line/negative/neg_invalid_cli_dep_flag.rb +22 -0
- data/integration/tests/command_line/negative/neg_invalid_cli_env_flag.rb +22 -0
- data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +24 -0
- data/integration/tests/git_source/git_source_git.rb +123 -0
- data/integration/tests/git_source/git_source_ssh.rb +84 -0
- data/integration/tests/git_source/git_source_submodule.rb +69 -0
- data/integration/tests/git_source/negative/neg_git_broken_remote.rb +37 -0
- data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +45 -0
- data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +72 -0
- data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +34 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +66 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +110 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +113 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +93 -0
- data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +132 -0
- data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +160 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +45 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +43 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +40 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +42 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +44 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +63 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +73 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +45 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +51 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +33 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +35 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +44 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +57 -0
- data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +44 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +73 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +103 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +80 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +48 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +73 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +81 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +67 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +93 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +92 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +116 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +59 -0
- data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +165 -0
- data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +162 -0
- data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +110 -0
- data/lib/r10k/action/cri_runner.rb +10 -13
- data/lib/r10k/cli.rb +3 -8
- data/lib/r10k/cli/version.rb +10 -1
- data/lib/r10k/deployment/config.rb +26 -6
- data/lib/r10k/deployment/config/loader.rb +38 -29
- data/lib/r10k/deployment/source.rb +2 -4
- data/lib/r10k/environment/git.rb +10 -19
- data/lib/r10k/environment/name.rb +86 -0
- data/lib/r10k/errors.rb +8 -5
- data/lib/r10k/feature.rb +35 -0
- data/lib/r10k/feature/collection.rb +23 -0
- data/lib/r10k/features.rb +18 -0
- data/lib/r10k/git.rb +106 -12
- data/lib/r10k/git/alternates.rb +2 -2
- data/lib/r10k/git/cache.rb +43 -26
- data/lib/r10k/git/errors.rb +12 -6
- data/lib/r10k/git/head.rb +3 -0
- data/lib/r10k/git/ref.rb +3 -0
- data/lib/r10k/git/remote_head.rb +6 -0
- data/lib/r10k/git/repository.rb +6 -0
- data/lib/r10k/git/rugged.rb +17 -0
- data/lib/r10k/git/rugged/bare_repository.rb +86 -0
- data/lib/r10k/git/rugged/base_repository.rb +90 -0
- data/lib/r10k/git/rugged/cache.rb +11 -0
- data/lib/r10k/git/rugged/thin_repository.rb +72 -0
- data/lib/r10k/git/rugged/working_repository.rb +99 -0
- data/lib/r10k/git/shellgit.rb +9 -0
- data/lib/r10k/git/shellgit/bare_repository.rb +29 -0
- data/lib/r10k/git/shellgit/base_repository.rb +102 -0
- data/lib/r10k/git/shellgit/cache.rb +11 -0
- data/lib/r10k/git/shellgit/thin_repository.rb +56 -0
- data/lib/r10k/git/shellgit/working_repository.rb +73 -0
- data/lib/r10k/git/stateful_repository.rb +80 -0
- data/lib/r10k/git/tag.rb +3 -0
- data/lib/r10k/git/working_dir.rb +15 -2
- data/lib/r10k/logging.rb +73 -36
- data/lib/r10k/logging/terminaloutputter.rb +36 -0
- data/lib/r10k/module/forge.rb +10 -9
- data/lib/r10k/module/git.rb +14 -44
- data/lib/r10k/module/metadata_file.rb +31 -0
- data/lib/r10k/module/svn.rb +0 -1
- data/lib/r10k/module_repository/forge.rb +20 -7
- data/lib/r10k/puppetfile.rb +1 -1
- data/lib/r10k/settings/container.rb +6 -0
- data/lib/r10k/settings/mixin.rb +9 -0
- data/lib/r10k/source.rb +2 -3
- data/lib/r10k/source/base.rb +5 -5
- data/lib/r10k/source/git.rb +11 -86
- data/lib/r10k/source/svn.rb +8 -52
- data/lib/r10k/util/basedir.rb +4 -4
- data/lib/r10k/util/commands.rb +31 -0
- data/lib/r10k/util/exec_env.rb +36 -0
- data/lib/r10k/util/platform.rb +4 -0
- data/lib/r10k/util/purgeable.rb +2 -2
- data/lib/r10k/util/subprocess.rb +3 -7
- data/lib/r10k/util/subprocess/runner.rb +3 -28
- data/lib/r10k/util/subprocess/runner/posix.rb +103 -0
- data/lib/r10k/util/subprocess/runner/pump.rb +59 -0
- data/lib/r10k/util/subprocess/{windows/runner.rb → runner/windows.rb} +2 -11
- data/lib/r10k/util/symbolize_keys.rb +31 -0
- data/lib/r10k/version.rb +1 -1
- data/lib/shared/puppet/module_tool/metadata.rb +197 -0
- data/r10k.gemspec +7 -5
- data/spec/fixtures/integration/git/puppet-boolean-bare.tar +0 -0
- data/spec/fixtures/module/forge/bad_module/metadata.json +1 -0
- data/spec/fixtures/unit/util/subprocess/posix/runner/no-execute.sh +3 -0
- data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_all_versions_of_a_given_module.yml +171 -26
- data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_the_latest_version_of_a_given_module.yml +171 -26
- data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/ignores_deleted_releases.yml +190 -0
- data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/it_handles_errors_from_forgeapi_puppetlabs_com/raises_an_error_for_a_non-existant_module.yml +34 -0
- data/spec/fixtures/vcr/cassettes/R10K_Module_Forge/and_the_expected_version_is_latest/sets_the_expected_version_based_on_the_latest_forge_version.yml +87 -26
- data/spec/integration/git/rugged/bare_repository_spec.rb +13 -0
- data/spec/integration/git/rugged/thin_repository_spec.rb +14 -0
- data/spec/integration/git/rugged/working_repository_spec.rb +13 -0
- data/spec/integration/git/shellgit/bare_repository_spec.rb +13 -0
- data/spec/integration/git/shellgit/thin_repository_spec.rb +14 -0
- data/spec/integration/git/shellgit/working_repository_spec.rb +13 -0
- data/spec/integration/git/stateful_repository_spec.rb +104 -0
- data/spec/matchers/match_realpath.rb +18 -0
- data/spec/shared-contexts/git-fixtures.rb +55 -0
- data/spec/shared-examples/git-repository.rb +38 -0
- data/spec/shared-examples/git/bare_repository.rb +70 -0
- data/spec/shared-examples/git/thin_repository.rb +26 -0
- data/spec/shared-examples/git/working_repository.rb +115 -0
- data/spec/shared-examples/subprocess-runner.rb +83 -0
- data/spec/spec_helper.rb +13 -9
- data/spec/unit/action/cri_runner_spec.rb +0 -6
- data/spec/unit/action/puppetfile/{cri_action_spec.rb → cri_runner_spec.rb} +0 -0
- data/spec/unit/deployment/config/loader_spec.rb +48 -0
- data/spec/unit/deployment/config_spec.rb +49 -0
- data/spec/unit/environment/git_spec.rb +5 -39
- data/spec/unit/environment/name_spec.rb +135 -0
- data/spec/unit/feature_spec.rb +50 -0
- data/spec/unit/git/alternates_spec.rb +1 -1
- data/spec/unit/git/cache_spec.rb +32 -19
- data/spec/unit/git/commit_spec.rb +1 -0
- data/spec/unit/git/head_spec.rb +1 -6
- data/spec/unit/git/ref_spec.rb +0 -23
- data/spec/unit/git/rugged/cache_spec.rb +26 -0
- data/spec/unit/git/shellgit/cache_spec.rb +27 -0
- data/spec/unit/git/stateful_repository_spec.rb +43 -0
- data/spec/unit/git/tag_spec.rb +1 -0
- data/spec/unit/git/working_dir_spec.rb +1 -0
- data/spec/unit/git_spec.rb +74 -0
- data/spec/unit/logging/terminaloutputter_spec.rb +53 -0
- data/spec/unit/logging_spec.rb +68 -0
- data/spec/unit/module/forge_spec.rb +7 -38
- data/spec/unit/module/git_spec.rb +7 -38
- data/spec/unit/module/metadata_file_spec.rb +69 -0
- data/spec/unit/module/svn_spec.rb +0 -4
- data/spec/unit/module_repository/forge_spec.rb +22 -1
- data/spec/unit/puppet/module_tool/metadata_spec.rb +301 -0
- data/spec/unit/settings/container_spec.rb +17 -0
- data/spec/unit/source/git_spec.rb +0 -123
- data/spec/unit/source/svn_spec.rb +66 -0
- data/spec/unit/util/commands_spec.rb +61 -0
- data/spec/unit/util/exec_env_spec.rb +56 -0
- data/spec/unit/util/subprocess/runner/posix_spec.rb +7 -0
- data/spec/unit/util/subprocess/runner/pump_spec.rb +79 -0
- data/spec/unit/util/subprocess_spec.rb +3 -2
- data/spec/unit/util/symbolize_keys_spec.rb +51 -0
- metadata +226 -45
- data/lib/r10k/execution.rb +0 -47
- data/lib/r10k/module/metadata.rb +0 -47
- data/lib/r10k/util/core_ext/hash_ext.rb +0 -19
- data/lib/r10k/util/subprocess/io.rb +0 -7
- data/lib/r10k/util/subprocess/posix.rb +0 -4
- data/lib/r10k/util/subprocess/posix/io.rb +0 -7
- data/lib/r10k/util/subprocess/posix/runner.rb +0 -140
- data/lib/r10k/util/subprocess/windows.rb +0 -4
- data/lib/r10k/util/subprocess/windows/io.rb +0 -6
- data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions.yml +0 -42
- data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_all_versions_of_a_given_module.yml +0 -42
- data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_the_latest_version_of_a_given_module.yml +0 -42
- data/spec/unit/deployment/source_spec.rb +0 -24
- data/spec/unit/module/metadata_spec.rb +0 -68
- data/spec/unit/util/core_ext/hash_ext_spec.rb +0 -63
data/lib/r10k/source/svn.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'r10k/svn'
|
2
2
|
require 'r10k/environment'
|
3
|
-
require 'r10k/
|
4
|
-
require 'r10k/util/core_ext/hash_ext'
|
3
|
+
require 'r10k/environment/name'
|
5
4
|
require 'r10k/util/setopts'
|
6
5
|
|
7
6
|
# This class implements a source for SVN environments.
|
@@ -79,10 +78,9 @@ class R10K::Source::SVN < R10K::Source::Base
|
|
79
78
|
# @return [Array<R10K::Environment::SVN>] An array of environments created
|
80
79
|
# from this source.
|
81
80
|
def generate_environments
|
82
|
-
|
83
|
-
branch_names.map do |branch|
|
81
|
+
names_and_paths.map do |(branch, path)|
|
84
82
|
options = {
|
85
|
-
:remote =>
|
83
|
+
:remote => path,
|
86
84
|
:username => @username,
|
87
85
|
:password => @password
|
88
86
|
}
|
@@ -90,20 +88,8 @@ class R10K::Source::SVN < R10K::Source::Base
|
|
90
88
|
end
|
91
89
|
end
|
92
90
|
|
93
|
-
include R10K::Util::Purgeable
|
94
|
-
|
95
|
-
def managed_directory
|
96
|
-
@basedir
|
97
|
-
end
|
98
|
-
|
99
|
-
def current_contents
|
100
|
-
Dir.glob(File.join(@basedir, '*')).map do |fname|
|
101
|
-
File.basename fname
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
91
|
# List all environments that should exist in the basedir for this source
|
106
|
-
# @note This
|
92
|
+
# @note This is required by {R10K::Util::Basedir}
|
107
93
|
# @return [Array<String>]
|
108
94
|
def desired_contents
|
109
95
|
@environments.map {|env| env.dirname }
|
@@ -113,46 +99,16 @@ class R10K::Source::SVN < R10K::Source::Base
|
|
113
99
|
|
114
100
|
private
|
115
101
|
|
116
|
-
def
|
102
|
+
def names_and_paths
|
117
103
|
branches = []
|
118
104
|
|
119
|
-
|
120
|
-
:prefix => @prefix,
|
121
|
-
:sourcename => @name,
|
122
|
-
}
|
105
|
+
opts = {:prefix => @prefix, :correct => false, :validate => false, :source => @name}
|
123
106
|
|
124
|
-
branches <<
|
107
|
+
branches << [R10K::Environment::Name.new('production', opts), "#{@remote}/trunk"]
|
125
108
|
@svn_remote.branches.each do |branch|
|
126
|
-
branches <<
|
109
|
+
branches << [R10K::Environment::Name.new(branch, opts), "#{@remote}/branches/#{branch}"]
|
127
110
|
end
|
128
111
|
|
129
112
|
branches
|
130
113
|
end
|
131
|
-
|
132
|
-
# @api private
|
133
|
-
# @todo respect environment name corrections
|
134
|
-
class BranchName
|
135
|
-
|
136
|
-
attr_reader :name
|
137
|
-
attr_reader :remote
|
138
|
-
|
139
|
-
def initialize(name, remote, opts)
|
140
|
-
@name = name
|
141
|
-
@remote = remote
|
142
|
-
@opts = opts
|
143
|
-
|
144
|
-
@prefix = opts[:prefix]
|
145
|
-
@sourcename = opts[:sourcename]
|
146
|
-
end
|
147
|
-
|
148
|
-
def dirname
|
149
|
-
dir = @name.dup
|
150
|
-
|
151
|
-
if @prefix
|
152
|
-
dir = "#{@sourcename}_#{dir}"
|
153
|
-
end
|
154
|
-
|
155
|
-
dir
|
156
|
-
end
|
157
|
-
end
|
158
114
|
end
|
data/lib/r10k/util/basedir.rb
CHANGED
@@ -28,10 +28,10 @@ module R10K
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# @param path [String] The path to the directory to manage
|
31
|
-
# @param sources [Array
|
31
|
+
# @param sources [Array<#desired_contents>] A list of objects that may create filesystem entries
|
32
32
|
def initialize(path, sources)
|
33
33
|
if sources.is_a? R10K::Deployment
|
34
|
-
raise ArgumentError, "Expected Array
|
34
|
+
raise ArgumentError, "Expected Array<#desired_contents>, got R10K::Deployment"
|
35
35
|
end
|
36
36
|
@path = path
|
37
37
|
@sources = sources
|
@@ -53,10 +53,10 @@ module R10K
|
|
53
53
|
|
54
54
|
def purge!
|
55
55
|
@sources.each do |source|
|
56
|
-
logger.debug1 "Source #{source.name} in #{@path}
|
56
|
+
logger.debug1 "Source #{source.name} in #{@path} manages contents #{source.desired_contents.inspect}"
|
57
57
|
end
|
58
58
|
if !stale_contents.empty?
|
59
|
-
logger.debug "
|
59
|
+
logger.debug "The path #{@path} has unmanaged contents #{stale_contents.inspect}"
|
60
60
|
end
|
61
61
|
super
|
62
62
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module R10K
|
2
|
+
module Util
|
3
|
+
module Commands
|
4
|
+
module_function
|
5
|
+
|
6
|
+
# Find the full path of a shell command.
|
7
|
+
#
|
8
|
+
# On POSIX platforms, the PATHEXT environment variable will be unset, so
|
9
|
+
# the first command named 'cmd' will be returned.
|
10
|
+
#
|
11
|
+
# On Windows platforms, the PATHEXT environment variable will contain a
|
12
|
+
# semicolon delimited list of executable file extensions, so the first
|
13
|
+
# command with a matching path extension will be returned.
|
14
|
+
#
|
15
|
+
# @param cmd [String] The name of the command to search for
|
16
|
+
# @return [String, nil] The path to the file if found, nil otherwise
|
17
|
+
def which(cmd)
|
18
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
19
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |dir|
|
20
|
+
exts.each do |ext|
|
21
|
+
path = File.join(dir, "#{cmd}#{ext}")
|
22
|
+
if File.executable?(path) && File.file?(path)
|
23
|
+
return path
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module R10K
|
2
|
+
module Util
|
3
|
+
|
4
|
+
# Utility methods for dealing with environment variables
|
5
|
+
module ExecEnv
|
6
|
+
module_function
|
7
|
+
|
8
|
+
# Swap out all environment settings
|
9
|
+
#
|
10
|
+
# @param env [Hash] The new environment to use
|
11
|
+
# @return [void]
|
12
|
+
def reset(env)
|
13
|
+
env.each_pair do |key, value|
|
14
|
+
ENV[key] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
(ENV.keys - env.keys).each do |key|
|
18
|
+
ENV.delete(key)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Add the specified settings to the env for the supplied block
|
23
|
+
#
|
24
|
+
# @param env [Hash] The values to add to the environment
|
25
|
+
# @param block [Proc] The code to call with the modified environnment
|
26
|
+
# @return [void]
|
27
|
+
def withenv(env, &block)
|
28
|
+
original = ENV.to_hash
|
29
|
+
reset(original.merge(env))
|
30
|
+
block.call
|
31
|
+
ensure
|
32
|
+
reset(original)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/r10k/util/platform.rb
CHANGED
data/lib/r10k/util/purgeable.rb
CHANGED
@@ -46,11 +46,11 @@ module R10K
|
|
46
46
|
# Forcibly remove all unmanaged content in `self.managed_directory`
|
47
47
|
def purge!
|
48
48
|
if stale_contents.empty?
|
49
|
-
logger.debug1 "No
|
49
|
+
logger.debug1 "No unmanaged contents in #{managed_directory}, nothing to purge"
|
50
50
|
else
|
51
51
|
stale_contents.each do |fname|
|
52
52
|
fpath = File.join(self.managed_directory, fname)
|
53
|
-
logger.
|
53
|
+
logger.info "Removing unmanaged path #{fpath}"
|
54
54
|
FileUtils.rm_rf(fpath, :secure => true)
|
55
55
|
end
|
56
56
|
end
|
data/lib/r10k/util/subprocess.rb
CHANGED
@@ -11,19 +11,15 @@ module R10K
|
|
11
11
|
class Subprocess
|
12
12
|
|
13
13
|
require 'r10k/util/subprocess/runner'
|
14
|
-
require 'r10k/util/subprocess/io'
|
15
14
|
require 'r10k/util/subprocess/result'
|
16
15
|
require 'r10k/util/subprocess/subprocess_error'
|
17
16
|
|
18
|
-
require 'r10k/util/subprocess/posix'
|
19
|
-
require 'r10k/util/subprocess/windows'
|
20
|
-
|
21
17
|
# @return [Class < R10K::Util::Subprocess::Runner]
|
22
18
|
def self.runner
|
23
19
|
if R10K::Util::Platform.windows?
|
24
|
-
R10K::Util::Subprocess::Windows
|
20
|
+
R10K::Util::Subprocess::Runner::Windows
|
25
21
|
else
|
26
|
-
R10K::Util::Subprocess::POSIX
|
22
|
+
R10K::Util::Subprocess::Runner::POSIX
|
27
23
|
end
|
28
24
|
end
|
29
25
|
|
@@ -75,7 +71,7 @@ module R10K
|
|
75
71
|
result = subprocess.run
|
76
72
|
logger.debug2("Finished process:\n#{result.format}")
|
77
73
|
|
78
|
-
if @raise_on_fail
|
74
|
+
if @raise_on_fail && result.failed?
|
79
75
|
raise SubprocessError.new("Command exited with non-zero exit code", :result => result)
|
80
76
|
end
|
81
77
|
|
@@ -3,19 +3,14 @@
|
|
3
3
|
# @api private
|
4
4
|
class R10K::Util::Subprocess::Runner
|
5
5
|
|
6
|
+
require 'r10k/util/subprocess/runner/windows'
|
7
|
+
require 'r10k/util/subprocess/runner/posix'
|
8
|
+
|
6
9
|
# @!attribute [rw] cwd
|
7
10
|
# @return [String] The directory to be used as the cwd when executing
|
8
11
|
# the command.
|
9
12
|
attr_accessor :cwd
|
10
13
|
|
11
|
-
attr_reader :io
|
12
|
-
|
13
|
-
attr_reader :pid
|
14
|
-
|
15
|
-
# @!attribute [r] status
|
16
|
-
# @return [Process::Status]
|
17
|
-
attr_reader :status
|
18
|
-
|
19
14
|
# @!attribute [r] result
|
20
15
|
# @return [R10K::Util::Subprocess::Result]
|
21
16
|
attr_reader :result
|
@@ -27,24 +22,4 @@ class R10K::Util::Subprocess::Runner
|
|
27
22
|
def run
|
28
23
|
raise NotImplementedError
|
29
24
|
end
|
30
|
-
|
31
|
-
# Start the process asynchronously and return. Not all runners will implement this.
|
32
|
-
def start
|
33
|
-
raise NotImplementedError
|
34
|
-
end
|
35
|
-
|
36
|
-
# Wait for the process to exit. Not all runners will implement this.
|
37
|
-
def wait
|
38
|
-
raise NotImplementedError
|
39
|
-
end
|
40
|
-
|
41
|
-
# Did the given process exit with a non-zero exit code?
|
42
|
-
def crashed?
|
43
|
-
raise NotImplementedError
|
44
|
-
end
|
45
|
-
|
46
|
-
# @return [Integer] The exit status of the given process.
|
47
|
-
def exit_code
|
48
|
-
raise NotImplementedError
|
49
|
-
end
|
50
25
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'r10k/util/subprocess/runner'
|
2
|
+
require 'r10k/util/subprocess/runner/pump'
|
3
|
+
require 'fcntl'
|
4
|
+
|
5
|
+
# Implement a POSIX command runner by using fork/exec.
|
6
|
+
#
|
7
|
+
# This implementation is optimized to run commands in the background, and has
|
8
|
+
# a few noteworthy implementation details.
|
9
|
+
#
|
10
|
+
# First off, when the child process is forked, it calls setsid() to detach from
|
11
|
+
# the controlling TTY. This has two main ramifications: sending signals will
|
12
|
+
# never be send to the forked process, and the forked process does not have
|
13
|
+
# access to stdin.
|
14
|
+
#
|
15
|
+
# @api private
|
16
|
+
class R10K::Util::Subprocess::Runner::POSIX < R10K::Util::Subprocess::Runner
|
17
|
+
|
18
|
+
def initialize(argv)
|
19
|
+
@argv = argv
|
20
|
+
mkpipes
|
21
|
+
end
|
22
|
+
|
23
|
+
def run
|
24
|
+
# Create a pipe so that the parent can verify that the child process
|
25
|
+
# successfully executed. The pipe will be closed on a successful exec(),
|
26
|
+
# and will contain an error message on failure.
|
27
|
+
exec_r, exec_w = pipe
|
28
|
+
|
29
|
+
@stdout_pump = R10K::Util::Subprocess::Runner::Pump.new(@stdout_r)
|
30
|
+
@stderr_pump = R10K::Util::Subprocess::Runner::Pump.new(@stderr_r)
|
31
|
+
@stdout_pump.start
|
32
|
+
@stderr_pump.start
|
33
|
+
|
34
|
+
pid = fork do
|
35
|
+
exec_r.close
|
36
|
+
execute_child(exec_w)
|
37
|
+
end
|
38
|
+
|
39
|
+
exec_w.close
|
40
|
+
execute_parent(exec_r, pid)
|
41
|
+
|
42
|
+
@result
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def execute_child(exec_w)
|
48
|
+
if @cwd
|
49
|
+
Dir.chdir @cwd
|
50
|
+
end
|
51
|
+
|
52
|
+
# Create a new session for the forked child. This prevents children from
|
53
|
+
# ever being the foreground process on a TTY, which is almost always what
|
54
|
+
# we want in r10k.
|
55
|
+
Process.setsid
|
56
|
+
|
57
|
+
# Reopen file descriptors
|
58
|
+
STDOUT.reopen(@stdout_w)
|
59
|
+
STDERR.reopen(@stderr_w)
|
60
|
+
|
61
|
+
executable = @argv.shift
|
62
|
+
exec([executable, executable], *@argv)
|
63
|
+
rescue SystemCallError => e
|
64
|
+
exec_w.write("#{e.class}: #{e.message}")
|
65
|
+
exit(254)
|
66
|
+
end
|
67
|
+
|
68
|
+
def execute_parent(exec_r, pid)
|
69
|
+
@stdout_w.close
|
70
|
+
@stderr_w.close
|
71
|
+
|
72
|
+
stdout = ''
|
73
|
+
stderr = ''
|
74
|
+
|
75
|
+
if !exec_r.eof?
|
76
|
+
stderr = exec_r.read || "exec() failed"
|
77
|
+
_, @status = Process.waitpid2(pid)
|
78
|
+
else
|
79
|
+
_, @status = Process.waitpid2(pid)
|
80
|
+
@stdout_pump.wait
|
81
|
+
@stderr_pump.wait
|
82
|
+
stdout = @stdout_pump.string
|
83
|
+
stderr = @stderr_pump.string
|
84
|
+
end
|
85
|
+
exec_r.close
|
86
|
+
|
87
|
+
@stdout_r.close
|
88
|
+
@stderr_r.close
|
89
|
+
|
90
|
+
@result = R10K::Util::Subprocess::Result.new(@argv, stdout, stderr, @status.exitstatus)
|
91
|
+
end
|
92
|
+
|
93
|
+
def mkpipes
|
94
|
+
@stdout_r, @stdout_w = pipe
|
95
|
+
@stderr_r, @stderr_w = pipe
|
96
|
+
end
|
97
|
+
|
98
|
+
def pipe
|
99
|
+
::IO.pipe.tap do |pair|
|
100
|
+
pair.each { |p| p.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'r10k/util/subprocess/runner'
|
2
|
+
|
3
|
+
# Perform nonblocking reads on a streaming IO instance.
|
4
|
+
#
|
5
|
+
# @api private
|
6
|
+
class R10K::Util::Subprocess::Runner::Pump
|
7
|
+
|
8
|
+
# !@attribute [r] string
|
9
|
+
# @return [String] The output collected from the IO device
|
10
|
+
attr_reader :string
|
11
|
+
|
12
|
+
# @!attribute [r] min_delay
|
13
|
+
# @return [Float] The minimum time to wait while polling the IO device
|
14
|
+
attr_accessor :min_delay
|
15
|
+
|
16
|
+
# @!attribute [r] max_delay
|
17
|
+
# @return [Float] The maximum time to wait while polling the IO device
|
18
|
+
attr_accessor :max_delay
|
19
|
+
|
20
|
+
def initialize(io)
|
21
|
+
@io = io
|
22
|
+
@thread = nil
|
23
|
+
@string = ''
|
24
|
+
@run = true
|
25
|
+
@min_delay = 0.05
|
26
|
+
@max_delay = 1.0
|
27
|
+
end
|
28
|
+
|
29
|
+
def start
|
30
|
+
@thread = Thread.new { pump }
|
31
|
+
end
|
32
|
+
|
33
|
+
def halt!
|
34
|
+
@run = false
|
35
|
+
@thread.join
|
36
|
+
end
|
37
|
+
|
38
|
+
# Block until the pumping thread reaches EOF on the IO object.
|
39
|
+
def wait
|
40
|
+
@thread.join
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def pump
|
46
|
+
backoff = @min_delay
|
47
|
+
while @run
|
48
|
+
begin
|
49
|
+
@string << @io.read_nonblock(4096)
|
50
|
+
backoff /= 2 if backoff > @min_delay
|
51
|
+
rescue Errno::EWOULDBLOCK, Errno::EAGAIN
|
52
|
+
backoff *= 2 if backoff < @max_delay
|
53
|
+
IO.select([@io], [], [], backoff)
|
54
|
+
rescue EOFError
|
55
|
+
@run = false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|