class KnifeSpork::SporkUpload
Constants
- CHECKSUM
- MATCH_CHECKSUM
Public Instance Methods
run()
click to toggle source
# File lib/chef/knife/spork-upload.rb, line 42 def run self.class.send(:include, KnifeSpork::Runner) self.config = Chef::Config.merge!(config) config[:cookbook_path] ||= Chef::Config[:cookbook_path] if @name_args.empty? show_usage ui.error("You must specify the --all flag or at least one cookbook name") exit 1 end # Temporary fix for #138 to allow Berkshelf functionality # to be bypassed until #85 has been completed and Berkshelf 3 support added unload_berkshelf_if_specified #First load so plugins etc know what to work with @cookbooks = load_cookbooks(name_args) include_dependencies if config[:depends] run_plugins(:before_upload) #Reload cookbook in case a VCS plugin found updates @cookbooks = load_cookbooks(name_args) include_dependencies if config[:depends] upload run_plugins(:after_upload) end
Private Instance Methods
check_dependencies(cookbook)
click to toggle source
Ensures that all the cookbooks dependencies are either already on the server or being uploaded in this pass
# File lib/chef/knife/spork-upload.rb, line 124 def check_dependencies(cookbook) negotiate_protocol_version cookbook.metadata.dependencies.each do |cookbook_name, version| unless server_has_version(cookbook_name, version) ui.error "#{cookbook.name} depends on #{cookbook_name} (#{version}), which is not currently being uploaded and cannot be found on the server!" exit(1) end end end
include_dependencies()
click to toggle source
# File lib/chef/knife/spork-upload.rb, line 72 def include_dependencies @cookbooks.each do |cookbook| @cookbooks.concat(load_cookbooks(cookbook.metadata.dependencies.keys)) end @cookbooks.uniq! end
negotiate_protocol_version()
click to toggle source
# File lib/chef/knife/spork-upload.rb, line 147 def negotiate_protocol_version server_side_cookbooks end
server_has_version(cookbook_name, version)
click to toggle source
# File lib/chef/knife/spork-upload.rb, line 134 def server_has_version(cookbook_name, version) hash = server_side_cookbooks[cookbook_name] hash && hash['versions'] && hash['versions'].any?{ |v| Chef::VersionConstraint.new(version).include?(v['version']) } end
server_side_cookbooks()
click to toggle source
# File lib/chef/knife/spork-upload.rb, line 139 def server_side_cookbooks if Chef::CookbookVersion.respond_to?(:list_all_versions) @server_side_cookbooks ||= Chef::CookbookVersion.list_all_versions else @server_side_cookbooks ||= Chef::CookbookVersion.list end end
upload()
click to toggle source
# File lib/chef/knife/spork-upload.rb, line 80 def upload # upload cookbooks in reverse so that dependencies are satisfied first @cookbooks.reverse.each do |cookbook| begin check_dependencies(cookbook) if name_args.include?(cookbook.name.to_s) if Gem::Version.new(Chef::VERSION).release >= Gem::Version.new('12.0.0') uploader = Chef::CookbookUploader.new(cookbook) else uploader = Chef::CookbookUploader.new(cookbook, ::Chef::Config.cookbook_path) end begin if uploader.respond_to?(:upload_cookbooks) # Chef >= 10.14.0 uploader.upload_cookbooks ui.info "Freezing #{cookbook.name} at #{cookbook.version}..." cookbook.freeze_version uploader.upload_cookbooks else uploader.upload_cookbook ui.info "Freezing #{cookbook.name} at #{cookbook.version}..." cookbook.freeze_version uploader.upload_cookbook end rescue Chef::Exceptions::CookbookFrozen => msg ui.error "#{cookbook.name}@#{cookbook.version} is frozen. Please bump your version number before continuing!" exit(1) end end rescue Net::HTTPServerException => e if e.response.code == '409' ui.error "#{cookbook.name}@#{cookbook.version} is frozen. Please bump your version number before continuing!" exit(1) else raise end end end ui.msg "Successfully uploaded #{@cookbooks.collect{|c| "#{c.name}@#{c.version}"}.join(', ')}!" end