class Bosh::Stemcell::StageRunner

Constants

REQUIRED_UID

Attributes

build_path[R]
command_env[R]
settings_file[R]
stages[R]
work_path[R]

Public Class Methods

new(options) click to toggle source
# File lib/bosh/stemcell/stage_runner.rb, line 8
def initialize(options)
  @build_path = options.fetch(:build_path)
  @command_env = options.fetch(:command_env)
  @settings_file = options.fetch(:settings_file)
  @work_path = options.fetch(:work_path)
end

Public Instance Methods

apply(stages) click to toggle source
# File lib/bosh/stemcell/stage_runner.rb, line 40
def apply(stages)
  stages.each do |stage|
    FileUtils.mkdir_p(work_path)

    puts "=== Applying '#{stage}' stage ==="
    puts "== Started #{Time.now.strftime('%a %b %e %H:%M:%S %Z %Y')} =="

    begin
      stage_apply_script = File.join(build_path, 'stages', stage.to_s, 'apply.sh')

      run_sudo_with_command_env("#{stage_apply_script} #{work_path}")

    rescue => _
      puts "=== You can resume_from the '#{stage}' stage by using resume_from=#{stage} ==="
      raise
    end

  end
end
check_correct_uid() click to toggle source
# File lib/bosh/stemcell/stage_runner.rb, line 15
def check_correct_uid
  if Process.euid != REQUIRED_UID
    raise "You must build stemcells as a user with UID #{REQUIRED_UID}. Your effective UID now is #{Process.euid}."
  end
end
configure(stages) click to toggle source
# File lib/bosh/stemcell/stage_runner.rb, line 28
def configure(stages)
  stages.each do |stage|
    stage_config_script = File.join(build_path, 'stages', stage.to_s, 'config.sh')

    puts "=== Configuring '#{stage}' stage ==="
    puts "== Started #{Time.now.strftime('%a %b %e %H:%M:%S %Z %Y')} =="
    if File.exists?(stage_config_script) && File.executable?(stage_config_script)
      run_sudo_with_command_env("#{stage_config_script} #{settings_file}")
    end
  end
end
configure_and_apply(stages, resume_from_stage = nil) click to toggle source
# File lib/bosh/stemcell/stage_runner.rb, line 21
def configure_and_apply(stages, resume_from_stage = nil)
  check_correct_uid()
  stages = resume_from(stages, resume_from_stage)
  configure(stages)
  apply(stages)
end

Private Instance Methods

resume_from(all_stages, resume_from_stage) click to toggle source
# File lib/bosh/stemcell/stage_runner.rb, line 64
def resume_from(all_stages, resume_from_stage)
  if resume_from_stage != NIL
    stage_index = all_stages.index(resume_from_stage.to_sym)
    if stage_index == NIL
      raise "Can't find stage '#{resume_from_stage}' to resume from. Aborting."
    end
    all_stages.drop(stage_index)
  else
    all_stages
  end
end
run_sudo_with_command_env(command) click to toggle source
# File lib/bosh/stemcell/stage_runner.rb, line 76
def run_sudo_with_command_env(command)
  shell = Bosh::Core::Shell.new

  shell.run("sudo #{command_env} #{command} 2>&1", output_command: true)
end