class OpenStax::Aws::Packer_1_2_5

Public Class Methods

new(absolute_file_path:, dry_run: true) click to toggle source
# 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

Public Instance Methods

command() click to toggle source
# 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!() click to toggle source
# File lib/openstax/aws/packer_1_2_5.rb, line 28
def debug!
  @debug = true
end
only(builders) click to toggle source
# File lib/openstax/aws/packer_1_2_5.rb, line 16
def only(builders)
  @only = [builders].flatten
end
run() click to toggle source
# 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|
      stdout_err.sync = true

      while char = stdout_err.getc do
        STDERR.print char
      end
    end
  end
end
var(key, value) click to toggle source
# File lib/openstax/aws/packer_1_2_5.rb, line 20
def var(key, value)
  @vars[key.to_s] = value.to_s
end
verbose!() click to toggle source
# File lib/openstax/aws/packer_1_2_5.rb, line 24
def verbose!
  @verbose = true
end