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"] @target = target if target @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 23 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 34 def dispatch(command, return_output = false) Vanagon::Utilities.remote_ssh_command("#{@target_user}@#{@target}", command, @platform.ssh_port, return_command_output: return_output) end
get_remote_workdir()
click to toggle source
# File lib/vanagon/engine/base.rb, line 60 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 18 def name 'base' end
retrieve_built_artifact(artifacts_to_fetch, no_packaging)
click to toggle source
# File lib/vanagon/engine/base.rb, line 76 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, @platform.ssh_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 29 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 44 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 72 def ship_workdir(workdir) Vanagon::Utilities.rsync_to("#{workdir}/*", "#{@target_user}@#{@target}", @remote_workdir, @platform.ssh_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 53 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 40 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 90 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