ami 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Kiln
1
+ # AMI
2
2
 
3
- A gem for automating the creation of EC2 AMIs
3
+ A gem for automating the creation of EC2 Instance Store AMIs
4
4
 
5
5
  ## Installation
6
6
 
@@ -13,7 +13,7 @@ or add to your Gemfile
13
13
  ```ruby
14
14
  source "https://rubygems.org"
15
15
 
16
- gem "ami", "~> 1.0.0"
16
+ gem "ami", "~> 1.2.0"
17
17
  ```
18
18
 
19
19
  ## Usage
@@ -34,6 +34,15 @@ information necessary to create your AMI, this can be located in either
34
34
 
35
35
  For an example of the values see: [example config.json](ami/config.json)
36
36
 
37
+ ## Planned Features
38
+
39
+ ### v1.3.0
40
+
41
+ * Provide more concise output options so that progress is easier to monitor
42
+ without terminal spam
43
+ * Provide some basic tools to aid in composing various installers such that
44
+ the same installer isn't run unnecessarily if its dependencies are already met
45
+
37
46
  ## LICENSE
38
47
 
39
48
  MIT, see LICENSE file
@@ -4,4 +4,4 @@ $:.unshift(File.expand_path("../../lib", __FILE__))
4
4
 
5
5
  require 'ami'
6
6
 
7
- AMI::Commands::CreateAmi.new.run(ARGV)
7
+ exit AMI::Commands::CreateAmi.new.run(ARGV)
data/lib/ami.rb CHANGED
@@ -4,6 +4,7 @@ require 'ami/definition'
4
4
  require 'ami/server'
5
5
  require 'ami/config'
6
6
  require 'ami/ssh'
7
+ require 'ami/include_helper'
7
8
  require 'ami/instance_provisioner'
8
9
  require 'ami/config_loader'
9
10
  require 'ami/commands/list'
@@ -3,15 +3,20 @@ module AMI
3
3
  module AmiBuilder
4
4
  class UbuntuPrecise
5
5
  def self.create(image_name, ssh, config, include_files = [])
6
- include_files << '/etc/apt/trusted.gpg'
7
- include_files << '/etc/apt/trustdb.gpg'
8
- ssh.upload(config.cert_path, '/tmp/cert.pem')
9
- ssh.upload(config.pk_path, '/tmp/pk.pem')
10
6
  ssh.run 'sudo sed -i -e "s/# deb\(.*\)multiverse/deb\1multiverse/g" /etc/apt/sources.list'
11
7
  ssh.run 'sudo apt-get update'
12
8
  ssh.run 'sudo apt-get -y install ec2-api-tools ec2-ami-tools'
9
+
10
+ # If we don't explicitly override include_files then by default include
11
+ # all gpg and pem files so we actually get a working instance
12
+ if include_files.empty? && !include_files.nil?
13
+ include_files = AMI::IncludeHelper.find(ssh, ["pem", "gpg", "crt"])
14
+ end
15
+
16
+ ssh.upload(config.cert_path, '/tmp/cert.pem')
17
+ ssh.upload(config.pk_path, '/tmp/pk.pem')
13
18
  ssh.run 'mkdir /tmp/ami'
14
- ssh.run "sudo ec2-bundle-vol -r x86_64 -d /tmp/ami -k /tmp/pk.pem -c /tmp/cert.pem -u #{config.account_id} -i #{include_files.join(',')}"
19
+ ssh.run "cd /; sudo ec2-bundle-vol --debug -r x86_64 -d /tmp/ami -k /tmp/pk.pem -c /tmp/cert.pem -u #{config.account_id} -i #{include_files.join(',')}"
15
20
  ssh.run "ec2-upload-bundle -b '#{config.s3_bucket}' -m '/tmp/ami/image.manifest.xml' -a #{config.access_key} -s #{config.secret_key}"
16
21
  ssh.run "ec2-register -K /tmp/pk.pem -C /tmp/cert.pem '#{config.s3_bucket}/image.manifest.xml' -n #{image_name}"
17
22
  end
@@ -3,12 +3,21 @@ module AMI
3
3
  module Commands
4
4
  class CreateAmi
5
5
  def run(argv)
