chef 0.9.12 → 0.9.14.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/distro/arch/etc/conf.d/chef-client.conf +5 -0
- data/distro/arch/etc/conf.d/chef-server-webui.conf +10 -0
- data/distro/arch/etc/conf.d/chef-server.conf +10 -0
- data/distro/arch/etc/conf.d/chef-solr-indexer.conf +8 -0
- data/distro/arch/etc/conf.d/chef-solr.conf +8 -0
- data/distro/arch/etc/rc.d/chef-client +76 -0
- data/distro/arch/etc/rc.d/chef-server +82 -0
- data/distro/arch/etc/rc.d/chef-server-webui +82 -0
- data/distro/arch/etc/rc.d/chef-solr +82 -0
- data/distro/arch/etc/rc.d/chef-solr-indexer +82 -0
- data/distro/common/markdown/knife.mkd +34 -1
- data/distro/debian/etc/default/chef-solr +1 -0
- data/distro/debian/etc/init.d/chef-client +1 -1
- data/distro/debian/etc/init.d/chef-solr +39 -40
- data/distro/debian/etc/init.d/chef-solr-indexer +1 -1
- data/distro/redhat/etc/init.d/chef-client +1 -1
- data/lib/chef.rb +1 -0
- data/lib/chef/api_client.rb +1 -1
- data/lib/chef/application/agent.rb +1 -1
- data/lib/chef/application/client.rb +1 -1
- data/lib/chef/application/solo.rb +1 -1
- data/lib/chef/cookbook/metadata.rb +2 -2
- data/lib/chef/cookbook/syntax_check.rb +1 -1
- data/lib/chef/cookbook_version.rb +5 -1
- data/lib/chef/couchdb.rb +1 -1
- data/lib/chef/data_bag.rb +1 -1
- data/lib/chef/data_bag_item.rb +35 -9
- data/lib/chef/exceptions.rb +2 -0
- data/lib/chef/file_cache.rb +1 -1
- data/lib/chef/handler/json_file.rb +1 -1
- data/lib/chef/index_queue/amqp_client.rb +2 -2
- data/lib/chef/index_queue/consumer.rb +2 -2
- data/lib/chef/json.rb +52 -0
- data/lib/chef/knife.rb +6 -6
- data/lib/chef/knife/bluebox_images_list.rb +54 -0
- data/lib/chef/knife/bluebox_server_create.rb +157 -0
- data/lib/chef/knife/bluebox_server_delete.rb +63 -0
- data/lib/chef/knife/bluebox_server_list.rb +59 -0
- data/lib/chef/knife/bootstrap.rb +3 -1
- data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
- data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -2
- data/lib/chef/knife/bootstrap/fedora13-gems.erb +1 -1
- data/lib/chef/knife/client_bulk_delete.rb +1 -1
- data/lib/chef/knife/client_create.rb +1 -1
- data/lib/chef/knife/client_delete.rb +1 -1
- data/lib/chef/knife/client_edit.rb +1 -1
- data/lib/chef/knife/client_list.rb +1 -1
- data/lib/chef/knife/client_reregister.rb +1 -1
- data/lib/chef/knife/client_show.rb +1 -1
- data/lib/chef/knife/cookbook_create.rb +1 -1
- data/lib/chef/knife/cookbook_list.rb +1 -1
- data/lib/chef/knife/cookbook_metadata.rb +1 -1
- data/lib/chef/knife/cookbook_show.rb +10 -18
- data/lib/chef/knife/cookbook_site_share.rb +1 -1
- data/lib/chef/knife/cookbook_site_vendor.rb +17 -11
- data/lib/chef/knife/ec2_instance_data.rb +1 -1
- data/lib/chef/knife/ec2_server_create.rb +8 -6
- data/lib/chef/knife/ec2_server_delete.rb +5 -8
- data/lib/chef/knife/ec2_server_list.rb +5 -4
- data/lib/chef/knife/exec.rb +1 -1
- data/lib/chef/knife/node_bulk_delete.rb +1 -1
- data/lib/chef/knife/node_create.rb +1 -1
- data/lib/chef/knife/node_delete.rb +1 -1
- data/lib/chef/knife/node_edit.rb +1 -1
- data/lib/chef/knife/node_from_file.rb +2 -2
- data/lib/chef/knife/node_list.rb +1 -1
- data/lib/chef/knife/node_run_list_add.rb +1 -1
- data/lib/chef/knife/node_run_list_remove.rb +1 -1
- data/lib/chef/knife/node_show.rb +1 -1
- data/lib/chef/knife/rackspace_server_create.rb +98 -70
- data/lib/chef/knife/rackspace_server_delete.rb +2 -2
- data/lib/chef/knife/rackspace_server_list.rb +2 -2
- data/lib/chef/knife/role_bulk_delete.rb +1 -1
- data/lib/chef/knife/role_create.rb +1 -1
- data/lib/chef/knife/role_delete.rb +1 -1
- data/lib/chef/knife/role_edit.rb +1 -1
- data/lib/chef/knife/role_from_file.rb +2 -2
- data/lib/chef/knife/role_list.rb +1 -1
- data/lib/chef/knife/role_show.rb +1 -1
- data/lib/chef/knife/slicehost_images_list.rb +2 -2
- data/lib/chef/knife/slicehost_server_create.rb +2 -2
- data/lib/chef/knife/slicehost_server_delete.rb +2 -2
- data/lib/chef/knife/slicehost_server_list.rb +2 -2
- data/lib/chef/knife/ssh.rb +36 -12
- data/lib/chef/knife/status.rb +1 -1
- data/lib/chef/knife/terremark_server_create.rb +1 -1
- data/lib/chef/knife/terremark_server_delete.rb +1 -1
- data/lib/chef/knife/terremark_server_list.rb +1 -1
- data/lib/chef/log.rb +31 -4
- data/lib/chef/mixin/command.rb +1 -1
- data/lib/chef/mixin/create_path.rb +1 -1
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +1 -1
- data/lib/chef/monkey_patches/numeric.rb +7 -0
- data/lib/chef/node.rb +6 -8
- data/lib/chef/node/attribute.rb +24 -2
- data/lib/chef/openid_registration.rb +1 -1
- data/lib/chef/platform.rb +11 -0
- data/lib/chef/provider/breakpoint.rb +1 -1
- data/lib/chef/provider/cookbook_file.rb +1 -1
- data/lib/chef/provider/deploy/revision.rb +1 -1
- data/lib/chef/provider/deploy/timestamped.rb +1 -1
- data/lib/chef/provider/erl_call.rb +14 -2
- data/lib/chef/provider/git.rb +79 -55
- data/lib/chef/provider/group/pw.rb +1 -1
- data/lib/chef/provider/package/easy_install.rb +35 -13
- data/lib/chef/provider/service/debian.rb +65 -40
- data/lib/chef/provider/service/insserv.rb +52 -0
- data/lib/chef/provider/service/windows.rb +74 -57
- data/lib/chef/provider/subversion.rb +45 -10
- data/lib/chef/provider/user/pw.rb +1 -1
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource/deploy_revision.rb +1 -1
- data/lib/chef/resource/easy_install_package.rb +16 -0
- data/lib/chef/resource/file.rb +8 -1
- data/lib/chef/resource_collection/stepable_iterator.rb +1 -1
- data/lib/chef/rest.rb +7 -7
- data/lib/chef/role.rb +2 -2
- data/lib/chef/run_status.rb +1 -1
- data/lib/chef/shef.rb +2 -2
- data/lib/chef/shef/ext.rb +2 -2
- data/lib/chef/shef/model_wrapper.rb +1 -1
- data/lib/chef/shef/shef_rest.rb +1 -1
- data/lib/chef/shef/shef_session.rb +13 -5
- data/lib/chef/tasks/chef_repo.rake +1 -1
- data/lib/chef/version.rb +1 -1
- data/lib/chef/webui_user.rb +1 -1
- metadata +329 -290
data/lib/chef/knife/status.rb
CHANGED
@@ -42,7 +42,7 @@ class Chef
|
|
42
42
|
q.search(:node, query) do |node|
|
43
43
|
all_nodes << node
|
44
44
|
end
|
45
|
-
all_nodes.sort { |n1, n2| n1["ohai_time"] <=> n2["ohai_time"] }.each do |node|
|
45
|
+
all_nodes.sort { |n1, n2| (n1["ohai_time"] or 0) <=> (n2["ohai_time"] or 0) }.each do |node|
|
46
46
|
if node.has_key?("ec2")
|
47
47
|
fqdn = node['ec2']['public_hostname']
|
48
48
|
ipaddress = node['ec2']['public_ipv4']
|
data/lib/chef/log.rb
CHANGED
@@ -43,13 +43,40 @@ class Chef
|
|
43
43
|
end
|
44
44
|
self.verbose
|
45
45
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
|
47
|
+
[:debug, :info, :warn, :error, :fatal].each do |method_name|
|
48
|
+
class_eval(<<-METHOD_DEFN, __FILE__, __LINE__)
|
49
|
+
def #{method_name}(msg=nil, &block)
|
50
|
+
@logger.#{method_name}(msg, &block)
|
51
|
+
end
|
52
|
+
METHOD_DEFN
|
53
|
+
end
|
54
|
+
|
55
|
+
[:debug?, :info?, :warn?, :error?, :fatal?].each do |method_name|
|
56
|
+
class_eval(<<-METHOD_DEFN, __FILE__, __LINE__)
|
57
|
+
def #{method_name}
|
58
|
+
@logger.#{method_name}
|
59
|
+
end
|
60
|
+
METHOD_DEFN
|
61
|
+
end
|
62
|
+
|
63
|
+
def <<(msg)
|
64
|
+
@logger << msg
|
65
|
+
end
|
66
|
+
|
67
|
+
def add(severity, message = nil, progname = nil, &block)
|
68
|
+
@logger.add(severity, message = nil, progname = nil, &block)
|
50
69
|
end
|
70
|
+
|
51
71
|
end
|
52
72
|
|
73
|
+
# NOTE: Mixlib::Log initially sets @logger to nil and depends on
|
74
|
+
# #init being called to initialize the logger. We don't want to
|
75
|
+
# incur extra method call overhead for every log message so we're
|
76
|
+
# accessing the logger by instance variable, which means we need to
|
77
|
+
# make Mixlib::Log initialize it.
|
78
|
+
init
|
79
|
+
|
53
80
|
class Formatter
|
54
81
|
def self.show_time=(*args)
|
55
82
|
Mixlib::Log::Formatter.show_time = *args
|
data/lib/chef/mixin/command.rb
CHANGED
data/lib/chef/node.rb
CHANGED
@@ -32,7 +32,7 @@ require 'chef/run_list'
|
|
32
32
|
require 'chef/node/attribute'
|
33
33
|
require 'chef/index_queue'
|
34
34
|
require 'extlib'
|
35
|
-
require 'json'
|
35
|
+
require 'chef/json'
|
36
36
|
|
37
37
|
class Chef
|
38
38
|
class Node
|
@@ -326,12 +326,11 @@ class Chef
|
|
326
326
|
# run_state[:seen_recipes], which is populated by include_recipe
|
327
327
|
# statements in the DSL (and thus would not be in the run list).
|
328
328
|
#
|
329
|
-
# NOTE:
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
329
|
+
# NOTE: It's used by cookbook authors
|
330
|
+
def recipe?(recipe_name)
|
331
|
+
run_list.include?(recipe_name) || run_state[:seen_recipes].include?(recipe_name)
|
332
|
+
end
|
333
|
+
|
335
334
|
# Returns true if this Node expects a given role, false if not.
|
336
335
|
def role?(role_name)
|
337
336
|
run_list.include?("role[#{role_name}]")
|
@@ -596,6 +595,5 @@ class Chef
|
|
596
595
|
self.from_file(attribute_filename)
|
597
596
|
self
|
598
597
|
end
|
599
|
-
|
600
598
|
end
|
601
599
|
end
|
data/lib/chef/node/attribute.rb
CHANGED
@@ -450,14 +450,36 @@ class Chef
|
|
450
450
|
end
|
451
451
|
end
|
452
452
|
|
453
|
+
def delete(key)
|
454
|
+
[@automatic, @override, @normal, @default].inject(nil) do |return_value, attrs|
|
455
|
+
deleted_value = delete_from_component(attrs, key)
|
456
|
+
return_value || deleted_value
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
def delete_from_component(component_attrs, key)
|
461
|
+
# get the Hash-like object at the current nesting level:
|
462
|
+
nested_attrs = value_at_current_nesting(component_attrs, key)
|
463
|
+
|
464
|
+
if nested_attrs.respond_to?(:delete)
|
465
|
+
nested_attrs.delete(key)
|
466
|
+
else
|
467
|
+
nil
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
453
471
|
def component_has_key?(component_attrs,key)
|
454
472
|
# get the Hash-like object at the current nesting level:
|
455
|
-
nested_attrs =
|
473
|
+
nested_attrs = value_at_current_nesting(component_attrs, key)
|
474
|
+
nested_attrs.respond_to?(:key?) && nested_attrs.key?(key)
|
475
|
+
end
|
476
|
+
|
477
|
+
def value_at_current_nesting(component_attrs, key)
|
478
|
+
@current_nesting_level.inject(component_attrs) do |subtree, intermediate_key|
|
456
479
|
# if the intermediate value isn't a hash or doesn't have the intermediate key,
|
457
480
|
# it can't have the bottom-level key we're looking for.
|
458
481
|
(subtree.respond_to?(:key?) && subtree[intermediate_key]) or (return false)
|
459
482
|
end
|
460
|
-
nested_attrs.respond_to?(:key?) && nested_attrs.key?(key)
|
461
483
|
end
|
462
484
|
|
463
485
|
end
|
data/lib/chef/platform.rb
CHANGED
@@ -70,6 +70,17 @@ class Chef
|
|
70
70
|
:service => Chef::Provider::Service::Debian,
|
71
71
|
:cron => Chef::Provider::Cron,
|
72
72
|
:mdadm => Chef::Provider::Mdadm
|
73
|
+
},
|
74
|
+
"6.0" => {
|
75
|
+
:service => Chef::Provider::Service::Insserv
|
76
|
+
}
|
77
|
+
},
|
78
|
+
:xenserver => {
|
79
|
+
:default => {
|
80
|
+
:service => Chef::Provider::Service::Redhat,
|
81
|
+
:cron => Chef::Provider::Cron,
|
82
|
+
:package => Chef::Provider::Package::Yum,
|
83
|
+
:mdadm => Chef::Provider::Mdadm
|
73
84
|
}
|
74
85
|
},
|
75
86
|
:centos => {
|
@@ -56,7 +56,7 @@ class Chef
|
|
56
56
|
|
57
57
|
def load_cache
|
58
58
|
begin
|
59
|
-
JSON.
|
59
|
+
Chef::JSON.from_json(Chef::FileCache.load("revision-deploys/#{new_resource.name}"))
|
60
60
|
rescue Chef::Exceptions::FileNotFound
|
61
61
|
sorted_releases_from_filesystem
|
62
62
|
end
|
@@ -55,16 +55,28 @@ class Chef
|
|
55
55
|
|
56
56
|
command = "erl_call -e #{distributed} #{node} #{cookie}"
|
57
57
|
|
58
|
-
|
58
|
+
begin
|
59
|
+
pid, stdin, stdout, stderr = popen4(command, :waitlast => true)
|
60
|
+
|
59
61
|
Chef::Log.debug("Running erl_call[#{@new_resource.name}]")
|
60
62
|
Chef::Log.debug("erl_call[#{@new_resource.name}] command: #{command}")
|
61
63
|
Chef::Log.debug("erl_call[#{@new_resource.name}] code: #{@new_resource.code}")
|
62
|
-
|
64
|
+
|
65
|
+
@new_resource.code.each_line { |line| stdin.puts(line.chomp) }
|
66
|
+
|
63
67
|
stdin.close
|
68
|
+
|
64
69
|
Chef::Log.info("Ran erl_call[#{@new_resource.name}] successfully")
|
65
70
|
Chef::Log.debug("erl_call[#{@new_resource.name}] output: ")
|
71
|
+
|
66
72
|
stdout.each_line { |line| Chef::Log.debug("#{line}")}
|
73
|
+
stderr.each_line { |line| Chef::Log.debug("#{line}")}
|
74
|
+
stdout.close
|
75
|
+
stderr.close
|
76
|
+
ensure
|
77
|
+
Process.wait(pid) if pid
|
67
78
|
end
|
79
|
+
|
68
80
|
end
|
69
81
|
|
70
82
|
end
|
data/lib/chef/provider/git.rb
CHANGED
@@ -36,7 +36,9 @@ class Chef
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def action_checkout
|
39
|
-
|
39
|
+
assert_target_directory_valid!
|
40
|
+
|
41
|
+
if target_dir_non_existant_or_empty?
|
40
42
|
clone
|
41
43
|
checkout
|
42
44
|
enable_submodules
|
@@ -53,24 +55,40 @@ class Chef
|
|
53
55
|
end
|
54
56
|
|
55
57
|
def action_sync
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
else
|
58
|
+
assert_target_directory_valid!
|
59
|
+
|
60
|
+
if existing_git_clone?
|
60
61
|
current_rev = find_current_revision
|
61
|
-
Chef::Log.debug "#{@new_resource} revision: #{current_rev}"
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
@new_resource.updated_by_last_action(false)
|
67
|
-
else
|
68
|
-
Chef::Log.info "#{@new_resource} updated revision is: #{new_rev}"
|
62
|
+
Chef::Log.debug "#{@new_resource} current revision: #{current_rev} target revision: #{target_revision}"
|
63
|
+
unless current_revision_matches_target_revision?
|
64
|
+
fetch_updates
|
65
|
+
enable_submodules
|
66
|
+
Chef::Log.info "#{@new_resource} updated to revision: #{target_revision}"
|
69
67
|
@new_resource.updated_by_last_action(true)
|
70
68
|
end
|
69
|
+
|
70
|
+
else
|
71
|
+
action_checkout
|
72
|
+
@new_resource.updated_by_last_action(true)
|
71
73
|
end
|
72
74
|
end
|
73
|
-
|
75
|
+
|
76
|
+
def assert_target_directory_valid!
|
77
|
+
target_parent_directory = ::File.dirname(@new_resource.destination)
|
78
|
+
unless ::File.directory?(target_parent_directory)
|
79
|
+
msg = "Cannot clone #{@new_resource} to #{@new_resource.destination}, the enclosing directory #{target_parent_directory} does not exist"
|
80
|
+
raise Chef::Exceptions::MissingParentDirectory, msg
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def existing_git_clone?
|
85
|
+
::File.exist?(::File.join(@new_resource.destination, ".git"))
|
86
|
+
end
|
87
|
+
|
88
|
+
def target_dir_non_existant_or_empty?
|
89
|
+
!::File.exist?(@new_resource.destination) || Dir.entries(@new_resource.destination).sort == ['.','..']
|
90
|
+
end
|
91
|
+
|
74
92
|
def find_current_revision
|
75
93
|
if ::File.exist?(::File.join(cwd, ".git"))
|
76
94
|
status, result, error_message = output_of_command("git rev-parse HEAD", run_options(:cwd=>cwd))
|
@@ -92,73 +110,80 @@ class Chef
|
|
92
110
|
|
93
111
|
Chef::Log.info "Cloning repo #{@new_resource.repository} to #{@new_resource.destination}"
|
94
112
|
|
95
|
-
clone_cmd = "
|
113
|
+
clone_cmd = "git clone #{args.join(' ')} #{@new_resource.repository} #{@new_resource.destination}"
|
96
114
|
run_command(run_options(:command => clone_cmd))
|
97
115
|
end
|
98
116
|
|
99
117
|
def checkout
|
100
|
-
sha_ref =
|
118
|
+
sha_ref = target_revision
|
101
119
|
Chef::Log.info "Checking out branch: #{@new_resource.revision} reference: #{sha_ref}"
|
102
120
|
# checkout into a local branch rather than a detached HEAD
|
103
|
-
run_command(run_options(:command => "
|
121
|
+
run_command(run_options(:command => "git checkout -b deploy #{sha_ref}", :cwd => @new_resource.destination))
|
104
122
|
end
|
105
123
|
|
106
124
|
def enable_submodules
|
107
125
|
if @new_resource.enable_submodules
|
108
126
|
Chef::Log.info "Enabling git submodules"
|
109
|
-
command = "
|
127
|
+
command = "git submodule init && git submodule update"
|
110
128
|
run_command(run_options(:command => command, :cwd => @new_resource.destination))
|
111
129
|
end
|
112
130
|
end
|
113
131
|
|
114
|
-
def
|
115
|
-
|
116
|
-
sync_command = []
|
117
|
-
|
118
|
-
# Use git-config to setup a remote tracking branches. Could use
|
119
|
-
# git-remote but it complains when a remote of the same name already
|
120
|
-
# exists, git-config will just silenty overwrite the setting every
|
121
|
-
# time. This could cause wierd-ness in the remote cache if the url
|
122
|
-
# changes between calls, but as long as the repositories are all
|
123
|
-
# based from each other it should still work fine.
|
124
|
-
if @new_resource.remote != 'origin'
|
125
|
-
Chef::Log.info "Configuring remote tracking branches for repository #{@new_resource.repository} "+
|
126
|
-
"at remote #{@new_resource.remote}"
|
127
|
-
sync_command << "#{git} config remote.#{@new_resource.remote}.url #{@new_resource.repository}"
|
128
|
-
sync_command << "#{git} config remote.#{@new_resource.remote}.fetch +refs/heads/*:refs/remotes/#{@new_resource.remote}/*"
|
129
|
-
end
|
132
|
+
def fetch_updates
|
133
|
+
setup_remote_tracking_branches if @new_resource.remote != 'origin'
|
130
134
|
|
131
135
|
# since we're in a local branch already, just reset to specified revision rather than merge
|
132
|
-
|
133
|
-
Chef::Log.
|
134
|
-
run_command(run_options(:command =>
|
136
|
+
fetch_command = "git fetch #{@new_resource.remote} && git fetch #{@new_resource.remote} --tags && git reset --hard #{target_revision}"
|
137
|
+
Chef::Log.debug "Fetching updates from #{new_resource.remote} and resetting to revison #{target_revision}"
|
138
|
+
run_command(run_options(:command => fetch_command, :cwd => @new_resource.destination))
|
135
139
|
end
|
136
|
-
|
137
|
-
|
138
|
-
|
140
|
+
|
141
|
+
# Use git-config to setup a remote tracking branches. Could use
|
142
|
+
# git-remote but it complains when a remote of the same name already
|
143
|
+
# exists, git-config will just silenty overwrite the setting every
|
144
|
+
# time. This could cause wierd-ness in the remote cache if the url
|
145
|
+
# changes between calls, but as long as the repositories are all
|
146
|
+
# based from each other it should still work fine.
|
147
|
+
def setup_remote_tracking_branches
|
148
|
+
command = []
|
149
|
+
|
150
|
+
Chef::Log.info "Configuring remote tracking branches for repository #{@new_resource.repository} "+
|
151
|
+
"at remote #{@new_resource.remote}"
|
152
|
+
command << "git config remote.#{@new_resource.remote}.url #{@new_resource.repository}"
|
153
|
+
command << "git config remote.#{@new_resource.remote}.fetch +refs/heads/*:refs/remotes/#{@new_resource.remote}/*"
|
154
|
+
run_command(run_options(:command => command.join(" && "), :cwd => @new_resource.destination))
|
155
|
+
end
|
156
|
+
|
157
|
+
def current_revision_matches_target_revision?
|
158
|
+
(!@current_resource.revision.nil?) && (target_revision.strip.to_i(16) == @current_resource.revision.strip.to_i(16))
|
159
|
+
end
|
160
|
+
|
161
|
+
def target_revision
|
162
|
+
@target_revision ||= begin
|
139
163
|
assert_revision_not_remote
|
140
164
|
|
141
165
|
if sha_hash?(@new_resource.revision)
|
142
|
-
@
|
166
|
+
@target_revision = @new_resource.revision
|
143
167
|
else
|
144
168
|
resolved_reference = remote_resolve_reference
|
145
|
-
@
|
169
|
+
@target_revision = extract_revision(resolved_reference)
|
146
170
|
end
|
147
171
|
end
|
148
172
|
end
|
149
173
|
|
150
|
-
alias :revision_slug :
|
174
|
+
alias :revision_slug :target_revision
|
151
175
|
|
152
176
|
def remote_resolve_reference
|
153
|
-
command =
|
177
|
+
command = git('ls-remote', @new_resource.repository, @new_resource.revision)
|
154
178
|
Chef::Log.debug("Executing #{command}")
|
155
179
|
begin
|
156
180
|
status, result, error_message = output_of_command(command, run_options)
|
157
181
|
handle_command_failures(status, "STDOUT: #{result}\nSTDERR: #{error_message}")
|
158
|
-
rescue
|
159
|
-
|
160
|
-
|
161
|
-
|
182
|
+
rescue Chef::Exceptions::Exec => e
|
183
|
+
msg = "Could not access the remote Git repository. If this is a private repository, "
|
184
|
+
msg << "verify that the deploy key for your application has been added to your remote Git account.\n"
|
185
|
+
msg << e.message
|
186
|
+
raise Chef::Exceptions::Exec, msg
|
162
187
|
end
|
163
188
|
result
|
164
189
|
end
|
@@ -176,14 +201,10 @@ class Chef
|
|
176
201
|
@new_resource.destination
|
177
202
|
end
|
178
203
|
|
179
|
-
def
|
180
|
-
[git, *args].compact.join(" ")
|
204
|
+
def git(*args)
|
205
|
+
["git", *args].compact.join(" ")
|
181
206
|
end
|
182
207
|
|
183
|
-
def git
|
184
|
-
'git'
|
185
|
-
end
|
186
|
-
|
187
208
|
def sha_hash?(string)
|
188
209
|
string =~ /^[0-9a-f]{40}$/
|
189
210
|
end
|
@@ -201,7 +222,10 @@ class Chef
|
|
201
222
|
|
202
223
|
def extract_revision(resolved_reference)
|
203
224
|
unless resolved_reference =~ /^([0-9a-f]{40})\s+(\S+)/
|
204
|
-
|
225
|
+
msg = "Unable to parse SHA reference for '#{@new_resource.revision}' in repository '#{@new_resource.repository}'. "
|
226
|
+
msg << "Verify your (case-sensitive) repository URL and revision.\n"
|
227
|
+
msg << "`git ls-remote` output: #{resolved_reference}"
|
228
|
+
raise Chef::Exceptions::UnresolvableGitReference, msg
|
205
229
|
end
|
206
230
|
$1
|
207
231
|
end
|