boxgrinder-core 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,17 @@
1
+ v0.2.0
2
+
3
+ * [BGBUILD-133] Support a consolidated configuration file
4
+ * [BGBUILD-68] Global .boxgrinder/config or rc style file for config
5
+ * [BGBUILD-127] Use appliance definition object instead of a file when using BG as a library
6
+ * [BGBUILD-79] Allow to use BoxGrinder Build as a library
7
+ * [BGBUILD-93] Add Red Hat Enterprise Linux 6 support
8
+ * [BGBUILD-101] Don't use 'includes' subsection when specifying packages
9
+ * [BGBUILD-60] Post section merging pattern for appliances depending on the same appliance
10
+ * [BGBUILD-151] Overriding hardware partitions via inclusion in Appliance Definition File causes build failure
11
+
12
+ v0.1.6
13
+
14
+ * [BGBUILD-100] Enable boxgrinder_build to create a Fedora image with encrypted partition(s)
1
15
 
2
16
  v0.1.5
3
17
 
data/Manifest CHANGED
@@ -5,7 +5,6 @@ README
5
5
  Rakefile
6
6
  boxgrinder-core.gemspec
7
7
  lib/boxgrinder-core.rb
8
- lib/boxgrinder-core/defaults.rb
9
8
  lib/boxgrinder-core/helpers/appliance-config-helper.rb
10
9
  lib/boxgrinder-core/helpers/appliance-helper.rb
11
10
  lib/boxgrinder-core/helpers/exec-helper.rb
@@ -20,10 +19,14 @@ spec/helpers/appliance-config-helper-spec.rb
20
19
  spec/helpers/appliance-helper-spec.rb
21
20
  spec/helpers/exec-helper-spec.rb
22
21
  spec/helpers/log-helper-spec.rb
22
+ spec/models/config-spec.rb
23
23
  spec/rspec/ls/one
24
24
  spec/rspec/ls/two
25
25
  spec/rspec/rspec-config-helper.rb
26
26
  spec/rspec/src/appliances/ephemeral-repo.appl
27
27
  spec/rspec/src/appliances/full.appl
28
+ spec/rspec/src/appliances/invalid_yaml.appl
28
29
  spec/rspec/src/appliances/repo.appl
30
+ spec/rspec/src/config/empty
31
+ spec/rspec/src/config/valid
29
32
  spec/validators/appliance-config-validator-spec.rb
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{boxgrinder-core}
5
- s.version = "0.1.5"
5
+ s.version = "0.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Marek Goldmann"]
9
- s.date = %q{2010-12-17}
9
+ s.date = %q{2011-02-09}
10
10
  s.description = %q{Core library for BoxGrinder}
11
11
  s.email = %q{info@boxgrinder.org}