6
- name = argv[0]
6
+ if argv.include?('--help') || argv.include?('-h')
7
+ puts "#{$0} <options> ClassName"
8
+ puts "Options:"
9
+ puts " --debug - Enable debug mode which stops auto-termination of servers"
10
+ puts ""
11
+ return 0
12
+ end
13
+
14
+ name = argv.pop
15
+ debug = argv.include?('--debug')
7
16
  AMI::Core.load_amis
8
17
 
9
18
  unless AMI::Core.valid_ami?(name)
10
19
  warn "Invalid AMI name #{name}. Use ami-list to see available AMIs"
11
- exit 1
20
+ return 1
12
21
  end
13
22
 
14
23
  ami = AMI::Core.ami(name).new
@@ -26,16 +35,26 @@ module AMI
26
35
  config
27
36
  )
28
37
 
38
+ at_exit do
39
+ if server.status == :running
40
+ server.terminate
41
+ end
42
+ end
43
+
29
44
  begin
30
45
  ssh = AMI::SSH.create_connection(server, server_template.user_name)
31
46
  ami.configure(ssh, config)
32
47
  ami.create_ami(ssh, config)
33
48
  puts 'done'
34
- rescue
35
- warn "failure occurred, terminating server"
36
- raise
37
- ensure
38
- server.terminate
49
+ return 0
50
+ rescue Exception => e
51
+ warn "Error Occurred: #{e.message}"
52
+ warn "Backtrace:\n\t#{e.backtrace.join("\n\t")}"
53
+ if debug
54
+ warn "Access server via 'ssh #{server_template.user_name}@#{server.dns_name}'"
55
+ sleep
56
+ end
57
+ return 1
39
58
  end
40
59
  end
41
60
  end
@@ -0,0 +1,19 @@
1
+
2
+ module AMI
3
+ # Assists in gathering a list of files to include when bundling an AMI.
4
+ # Particularly useful for dealing with the EC2 AMI tools default of excluding
5
+ # all possibly sensitive files, even ones which are perfectly safe to
6
+ # distribute and are necessary to use some libraries/tools
7
+ class IncludeHelper
8
+ def self.find(ssh, file_types = [])
9
+ includes = []
10
+ file_types.each do |type|
11
+ response = ssh.run("sudo find / -type f -name \\*#{type}", :quiet => true)
12
+ includes += response.output.split("\n")
13
+ response = ssh.run("sudo find / -type l -name \\*#{type}", :quiet => true)
14
+ includes += response.output.split("\n")
15
+ end
16
+ includes
17
+ end
18
+ end
19
+ end
@@ -7,7 +7,7 @@ module AMI
7
7
  begin
8
8
  ssh = Gofer::Host.new(server.dns_name, user, :timeout => 30)
9
9
  ssh.ls '/' # force gofer to connect to the host
10
- return ssh
10
+ return AMI::SSH.new(ssh)
11
11
  rescue Errno::ECONNREFUSED, Timeout::Error, Errno::EHOSTUNREACH
12
12
  retries -= 1
13
13
  if retries > 0
@@ -19,5 +19,22 @@ module AMI
19
19
  end
20
20
  end
21
21
  end
22
+
23
+ def initialize(ssh)
24
+ @ssh = ssh
25
+ end
26
+
27
+ def run(command, opts = {})
28
+ puts command
29
+ @ssh.run(command, opts)
30
+ end
31
+
32
+ def method_missing(method, *args)
33
+ @ssh.send(method, *args)
34
+ end
35
+
36
+ def respond_to?(method)
37
+ @ssh.respond_to?(method)
38
+ end
22
39
  end
23
40
  end
@@ -1,3 +1,3 @@
1
1
  module AMI
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ami
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-24 00:00:00.000000000 Z
12
+ date: 2013-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gofer
@@ -70,6 +70,7 @@ files:
70
70
  - lib/ami/config_loader.rb
71
71
  - lib/ami/core.rb
72
72
  - lib/ami/definition.rb
73
+ - lib/ami/include_helper.rb
73
74
  - lib/ami/installer/ruby_under_rbenv.rb
74
75
  - lib/ami/instance_provisioner.rb
75
76
  - lib/ami/server.rb