Sha256: b884192d0d33c1590177ad4d21811a8f3c62db0c7fe19ecdb7d8ee5b5b894156

Contents?: true

Size: 1.45 KB

Versions: 112

Compression:

Stored size: 1.45 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 ==="
        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)
      work_directory = File.join(work_path, 'work')

      stages.each do |stage|
        FileUtils.mkdir_p(work_directory)

        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_directory}")
      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")
    end
  end
end

Version data entries

112 entries across 112 versions & 1 rubygems

Version Path
bosh-stemcell-1.2175.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2168.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2131.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2129.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2124.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2121.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2089.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2086.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2068.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2063.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.2005.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.1975.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.1868.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.1858.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.1840.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.1836.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.1798.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.1782.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.1777.0 lib/bosh/stemcell/stage_runner.rb
bosh-stemcell-1.1761.0 lib/bosh/stemcell/stage_runner.rb