boxgrinder-build 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +6 -3
- data/bin/boxgrinder-build +6 -5
- data/lib/boxgrinder-build/plugins/delivery/s3/aws-helper.rb +8 -14
- data/lib/boxgrinder-build/plugins/delivery/s3/s3-plugin.rb +57 -18
- data/lib/boxgrinder-build/plugins/platform/ec2/ec2-plugin.rb +6 -8
- metadata +5 -6
- data/lib/boxgrinder-build/validators/aws-validator.rb +0 -51
data/README
CHANGED
data/bin/boxgrinder-build
CHANGED
@@ -26,7 +26,7 @@ require 'boxgrinder-core/helpers/log-helper'
|
|
26
26
|
require 'boxgrinder-build/helpers/plugin-helper'
|
27
27
|
require 'boxgrinder-build/appliance'
|
28
28
|
|
29
|
-
gem 'boxgrinder-core', '>= 0.0.
|
29
|
+
gem 'boxgrinder-core', '>= 0.0.8'
|
30
30
|
gem 'aws-s3', '>= 0.6.2'
|
31
31
|
gem 'amazon-ec2', '>= 0.9.6'
|
32
32
|
gem 'net-sftp', '>= 2.0.4'
|
@@ -44,7 +44,9 @@ program :version, '0.3.0'
|
|
44
44
|
program :description, 'A tool for building VM images from simple definition files.'
|
45
45
|
default_command :build
|
46
46
|
|
47
|
-
|
47
|
+
$verbose = false
|
48
|
+
|
49
|
+
global_option('-V', '--verbose', TrueClass, "Prints verbose information while building. Default: false.") { $verbose = true}
|
48
50
|
|
49
51
|
module BoxGrinder
|
50
52
|
log = LogHelper.new
|
@@ -58,14 +60,13 @@ module BoxGrinder
|
|
58
60
|
c.option '-p STRING', '--platform STRING', String, "The type of platform. Valid types are: #{PlatformPluginManager.instance.plugins.keys.join(', ')}. Default: none."
|
59
61
|
c.option '-d STRING', '--delivery STRING', String, "The delivery type for selected image. Valid types are: #{DeliveryPluginManager.instance.types.keys.join(', ')}. Default: none."
|
60
62
|
c.option '-f', '--force', TrueClass, "Force image creation - removes all previous builds for selected appliance. Default: false."
|
61
|
-
#c.option '-V', '--verbose', TrueClass, "Prints verbose information while building. Default: false."
|
62
63
|
|
63
64
|
c.action do |args, options|
|
64
65
|
options.default :platform => :none
|
65
66
|
options.default :delivery => :none
|
66
67
|
options.default :force => false
|
67
|
-
options.default :verbose => false
|
68
68
|
|
69
|
+
options.verbose = $verbose
|
69
70
|
options.platform = options.platform.to_s.downcase.to_sym
|
70
71
|
options.delivery = options.delivery.to_s.downcase.to_sym
|
71
72
|
|
@@ -75,7 +76,7 @@ module BoxGrinder
|
|
75
76
|
raise "Not known platform: #{options.platform}. Available platforms: #{PlatformPluginManager.instance.plugins.keys.join(', ')}." if PlatformPluginManager.instance.plugins[options.platform].nil? and options.platform != :none
|
76
77
|
raise "Not known delivery type: #{options.delivery}. Available types: #{DeliveryPluginManager.instance.types.keys.join(', ')}." if DeliveryPluginManager.instance.types.keys.include?(options.delivery).nil? and options.delivery != :none
|
77
78
|
|
78
|
-
Appliance.new( appliance_definition_file, :options => options, :log =>
|
79
|
+
Appliance.new( appliance_definition_file, :options => options, :log => LogHelper.new( :threshold => $verbose ? :debug : :info ) ).create
|
79
80
|
end
|
80
81
|
end
|
81
82
|
end
|
@@ -20,33 +20,27 @@
|
|
20
20
|
|
21
21
|
require 'AWS'
|
22
22
|
require 'aws/s3'
|
23
|
-
require 'boxgrinder-core/defaults'
|
24
|
-
require 'boxgrinder-build/validators/aws-validator'
|
25
23
|
|
26
24
|
module BoxGrinder
|
27
25
|
class AWSHelper
|
28
|
-
def initialize( config, appliance_config )
|
26
|
+
def initialize( config, appliance_config, plugin_config )
|
29
27
|
@config = config
|
30
28
|
@appliance_config = appliance_config
|
31
|
-
|
32
|
-
aws_validator = AWSValidator.new( @config )
|
33
|
-
aws_validator.validate_aws_config( @config.data['aws'] )
|
34
|
-
|
35
|
-
@aws_data = @config.data['aws']
|
29
|
+
@plugin_config = plugin_config
|
36
30
|
|
37
31
|
# remove dashes from account number
|
38
|
-
@
|
32
|
+
@plugin_config['account_number'] = @plugin_config['account_number'].to_s.gsub(/-/, '')
|
39
33
|
|
40
|
-
@ec2 = AWS::EC2::Base.new(:access_key_id => @
|
41
|
-
@s3 = AWS::S3::Base.establish_connection!(:access_key_id => @
|
34
|
+
@ec2 = AWS::EC2::Base.new(:access_key_id => @plugin_config['access_key'], :secret_access_key => @plugin_config['secret_access_key'])
|
35
|
+
@s3 = AWS::S3::Base.establish_connection!(:access_key_id => @plugin_config['access_key'], :secret_access_key => @plugin_config['secret_access_key'] )
|
42
36
|
end
|
43
37
|
|
44
|
-
attr_reader :
|
38
|
+
attr_reader :plugin_config
|
45
39
|
attr_reader :ec2
|
46
40
|
attr_reader :s3
|
47
41
|
|
48
42
|
def bucket_key( appliance_name )
|
49
|
-
"#{@
|
43
|
+
"#{@plugin_config['bucket']}/#{appliance_name}/#{@appliance_config.version}.#{@appliance_config.release}/#{@appliance_config.hardware.arch}"
|
50
44
|
end
|
51
45
|
|
52
46
|
def bucket_manifest_key( appliance_name )
|
@@ -60,7 +54,7 @@ module BoxGrinder
|
|
60
54
|
def ami_info( appliance_name )
|
61
55
|
ami_info = nil
|
62
56
|
|
63
|
-
images = @ec2.describe_images( :owner_id => @
|
57
|
+
images = @ec2.describe_images( :owner_id => @plugin_config['account_number'] ).imagesSet
|
64
58
|
|
65
59
|
return nil if images.nil?
|
66
60
|
|
@@ -27,6 +27,21 @@ include AWS::S3
|
|
27
27
|
module BoxGrinder
|
28
28
|
class S3Plugin < BaseDeliveryPlugin
|
29
29
|
|
30
|
+
AMI_OSES = {
|
31
|
+
'fedora' => ["11"]
|
32
|
+
}
|
33
|
+
|
34
|
+
KERNELS = {
|
35
|
+
'us_east' => {
|
36
|
+
'fedora' => {
|
37
|
+
'11' => {
|
38
|
+
'i386' => { :aki => 'aki-a71cf9ce', :ari => 'ari-a51cf9cc' },
|
39
|
+
'x86_64' => { :aki => 'aki-b51cf9dc', :ari => 'ari-b31cf9da' }
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
30
45
|
def info
|
31
46
|
{
|
32
47
|
:name => :s3,
|
@@ -37,10 +52,26 @@ module BoxGrinder
|
|
37
52
|
|
38
53
|
def after_init
|
39
54
|
set_default_config_value('overwrite', false)
|
55
|
+
set_default_config_value('path', '/')
|
56
|
+
|
57
|
+
@ami_build_dir = "#{@appliance_config.path.dir.build}/ec2/ami"
|
58
|
+
@ami_manifest = "#{@ami_build_dir}/#{@appliance_config.name}.ec2.manifest.xml"
|
40
59
|
end
|
41
60
|
|
42
|
-
def
|
43
|
-
|
61
|
+
def supported_os
|
62
|
+
supported = ""
|
63
|
+
|
64
|
+
AMI_OSES.each_key do |os_name|
|
65
|
+
supported << "#{os_name}, versions: #{AMI_OSES[os_name].join(", ")}"
|
66
|
+
end
|
67
|
+
|
68
|
+
supported
|
69
|
+
end
|
70
|
+
|
71
|
+
def execute( deliverables, type = :ami )
|
72
|
+
validate_plugin_config(['bucket', 'access_key', 'secret_access_key'])
|
73
|
+
|
74
|
+
@aws_helper = AWSHelper.new( @config, @appliance_config, @plugin_config )
|
44
75
|
|
45
76
|
case type
|
46
77
|
when :s3
|
@@ -48,16 +79,25 @@ module BoxGrinder
|
|
48
79
|
when :cloudfront
|
49
80
|
upload_to_bucket(deliverables, :public_read)
|
50
81
|
when :ami
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
82
|
+
validate_plugin_config(['cert_file', 'key_file'])
|
83
|
+
|
84
|
+
unless AMI_OSES[@appliance_config.os.name].include?(@appliance_config.os.version)
|
85
|
+
@log.error "You cannot convert selected image to AMI because of unsupported operating system: #{@appliance_config.os.name} #{@appliance_config.os.version}. Supported systems: #{supported_os}."
|
86
|
+
return
|
87
|
+
end
|
88
|
+
|
89
|
+
unless image_already_uploaded?
|
90
|
+
bundle_image( deliverables )
|
91
|
+
upload_image
|
92
|
+
else
|
93
|
+
@log.debug "AMI for #{@appliance_config.name} appliance already uploaded, skipping..."
|
94
|
+
end
|
95
|
+
|
96
|
+
register_image
|
55
97
|
end
|
56
98
|
end
|
57
99
|
|
58
100
|
def upload_to_bucket(deliverables, permissions = :private)
|
59
|
-
AWSHelper.new(@config, @appliance_config)
|
60
|
-
|
61
101
|
package = PackageHelper.new(@config, @appliance_config, {:log => @log, :exec_helper => @exec_helper}).package(deliverables)
|
62
102
|
|
63
103
|
@log.info "Uploading #{@appliance_config.name} appliance to S3 bucket '#{@plugin_config['bucket']}'..."
|
@@ -81,15 +121,19 @@ module BoxGrinder
|
|
81
121
|
end
|
82
122
|
|
83
123
|
|
84
|
-
def bundle_image(deliverables)
|
124
|
+
def bundle_image( deliverables )
|
125
|
+
return if File.exists?( @ami_build_dir )
|
126
|
+
|
85
127
|
@log.info "Bundling AMI..."
|
86
128
|
|
87
|
-
|
129
|
+
FileUtils.mkdir_p( @ami_build_dir )
|
130
|
+
|
131
|
+
@exec_helper.execute("ec2-bundle-image -i #{deliverables[:disk]} --kernel #{KERNELS['us_east'][@appliance_config.os.name][@appliance_config.os.version][@appliance_config.hardware.arch][:aki]} --ramdisk #{KERNELS['us_east'][@appliance_config.os.name][@appliance_config.os.version][@appliance_config.hardware.arch][:ari]} -c #{@plugin_config['cert_file']} -k #{@plugin_config['key_file']} -u #{@plugin_config['account_number']} -r #{@appliance_config.hardware.arch} -d #{@ami_build_dir}")
|
88
132
|
|
89
133
|
@log.info "Bundling AMI finished."
|
90
134
|
end
|
91
135
|
|
92
|
-
def
|
136
|
+
def image_already_uploaded?
|
93
137
|
begin
|
94
138
|
bucket = Bucket.find(@aws_helper.aws_data['bucket_name'])
|
95
139
|
rescue
|
@@ -107,14 +151,9 @@ module BoxGrinder
|
|
107
151
|
end
|
108
152
|
|
109
153
|
def upload_image
|
110
|
-
|
111
|
-
@log.debug "Image for #{@appliance_config.name} appliance is already uploaded, skipping..."
|
112
|
-
return
|
113
|
-
end
|
114
|
-
|
115
|
-
@log.info "Uploading #{@appliance_config.name} AMI to bucket '#{@aws_helper.aws_data['bucket_name']}'..."
|
154
|
+
@log.info "Uploading #{@appliance_config.name} AMI to bucket '#{@plugin_config['bucket']}'..."
|
116
155
|
|
117
|
-
@exec_helper.execute("ec2-upload-bundle -b #{@aws_helper.bucket_key(@appliance_config.name)} -m #{@
|
156
|
+
@exec_helper.execute("ec2-upload-bundle -b #{@aws_helper.bucket_key(@appliance_config.name)} -m #{@ami_manifest} -a #{@plugin_config['access_key']} -s #{@plugin_config['secret_access_key']} --retry")
|
118
157
|
end
|
119
158
|
|
120
159
|
def register_image
|
@@ -36,19 +36,17 @@ module BoxGrinder
|
|
36
36
|
REGIONS = {'us_east' => 'url'}
|
37
37
|
|
38
38
|
KERNELS = {
|
39
|
-
'
|
40
|
-
'
|
41
|
-
'
|
42
|
-
|
43
|
-
'x86_64' => {:aki => 'aki-b51cf9dc', :ari => 'ari-b31cf9da', :rpm => 'http://repo.oddthesis.org/packages/other/kernel-xen-2.6.21.7-2.fc8.x86_64.rpm'}
|
44
|
-
}
|
39
|
+
'fedora' => {
|
40
|
+
'11' => {
|
41
|
+
'i386' => { :rpm => 'http://repo.oddthesis.org/packages/other/kernel-xen-2.6.21.7-2.fc8.i686.rpm' },
|
42
|
+
'x86_64' => { :rpm => 'http://repo.oddthesis.org/packages/other/kernel-xen-2.6.21.7-2.fc8.x86_64.rpm' }
|
45
43
|
}
|
46
44
|
}
|
45
|
+
|
47
46
|
}
|
48
47
|
|
49
48
|
def after_init
|
50
49
|
@deliverables[:disk] = "#{@appliance_config.path.dir.build}/ec2/#{@appliance_config.name}.ec2"
|
51
|
-
|
52
50
|
end
|
53
51
|
|
54
52
|
def supported_os
|
@@ -241,7 +239,7 @@ module BoxGrinder
|
|
241
239
|
"ec2-ami-tools.noarch.rpm" => "http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.noarch.rpm"
|
242
240
|
}
|
243
241
|
|
244
|
-
kernel_rpm = KERNELS[
|
242
|
+
kernel_rpm = KERNELS[@appliance_config.os.name][@appliance_config.os.version][@appliance_config.hardware.arch][:rpm]
|
245
243
|
rpms[File.basename(kernel_rpm)] = kernel_rpm unless kernel_rpm.nil?
|
246
244
|
|
247
245
|
cache_rpms(rpms)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 3
|
9
|
+
version: 0.3.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- BoxGrinder Project
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-20 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -27,8 +27,8 @@ dependencies:
|
|
27
27
|
segments:
|
28
28
|
- 0
|
29
29
|
- 0
|
30
|
-
-
|
31
|
-
version: 0.0.
|
30
|
+
- 8
|
31
|
+
version: 0.0.8
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
34
|
- !ruby/object:Gem::Dependency
|
@@ -176,7 +176,6 @@ files:
|
|
176
176
|
- lib/boxgrinder-build/validators/ssh-validator.rb
|
177
177
|
- lib/boxgrinder-build/validators/validator.rb
|
178
178
|
- lib/boxgrinder-build/validators/config-validator.rb
|
179
|
-
- lib/boxgrinder-build/validators/aws-validator.rb
|
180
179
|
- lib/boxgrinder-build/appliance.rb
|
181
180
|
- lib/boxgrinder-build/helpers/plugin-helper.rb
|
182
181
|
- lib/boxgrinder-build/helpers/guestfs-helper.rb
|
@@ -1,51 +0,0 @@
|
|
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 'boxgrinder-core/validators/errors'
|
22
|
-
|
23
|
-
module BoxGrinder
|
24
|
-
class AWSValidator
|
25
|
-
|
26
|
-
def initialize( config )
|
27
|
-
@config = config
|
28
|
-
end
|
29
|
-
|
30
|
-
def validate_aws_config( config )
|
31
|
-
secure_permissions = "600"
|
32
|
-
|
33
|
-
raise ValidationError, "Please specify aws section in configuration file (#{@config.config_file}). #{DEFAULT_HELP_TEXT[:general]}" if config.nil?
|
34
|
-
|
35
|
-
raise ValidationError, "Please specify path to cert in aws section in configuration file (#{@config.config_file}). #{DEFAULT_HELP_TEXT[:general]}" if config['cert_file'].nil?
|
36
|
-
raise ValidationError, "Certificate file '#{config['cert_file']}' specified in configuration file (#{@config.config_file}) doesn't exists. Please check your path. #{DEFAULT_HELP_TEXT[:general]}" unless File.exists?( config['cert_file'] )
|
37
|
-
cert_permission = sprintf( "%o", File.stat( config['cert_file'] ).mode )[ 3, 5 ]
|
38
|
-
raise ValidationError, "Certificate file '#{config['cert_file']}' specified in aws section in configuration file (#{@config.config_file}) has wrong permissions (#{cert_permission}), please correct it, run: 'chmod #{secure_permissions} #{config['cert_file']}'." unless cert_permission.eql?( secure_permissions )
|
39
|
-
|
40
|
-
raise ValidationError, "Please specify path to private key in aws section in configuration file (#{@config.config_file}). #{DEFAULT_HELP_TEXT[:general]}" if config['key_file'].nil?
|
41
|
-
raise ValidationError, "Private key file '#{config['key_file']}' specified in aws section in configuration file (#{@config.config_file}) doesn't exists. Please check your path." unless File.exists?( config['key_file'] )
|
42
|
-
key_permission = sprintf( "%o", File.stat( config['key_file'] ).mode )[ 3, 5 ]
|
43
|
-
raise ValidationError, "Private key file '#{config['key_file']}' specified in aws section in configuration file (#{@config.config_file}) has wrong permissions (#{key_permission}), please correct it, run: 'chmod #{secure_permissions} #{config['key_file']}'." unless key_permission.eql?( secure_permissions )
|
44
|
-
|
45
|
-
raise ValidationError, "Please specify account number in aws section in configuration file (#{@config.config_file}). #{DEFAULT_HELP_TEXT[:general]}" if config['account_number'].nil?
|
46
|
-
raise ValidationError, "Please specify access key in aws section in configuration file (#{@config.config_file}). #{DEFAULT_HELP_TEXT[:general]}" if config['access_key'].nil?
|
47
|
-
raise ValidationError, "Please specify secret access key in aws section in configuration file (#{@config.config_file}). #{DEFAULT_HELP_TEXT[:general]}" if config['secret_access_key'].nil?
|
48
|
-
raise ValidationError, "Please specify bucket name in in aws section in configuration file (#{@config.config_file})." if config['bucket_name'].nil? or config['bucket_name'].length == 0
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|