Sha256: b90256d890327d02a2790cd5b4fe67b66f4e5100aa08aaa9acaf4f84c8776459

Contents?: true

Size: 1.48 KB

Versions: 108

Compression:

Stored size: 1.48 KB

Contents

require 'bosh/core/shell'

module Bosh::Stemcell
  class StageRunner
    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

    def configure_and_apply(stages)
      configure(stages)
      apply(stages)
    end

    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

    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')} =="

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

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

    private

    attr_reader :stages, :build_path, :command_env, :settings_file, :work_path

    def run_sudo_with_command_env(command)
      shell = Bosh::Core::Shell.new

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

Version data entries

108 entries across 108 versions & 1 rubygems

Version Path
bosh-stemcell-1.2881.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2865.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2862.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2859.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2858.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2855.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2852.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2849.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2847.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2840.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2839.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2831.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2830.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2829.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2827.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2824.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2820.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2818.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2811.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2810.0 lib/bosh/stemcell/stage_runner.rb