12
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/boxgrinder-core.rb", "lib/boxgrinder-core/defaults.rb", "lib/boxgrinder-core/helpers/appliance-config-helper.rb", "lib/boxgrinder-core/helpers/appliance-helper.rb", "lib/boxgrinder-core/helpers/exec-helper.rb", "lib/boxgrinder-core/helpers/log-helper.rb", "lib/boxgrinder-core/models/appliance-config.rb", "lib/boxgrinder-core/models/config.rb", "lib/boxgrinder-core/models/task.rb", "lib/boxgrinder-core/validators/appliance-config-validator.rb", "lib/boxgrinder-core/validators/errors.rb"]
13
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "boxgrinder-core.gemspec", "lib/boxgrinder-core.rb", "lib/boxgrinder-core/defaults.rb", "lib/boxgrinder-core/helpers/appliance-config-helper.rb", "lib/boxgrinder-core/helpers/appliance-helper.rb", "lib/boxgrinder-core/helpers/exec-helper.rb", "lib/boxgrinder-core/helpers/log-helper.rb", "lib/boxgrinder-core/models/appliance-config.rb", "lib/boxgrinder-core/models/config.rb", "lib/boxgrinder-core/models/task.rb", "lib/boxgrinder-core/validators/appliance-config-validator.rb", "lib/boxgrinder-core/validators/errors.rb", "rubygem-boxgrinder-core.spec", "spec/helpers/appliance-config-helper-spec.rb", "spec/helpers/appliance-helper-spec.rb", "spec/helpers/exec-helper-spec.rb", "spec/helpers/log-helper-spec.rb", "spec/rspec/ls/one", "spec/rspec/ls/two", "spec/rspec/rspec-config-helper.rb", "spec/rspec/src/appliances/ephemeral-repo.appl", "spec/rspec/src/appliances/full.appl", "spec/rspec/src/appliances/repo.appl", "spec/validators/appliance-config-validator-spec.rb"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/boxgrinder-core.rb", "lib/boxgrinder-core/helpers/appliance-config-helper.rb", "lib/boxgrinder-core/helpers/appliance-helper.rb", "lib/boxgrinder-core/helpers/exec-helper.rb", "lib/boxgrinder-core/helpers/log-helper.rb", "lib/boxgrinder-core/models/appliance-config.rb", "lib/boxgrinder-core/models/config.rb", "lib/boxgrinder-core/models/task.rb", "lib/boxgrinder-core/validators/appliance-config-validator.rb", "lib/boxgrinder-core/validators/errors.rb"]
13
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "boxgrinder-core.gemspec", "lib/boxgrinder-core.rb", "lib/boxgrinder-core/helpers/appliance-config-helper.rb", "lib/boxgrinder-core/helpers/appliance-helper.rb", "lib/boxgrinder-core/helpers/exec-helper.rb", "lib/boxgrinder-core/helpers/log-helper.rb", "lib/boxgrinder-core/models/appliance-config.rb", "lib/boxgrinder-core/models/config.rb", "lib/boxgrinder-core/models/task.rb", "lib/boxgrinder-core/validators/appliance-config-validator.rb", "lib/boxgrinder-core/validators/errors.rb", "rubygem-boxgrinder-core.spec", "spec/helpers/appliance-config-helper-spec.rb", "spec/helpers/appliance-helper-spec.rb", "spec/helpers/exec-helper-spec.rb", "spec/helpers/log-helper-spec.rb", "spec/models/config-spec.rb", "spec/rspec/ls/one", "spec/rspec/ls/two", "spec/rspec/rspec-config-helper.rb", "spec/rspec/src/appliances/ephemeral-repo.appl", "spec/rspec/src/appliances/full.appl", "spec/rspec/src/appliances/invalid_yaml.appl", "spec/rspec/src/appliances/repo.appl", "spec/rspec/src/config/empty", "spec/rspec/src/config/valid", "spec/validators/appliance-config-validator-spec.rb"]
14
14
  s.homepage = %q{http://www.jboss.org/boxgrinder}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Boxgrinder-core", "--main", "README"]
16
16
  s.require_paths = ["lib"]
@@ -15,5 +15,3 @@
15
15
  # License along with this software; if not, write to the Free
16
16
  # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17
17
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18
-
19
- require 'boxgrinder-core/defaults'
@@ -23,7 +23,7 @@ module BoxGrinder
23
23
  class ApplianceConfigHelper
24
24
 
25
25
  def initialize(appliance_configs)
26
- @appliance_configs = appliance_configs.reverse
26
+ @appliance_configs = appliance_configs.reverse
27
27
  end
28
28
 
29
29
  def merge(appliance_config)
@@ -125,6 +125,7 @@ module BoxGrinder
125
125
  end
126
126
  end
127
127
 
128
+ partitions[root]['passphrase'] = partition['passphrase'] unless partition['passphrase'].nil?
128
129
  partitions[root]['options'] = partition['options'] unless partition['options'].nil?
129
130
  end
130
131
  end
@@ -133,14 +134,13 @@ module BoxGrinder
133
134
  end
134
135
 
135
136
  def default_filesystem_type
136
- fs = 'ext3'
137
+ fs = 'ext4'
137
138
 
138
139
  case @appliance_config.os.name
139
- when 'fedora'
140
-
140
+ when 'rhel', 'centos'
141
141
  case @appliance_config.os.version
142
- when '13', '14'
143
- fs = 'ext4'
142
+ when '5'
143
+ fs = 'ext3'
144
144
  end
145
145
  end
146
146
 
@@ -155,8 +155,6 @@ module BoxGrinder
155
155
  merge_field('os.name') { |name| @appliance_config.os.name = name.to_s }
156
156
  merge_field('os.version') { |version| @appliance_config.os.version = version.to_s }
157
157
  merge_field('os.password') { |password| @appliance_config.os.password = password.to_s }
158
-
159
- @appliance_config.os.password = APPLIANCE_DEFAULTS[:os][:password] if @appliance_config.os.password.nil?
160
158
  end
161
159
 
162
160
  def prepare_appliances
@@ -191,16 +189,11 @@ module BoxGrinder
191
189
  end
192
190
 
193
191
  def merge_packages
194
- @appliance_config.packages.includes.clear
195
- @appliance_config.packages.excludes.clear
192
+ @appliance_config.packages.clear
196
193
 
197
194
  @appliance_configs.each do |appliance_config|
198
- appliance_config.packages.includes.each do |package|
199
- @appliance_config.packages.includes << package
200
- end
201
-
202
- appliance_config.packages.excludes.each do |package|
203
- @appliance_config.packages.excludes << package
195
+ appliance_config.packages.each do |package|
196
+ @appliance_config.packages << package
204
197
  end
205
198
  end
206
199
  end
@@ -208,11 +201,15 @@ module BoxGrinder
208
201
  def merge_post_operations
209
202
  @appliance_config.post.each_value { |cmds| cmds.clear }
210
203
 
204
+ included = []
205
+
211
206
  @appliance_configs.each do |appliance_config|
207
+ next if included.include?(appliance_config)
212
208
  appliance_config.post.each do |platform, cmds|
213
209
  @appliance_config.post[platform] = [] if @appliance_config.post[platform].nil?
214
210
  cmds.each { |cmd| @appliance_config.post[platform] << substitute_vars(cmd) }
215
211
  end
212
+ included << appliance_config
216
213
  end
217
214
  end
218
215
 
@@ -25,49 +25,77 @@ module BoxGrinder
25
25
  @log = options[:log] || Logger.new(STDOUT)
26
26
  end
27
27
 
28
- def read_definitions(definition_file, content_type = nil)
29
- @log.debug "Reading definition from '#{definition_file}' file..."
30
-
31
- definition_file_extension = File.extname(definition_file)
28
+ # Reads definition provided as string. This string can be a YAML document. In this case
29
+ # definition is parsed and an ApplianceConfig object is returned. In other cases it tries to search
30
+ # for a file with provided name.
31
+ def read_definitions(definition, content_type = nil)
32
32
  configs = []
33
33
 
34
- appliance_config =
35
- case definition_file_extension
36
- when '.appl', '.yml', '.yaml'
37
- read_yaml(definition_file)
38
- when '.xml'
39
- read_xml(definition_file)
40
- else
41
- unless content_type.nil?
42
- case content_type
43
- when 'application/x-yaml', 'text/yaml'
44
- read_yaml(definition_file)
45
- when 'application/xml', 'text/xml', 'application/x-xml'
46
- read_xml(definition_file)
34
+ if File.exists?(definition)
35
+ @log.debug "Reading definition from '#{definition}' file..."
36
+
37
+ definition_file_extension = File.extname(definition)
38
+
39
+ appliance_config =
40
+ case definition_file_extension
41
+ when '.appl', '.yml', '.yaml'
42
+ read_yaml_file(definition)
43
+ when '.xml'
44
+ read_xml_file(definition)
45
+ else
46
+ unless content_type.nil?
47
+ case content_type
48
+ when 'application/x-yaml', 'text/yaml'
49
+ read_yaml_file(definition)
50
+ when 'application/xml', 'text/xml', 'application/x-xml'
51
+ read_xml_file(definition)
52
+ end
47
53
  end
48
- end
49
- end
54
+ end
55
+
56
+ raise 'Unsupported file format for appliance definition file.' if appliance_config.nil?
50
57
 
51
- raise 'Unsupported file format for appliance definition file' if appliance_config.nil?
58
+ configs << appliance_config
52
59
 
53
- configs << appliance_config
60
+ appliance_config.appliances.reverse.each do |appliance_name|
61
+ configs << read_definitions("#{File.dirname(definition)}/#{appliance_name}#{definition_file_extension}").first
62
+ end unless appliance_config.appliances.nil? or !appliance_config.appliances.is_a?(Array)
63
+ else
64
+ @log.debug "Reading definition..."
54
65
 
55
- appliance_config.appliances.reverse.each do |appliance_name|
56
- configs << read_definitions("#{File.dirname(definition_file)}/#{appliance_name}#{definition_file_extension}").first
57
- end unless appliance_config.appliances.nil? or !appliance_config.appliances.is_a?(Array)
66
+ appliance_config = read_yaml(definition)
67
+ configs << appliance_config
68
+ end
58
69
 
59
70
  [configs.flatten, appliance_config]
60
71
  end
61
72
 
62
- def read_yaml(file)
73
+ def read_yaml(content)
74
+ begin
75
+ definition = YAML.load(content)
76
+ raise "Not a valid YAML content." if definition.nil? or definition == false
77
+ rescue
78
+ raise "Provided definition could not be read."
79
+ end
80
+
81
+ parse_yaml(definition)
82
+ end
83
+
84
+ def read_yaml_file(file)
63
85
  begin
64
86
  definition = YAML.load_file(file)
65
- raise if definition.nil? or definition == false
87
+ raise "Not a valid YAML file." if definition.nil? or definition == false
66
88
  rescue
67
89
  raise "File '#{file}' could not be read."
68
90
  end
69
91
 
92
+ parse_yaml(definition)
93
+ end
94
+
95
+ # TODO this needs to be rewritten
96
+ def parse_yaml(definition)
70
97
  return definition if definition.is_a?(ApplianceConfig)
98
+ raise "Provided definition is not a Hash." unless definition.is_a?(Hash)
71
99
 
72
100
  appliance_config = ApplianceConfig.new
73
101
 
@@ -76,6 +104,7 @@ module BoxGrinder
76
104
 
77
105
  definition['variables'].each { |key, value| appliance_config.variables[key] = value } unless definition['variables'].nil?
78
106
 
107
+ appliance_config.packages = definition['packages'] unless definition['packages'].nil?
79
108
  appliance_config.appliances = definition['appliances'] unless definition['appliances'].nil?
80
109
  appliance_config.repos = definition['repos'] unless definition['repos'].nil?
81
110
 
@@ -84,12 +113,7 @@ module BoxGrinder
84
113
 
85
114
  unless definition['default_repos'].nil?
86
115
  appliance_config.default_repos = definition['default_repos']
87
- raise "#{File.basename(file)}: default_repos should be set to true or false" unless appliance_config.default_repos.is_a?(TrueClass) or appliance_config.default_repos.is_a?(FalseClass)
88
- end
89
-
90
- unless definition['packages'].nil?
91
- appliance_config.packages.includes = definition['packages']['includes'] unless definition['packages']['includes'].nil?
92
- appliance_config.packages.excludes = definition['packages']['excludes'] unless definition['packages']['excludes'].nil?
116
+ raise "default_repos should be set to true or false" unless appliance_config.default_repos.is_a?(TrueClass) or appliance_config.default_repos.is_a?(FalseClass)
93
117
  end
94
118
 
95
119
  unless definition['os'].nil?
@@ -103,7 +127,12 @@ module BoxGrinder
103
127
  appliance_config.hardware.cpus = definition['hardware']['cpus'] unless definition['hardware']['cpus'].nil?
104
128
  appliance_config.hardware.memory = definition['hardware']['memory'] unless definition['hardware']['memory'].nil?
105
129
  appliance_config.hardware.network = definition['hardware']['network'] unless definition['hardware']['network'].nil?
106
- appliance_config.hardware.partitions = definition['hardware']['partitions'] unless definition['hardware']['partitions'].nil?
130
+
131
+ unless definition['hardware']['partitions'].nil?
132
+ definition['hardware']['partitions'].each do |key, part|
133
+ appliance_config.hardware.partitions[key] = part
134
+ end if definition['hardware']['partitions'].is_a?(Hash)
135
+ end
107
136
  end
108
137
 
109
138
  definition['post'].each { |key, value| appliance_config.post[key] = value } unless definition['post'].nil?
@@ -111,8 +140,8 @@ module BoxGrinder
111
140
  appliance_config
112
141
  end
113
142
 
114
- def read_xml(file)
115
- raise "Reading XML files is not supported right now. File '#{file}' could not be read"
143
+ def read_xml_file(file)
144
+ raise "Reading XML files is not supported right now. File '#{file}' could not be read."
116
145
  end
117
146
  end
118
147
  end
@@ -31,6 +31,9 @@ module BoxGrinder
31
31
 
32
32
  output = ""
33
33
 
34
+ # dirty workaround for ruby segfaults related to logger.rb
35
+ STDOUT.flush
36
+
34
37
  begin
35
38
  status = Open4::popen4( command ) do |pid, stdin, stdout, stderr|
36
39
  threads = []
@@ -17,7 +17,6 @@
17
17
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18
18
 
19
19
  require 'logger'
20
- require 'boxgrinder-core/defaults'
21
20
  require 'fileutils'
22
21
 
23
22
  Logger.const_set(:TRACE, 0)
@@ -53,8 +52,8 @@ module BoxGrinder
53
52
  }
