Class: Builderator::Tasks::Cookbook
Instance Method Summary
collapse
#run_with_input, #template
Instance Method Details
#build(cookbook = nil) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/builderator/tasks/cookbook.rb', line 33
def build(cookbook = nil)
Util::Cookbook.path(cookbook) unless cookbook.nil?
metadata = invoke(Tasks::Cookbook, :metadata, [], options)
say_status :package, "cookbook into #{ metadata.archive }"
metadata.archive.open('wb') do |package|
Zlib::GzipWriter.wrap(package) do |gz|
Gem::Package::TarWriter.new(gz) do |tar|
metadata.files.each do |f|
f_stat = File.stat(f)
next tar.mkdir(Util::Cookbook.archive_path(metadata, f).to_s, f_stat.mode) if File.directory?(f)
tar.add_file_simple(Util::Cookbook.archive_path(metadata, f).to_s, f_stat.mode, f_stat.size) do |entry|
f.open('rb') { |h| entry.write(h.read) }
end
end
end
end
end
metadata
end
|
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/builderator/tasks/cookbook.rb', line 21
def metadata(cookbook = nil)
Util::Cookbook.path(cookbook) unless cookbook.nil?
metadata = Util::Cookbook.metadata
invoke 'version:current', [], options if options['version']
say_status :metadata, "for cookbook #{ metadata.name }@#{ metadata.version }"
create_file Util::Cookbook.path.join('metadata.json').to_s, metadata.to_json, :force => true
metadata
end
|
#push(cookbook = nil) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/builderator/tasks/cookbook.rb', line 71
def push(cookbook = nil)
Chef::Config.from_file(options['chef-config'])
Util::Cookbook.path(cookbook) unless cookbook.nil?
options['site'] ||= Chef::Config.knife['supermarket_site'] || 'https://supermarket.chef.io/'
options['user'] ||= Chef::Config.knife['supermarket_user'] || Chef::Config.node_name
options['key'] ||= Chef::Config.knife['supermarket_key'] || Chef::Config.client_key
metadata = invoke(Tasks::Cookbook, :build, [cookbook], options)
say_status :upload, "cookbook #{ metadata.name }@#{ metadata.version } to #{ options['site'] }"
metadata.archive.open('rb') do |c|
http_resp = Chef::CookbookSiteStreamingUploader.post(
File.join(options['site'], '/api/v1/cookbooks'),
options['user'],
options['key'],
:tarball => c,
:cookbook => { :category => '' }.to_json
)
if http_resp.code.to_i != 201
say_status :error, "Error uploading cookbook: #{ http_resp.code } #{ http_resp.message }", :red
say http_resp.body
exit(1)
end
end
end
|
#version(cookbook) ⇒ Object
103
104
105
106
|
# File 'lib/builderator/tasks/cookbook.rb', line 103
def version(cookbook)
Util::Cookbook.path(File.join(options['path'], cookbook))
puts Util::Cookbook.metadata.version
end
|