Class: AMI::AmiBuilder::UbuntuPrecise

Inherits:
Object
  • Object
show all
Defined in:
lib/ami/ami_builder/ubuntu_precise.rb

Class Method Summary collapse

Class Method Details

.create(image_name, ssh, config, include_files = []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ami/ami_builder/ubuntu_precise.rb', line 5

def self.create(image_name, ssh, config, include_files = [])
  ssh.run 'sudo sed -i -e "s/# deb\(.*\)multiverse/deb\1multiverse/g" /etc/apt/sources.list'
  ssh.run 'sudo apt-get update'
  ssh.run 'sudo apt-get -y install ec2-api-tools ec2-ami-tools'

  # If we don't explicitly override include_files then by default include
  # all gpg and pem files so we actually get a working instance
  if include_files.empty? && !include_files.nil?
    include_files = AMI::IncludeHelper.find(ssh, ["pem", "gpg", "crt"])
  end

  ssh.upload(config.cert_path, '/tmp/cert.pem')
  ssh.upload(config.pk_path, '/tmp/pk.pem')
  ssh.run 'mkdir /tmp/ami'
  ssh.run "cd /; sudo ec2-bundle-vol --debug -r x86_64 -d /tmp/ami -k /tmp/pk.pem -c /tmp/cert.pem -u #{config.} -i #{include_files.join(',')}"
  ssh.run "ec2-upload-bundle -b '#{config.s3_bucket}' -m '/tmp/ami/image.manifest.xml' -a #{config.access_key} -s #{config.secret_key}"
  ssh.run "ec2-register -K /tmp/pk.pem -C /tmp/cert.pem '#{config.s3_bucket}/image.manifest.xml' -n #{image_name}"
end