54
53
 
55
54
  def initialize(options = {})
56
- location = options[:location] || DEFAULT_LOCATION[:log]
57
- threshold = options[:threshold] || :info
55
+ location = options[:location] || 'log/boxgrinder.log'
56
+ threshold = options[:level].nil? ? :info : options[:level].to_sym
58
57
  type = options[:type] || [:stdout, :file]
59
58
 
60
59
  unless type.is_a?(Array)
@@ -17,7 +17,6 @@
17
17
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18
18
 
19
19
  require 'rubygems'
20
- require 'boxgrinder-core/defaults'
21
20
  require 'hashery/opencascade'
22
21
 
23
22
  module BoxGrinder
@@ -32,21 +31,18 @@ module BoxGrinder
32
31
 
33
32
  @os.name = nil
34
33
  @os.version = nil
35
- @os.password = nil
34
+ @os.password = 'boxgrinder'
36
35
 
37
36
  @hardware = OpenCascade.new
38
37
 
39
- @hardware.cpus = APPLIANCE_DEFAULTS[:hardware][:cpus]
40
- @hardware.memory = APPLIANCE_DEFAULTS[:hardware][:memory]
41
- @hardware.network = APPLIANCE_DEFAULTS[:hardware][:network]
42
- @hardware.partitions = APPLIANCE_DEFAULTS[:hardware][:partitions]
38
+ @hardware.cpus = 1
39
+ @hardware.memory = 256
40
+ @hardware.network = 'NAT'
41
+ @hardware.partitions = {"/" => { 'size' => 1 }}
43
42
 
