Class: ReleasedCookbook
Instance Attribute Summary
Attributes inherited from Cookbook
#cookbooks_url, #mofa_yml, #mofa_yml_local, #name, #override_mofa_secrets, #pkg_dir, #pkg_name, #pkg_uri, #source_uri, #token, #type, #version
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Cookbook
#autodetect_type, create, #error, #ok, #run, #say
Constructor Details
#initialize(cookbook_name_or_path, override_mofa_secrets = nil) ⇒ ReleasedCookbook
17
18
19
20
21
22
23
|
# File 'lib/mofa/released_cookbook.rb', line 17
def initialize(cookbook_name_or_path, override_mofa_secrets = nil)
super()
nv = ReleasedCookbook.get_name_and_version(cookbook_name_or_path)
@name = nv['name']
@version = nv['version']
@override_mofa_secrets = override_mofa_secrets
end
|
Class Method Details
.exists?(cookbook_name_or_path) ⇒ Boolean
10
11
12
13
14
15
|
# File 'lib/mofa/released_cookbook.rb', line 10
def self.exists?(cookbook_name_or_path)
nv = get_name_and_version(cookbook_name_or_path)
url = "#{Mofa::Config.config['binrepo_base_url']}/#{nv['name']}/#{nv['version']}/#{nv['name']}_#{nv['version']}-full.tar.gz"
puts "Checking if cookbook exists: #{url}"
RestClient.head(url)
end
|
.get_name_and_version(cookbook_name_or_path) ⇒ Object
3
4
5
6
7
8
|
# File 'lib/mofa/released_cookbook.rb', line 3
def self.get_name_and_version(cookbook_name_or_path)
name = cookbook_name_or_path.split(/@/).first
version = cookbook_name_or_path.split(/@/).last
{ 'name' => name, 'version' => version }
end
|
Instance Method Details
#cleanup ⇒ Object
37
38
39
40
41
|
# File 'lib/mofa/released_cookbook.rb', line 37
def cleanup
say "Removing folder #{pkg_dir}...#{nl}"
run "rm -rf #{pkg_dir}"
ok
end
|
#cleanup! ⇒ Object
112
113
114
115
116
117
118
119
|
# File 'lib/mofa/released_cookbook.rb', line 112
def cleanup!
unless (Dir.entries("#{Mofa::Config.config['tmp_dir']}/.mofa") - %w{ . .. }).empty?
say "Removing content of folder #{Mofa::Config.config['tmp_dir']}/.mofa"
run "rm -r #{Mofa::Config.config['tmp_dir']}/.mofa/*"
else
say "Folder #{Mofa::Config.config['tmp_dir']}/.mofa is (already) clean."
end
end
|
#execute ⇒ Object
33
34
35
|
# File 'lib/mofa/released_cookbook.rb', line 33
def execute package
end
|
#load_mofa_yml ⇒ Object
99
100
101
|
# File 'lib/mofa/released_cookbook.rb', line 99
def load_mofa_yml
@mofa_yml = MofaYml.load_from_file("#{pkg_dir}/.mofa.yml", self)
end
|
#load_mofa_yml_local ⇒ Object
103
104
105
|
# File 'lib/mofa/released_cookbook.rb', line 103
def load_mofa_yml_local
@mofa_yml_local = MofaYml.load_from_file("#{pkg_dir}/.mofa.local.yml", self)
end
|
#package ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
|
# File 'lib/mofa/released_cookbook.rb', line 43
def package
tar_verbose = (Mofa::CLI::option_debug) ? 'v' : ''
mkdir_p @pkg_dir
say "Downloading released cookbook from: #{cookbooks_url} to #{pkg_dir}/#{pkg_name}..."
File.open("#{pkg_dir}/#{pkg_name}", "wb") do |saved_file|
open(cookbooks_url, "rb") do |read_file|
saved_file.write(read_file.read)
end
end
mkdir_p "#{pkg_dir}/tmp"
run "tar x#{tar_verbose}fz #{pkg_dir}/#{pkg_name} -C #{pkg_dir}/tmp/"
if File.directory?("#{pkg_dir}/tmp/cookbooks/#{name}/data_bags")
FileUtils.cp_r "#{pkg_dir}/tmp/cookbooks/#{name}/data_bags", pkg_dir
end
if File.directory?("#{pkg_dir}/tmp/cookbooks/#{name}/recipes")
FileUtils.cp_r "#{pkg_dir}/tmp/cookbooks/#{name}/recipes", pkg_dir
end
if override_mofa_secrets
if File.directory?("#{override_mofa_secrets}/#{name}/cookbooks")
run "rsync -vr #{override_mofa_secrets}/#{name}/cookbooks/ #{pkg_dir}/tmp/cookbooks/"
if File.file?("#{override_mofa_secrets}/#{name}/.mofa.local.yml")
FileUtils.cp "#{override_mofa_secrets}/#{name}/.mofa.local.yml", "#{pkg_dir}/tmp/cookbooks/#{name}/"
end
if File.file?("#{override_mofa_secrets}/#{name}/.mofa.yml")
FileUtils.cp "#{override_mofa_secrets}/#{name}/.mofa.yml", "#{pkg_dir}/tmp/cookbooks/#{name}/"
end
else
run "rsync -vr #{override_mofa_secrets}/#{name}/ #{pkg_dir}/tmp/cookbooks/#{name}/"
end
end
if File.file?("#{pkg_dir}/tmp/cookbooks/#{name}/.mofa.yml")
FileUtils.cp "#{pkg_dir}/tmp/cookbooks/#{name}/.mofa.yml", pkg_dir
end
if File.file?("#{pkg_dir}/tmp/cookbooks/#{name}/.mofa.local.yml")
FileUtils.cp "#{pkg_dir}/tmp/cookbooks/#{name}/.mofa.local.yml", pkg_dir
end
load_mofa_yml
load_mofa_yml_local
run "cd #{pkg_dir}/tmp/;tar c#{tar_verbose}fz #{pkg_dir}/#{pkg_name}.new ."
run "rm #{pkg_dir}/#{pkg_name}"
run "mv #{pkg_dir}/#{pkg_name}.new #{pkg_dir}/#{pkg_name}"
run "rm -rf #{pkg_dir}/tmp/"
end
|
#prepare ⇒ Object
27
28
29
30
31
|
# File 'lib/mofa/released_cookbook.rb', line 27
def prepare
@pkg_name ||= "#{name}_#{version}-full.tar.gz"
@pkg_dir = "#{Mofa::Config.config['tmp_dir']}/.mofa/#{token}"
set_cookbooks_url
end
|
#recipes ⇒ Object
127
128
129
130
131
|
# File 'lib/mofa/released_cookbook.rb', line 127
def recipes
raise 'Cookbook not unpacked yet or no recipes found.' unless (Dir.exists?("#{pkg_dir}/recipes"))
recipes = Dir.entries("#{pkg_dir}/recipes").select { |f| f.match(/.rb$/) }
recipes.map! { |f| f.gsub(/\.rb/, '') }
end
|
#set_cookbooks_url ⇒ Object
121
122
123
124
125
|
# File 'lib/mofa/released_cookbook.rb', line 121
def set_cookbooks_url
say 'Using remote URI as cookbooks_url: '
@cookbooks_url = "#{Mofa::Config.config['binrepo_base_url']}/#{@name}/#{@version}/#{@name}_#{@version}-full.tar.gz"
say "#{@cookbooks_url}"
end
|
#source_dir ⇒ Object
108
109
110
|
# File 'lib/mofa/released_cookbook.rb', line 108
def source_dir
"#{pkg_dir}"
end
|