Class: Vanagon::Engine::Base
- Inherits:
-
Object
- Object
- Vanagon::Engine::Base
- Defined in:
- lib/vanagon/engine/base.rb
Instance Attribute Summary collapse
-
#remote_workdir ⇒ Object
Returns the value of attribute remote_workdir.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
-
#build_host_name ⇒ Object
Get the engine specific name of the host to build on.
-
#dispatch(command, return_output = false) ⇒ Object
Dispatches the command for execution.
- #get_remote_workdir ⇒ Object
-
#initialize(platform, target = nil, **opts) ⇒ Base
constructor
A new instance of Base.
-
#name ⇒ Object
Get the engine name.
- #parse_target_defaults(target) ⇒ Object
- #retrieve_built_artifact(artifacts_to_fetch, no_packaging) ⇒ Object
-
#select_target ⇒ Object
This method is used to obtain a vm to build upon For the base class we just return the target that was passed in.
-
#setup ⇒ Object
Applies the steps needed to extend the system to build packages against the target system.
- #ship_workdir(workdir) ⇒ Object
-
#startup(workdir) ⇒ Object
This method will take care of validation and target selection all at once as an easy shorthand to call from the driver.
-
#teardown ⇒ Object
Steps needed to tear down or clean up the system after the build is complete.
-
#validate_platform ⇒ Object
Ensures that the platform defines the attributes that the engine needs to function.
Constructor Details
#initialize(platform, target = nil, **opts) ⇒ Base
Returns a new instance of Base.
9 10 11 12 13 14 15 16 |
# 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 |
Instance Attribute Details
#remote_workdir ⇒ Object
Returns the value of attribute remote_workdir.
7 8 9 |
# File 'lib/vanagon/engine/base.rb', line 7 def remote_workdir @remote_workdir end |
#target ⇒ Object
Returns the value of attribute target.
7 8 9 |
# File 'lib/vanagon/engine/base.rb', line 7 def target @target end |
Instance Method Details
#build_host_name ⇒ Object
Get the engine specific name of the host to build on
35 36 37 |
# 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) ⇒ Object
Dispatches the command for execution
46 47 48 |
# 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 ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# 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 ⇒ Object
Get the engine name
19 20 21 |
# File 'lib/vanagon/engine/base.rb', line 19 def name 'base' end |
#parse_target_defaults(target) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# 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) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# 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 ⇒ Object
This method is used to obtain a vm to build upon For the base class we just return the target that was passed in
41 42 43 |
# 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 ⇒ Object
Applies the steps needed to extend the system to build packages against the target system
56 57 58 59 60 61 |
# 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) ⇒ Object
84 85 86 |
# 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) ⇒ Object
This method will take care of validation and target selection all at once as an easy shorthand to call from the driver
65 66 67 68 69 70 |
# File 'lib/vanagon/engine/base.rb', line 65 def startup(workdir) validate_platform select_target setup get_remote_workdir end |
#teardown ⇒ Object
Steps needed to tear down or clean up the system after the build is complete
52 |
# File 'lib/vanagon/engine/base.rb', line 52 def teardown; end |
#validate_platform ⇒ Object
Ensures that the platform defines the attributes that the engine needs to function.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# 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 |