Class: OpenStax::Aws::Packer_1_2_5

Inherits:
Object
  • Object
show all
Defined in:
lib/openstax/aws/packer_1_2_5.rb

Instance Method Summary collapse

Constructor Details

#initialize(absolute_file_path:, dry_run: true) ⇒ Packer_1_2_5

Returns a new instance of Packer_1_2_5.



6
7
8
9
10
11
12
13
14
# File 'lib/openstax/aws/packer_1_2_5.rb', line 6

def initialize(absolute_file_path:, dry_run: true)
  @logger = OpenStax::Aws.configuration.logger
  @only = []
  @vars = {}
  @dry_run = dry_run
  @verbose = false
  @debug = false
  @absolute_file_path = absolute_file_path
end

Instance Method Details

#commandObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/openstax/aws/packer_1_2_5.rb', line 32

def command
  cmd = "packer build --only=amazon-ebs"

  cmd = "#{cmd} --only=#{@only.join(',')}" if !@only.empty?

  @vars.each do |key, value|
    cmd = "#{cmd} --var '#{key}=#{value}'"
  end

  cmd = "PACKER_LOG=1 #{cmd}" if @verbose
  cmd = "#{cmd} --debug" if @debug

  cmd = "#{cmd} #{@absolute_file_path}"
end

#debug!Object



28
29
30
# File 'lib/openstax/aws/packer_1_2_5.rb', line 28

def debug!
  @debug = true
end

#only(builders) ⇒ Object



16
17
18
# File 'lib/openstax/aws/packer_1_2_5.rb', line 16

def only(builders)
  @only = [builders].flatten
end

#runObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/openstax/aws/packer_1_2_5.rb', line 47

def run
  @logger.info("**** DRY RUN ****") if @dry_run
  @logger.info("Running: #{command}")

  if !@dry_run
    @logger.info("Printing stderr for desired verbosity")

    Open3.popen2e(command) do |stdin, stdout_err, wait_thr|
      while line=stdout_err.gets do
        puts(line)
      end
    end
  end
end

#var(key, value) ⇒ Object



20
21
22
# File 'lib/openstax/aws/packer_1_2_5.rb', line 20

def var(key, value)
  @vars[key.to_s] = value.to_s
end

#verbose!Object



24
25
26
# File 'lib/openstax/aws/packer_1_2_5.rb', line 24

def verbose!
  @verbose = true
end