44
43
  @post = {}
45
44
 
46
- @packages = OpenCascade.new
47
- @packages.includes = []
48
- @packages.excludes = []
49
-
45
+ @packages = []
50
46
  @appliances = []
51
47
  @repos = []
52
48
 
@@ -58,7 +54,6 @@ module BoxGrinder
58
54
  attr_reader :os
59
55
  attr_reader :hardware
60
56
  attr_reader :path
61
- attr_reader :file
62
57
  attr_reader :post
63
58
 
64
59
  attr_accessor :packages
@@ -16,55 +16,46 @@
16
16
  # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17
17
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18
18
 
19
- require 'boxgrinder-core/defaults'
20
- require 'ostruct'
19
+ require 'rubygems'
20
+ require 'hashery/opencascade'
21
+ require 'yaml'
21
22
 
22
23
  module BoxGrinder
23
- class Config
24
- def initialize
25
-
26
- @name = DEFAULT_PROJECT_CONFIG[:name]
27
-
28
- @dir = OpenStruct.new
29
- @dir.root = `pwd`.strip
30
- @dir.base = "#{File.dirname( __FILE__ )}/../../"
31
- @dir.build = DEFAULT_PROJECT_CONFIG[:dir_build]
32
- @dir.top = "#{@dir.build}/topdir"
33
- @dir.src_cache = DEFAULT_PROJECT_CONFIG[:dir_src_cache]
34
- @dir.rpms_cache = DEFAULT_PROJECT_CONFIG[:dir_rpms_cache]
35
- @dir.specs = DEFAULT_PROJECT_CONFIG[:dir_specs]
36
- @dir.appliances = DEFAULT_PROJECT_CONFIG[:dir_appliances]
37
- @dir.src = DEFAULT_PROJECT_CONFIG[:dir_src]
38
- @dir.kickstarts = DEFAULT_PROJECT_CONFIG[:dir_kickstarts]
39
-
40
- @config_file = ENV['BG_CONFIG_FILE'] || "#{ENV['HOME']}/.boxgrinder/config"
41
-
42
- @version = OpenStruct.new
43
- @version.version = DEFAULT_PROJECT_CONFIG[:version]
44
- @version.release = DEFAULT_PROJECT_CONFIG[:release]
45
-
46
- @files = OpenStruct.new
47
- @data = {}
48
-
49
- if File.exists?( @config_file )
50
- @data = YAML.load_file( @config_file )
51
- @data['gpg_password'].gsub!(/\$/, "\\$") unless @data['gpg_password'].nil? or @data['gpg_password'].length == 0
52
- @dir.rpms_cache = @data['rpms_cache'] || @dir.rpms_cache
53
- @dir.src_cache = @data['src_cache'] || @dir.src_cache
54
- end
24
+ class Config < OpenCascade
25
+ def initialize(values = {})
26
+ super({})
27
+
28
+ merge!(
29
+ :file => ENV['BG_CONFIG_FILE'] || "#{ENV['HOME']}/.boxgrinder/config",
30
+ :name => 'BoxGrinder Build',
31
+ :platform => :none,
32
+ :delivery => :none,
33
+ :force => false,
34
+ :log_level => :info,
35
+ :dir => {
36
+ :root => Dir.pwd,
37
+ :build => 'build',
38
+ :cache => '/var/cache/boxgrinder' # required for appliance-creator
39
+ },
40
+ :os_config => {},
41
+ :platform_config => {},
42
+ :delivery_config => {},
43
+ :additional_plugins => []
44
+ )
45
+
46
+ merge!(values.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo })
47
+
48
+ deep_merge(self, YAML.load_file(self.file)) if File.exists?(self.file)
55
49
  end
56
50
 
57
- def version_with_release
58
- @version.version + ((@version.release.nil? or @version.release.empty?) ? "" : "-" + @version.release)
51
+ def deep_merge(first, second)
52
+ second.each_key do |k|
53
+ if first[k.to_sym].is_a?(Hash) and second[k].is_a?(Hash)
54
+ deep_merge(first[k.to_sym], second[k])
55
+ else
56
+ first[k.to_sym] = second[k]
57
+ end
58
+ end if second
59
59
  end
60
-
61
- attr_accessor :name
62
- attr_accessor :version
63
- attr_accessor :release
64
- attr_accessor :config_file
65
- attr_reader :files
66
-
67
- attr_reader :data
68
- attr_reader :dir
69
60
  end
70
61
  end