boxgrinder-build 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +165 -0
- data/README +4 -0
- data/appliances/jeos.appl +22 -0
- data/appliances/meta.appl +41 -0
- data/bin/boxgrinder +23 -0
- data/docs/examples/appliances/appliances-appliance/appliances-appliance.appl +6 -0
- data/docs/examples/appliances/appliances-appliance/appliances-appliance.pp +16 -0
- data/docs/examples/appliances/minimal-appliance/minimal-appliance.appl +2 -0
- data/docs/examples/appliances/minimal-appliance/minimal-appliance.pp +16 -0
- data/docs/examples/appliances/mix-appliance/mix-appliance.appl +9 -0
- data/docs/examples/appliances/mix-appliance/mix-appliance.pp +16 -0
- data/docs/examples/appliances/packages-appliance/packages-appliance.appl +6 -0
- data/docs/examples/appliances/packages-appliance/packages-appliance.pp +16 -0
- data/docs/node-info/pom.xml +31 -0
- data/docs/node-info/src/main/webapp/META-INF/MANIFEST.MF +3 -0
- data/docs/node-info/src/main/webapp/WEB-INF/web.xml +7 -0
- data/docs/node-info/src/main/webapp/index.jsp +70 -0
- data/extras/sign-rpms +12 -0
- data/lib/boxgrinder-build/appliance-kickstart.rb +159 -0
- data/lib/boxgrinder-build/appliance.rb +52 -0
- data/lib/boxgrinder-build/boxgrinder.rb +92 -0
- data/lib/boxgrinder-build/erb/appliance.ks.erb +44 -0
- data/lib/boxgrinder-build/helpers/appliance-customize-helper.rb +92 -0
- data/lib/boxgrinder-build/helpers/aws-helper.rb +75 -0
- data/lib/boxgrinder-build/helpers/guestfs-helper.rb +86 -0
- data/lib/boxgrinder-build/helpers/rake-helper.rb +71 -0
- data/lib/boxgrinder-build/helpers/release-helper.rb +135 -0
- data/lib/boxgrinder-build/helpers/ssh-helper.rb +140 -0
- data/lib/boxgrinder-build/images/ec2-image.rb +301 -0
- data/lib/boxgrinder-build/images/raw-image.rb +137 -0
- data/lib/boxgrinder-build/images/vmware-image.rb +214 -0
- data/lib/boxgrinder-build/models/ssh-config.rb +44 -0
- data/lib/boxgrinder-build/validators/appliance-config-parameter-validator.rb +37 -0
- data/lib/boxgrinder-build/validators/appliance-definition-validator.rb +89 -0
- data/lib/boxgrinder-build/validators/appliance-dependency-validator.rb +163 -0
- data/lib/boxgrinder-build/validators/appliance-validator.rb +84 -0
- data/lib/boxgrinder-build/validators/aws-validator.rb +58 -0
- data/lib/boxgrinder-build/validators/config-validator.rb +67 -0
- data/lib/boxgrinder-build/validators/ssh-validator.rb +35 -0
- data/lib/boxgrinder-build/validators/validator.rb +91 -0
- data/lib/boxgrinder-build.rb +48 -0
- data/lib/progressbar/progressbar.rb +236 -0
- data/src/README.vmware +38 -0
- data/src/base.repo +4 -0
- data/src/base.vmdk +19 -0
- data/src/base.vmx +45 -0
- data/src/ec2/fstab_32bit +8 -0
- data/src/ec2/fstab_64bit +8 -0
- data/src/ec2/ifcfg-eth0 +7 -0
- data/src/ec2/rc_local +32 -0
- data/src/f12/yum.conf +24 -0
- data/src/motd.init +21 -0
- data/src/oddthesis/RPM-GPG-KEY-oddthesis +30 -0
- data/src/oddthesis/oddthesis.repo +23 -0
- metadata +197 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
# JBoss, Home of Professional Open Source
|
2
|
+
# Copyright 2009, Red Hat Middleware LLC, and individual contributors
|
3
|
+
# by the @authors tag. See the copyright.txt in the distribution for a
|
4
|
+
# full listing of individual contributors.
|
5
|
+
#
|
6
|
+
# This is free software; you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Lesser General Public License as
|
8
|
+
# published by the Free Software Foundation; either version 2.1 of
|
9
|
+
# the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This software is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this software; if not, write to the Free
|
18
|
+
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
19
|
+
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
20
|
+
|
21
|
+
require 'rake/tasklib'
|
22
|
+
|
23
|
+
require 'boxgrinder-build/appliance-kickstart.rb'
|
24
|
+
require 'boxgrinder-build/images/raw-image.rb'
|
25
|
+
require 'boxgrinder-build/images/vmware-image'
|
26
|
+
require 'boxgrinder-build/images/ec2-image'
|
27
|
+
require 'boxgrinder-build/helpers/release-helper'
|
28
|
+
require 'boxgrinder-build/validators/appliance-dependency-validator'
|
29
|
+
|
30
|
+
module BoxGrinder
|
31
|
+
class Appliance < Rake::TaskLib
|
32
|
+
|
33
|
+
def initialize( config, appliance_config, options = {} )
|
34
|
+
@config = config
|
35
|
+
@appliance_config = appliance_config
|
36
|
+
@log = options[:log] || Logger.new(STDOUT)
|
37
|
+
|
38
|
+
define
|
39
|
+
end
|
40
|
+
|
41
|
+
def define
|
42
|
+
ApplianceKickstart.new( @config, @appliance_config, :log => @log )
|
43
|
+
ApplianceDependencyValidator.new( @config, @appliance_config, :log => @log )
|
44
|
+
|
45
|
+
RAWImage.new( @config, @appliance_config, :log => @log )
|
46
|
+
VMwareImage.new( @config, @appliance_config, :log => @log )
|
47
|
+
EC2Image.new( @config, @appliance_config, :log => @log )
|
48
|
+
|
49
|
+
ReleaseHelper.new( @config, @appliance_config, :log => @log )
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# JBoss, Home of Professional Open Source
|
2
|
+
# Copyright 2009, Red Hat Middleware LLC, and individual contributors
|
3
|
+
# by the @authors tag. See the copyright.txt in the distribution for a
|
4
|
+
# full listing of individual contributors.
|
5
|
+
#
|
6
|
+
# This is free software; you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Lesser General Public License as
|
8
|
+
# published by the Free Software Foundation; either version 2.1 of
|
9
|
+
# the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This software is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this software; if not, write to the Free
|
18
|
+
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
19
|
+
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
20
|
+
|
21
|
+
require 'rake'
|
22
|
+
require 'boxgrinder-core/defaults'
|
23
|
+
require 'boxgrinder-core/models/config'
|
24
|
+
require 'boxgrinder-core/models/appliance-config'
|
25
|
+
require 'boxgrinder-core/helpers/appliance-config-helper'
|
26
|
+
require 'boxgrinder-build/appliance'
|
27
|
+
require 'boxgrinder-build/validators/validator'
|
28
|
+
require 'boxgrinder-build/validators/appliance-config-parameter-validator'
|
29
|
+
require 'boxgrinder-build/validators/appliance-definition-validator'
|
30
|
+
require 'boxgrinder-build/helpers/rake-helper'
|
31
|
+
require 'ostruct'
|
32
|
+
require 'yaml'
|
33
|
+
|
34
|
+
$stderr.reopen($stdout)
|
35
|
+
|
36
|
+
module BoxGrinder
|
37
|
+
class BoxGrinder
|
38
|
+
def initialize( project_config = Hash.new )
|
39
|
+
@log = LOG
|
40
|
+
# validates parameters, this is a pre-validation
|
41
|
+
ApplianceConfigParameterValidator.new.validate
|
42
|
+
|
43
|
+
name = project_config[:name] || DEFAULT_PROJECT_CONFIG[:name]
|
44
|
+
version = project_config[:version] || DEFAULT_PROJECT_CONFIG[:version]
|
45
|
+
release = project_config[:release] || DEFAULT_PROJECT_CONFIG[:release]
|
46
|
+
|
47
|
+
# dirs
|
48
|
+
|
49
|
+
dir = OpenStruct.new
|
50
|
+
dir.root = `pwd`.strip
|
51
|
+
dir.base = "#{File.dirname( __FILE__ )}/../../"
|
52
|
+
dir.build = project_config[:dir_build] || DEFAULT_PROJECT_CONFIG[:dir_build]
|
53
|
+
dir.top = project_config[:dir_top] || "#{dir.build}/topdir"
|
54
|
+
dir.src_cache = project_config[:dir_src_cache] || DEFAULT_PROJECT_CONFIG[:dir_src_cache]
|
55
|
+
dir.rpms_cache = project_config[:dir_rpms_cache] || DEFAULT_PROJECT_CONFIG[:dir_rpms_cache]
|
56
|
+
dir.specs = project_config[:dir_specs] || DEFAULT_PROJECT_CONFIG[:dir_specs]
|
57
|
+
dir.appliances = project_config[:dir_appliances] || DEFAULT_PROJECT_CONFIG[:dir_appliances]
|
58
|
+
dir.src = project_config[:dir_src] || DEFAULT_PROJECT_CONFIG[:dir_src]
|
59
|
+
dir.kickstarts = project_config[:dir_kickstarts] || DEFAULT_PROJECT_CONFIG[:dir_kickstarts]
|
60
|
+
|
61
|
+
config_file = ENV['BG_CONFIG_FILE'] || "#{ENV['HOME']}/.boxgrinder/config"
|
62
|
+
|
63
|
+
@config = Config.new( name, version, release, dir, config_file )
|
64
|
+
|
65
|
+
define_rules
|
66
|
+
end
|
67
|
+
|
68
|
+
def define_rules
|
69
|
+
Validator.new( @config, :log => @log )
|
70
|
+
|
71
|
+
Rake::Task[ 'validate:all' ].invoke
|
72
|
+
|
73
|
+
directory @config.dir.build
|
74
|
+
|
75
|
+
definitions = {}
|
76
|
+
|
77
|
+
Dir[ "#{@config.dir.appliances}/**/*.appl", "#{@config.dir.base}/appliances/*.appl" ].each do |file|
|
78
|
+
definition = YAML.load_file( file )
|
79
|
+
|
80
|
+
ApplianceDefinitionValidator.new( definition ).validate
|
81
|
+
|
82
|
+
definitions[definition['name']] = definition
|
83
|
+
end
|
84
|
+
|
85
|
+
for definition in definitions.values
|
86
|
+
Appliance.new( @config, ApplianceConfigHelper.new( definitions ).merge( ApplianceConfig.new( definition ).init_arch ).initialize_paths, :log => @log )
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
attr_reader :config
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
lang en_US.UTF-8
|
2
|
+
keyboard us
|
3
|
+
timezone US/Eastern
|
4
|
+
auth --useshadow --enablemd5
|
5
|
+
selinux --permissive
|
6
|
+
firewall --disabled
|
7
|
+
bootloader --timeout=1 --append="acpi=force scsi_mod.scan=sync"
|
8
|
+
firstboot --disabled
|
9
|
+
|
10
|
+
<% if graphical %>
|
11
|
+
xconfig --startxonboot
|
12
|
+
services --enabled=NetworkManager --disabled=network,sshd
|
13
|
+
<% else %>
|
14
|
+
network --bootproto=dhcp --device=eth0 --onboot=on
|
15
|
+
services --enabled=network
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
rootpw <%= root_password %>
|
19
|
+
|
20
|
+
<% for partition in partitions %>
|
21
|
+
part <%= partition['root'] %> --size <%= partition['size'].to_i * 1024 %> --fstype <%= fstype %> --ondisk sda<% end %>
|
22
|
+
|
23
|
+
<% for user in users %>
|
24
|
+
user --name=<%= user['name'] %><% unless user['home'].nil? %> --homedir=<%= user['home'] %><% end %><% unless user['group'].nil? %> --groups=<%= user['group'] %><% end %><% end unless users.nil? %>
|
25
|
+
|
26
|
+
<% for repo in repos %>
|
27
|
+
<%= repo %><% end %>
|
28
|
+
|
29
|
+
<% if graphical %>
|
30
|
+
%packages --excludedocs
|
31
|
+
<% else %>
|
32
|
+
%packages --excludedocs --nobase
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
<% for package in packages %>
|
36
|
+
<%= package %><% end %>
|
37
|
+
%end
|
38
|
+
%post
|
39
|
+
|
40
|
+
<% if graphical %>
|
41
|
+
chkconfig --level 345 firstboot off 2>/dev/null<% end %>
|
42
|
+
|
43
|
+
%end
|
44
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# JBoss, Home of Professional Open Source
|
2
|
+
# Copyright 2009, Red Hat Middleware LLC, and individual contributors
|
3
|
+
# by the @authors tag. See the copyright.txt in the distribution for a
|
4
|
+
# full listing of individual contributors.
|
5
|
+
#
|
6
|
+
# This is free software; you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Lesser General Public License as
|
8
|
+
# published by the Free Software Foundation; either version 2.1 of
|
9
|
+
# the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This software is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this software; if not, write to the Free
|
18
|
+
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
19
|
+
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
20
|
+
|
21
|
+
require 'rake/tasklib'
|
22
|
+
require 'boxgrinder-core/validators/errors'
|
23
|
+
require 'boxgrinder-build/helpers/guestfs-helper'
|
24
|
+
require 'tempfile'
|
25
|
+
|
26
|
+
module BoxGrinder
|
27
|
+
class ApplianceCustomizeHelper < Rake::TaskLib
|
28
|
+
|
29
|
+
def initialize( config, appliance_config, disk, options = {} )
|
30
|
+
@config = config
|
31
|
+
@appliance_config = appliance_config
|
32
|
+
@disk = disk
|
33
|
+
|
34
|
+
@log = options[:log] || Logger.new(STDOUT)
|
35
|
+
@exec_helper = options[:exec_helper] || ExecHelper.new( { :log => @log } )
|
36
|
+
end
|
37
|
+
|
38
|
+
def customize
|
39
|
+
@guestfs_helper = GuestFSHelper.new( @disk, :log => @log )
|
40
|
+
@guestfs = @guestfs_helper.guestfs
|
41
|
+
|
42
|
+
yield self, @guestfs
|
43
|
+
|
44
|
+
@guestfs.close
|
45
|
+
end
|
46
|
+
|
47
|
+
def validate_options( options )
|
48
|
+
options = {
|
49
|
+
:packages => {},
|
50
|
+
:repos => []
|
51
|
+
}.merge(options)
|
52
|
+
|
53
|
+
options[:packages][:yum] = options[:packages][:yum] || []
|
54
|
+
options[:packages][:yum_local] = options[:packages][:yum_local] || []
|
55
|
+
options[:packages][:rpm] = options[:packages][:rpm] || []
|
56
|
+
|
57
|
+
if ( options[:packages][:yum_local].size == 0 and options[:packages][:rpm].size == 0 and options[:packages][:yum].size == 0 and options[:repos].size == 0)
|
58
|
+
@log.debug "No additional local or remote packages or gems to install, skipping..."
|
59
|
+
return false
|
60
|
+
end
|
61
|
+
|
62
|
+
true
|
63
|
+
end
|
64
|
+
|
65
|
+
def install_packages( options = {} )
|
66
|
+
# silent return, we don't have any packages to install
|
67
|
+
return unless validate_options( options )
|
68
|
+
|
69
|
+
@guestfs_helper.rebuild_rpm_database
|
70
|
+
|
71
|
+
for repo in options[:repos]
|
72
|
+
@log.debug "Installing repo file '#{repo}'..."
|
73
|
+
@guestfs.sh( "rpm -Uvh #{repo}" )
|
74
|
+
@log.debug "Repo file '#{repo}' installed."
|
75
|
+
end unless options[:repos].nil?
|
76
|
+
|
77
|
+
unless options[:packages].nil?
|
78
|
+
for yum_package in options[:packages][:yum]
|
79
|
+
@log.debug "Installing package '#{yum_package}'..."
|
80
|
+
@guestfs.sh( "yum -y install #{yum_package}" )
|
81
|
+
@log.debug "Package '#{yum_package}' installed."
|
82
|
+
end unless options[:packages][:yum].nil?
|
83
|
+
|
84
|
+
for package in options[:packages][:rpm]
|
85
|
+
@log.debug "Installing package '#{package}'..."
|
86
|
+
@guestfs.sh( "rpm -Uvh --force #{package}" )
|
87
|
+
@log.debug "Package '#{package}' installed."
|
88
|
+
end unless options[:packages][:rpm].nil?
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# JBoss, Home of Professional Open Source
|
2
|
+
# Copyright 2009, Red Hat Middleware LLC, and individual contributors
|
3
|
+
# by the @authors tag. See the copyright.txt in the distribution for a
|
4
|
+
# full listing of individual contributors.
|
5
|
+
#
|
6
|
+
# This is free software; you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Lesser General Public License as
|
8
|
+
# published by the Free Software Foundation; either version 2.1 of
|
9
|
+
# the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This software is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this software; if not, write to the Free
|
18
|
+
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
19
|
+
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
20
|
+
|
21
|
+
require 'AWS'
|
22
|
+
require 'aws/s3'
|
23
|
+
require 'boxgrinder-core/defaults'
|
24
|
+
require 'boxgrinder-build/validators/aws-validator'
|
25
|
+
|
26
|
+
module BoxGrinder
|
27
|
+
class AWSHelper
|
28
|
+
def initialize( config, appliance_config )
|
29
|
+
@config = config
|
30
|
+
@appliance_config = appliance_config
|
31
|
+
|
32
|
+
aws_validator = AWSValidator.new( @config )
|
33
|
+
aws_validator.validate_aws_config( @config.data['aws'] )
|
34
|
+
aws_validator.validate_aws_release_config( @config.data['release'] )
|
35
|
+
|
36
|
+
@aws_data = @config.data['aws']
|
37
|
+
|
38
|
+
# remove dashes from account number
|
39
|
+
@aws_data['account_number'] = @aws_data['account_number'].to_s.gsub(/-/, '')
|
40
|
+
|
41
|
+
@ec2 = AWS::EC2::Base.new(:access_key_id => @aws_data['access_key'], :secret_access_key => @aws_data['secret_access_key'])
|
42
|
+
@s3 = AWS::S3::Base.establish_connection!(:access_key_id => @aws_data['access_key'], :secret_access_key => @aws_data['secret_access_key'] )
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_reader :aws_data
|
46
|
+
attr_reader :ec2
|
47
|
+
attr_reader :s3
|
48
|
+
|
49
|
+
def bucket_key( appliance_name )
|
50
|
+
"#{@config.release.s3['bucket_name']}/#{@config.version_with_release}/#{@appliance_config.hardware.arch}/#{appliance_name}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def bucket_manifest_key( appliance_name )
|
54
|
+
"#{bucket_key( appliance_name )}/#{appliance_name}.ec2.manifest.xml"
|
55
|
+
end
|
56
|
+
|
57
|
+
def appliance_is_registered?( appliance_name )
|
58
|
+
!ami_info( appliance_name ).nil?
|
59
|
+
end
|
60
|
+
|
61
|
+
def ami_info( appliance_name )
|
62
|
+
ami_info = nil
|
63
|
+
|
64
|
+
images = @ec2.describe_images( :owner_id => @aws_data['account_number'] ).imagesSet
|
65
|
+
|
66
|
+
return nil if images.nil?
|
67
|
+
|
68
|
+
for image in images.item do
|
69
|
+
ami_info = image if (image.imageLocation.eql?( bucket_manifest_key( appliance_name ) ))
|
70
|
+
end
|
71
|
+
|
72
|
+
ami_info
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# JBoss, Home of Professional Open Source
|
2
|
+
# Copyright 2009, Red Hat Middleware LLC, and individual contributors
|
3
|
+
# by the @authors tag. See the copyright.txt in the distribution for a
|
4
|
+
# full listing of individual contributors.
|
5
|
+
#
|
6
|
+
# This is free software; you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Lesser General Public License as
|
8
|
+
# published by the Free Software Foundation; either version 2.1 of
|
9
|
+
# the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This software is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this software; if not, write to the Free
|
18
|
+
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
19
|
+
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
20
|
+
|
21
|
+
require 'guestfs'
|
22
|
+
|
23
|
+
module BoxGrinder
|
24
|
+
class GuestFSHelper
|
25
|
+
def initialize( raw_disk, options = {} )
|
26
|
+
@raw_disk = raw_disk
|
27
|
+
@log = options[:log] || Logger.new(STDOUT)
|
28
|
+
|
29
|
+
launch
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_reader :guestfs
|
33
|
+
|
34
|
+
def launch
|
35
|
+
@log.debug "Preparing guestfs..."
|
36
|
+
@guestfs = Guestfs::create
|
37
|
+
|
38
|
+
# TODO remove this, https://bugzilla.redhat.com/show_bug.cgi?id=502058
|
39
|
+
@guestfs.set_append( "noapic" )
|
40
|
+
|
41
|
+
# workaround for latest qemu
|
42
|
+
# It'll only work if qemu-stable package is installed. It is installed by default on meta-appliance
|
43
|
+
# TODO wait for stable qemu and remove this
|
44
|
+
qemu_wrapper = "/usr/share/qemu-stable/bin/qemu.wrapper"
|
45
|
+
|
46
|
+
if File.exists?( qemu_wrapper )
|
47
|
+
@guestfs.set_qemu( qemu_wrapper )
|
48
|
+
end
|
49
|
+
|
50
|
+
@log.debug "Adding drive '#{@raw_disk}'..."
|
51
|
+
@guestfs.add_drive( @raw_disk )
|
52
|
+
@log.debug "Drive added."
|
53
|
+
|
54
|
+
@log.debug "Launching guestfs..."
|
55
|
+
@guestfs.launch
|
56
|
+
@log.debug "Waiting for guestfs..."
|
57
|
+
@guestfs.wait_ready
|
58
|
+
@log.debug "Guestfs launched."
|
59
|
+
|
60
|
+
if @guestfs.list_partitions.size > 0
|
61
|
+
partition_to_mount = "/dev/sda1"
|
62
|
+
else
|
63
|
+
partition_to_mount = "/dev/sda"
|
64
|
+
end
|
65
|
+
|
66
|
+
@log.debug "Mounting root partition..."
|
67
|
+
@guestfs.mount( partition_to_mount, "/" )
|
68
|
+
@log.debug "Root partition mounted."
|
69
|
+
|
70
|
+
# TODO is this really needed?
|
71
|
+
@log.debug "Uploading '/etc/resolv.conf'..."
|
72
|
+
@guestfs.upload( "/etc/resolv.conf", "/etc/resolv.conf" )
|
73
|
+
@log.debug "'/etc/resolv.conf' uploaded."
|
74
|
+
|
75
|
+
@log.debug "Guestfs launched."
|
76
|
+
end
|
77
|
+
|
78
|
+
# TODO this is shitty, I know... https://bugzilla.redhat.com/show_bug.cgi?id=507188
|
79
|
+
def rebuild_rpm_database
|
80
|
+
@log.debug "Cleaning RPM database..."
|
81
|
+
@guestfs.sh( "rm -f /var/lib/rpm/__db.*" )
|
82
|
+
@guestfs.sh( "rpm --rebuilddb" )
|
83
|
+
@log.debug "Cleaning RPM database finished."
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# JBoss, Home of Professional Open Source
|
2
|
+
# Copyright 2009, Red Hat Middleware LLC, and individual contributors
|
3
|
+
# by the @authors tag. See the copyright.txt in the distribution for a
|
4
|
+
# full listing of individual contributors.
|
5
|
+
#
|
6
|
+
# This is free software; you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Lesser General Public License as
|
8
|
+
# published by the Free Software Foundation; either version 2.1 of
|
9
|
+
# the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This software is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this software; if not, write to the Free
|
18
|
+
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
19
|
+
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
20
|
+
|
21
|
+
require 'rubygems'
|
22
|
+
require 'boxgrinder-build/boxgrinder'
|
23
|
+
require 'boxgrinder-core/helpers/log-helper'
|
24
|
+
|
25
|
+
gem 'amazon-ec2', '>= 0.9.6'
|
26
|
+
gem 'aws-s3', '>= 0.6.2'
|
27
|
+
gem 'net-sftp', '>= 2.0.4'
|
28
|
+
gem 'net-ssh', '>= 2.0.20'
|
29
|
+
|
30
|
+
module Rake
|
31
|
+
class Task
|
32
|
+
alias_method :execute_original_boxgrinder, :execute
|
33
|
+
|
34
|
+
def execute( args = nil )
|
35
|
+
begin
|
36
|
+
execute_original_boxgrinder( args )
|
37
|
+
rescue => e
|
38
|
+
log = BoxGrinder::LOG
|
39
|
+
log.fatal e.info
|
40
|
+
log.fatal "Aborting: #{e.message}. See previous errors for more information."
|
41
|
+
abort
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module BoxGrinder
|
48
|
+
|
49
|
+
LOG = LogHelper.new
|
50
|
+
|
51
|
+
class RakeHelper
|
52
|
+
def initialize( project_config = {} )
|
53
|
+
log = LOG
|
54
|
+
begin
|
55
|
+
log.debug "Running new Rake session..."
|
56
|
+
@config = BoxGrinder.new( project_config ).config
|
57
|
+
rescue ValidationError => e
|
58
|
+
log.fatal "ValidationError: #{e.message}."
|
59
|
+
abort
|
60
|
+
rescue => e
|
61
|
+
log.fatal e
|
62
|
+
log.fatal "Aborting: #{e.message}. See previous errors for more information."
|
63
|
+
abort
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
attr_reader :config
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# JBoss, Home of Professional Open Source
|
2
|
+
# Copyright 2009, Red Hat Middleware LLC, and individual contributors
|
3
|
+
# by the @authors tag. See the copyright.txt in the distribution for a
|
4
|
+
# full listing of individual contributors.
|
5
|
+
#
|
6
|
+
# This is free software; you can redistribute it and/or modify it
|
7
|
+
# under the terms of the GNU Lesser General Public License as
|
8
|
+
# published by the Free Software Foundation; either version 2.1 of
|
9
|
+
# the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This software is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this software; if not, write to the Free
|
18
|
+
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
19
|
+
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
20
|
+
|
21
|
+
require 'rake/tasklib'
|
22
|
+
require 'boxgrinder-core/validators/errors'
|
23
|
+
require 'boxgrinder-build/validators/ssh-validator'
|
24
|
+
require 'boxgrinder-build/models/ssh-config'
|
25
|
+
require 'boxgrinder-build/helpers/ssh-helper'
|
26
|
+
|
27
|
+
module BoxGrinder
|
28
|
+
class ReleaseHelper < Rake::TaskLib
|
29
|
+
def initialize( config, appliance_config, options = {} )
|
30
|
+
@config = config
|
31
|
+
@appliance_config = appliance_config
|
32
|
+
|
33
|
+
@log = options[:log] || Logger.new(STDOUT)
|
34
|
+
@exec_helper = options[:exec_helper] || ExecHelper.new( { :log => @log } )
|
35
|
+
|
36
|
+
@package_build_commands = {
|
37
|
+
:raw => {
|
38
|
+
:tgz => "tar -C #{@appliance_config.path.dir.raw.build_full} -cvzf #{@appliance_config.path.file.package[:raw][:tgz]} #{@appliance_config.name}-sda.raw #{@appliance_config.name}.xml",
|
39
|
+
:zip => "cd #{@appliance_config.path.dir.raw.build_full} && zip -r #{Dir.pwd}/#{@appliance_config.path.file.package[:raw][:zip]} ."
|
40
|
+
},
|
41
|
+
:vmware => {
|
42
|
+
:tgz => "tar -C #{@appliance_config.path.dir.vmware.build} -cvzf '#{@appliance_config.path.file.package[:vmware][:tgz]}' README #{@appliance_config.name}-sda.raw personal/#{@appliance_config.name}.vmx personal/#{@appliance_config.name}.vmdk enterprise/#{@appliance_config.name}.vmx enterprise/#{@appliance_config.name}.vmdk",
|
43
|
+
:zip => "cd #{@appliance_config.path.dir.vmware.build} && zip #{Dir.pwd}/#{@appliance_config.path.file.package[:vmware][:zip]} README #{@appliance_config.name}-sda.raw personal/#{@appliance_config.name}.vmx personal/#{@appliance_config.name}.vmdk enterprise/#{@appliance_config.name}.vmx enterprise/#{@appliance_config.name}.vmdk"
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
@base_remote_file_path = "#{@config.version_with_release}/#{@appliance_config.hardware.arch}"
|
48
|
+
|
49
|
+
define_tasks
|
50
|
+
end
|
51
|
+
|
52
|
+
def define_tasks
|
53
|
+
|
54
|
+
directory @appliance_config.path.dir.packages
|
55
|
+
|
56
|
+
[ :tgz, :zip ].each do |package_format|
|
57
|
+
task "appliance:#{@appliance_config.name}:package:#{package_format}" => [ @appliance_config.path.file.package[:raw][package_format], @appliance_config.path.file.package[:vmware][package_format] ]
|
58
|
+
|
59
|
+
[ :vmware, :raw ].each do |image_format|
|
60
|
+
basename = File.basename( @appliance_config.path.file.package[image_format][package_format] )
|
61
|
+
files_to_upload = { basename => @appliance_config.path.file.package[image_format][package_format] }
|
62
|
+
|
63
|
+
desc "Create #{image_format.to_s.upcase} #{package_format.to_s.upcase} package for #{@appliance_config.simple_name} appliance"
|
64
|
+
task "appliance:#{@appliance_config.name}:package:#{image_format}:#{package_format}" => [ @appliance_config.path.file.package[image_format][package_format] ]
|
65
|
+
|
66
|
+
file @appliance_config.path.file.package[image_format][package_format] => [ @appliance_config.path.dir.packages, "appliance:#{@appliance_config.name}" ] do
|
67
|
+
@log.info "Packaging #{@appliance_config.name} appliance #{image_format.to_s.upcase} image (#{@appliance_config.os.name} #{@appliance_config.os.version}, #{@appliance_config.hardware.arch} arch, #{package_format.to_s.upcase} format)..."
|
68
|
+
|
69
|
+
Rake::Task[ "#{@appliance_config.path.dir.vmware.build}/README" ].invoke if image_format.eql?(:vmware)
|
70
|
+
|
71
|
+
@exec_helper.execute @package_build_commands[image_format][package_format]
|
72
|
+
@log.info "#{image_format.to_s.upcase} #{package_format.to_s.upcase} package created."
|
73
|
+
end
|
74
|
+
|
75
|
+
task "appliance:#{@appliance_config.name}:upload:#{image_format}:#{package_format}:ssh" => [ "appliance:#{@appliance_config.name}:package:#{image_format}:#{package_format}" ] do
|
76
|
+
upload_via_ssh( files_to_upload )
|
77
|
+
end
|
78
|
+
|
79
|
+
task "appliance:#{@appliance_config.name}:upload:#{image_format}:#{package_format}:cloudfront" => [ "appliance:#{@appliance_config.name}:package:#{image_format}:#{package_format}" ] do
|
80
|
+
upload_to_cloudfront( files_to_upload )
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
file "#{@appliance_config.path.dir.vmware.build}/README" => [ "appliance:#{@appliance_config.name}:vmware:personal", "appliance:#{@appliance_config.name}:vmware:enterprise" ] do
|
86
|
+
readme = File.open( "#{@config.dir.base}/src/README.vmware" ).read
|
87
|
+
|
88
|
+
readme.gsub!( /#APPLIANCE_NAME#/, @appliance_config.name )
|
89
|
+
readme.gsub!( /#NAME#/, @config.name )
|
90
|
+
readme.gsub!( /#VERSION#/, @config.version_with_release )
|
91
|
+
|
92
|
+
File.open( "#{@appliance_config.path.dir.vmware.build}/README", "w") {|f| f.write( readme ) }
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
def upload_via_ssh( files )
|
98
|
+
@log.info "Uploading #{@appliance_config.name} appliance via SSH..."
|
99
|
+
|
100
|
+
SSHValidator.new( @config ).validate
|
101
|
+
|
102
|
+
ssh_config = SSHConfig.new( @config )
|
103
|
+
|
104
|
+
ssh_helper = SSHHelper.new( ssh_config.options, { :log => @log } )
|
105
|
+
ssh_helper.connect
|
106
|
+
ssh_helper.upload_files( ssh_config.cfg['remote_release_path'], files )
|
107
|
+
ssh_helper.disconnect
|
108
|
+
|
109
|
+
@log.info "Appliance #{@appliance_config.simple_name} uploaded."
|
110
|
+
end
|
111
|
+
|
112
|
+
def upload_to_cloudfront( files )
|
113
|
+
|
114
|
+
bucket = @config.release.cloudfront['bucket_name']
|
115
|
+
|
116
|
+
@log.info "Uploading #{@appliance_config.name} appliance to CloudFront bucket '#{bucket}'..."
|
117
|
+
|
118
|
+
begin
|
119
|
+
AWS::S3::Bucket.find( bucket )
|
120
|
+
rescue AWS::S3::NoSuchBucket
|
121
|
+
AWS::S3::Bucket.create( bucket )
|
122
|
+
retry
|
123
|
+
end
|
124
|
+
|
125
|
+
for key in files.keys
|
126
|
+
unless S3Object.exists?( key, bucket )
|
127
|
+
AWS::S3::S3Object.store( key, open( files[key] ), bucket, :access => :public_read )
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
@log.info "Appliance #{@appliance_config.simple_name} uploaded."
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|