Class: Builderator::Tasks::Packer

Inherits:
Thor
  • Object
show all
Includes:
Util::Shell, Thor::Actions
Defined in:
lib/builderator/tasks/packer.rb

Instance Method Summary collapse

Methods included from Util::Shell

#execute

Instance Method Details

#build(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/builderator/tasks/packer.rb', line 33

def build(*args)
  invoke Tasks::Berks, 'vendor', [], options

  packer_output = execute("#{ Util::Packer.bin } build #{ args.join(' ') }")

  ## Try to find the ID of the new AMI
  ami_id_search = /AMI: (ami-[0-9a-f]{8})/.match(packer_output.string)
  if ami_id_search.nil? && options.include?('properties-file')
    say_status :failure, 'Unable to find AMI ID from packer build', :red
    return
  end

  return unless options['properties-file']
  say_status :success, "Created AMI #{ ami_id_search[1] }"

  create_file options['properties-file'], '', :force => true
  append_file options['properties-file'], "image.useast1=#{ ami_id_search[1] }"
end

#find_ami ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/builderator/tasks/packer.rb', line 54

def find_ami
  tee = Builderator::Util::Shell::BufferTee.new($stdout)
  $stdin.each { |l| tee.write(l) } # Buffer stdin

  ami_id_search = /AMI: (ami-[0-9a-f]{8})/.match(tee.string)
  if ami_id_search.nil?
    say_status :failure, 'Unable to find AMI ID from packer build', :red
    return
  end

  say_status :success, "Created AMI #{ ami_id_search[1] }"
  return unless options['properties-file']

  create_file options['properties-file'], '', :force => true
  append_file options['properties-file'], "image.useast1=#{ ami_id_search[1] }"
end

#install(version = '0.8.2') ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/builderator/tasks/packer.rb', line 17

def install(version = '0.8.2')
  Util::Packer.use(version)

  if Util::Packer.installed?
    say_status :packer, "is already installed at version #{ version }"
    return
  end

  say_status :packer, "install version #{ version } to #{ Util::Packer.path }"
  run "wget #{ Util::Packer.url } -O packer.zip -q"
  run "unzip -d #{ Util::Packer.path } -q packer.zip"
  run "ln -sf #{ Util::Packer.path } $HOME/packer"
end