boxgrinder-build 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +21 -0
- data/Manifest +92 -0
- data/Rakefile +9 -0
- data/boxgrinder-build.gemspec +4 -4
- data/integ/appliances/_hardware_cpus.appl +13 -0
- data/integ/appliances/_hardware_memory.appl +13 -0
- data/integ/appliances/_hardware_partitions_home.appl +15 -0
- data/integ/appliances/_hardware_partitions_root.appl +15 -0
- data/integ/appliances/_os_password.appl +15 -0
- data/integ/appliances/_packages_groups_base.appl +13 -0
- data/integ/appliances/_packages_groups_core.appl +13 -0
- data/integ/appliances/_packages_squid.appl +13 -0
- data/integ/appliances/_packages_utils.appl +7 -0
- data/integ/appliances/_repos_boxgrinder_permanent_noarch.appl +14 -0
- data/integ/appliances/_repos_testlocal_ephemeral_noarch.appl +17 -0
- data/integ/appliances/_test_base.appl +22 -0
- data/integ/appliances/gnome-fedora.appl +19 -0
- data/integ/appliances/jeos-centos.appl +4 -0
- data/integ/appliances/jeos-fedora.appl +5 -0
- data/integ/appliances/modular.appl +16 -0
- data/integ/packages/ephemeral-repo-test-0.1-1.noarch.rpm +0 -0
- data/integ/packages/local-repo-test.spec +20 -0
- data/integ/spec/jeos-spec.rb +69 -0
- data/integ/spec/modular-spec.rb +71 -0
- data/lib/boxgrinder-build/appliance.rb +48 -48
- data/lib/boxgrinder-build/helpers/guestfs-helper.rb +11 -8
- data/lib/boxgrinder-build/helpers/plugin-helper.rb +1 -0
- data/lib/boxgrinder-build/helpers/qemu.wrapper +1 -1
- data/lib/boxgrinder-build/plugins/base-plugin.rb +55 -14
- data/lib/boxgrinder-build/plugins/delivery/ebs/ebs-plugin.rb +270 -54
- data/lib/boxgrinder-build/plugins/delivery/elastichosts/elastichosts-plugin.rb +3 -4
- data/lib/boxgrinder-build/plugins/delivery/local/local-plugin.rb +20 -16
- data/lib/boxgrinder-build/plugins/delivery/s3/s3-plugin.rb +57 -20
- data/lib/boxgrinder-build/plugins/delivery/sftp/sftp-plugin.rb +6 -4
- data/lib/boxgrinder-build/plugins/os/fedora/fedora-plugin.rb +2 -1
- data/lib/boxgrinder-build/plugins/os/rpm-based/kickstart.rb +2 -32
- data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-based-os-plugin.rb +29 -4
- data/lib/boxgrinder-build/plugins/os/rpm-based/rpm-dependency-validator.rb +15 -46
- data/lib/boxgrinder-build/plugins/os/sl/sl-plugin.rb +56 -0
- data/lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb +1 -0
- data/lib/boxgrinder-build/plugins/platform/ec2/src/rc_local +15 -8
- data/lib/boxgrinder-build/plugins/platform/vmware/vmware-plugin.rb +8 -6
- data/rubygem-boxgrinder-build.spec +23 -3
- data/spec/appliance-spec.rb +114 -73
- data/spec/helpers/guestfs-helper-spec.rb +12 -3
- data/spec/plugins/base-plugin-spec.rb +24 -18
- data/spec/plugins/delivery/ebs/ebs-plugin-spec.rb +206 -67
- data/spec/plugins/delivery/elastichosts/elastichosts-plugin-spec.rb +228 -225
- data/spec/plugins/delivery/local/local-plugin-spec.rb +13 -34
- data/spec/plugins/delivery/s3/s3-plugin-spec.rb +107 -50
- data/spec/plugins/os/centos/centos-plugin-spec.rb +1 -1
- data/spec/plugins/os/fedora/fedora-plugin-spec.rb +14 -8
- data/spec/plugins/os/rhel/rhel-plugin-spec.rb +1 -1
- data/spec/plugins/os/rpm-based/kickstart-spec.rb +0 -44
- data/spec/plugins/os/rpm-based/rpm-based-os-plugin-spec.rb +31 -2
- data/spec/plugins/os/rpm-based/rpm-dependency-validator-spec.rb +20 -7
- data/spec/plugins/os/sl/sl-plugin-spec.rb +44 -0
- data/spec/plugins/platform/ec2/ec2-plugin-spec.rb +1 -1
- data/spec/plugins/platform/virtualbox/virtualbox-plugin-spec.rb +6 -6
- data/spec/plugins/platform/vmware/vmware-plugin-spec.rb +14 -13
- metadata +27 -5
- data/spec/Rakefile +0 -32
@@ -23,20 +23,19 @@ require 'cgi'
|
|
23
23
|
|
24
24
|
module BoxGrinder
|
25
25
|
class ElasticHostsPlugin < BasePlugin
|
26
|
-
def
|
26
|
+
def validate
|
27
27
|
set_default_config_value('chunk', 64) # chunk size in MB
|
28
28
|
set_default_config_value('start_part', 0) # part number to start uploading
|
29
29
|
set_default_config_value('wait', 5) # wait time before retrying upload
|
30
30
|
set_default_config_value('retry', 3) # number of retries
|
31
31
|
set_default_config_value('ssl', false) # use SSL?
|
32
32
|
set_default_config_value('drive_name', @appliance_config.name)
|
33
|
-
end
|
34
33
|
|
35
|
-
def execute(type = :elastichosts)
|
36
34
|
validate_plugin_config(['endpoint', 'username', 'password'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#ElasticHosts_Delivery_Plugin')
|
37
|
-
|
38
35
|
raise PluginValidationError, "You can use ElasticHosts plugin with base appliances (appliances created with operating system plugins) only, see http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#ElasticHosts_Delivery_Plugin." unless @previous_plugin_info[:type] == :os
|
36
|
+
end
|
39
37
|
|
38
|
+
def execute
|
40
39
|
upload
|
41
40
|
create_server
|
42
41
|
end
|
@@ -23,36 +23,40 @@ require 'boxgrinder-build/plugins/base-plugin'
|
|
23
23
|
module BoxGrinder
|
24
24
|
class LocalPlugin < BasePlugin
|
25
25
|
def after_init
|
26
|
+
@package_name = "#{@appliance_config.name}-#{@appliance_config.version}.#{@appliance_config.release}-#{@appliance_config.os.name}-#{@appliance_config.os.version}-#{@appliance_config.hardware.arch}-#{current_platform}.tgz"
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate
|
26
30
|
set_default_config_value('overwrite', false)
|
27
31
|
set_default_config_value('package', true)
|
28
32
|
|
29
|
-
if @plugin_config['package']
|
30
|
-
register_deliverable(:package => "#{@appliance_config.name}-#{@appliance_config.version}.#{@appliance_config.release}-#{@appliance_config.os.name}-#{@appliance_config.os.version}-#{@appliance_config.hardware.arch}-#{current_platform}.tgz")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def execute(type = :local)
|
35
33
|
validate_plugin_config(['path'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#Local_delivery_plugin')
|
34
|
+
end
|
36
35
|
|
36
|
+
def execute
|
37
37
|
if @plugin_config['overwrite'] or !deliverables_exists?
|
38
|
-
PackageHelper.new(@config, @appliance_config, :log => @log, :exec_helper => @exec_helper).package(File.dirname(@previous_deliverables[:disk]), @deliverables[:package]) if @plugin_config['package']
|
39
|
-
|
40
38
|
FileUtils.mkdir_p @plugin_config['path']
|
41
39
|
|
42
|
-
|
40
|
+
if @plugin_config['package']
|
41
|
+
PackageHelper.new(@config, @appliance_config, :log => @log, :exec_helper => @exec_helper).package(File.dirname(@previous_deliverables[:disk]), "#{@plugin_config['path']}/#{@package_name}") if @plugin_config['package']
|
42
|
+
else
|
43
|
+
@log.debug "Copying files to '#{@plugin_config['path']}'..."
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
@previous_deliverables.each_value do |file|
|
46
|
+
@log.debug "Copying '#{file}'..."
|
47
|
+
@exec_helper.execute("cp '#{file}' '#{@plugin_config['path']}'")
|
48
|
+
end
|
49
|
+
@log.info "Appliance delivered to '#{@plugin_config['path']}'."
|
47
50
|
end
|
48
|
-
@log.info "Appliance delivered to '#{@plugin_config['path']}'."
|
49
51
|
else
|
50
52
|
@log.info "Appliance already delivered to '#{@plugin_config['path']}'."
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
54
|
-
def deliverables_exists?
|
55
|
-
(@plugin_config['
|
56
|
+
def deliverables_exists?
|
57
|
+
return File.exists?("#{@plugin_config['path']}/#{@package_name}") if @plugin_config['package']
|
58
|
+
|
59
|
+
@previous_deliverables.each_value do |file|
|
56
60
|
return false unless File.exists?("#{@plugin_config['path']}/#{File.basename(file)}")
|
57
61
|
end
|
58
62
|
|
@@ -63,4 +67,4 @@ module BoxGrinder
|
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
66
|
-
plugin :class => BoxGrinder::LocalPlugin, :type => :delivery, :name => :local, :full_name => "Local file system"
|
70
|
+
plugin :class => BoxGrinder::LocalPlugin, :type => :delivery, :name => :local, :full_name => "Local file system"
|
@@ -22,16 +22,11 @@ require 'boxgrinder-build/helpers/package-helper'
|
|
22
22
|
require 'AWS'
|
23
23
|
require 'aws'
|
24
24
|
|
25
|
-
# TODO remove this when it'll become not necessary
|
26
|
-
# quick fix for old active_support require issue in EPEL 5
|
27
|
-
require 'active_support/basic_object'
|
28
|
-
require 'active_support/duration'
|
29
|
-
|
30
25
|
module BoxGrinder
|
31
26
|
class S3Plugin < BasePlugin
|
32
27
|
REGION_OPTIONS = {
|
33
28
|
'eu-west-1' => {
|
34
|
-
:endpoint => 's3.amazonaws.com',
|
29
|
+
:endpoint => 's3-eu-west-1.amazonaws.com',
|
35
30
|
:location => 'EU',
|
36
31
|
:kernel => {
|
37
32
|
'i386' => {:aki => 'aki-4deec439'},
|
@@ -48,6 +43,16 @@ module BoxGrinder
|
|
48
43
|
}
|
49
44
|
},
|
50
45
|
|
46
|
+
'ap-northeast-1' => {
|
47
|
+
:endpoint => 's3-ap-northeast-1.amazonaws.com',
|
48
|
+
:location => 'ap-northeast-1',
|
49
|
+
:kernel => {
|
50
|
+
'i386' => {:aki => 'aki-d209a2d3'},
|
51
|
+
'x86_64' => {:aki => 'aki-d409a2d5'}
|
52
|
+
}
|
53
|
+
|
54
|
+
},
|
55
|
+
|
51
56
|
'us-west-1' => {
|
52
57
|
:endpoint => 's3-us-west-1.amazonaws.com',
|
53
58
|
:location => 'us-west-1',
|
@@ -68,38 +73,55 @@ module BoxGrinder
|
|
68
73
|
}
|
69
74
|
|
70
75
|
def after_init
|
71
|
-
set_default_config_value('overwrite', false)
|
72
|
-
set_default_config_value('path', '/')
|
73
|
-
set_default_config_value('region', 'us-east-1')
|
74
|
-
|
75
76
|
register_supported_os("fedora", ['13', '14', '15'])
|
76
77
|
register_supported_os("centos", ['5'])
|
77
78
|
register_supported_os("rhel", ['5', '6'])
|
79
|
+
register_supported_os("sl", ['5', '6'])
|
78
80
|
|
79
81
|
@ami_build_dir = "#{@dir.base}/ami"
|
80
82
|
@ami_manifest = "#{@ami_build_dir}/#{@appliance_config.name}.ec2.manifest.xml"
|
81
83
|
end
|
82
84
|
|
83
|
-
def
|
85
|
+
def validate
|
86
|
+
set_default_config_value('overwrite', false)
|
87
|
+
set_default_config_value('path', '/')
|
88
|
+
set_default_config_value('region', 'us-east-1')
|
84
89
|
validate_plugin_config(['bucket', 'access_key', 'secret_access_key'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin')
|
85
90
|
|
86
|
-
|
91
|
+
subtype(:ami) do
|
92
|
+
set_default_config_value('snapshot', false)
|
93
|
+
validate_plugin_config(['cert_file', 'key_file', 'account_number'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin')
|
94
|
+
end
|
95
|
+
|
96
|
+
raise PluginValidationError, "Invalid region specified: #{@plugin_config['region']}. This plugin only aware of the following regions: #{REGION_OPTIONS.keys.join(", ")}" unless REGION_OPTIONS.has_key?(@plugin_config['region'])
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
def execute
|
101
|
+
case @type
|
87
102
|
when :s3
|
88
103
|
upload_to_bucket(@previous_deliverables)
|
89
104
|
when :cloudfront
|
90
105
|
upload_to_bucket(@previous_deliverables, 'public-read')
|
91
106
|
when :ami
|
92
|
-
set_default_config_value('snapshot', false)
|
93
|
-
validate_plugin_config(['cert_file', 'key_file', 'account_number'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#S3_Delivery_Plugin')
|
94
|
-
|
95
107
|
@plugin_config['account_number'] = @plugin_config['account_number'].to_s.gsub(/-/, '')
|
96
108
|
|
97
109
|
@ec2 = AWS::EC2::Base.new(:access_key_id => @plugin_config['access_key'], :secret_access_key => @plugin_config['secret_access_key'], :server => "ec2.#{@plugin_config['region']}.amazonaws.com")
|
98
110
|
|
99
111
|
ami_dir = ami_key(@appliance_config.name, @plugin_config['path'])
|
100
112
|
ami_manifest_key = "#{ami_dir}/#{@appliance_config.name}.ec2.manifest.xml"
|
113
|
+
s3_object_exists = s3_object_exists?(ami_manifest_key)
|
101
114
|
|
102
|
-
|
115
|
+
@log.debug "Going to check whether s3 object exists"
|
116
|
+
|
117
|
+
if s3_object_exists and @plugin_config['overwrite']
|
118
|
+
@log.info "Object exists, attempting to deregister an existing image"
|
119
|
+
deregister_image(ami_manifest_key) # Remove existing image
|
120
|
+
bucket().delete_folder(ami_dir) # Avoid triggering dupe detection
|
121
|
+
end
|
122
|
+
|
123
|
+
if !s3_object_exists or @plugin_config['snapshot']
|
124
|
+
@log.info "Doing bundle/snapshot"
|
103
125
|
bundle_image(@previous_deliverables)
|
104
126
|
fix_sha1_sum
|
105
127
|
upload_image(ami_dir)
|
@@ -131,10 +153,10 @@ module BoxGrinder
|
|
131
153
|
|
132
154
|
remote_path = "#{s3_path(@plugin_config['path'])}#{File.basename(@deliverables[:package])}"
|
133
155
|
size_b = File.size(@deliverables[:package])
|
134
|
-
|
135
156
|
key = bucket(true, permissions).key(remote_path.gsub(/^\//, '').gsub(/\/\//, ''))
|
136
157
|
|
137
|
-
|
158
|
+
if !key.exists? or @plugin_config['overwrite']
|
159
|
+
@log.info "Will overwrite existing file #{remote_path}" if key.exists? and @plugin_config['overwrite']
|
138
160
|
@log.info "Uploading #{File.basename(@deliverables[:package])} (#{size_b/1024/1024}MB) to '#{@plugin_config['bucket']}#{remote_path}' path..."
|
139
161
|
key.put(open(@deliverables[:package]), permissions, :server => REGION_OPTIONS[@plugin_config['region']][:endpoint])
|
140
162
|
@log.info "Appliance #{@appliance_config.name} uploaded to S3."
|
@@ -185,6 +207,16 @@ module BoxGrinder
|
|
185
207
|
end
|
186
208
|
end
|
187
209
|
|
210
|
+
def deregister_image(ami_manifest_key)
|
211
|
+
info = ami_info(ami_manifest_key)
|
212
|
+
if info
|
213
|
+
@ec2.deregister_image(:image_id => info.imageId)
|
214
|
+
@log.info "Preexisting image '#{info.imageLocation}' for #{@appliance_config.name} was successfully de-registered, it had id: #{info.imageId} (region: #{@plugin_config['region']})."
|
215
|
+
else # This occurs when the AMI is de-registered externally but the file structure is left intact in S3. In this instance, we simply overwrite and register the image as if it were "new".
|
216
|
+
@log.info "Possible dangling/unregistered AMI skeleton structure in S3, there is nothing to deregister"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
188
220
|
def ami_info(ami_manifest_key)
|
189
221
|
ami_info = nil
|
190
222
|
|
@@ -210,12 +242,17 @@ module BoxGrinder
|
|
210
242
|
|
211
243
|
return "#{base_path}/#{@appliance_config.hardware.arch}" unless @plugin_config['snapshot']
|
212
244
|
|
245
|
+
@log.info "Determining snapshot name"
|
246
|
+
|
213
247
|
snapshot = 1
|
214
248
|
|
215
249
|
while s3_object_exists?("#{base_path}-SNAPSHOT-#{snapshot}/#{@appliance_config.hardware.arch}/")
|
216
250
|
snapshot += 1
|
217
251
|
end
|
218
252
|
|
253
|
+
# Reuse the last key (if there was one)
|
254
|
+
snapshot -=1 if snapshot > 1 and @plugin_config['overwrite']
|
255
|
+
|
219
256
|
"#{base_path}-SNAPSHOT-#{snapshot}/#{@appliance_config.hardware.arch}"
|
220
257
|
end
|
221
258
|
|
@@ -224,7 +261,7 @@ module BoxGrinder
|
|
224
261
|
|
225
262
|
begin
|
226
263
|
b = bucket(false)
|
227
|
-
# Retrieve only one or no keys (if bucket is empty), throw an exception if bucket doesn't
|
264
|
+
# Retrieve only one or no keys (if bucket is empty), throw an exception if bucket doesn't exist
|
228
265
|
b.keys('max-keys' => 1)
|
229
266
|
|
230
267
|
if b.key(path).exists?
|
@@ -239,4 +276,4 @@ module BoxGrinder
|
|
239
276
|
end
|
240
277
|
end
|
241
278
|
|
242
|
-
plugin :class => BoxGrinder::S3Plugin, :type => :delivery, :name => :s3, :full_name => "Amazon Simple Storage Service (Amazon S3)", :types => [:s3, :cloudfront, :ami]
|
279
|
+
plugin :class => BoxGrinder::S3Plugin, :type => :delivery, :name => :s3, :full_name => "Amazon Simple Storage Service (Amazon S3)", :types => [:s3, :cloudfront, :ami]
|
@@ -25,16 +25,18 @@ require 'boxgrinder-build/helpers/package-helper'
|
|
25
25
|
|
26
26
|
module BoxGrinder
|
27
27
|
class SFTPPlugin < BasePlugin
|
28
|
-
def
|
28
|
+
def validate
|
29
29
|
set_default_config_value('overwrite', false)
|
30
30
|
set_default_config_value('default_permissions', 0644)
|
31
31
|
|
32
|
-
|
32
|
+
validate_plugin_config(['path', 'username', 'host'], 'http://boxgrinder.org/tutorials/boxgrinder-build-plugins/#SFTP_Delivery_Plugin')
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
|
35
|
+
def after_init
|
36
|
+
register_deliverable(:package => "#{@appliance_config.name}-#{@appliance_config.version}.#{@appliance_config.release}-#{@appliance_config.os.name}-#{@appliance_config.os.version}-#{@appliance_config.hardware.arch}-#{current_platform}.tgz")
|
37
|
+
end
|
37
38
|
|
39
|
+
def execute
|
38
40
|
PackageHelper.new(@config, @appliance_config, :log => @log, :exec_helper => @exec_helper).package( File.dirname(@previous_deliverables[:disk]), @deliverables[:package] )
|
39
41
|
|
40
42
|
@log.info "Uploading #{@appliance_config.name} appliance via SSH..."
|
@@ -23,6 +23,7 @@ module BoxGrinder
|
|
23
23
|
def after_init
|
24
24
|
super
|
25
25
|
register_supported_os('fedora', ["13", "14", "15", "rawhide"])
|
26
|
+
set_default_config_value('PAE',true)
|
26
27
|
end
|
27
28
|
|
28
29
|
def execute(appliance_definition_file)
|
@@ -56,7 +57,7 @@ module BoxGrinder
|
|
56
57
|
if @appliance_config.is64bit?
|
57
58
|
packages << "kernel"
|
58
59
|
else
|
59
|
-
@
|
60
|
+
@plugin_config['PAE'] ? packages << "kernel-PAE" : packages << "kernel"
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
@@ -24,9 +24,8 @@ require 'zlib'
|
|
24
24
|
module BoxGrinder
|
25
25
|
|
26
26
|
class Kickstart
|
27
|
-
def initialize(config, appliance_config,
|
27
|
+
def initialize(config, appliance_config, dir, options = {})
|
28
28
|
@config = config
|
29
|
-
@repos = repos
|
30
29
|
@appliance_config = appliance_config
|
31
30
|
@dir = dir
|
32
31
|
@log = options[:log] || Logger.new(STDOUT)
|
@@ -59,11 +58,7 @@ module BoxGrinder
|
|
59
58
|
|
60
59
|
definition['mount_points'] = @linux_helper.partition_mount_points(@appliance_config.hardware.partitions)
|
61
60
|
|
62
|
-
|
63
|
-
repos += default_repos if @appliance_config.default_repos
|
64
|
-
repos += @appliance_config.repos
|
65
|
-
|
66
|
-
for repo in repos
|
61
|
+
for repo in @appliance_config.repos
|
67
62
|
if repo.keys.include?('mirrorlist')
|
68
63
|
urltype = 'mirrorlist'
|
69
64
|
else
|
@@ -92,30 +87,5 @@ module BoxGrinder
|
|
92
87
|
|
93
88
|
definition
|
94
89
|
end
|
95
|
-
|
96
|
-
def default_repos
|
97
|
-
os_repos = @repos[@appliance_config.os.version]
|
98
|
-
|
99
|
-
repos = Array.new
|
100
|
-
|
101
|
-
for type in ["base", "updates"]
|
102
|
-
unless os_repos.nil? or os_repos[type].nil?
|
103
|
-
|
104
|
-
mirrorlist = os_repos[type]['mirrorlist']
|
105
|
-
baseurl = os_repos[type]['baseurl']
|
106
|
-
|
107
|
-
name = "#{@appliance_config.os.name}-#{@appliance_config.os.version}-#{type}"
|
108
|
-
|
109
|
-
if mirrorlist.nil?
|
110
|
-
repos.push({"name" => name, "baseurl" => baseurl})
|
111
|
-
else
|
112
|
-
repos.push({"name" => name, "mirrorlist" => mirrorlist})
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
repos
|
118
|
-
end
|
119
90
|
end
|
120
|
-
|
121
91
|
end
|
@@ -25,8 +25,6 @@ require 'boxgrinder-build/helpers/linux-helper'
|
|
25
25
|
module BoxGrinder
|
26
26
|
class RPMBasedOSPlugin < BasePlugin
|
27
27
|
def after_init
|
28
|
-
set_default_config_value('format', 'raw')
|
29
|
-
|
30
28
|
register_deliverable(
|
31
29
|
:disk => "#{@appliance_config.name}-sda.#{@plugin_config['format']}",
|
32
30
|
:descriptor => "#{@appliance_config.name}.xml"
|
@@ -35,6 +33,10 @@ module BoxGrinder
|
|
35
33
|
@linux_helper = LinuxHelper.new(:log => @log)
|
36
34
|
end
|
37
35
|
|
36
|
+
def validate
|
37
|
+
set_default_config_value('format', 'raw')
|
38
|
+
end
|
39
|
+
|
38
40
|
def read_file(file)
|
39
41
|
read_kickstart(file) if File.extname(file).eql?('.ks')
|
40
42
|
end
|
@@ -88,12 +90,35 @@ module BoxGrinder
|
|
88
90
|
appliance_config
|
89
91
|
end
|
90
92
|
|
93
|
+
# Add default repos (if present) to the list of additional repositories specified in appliance definition.
|
94
|
+
def add_repos(repos)
|
95
|
+
return if repos.empty?
|
96
|
+
|
97
|
+
repos[@appliance_config.os.version].each do |name, repo|
|
98
|
+
r = { 'name' => name, 'ephemeral' => true }
|
99
|
+
|
100
|
+
['baseurl', 'mirrorlist'].each { |type| r[type] = substitute_vars(repo[type]) unless repo[type].nil? }
|
101
|
+
|
102
|
+
@appliance_config.repos << r
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Substitute variables in selected string.
|
107
|
+
def substitute_vars(str)
|
108
|
+
return if str.nil?
|
109
|
+
@appliance_config.variables.keys.each do |var|
|
110
|
+
str = str.gsub("##{var}#", @appliance_config.variables[var])
|
111
|
+
end
|
112
|
+
str
|
113
|
+
end
|
114
|
+
|
91
115
|
def build_with_appliance_creator(appliance_definition_file, repos = {})
|
92
116
|
if File.extname(appliance_definition_file).eql?('.ks')
|
93
117
|
kickstart_file = appliance_definition_file
|
94
118
|
else
|
95
|
-
|
96
|
-
|
119
|
+
add_repos(repos) if @appliance_config.default_repos
|
120
|
+
kickstart_file = Kickstart.new(@config, @appliance_config, @dir, :log => @log).create
|
121
|
+
RPMDependencyValidator.new(@config, @appliance_config, @dir, :log => @log).resolve_packages
|
97
122
|
end
|
98
123
|
|
99
124
|
@log.info "Building #{@appliance_config.name} appliance..."
|
@@ -16,6 +16,7 @@
|
|
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/helpers/log-helper'
|
19
20
|
require 'yaml'
|
20
21
|
|
21
22
|
module BoxGrinder
|
@@ -32,14 +33,13 @@ module BoxGrinder
|
|
32
33
|
end
|
33
34
|
|
34
35
|
class RPMDependencyValidator
|
35
|
-
def initialize( config, appliance_config, dir,
|
36
|
+
def initialize( config, appliance_config, dir, options = {} )
|
36
37
|
@config = config
|
37
38
|
@appliance_config = appliance_config
|
38
|
-
@kickstart_file = kickstart_file
|
39
39
|
@dir = dir
|
40
40
|
|
41
|
-
@log = options[:log] ||
|
42
|
-
@exec_helper = options[:exec_helper] || ExecHelper.new(
|
41
|
+
@log = options[:log] || LogHelper.new
|
42
|
+
@exec_helper = options[:exec_helper] || ExecHelper.new( :log => @log )
|
43
43
|
|
44
44
|
@yum_config_file = "#{@dir.tmp}/yum.conf"
|
45
45
|
|
@@ -51,18 +51,15 @@ module BoxGrinder
|
|
51
51
|
def resolve_packages
|
52
52
|
@log.info "Resolving packages added to #{@appliance_config.name} appliance definition file..."
|
53
53
|
|
54
|
-
repos = read_repos_from_kickstart_file
|
55
54
|
package_list = generate_package_list
|
56
|
-
|
55
|
+
generate_yum_config
|
57
56
|
|
58
|
-
|
57
|
+
invalid = invalid_names( @appliance_config.repos, package_list )
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
if invalid_names.size == 0
|
59
|
+
if invalid.empty?
|
63
60
|
@log.info "All additional packages for #{@appliance_config.name} appliance successfully resolved."
|
64
61
|
else
|
65
|
-
raise "Package#{
|
62
|
+
raise "Package#{invalid.size > 1 ? "s" : ""} #{invalid.join(', ')} for #{@appliance_config.name} appliance not found in repositories. Please check package names in appliance definition file."
|
66
63
|
end
|
67
64
|
end
|
68
65
|
|
@@ -75,7 +72,7 @@ module BoxGrinder
|
|
75
72
|
arches = "x86_64"
|
76
73
|
end
|
77
74
|
|
78
|
-
repoquery_output = @exec_helper.execute( "repoquery --quiet --disablerepo=* --enablerepo=#{
|
75
|
+
repoquery_output = @exec_helper.execute( "repoquery --quiet --disablerepo=* --enablerepo=#{@appliance_config.repos.collect {|r| "#{@magic_hash}#{r['name']}"}.join(",")} -c '#{@yum_config_file}' list available #{package_list.join( ' ' )} --nevra --archlist=#{arches},noarch" )
|
79
76
|
|
80
77
|
invalid_names = []
|
81
78
|
|
@@ -106,44 +103,16 @@ module BoxGrinder
|
|
106
103
|
packages
|
107
104
|
end
|
108
105
|
|
109
|
-
def
|
110
|
-
repo_list = ""
|
111
|
-
|
112
|
-
repos.each do |repo|
|
113
|
-
repo_list += "#{@magic_hash}#{repo.name},"
|
114
|
-
end
|
115
|
-
|
116
|
-
repo_list = repo_list[0, repo_list.length - 1]
|
117
|
-
end
|
118
|
-
|
119
|
-
def read_repos_from_kickstart_file
|
120
|
-
repos = `grep -e "^repo" '#{@kickstart_file}'`
|
121
|
-
repo_list = []
|
122
|
-
|
123
|
-
repos.each do |repo_line|
|
124
|
-
name = repo_line.match( /--name=([\w\-]+)/ )[1]
|
125
|
-
baseurl = repo_line.match( /--baseurl=([\w\-\:\/\.&\?=]+)/ )
|
126
|
-
mirrorlist = repo_line.match( /--mirrorlist=([\w\-\:\/\.&\?=]+)/ )
|
127
|
-
|
128
|
-
baseurl = baseurl[1] unless baseurl.nil?
|
129
|
-
mirrorlist = mirrorlist[1] unless mirrorlist.nil?
|
130
|
-
|
131
|
-
repo_list.push( Repo.new( name, baseurl, mirrorlist ) )
|
132
|
-
end
|
133
|
-
|
134
|
-
repo_list
|
135
|
-
end
|
136
|
-
|
137
|
-
def generate_yum_config( repo_list )
|
106
|
+
def generate_yum_config
|
138
107
|
File.open( @yum_config_file, "w") do |f|
|
139
108
|
|
140
109
|
f.puts( "[main]\r\ncachedir=#{Dir.pwd}/#{@dir.tmp}/#{@magic_hash}#{@appliance_config.hardware.arch}-yum-cache/\r\n\r\n" )
|
141
110
|
|
142
|
-
for repo in
|
143
|
-
f.puts( "[#{@magic_hash}#{repo
|
144
|
-
f.puts( "name=#{repo
|
145
|
-
f.puts( "baseurl=#{repo
|
146
|
-
f.puts( "mirrorlist=#{repo
|
111
|
+
for repo in @appliance_config.repos
|
112
|
+
f.puts( "[#{@magic_hash}#{repo['name']}]" )
|
113
|
+
f.puts( "name=#{repo['name']}" )
|
114
|
+
f.puts( "baseurl=#{repo['baseurl']}" ) unless repo['baseurl'].nil?
|
115
|
+
f.puts( "mirrorlist=#{repo['mirrorlist']}" ) unless repo['mirrorlist'].nil?
|
147
116
|
f.puts( "enabled=1" )
|
148
117
|
f.puts
|
149
118
|
end
|