class Vanagon::Engine::Base

Attributes

remote_workdir[RW]
target[RW]

Public Class Methods

new(platform, target = nil, **opts) click to toggle source
# File lib/vanagon/engine/base.rb, line 9
def initialize(platform, target = nil, **opts)
  @platform = platform
  @required_attributes = ["ssh_port"]
  parse_target_defaults(target) if target
  @target_port ||= @platform.ssh_port
  @target_user ||= @platform.target_user
  @remote_workdir_path = opts[:remote_workdir]
end

Public Instance Methods

build_host_name() click to toggle source

Get the engine specific name of the host to build on

# File lib/vanagon/engine/base.rb, line 35
def build_host_name
  raise Vanagon::Error, '#build_host_name has not been implemented for your engine.'
end
dispatch(command, return_output = false) click to toggle source

Dispatches the command for execution

# File lib/vanagon/engine/base.rb, line 46
def dispatch(command, return_output = false)
  Vanagon::Utilities.remote_ssh_command("#{@target_user}@#{@target}", command, @target_port, return_command_output: return_output)
end
get_remote_workdir() click to toggle source
# File lib/vanagon/engine/base.rb, line 72
def get_remote_workdir
  unless @remote_workdir
    if @remote_workdir_path
      dispatch("mkdir -p #{@remote_workdir_path}", true)
      @remote_workdir = @remote_workdir_path
    else
      @remote_workdir = dispatch("#{@platform.mktemp} 2>/dev/null", true)
    end
  end
  @remote_workdir
end
name() click to toggle source

Get the engine name

# File lib/vanagon/engine/base.rb, line 19
def name
  'base'
end
parse_target_defaults(target) click to toggle source
# File lib/vanagon/engine/base.rb, line 23
def parse_target_defaults(target)
  # If there's no scheme, we need to add // to make it parse properly
  target_uri = target.include?('//') ? URI.parse(target) : URI.parse("//#{target}")
  @target = target_uri.hostname
  @target_port = target_uri.port
  @target_user = target_uri.user
rescue URI::Error
  # Just assume it's not meant to be a URI
  @target = target
end
retrieve_built_artifact(artifacts_to_fetch, no_packaging) click to toggle source
# File lib/vanagon/engine/base.rb, line 88
def retrieve_built_artifact(artifacts_to_fetch, no_packaging)
  output_path = 'output/'
  FileUtils.mkdir_p(output_path)
  unless no_packaging
    artifacts_to_fetch << "#{@remote_workdir}/output/*"
  end
  artifacts_to_fetch.each do |path|
    Vanagon::Utilities.rsync_from(path, "#{@target_user}@#{@target}", output_path, @target_port)
  end
end
select_target() click to toggle source

This method is used to obtain a vm to build upon For the base class we just return the target that was passed in

# File lib/vanagon/engine/base.rb, line 41
def select_target
  @target or raise Vanagon::Error, '#select_target has not been implemented for your engine.'
end
setup() click to toggle source

Applies the steps needed to extend the system to build packages against the target system

# File lib/vanagon/engine/base.rb, line 56
def setup
  unless @platform.provisioning.empty?
    script = @platform.provisioning.join(' && ')
    dispatch(script)
  end
end
ship_workdir(workdir) click to toggle source
# File lib/vanagon/engine/base.rb, line 84
def ship_workdir(workdir)
  Vanagon::Utilities.rsync_to("#{workdir}/*", "#{@target_user}@#{@target}", @remote_workdir, @target_port)
end
startup(workdir) click to toggle source

This method will take care of validation and target selection all at once as an easy shorthand to call from the driver

# File lib/vanagon/engine/base.rb, line 65
def startup(workdir)
  validate_platform
  select_target
  setup
  get_remote_workdir
end
teardown() click to toggle source

Steps needed to tear down or clean up the system after the build is complete

# File lib/vanagon/engine/base.rb, line 52
def teardown; end
validate_platform() click to toggle source

Ensures that the platform defines the attributes that the engine needs to function.

@raise [Vanagon::Error] an error is raised if a needed attribute is not defined

# File lib/vanagon/engine/base.rb, line 102
def validate_platform
  missing_attrs = []
  @required_attributes.each do |attr|
    if !@platform.instance_variables.include?("@#{attr}".to_sym) || @platform.instance_variable_get("@#{attr}".to_sym).nil?
      missing_attrs << attr
    end
  end

  if missing_attrs.empty?
    return true
  else
    raise Vanagon::Error, "The following required attributes were not set in '#{@platform.name}': #{missing_attrs.join(', ')}."
  end
end