Class: Vanagon::Driver
- Inherits:
-
Object
- Object
- Vanagon::Driver
- Includes:
- Utilities
- Defined in:
- lib/vanagon/driver.rb
Instance Attribute Summary collapse
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#preserve ⇒ Object
Returns the value of attribute preserve.
-
#project ⇒ Object
Returns the value of attribute project.
-
#remote_workdir ⇒ Object
Returns the value of attribute remote_workdir.
-
#target ⇒ Object
Returns the value of attribute target.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
-
#workdir ⇒ Object
Returns the value of attribute workdir.
Class Method Summary collapse
Instance Method Summary collapse
- #build_host_info ⇒ Object
- #camelize(string) ⇒ Object
- #cleanup_workdir ⇒ Object
- #filter_out_components(only_build) ⇒ Object
-
#initialize(platform, project, options = { workdir: nil, configdir: nil, target: nil, engine: nil, components: nil, skipcheck: false, verbose: false, preserve: false, only_build: nil, remote_workdir: nil }) ⇒ Driver
constructor
rubocop:disable Metrics/AbcSize.
-
#install_build_dependencies ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#list_build_dependencies ⇒ Object
Returns the set difference between the build_requires and the components to get a list of external dependencies that need to be installed.
- #load_engine(engine_type, platform, target) ⇒ Object
- #load_engine_object(engine_type, platform, target) ⇒ Object
-
#render ⇒ Object
rubocop:disable Metrics/AbcSize.
- #retry_count ⇒ Object
-
#run ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity.
- #timeout ⇒ Object
Methods included from Utilities
#erb_file, #erb_string, #ex, #find_program_on_path, #get_md5sum, #get_sum, #http_request, #local_command, #remote_ssh_command, #retry_with_timeout, #rsync_from, #rsync_to, #ssh_command
Constructor Details
#initialize(platform, project, options = { workdir: nil, configdir: nil, target: nil, engine: nil, components: nil, skipcheck: false, verbose: false, preserve: false, only_build: nil, remote_workdir: nil }) ⇒ Driver
rubocop:disable Metrics/AbcSize
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vanagon/driver.rb', line 23 def initialize(platform, project, = { workdir: nil, configdir: nil, target: nil, engine: nil, components: nil, skipcheck: false, verbose: false, preserve: false, only_build: nil, remote_workdir: nil }) # rubocop:disable Metrics/AbcSize @verbose = [:verbose] @preserve = [:preserve] @workdir = [:workdir] || Dir.mktmpdir @@configdir = [:configdir] || File.join(Dir.pwd, "configs") components = [:components] || [] only_build = [:only_build] target = [:target] engine = [:engine] || 'pooler' @platform = Vanagon::Platform.load_platform(platform, File.join(@@configdir, "platforms")) @project = Vanagon::Project.load_project(project, File.join(@@configdir, "projects"), @platform, components) @project.settings[:verbose] = [:verbose] @project.settings[:skipcheck] = [:skipcheck] filter_out_components(only_build) if only_build loginit('vanagon_hosts.log') @remote_workdir = [:"remote-workdir"] load_engine(engine, @platform, target) rescue LoadError => e raise Vanagon::Error.wrap(e, "Could not load the desired engine '#{engine}'") end |
Instance Attribute Details
#platform ⇒ Object
Returns the value of attribute platform.
13 14 15 |
# File 'lib/vanagon/driver.rb', line 13 def platform @platform end |
#preserve ⇒ Object
Returns the value of attribute preserve.
13 14 15 |
# File 'lib/vanagon/driver.rb', line 13 def preserve @preserve end |
#project ⇒ Object
Returns the value of attribute project.
13 14 15 |
# File 'lib/vanagon/driver.rb', line 13 def project @project end |
#remote_workdir ⇒ Object
Returns the value of attribute remote_workdir.
13 14 15 |
# File 'lib/vanagon/driver.rb', line 13 def remote_workdir @remote_workdir end |
#target ⇒ Object
Returns the value of attribute target.
13 14 15 |
# File 'lib/vanagon/driver.rb', line 13 def target @target end |
#verbose ⇒ Object
Returns the value of attribute verbose.
13 14 15 |
# File 'lib/vanagon/driver.rb', line 13 def verbose @verbose end |
#workdir ⇒ Object
Returns the value of attribute workdir.
13 14 15 |
# File 'lib/vanagon/driver.rb', line 13 def workdir @workdir end |
Class Method Details
.configdir ⇒ Object
90 91 92 |
# File 'lib/vanagon/driver.rb', line 90 def self.configdir @@configdir end |
.logger ⇒ Object
94 95 96 |
# File 'lib/vanagon/driver.rb', line 94 def self.logger @@logger end |
Instance Method Details
#build_host_info ⇒ Object
98 99 100 |
# File 'lib/vanagon/driver.rb', line 98 def build_host_info { "name" => @engine.build_host_name, "engine" => @engine.name } end |
#camelize(string) ⇒ Object
80 81 82 83 84 |
# File 'lib/vanagon/driver.rb', line 80 def camelize(string) string.gsub(/(?:^|_)([a-z])?/) do |match| (Regexp.last_match[1] || '').capitalize end end |
#cleanup_workdir ⇒ Object
86 87 88 |
# File 'lib/vanagon/driver.rb', line 86 def cleanup_workdir FileUtils.rm_rf(workdir) end |
#filter_out_components(only_build) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/vanagon/driver.rb', line 48 def filter_out_components(only_build) # map each element in the only_build array to it's set of filtered components, then # flatten all the results in to one array and set project.components to that. @project.components = only_build.flat_map { |comp| @project.filter_component(comp) }.uniq if @verbose warn "Only building:" @project.components.each { |comp| warn comp.name } end end |
#install_build_dependencies ⇒ Object
rubocop:disable Metrics/AbcSize
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/vanagon/driver.rb', line 107 def install_build_dependencies # rubocop:disable Metrics/AbcSize unless list_build_dependencies.empty? if @platform.build_dependencies && @platform.build_dependencies.command && !@platform.build_dependencies.command.empty? @engine.dispatch("#{@platform.build_dependencies.command} #{list_build_dependencies.join(' ')} #{@platform.build_dependencies.suffix}") elsif @platform.respond_to?(:install_build_dependencies) @engine.dispatch(@platform.install_build_dependencies(list_build_dependencies)) else raise Vanagon::Error, "No method defined to install build dependencies for #{@platform.name}" end end end |
#list_build_dependencies ⇒ Object
Returns the set difference between the build_requires and the components to get a list of external dependencies that need to be installed.
103 104 105 |
# File 'lib/vanagon/driver.rb', line 103 def list_build_dependencies @project.components.map(&:build_requires).flatten.uniq - @project.components.map(&:name) end |
#load_engine(engine_type, platform, target) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vanagon/driver.rb', line 58 def load_engine(engine_type, platform, target) if engine_type != 'always_be_scheduling' if platform.build_hosts engine_type = 'hardware' elsif platform.aws_ami engine_type = 'ec2' elsif platform.docker_image engine_type = 'docker' elsif target engine_type = 'base' end end load_engine_object(engine_type, platform, target) end |
#load_engine_object(engine_type, platform, target) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/vanagon/driver.rb', line 73 def load_engine_object(engine_type, platform, target) require "vanagon/engine/#{engine_type}" @engine = Object::const_get("Vanagon::Engine::#{camelize(engine_type)}").new(platform, target, remote_workdir: remote_workdir) rescue StandardError fail "No such engine '#{camelize(engine_type)}'" end |
#render ⇒ Object
rubocop:disable Metrics/AbcSize
167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/vanagon/driver.rb', line 167 def render # rubocop:disable Metrics/AbcSize # Simple sanity check for the project if @project.version.nil? or @project.version.empty? raise Vanagon::Error, "Project requires a version set, all is lost." end warn "rendering Makefile" @project.fetch_sources(workdir, retry_count, timeout) @project.make_bill_of_materials(workdir) @project.generate_packaging_artifacts(workdir) @project.make_makefile(workdir) end |
#retry_count ⇒ Object
19 20 21 |
# File 'lib/vanagon/driver.rb', line 19 def retry_count @retry_count ||= @project.retry_count || ENV["VANAGON_RETRY_COUNT"] || 1 end |
#run ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/vanagon/driver.rb', line 119 def run # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity # Simple sanity check for the project if @project.version.nil? or @project.version.empty? raise Vanagon::Error, "Project requires a version set, all is lost." end # if no_packaging has been set in the project, don't execute the # whole makefile. Instead just perform the installation. make_target = '' if @project.no_packaging make_target = @project.name + '-project' end @engine.startup(workdir) warn "Target is #{@engine.target}" Vanagon::Utilities.retry_with_timeout(retry_count, timeout) do install_build_dependencies end @project.fetch_sources(workdir, retry_count, timeout) @project.make_makefile(workdir) @project.make_bill_of_materials(workdir) # Don't generate packaging artifacts if no_packaging is set @project.generate_packaging_artifacts(workdir) unless @project.no_packaging @project.save_manifest_json(@platform) @engine.ship_workdir(workdir) @engine.dispatch("(cd #{@engine.remote_workdir}; #{@platform.make} #{make_target})") @engine.retrieve_built_artifact(@project.artifacts_to_fetch, @project.no_packaging) @project.publish_yaml_settings(@platform) if %i[never on-failure].include? @preserve @engine.teardown cleanup_workdir end rescue StandardError => e if [:never].include? @preserve @engine.teardown cleanup_workdir end warn e warn e.backtrace.join("\n") raise e ensure if ["hardware", "ec2"].include?(@engine.name) @engine.teardown end end |
#timeout ⇒ Object
15 16 17 |
# File 'lib/vanagon/driver.rb', line 15 def timeout @timeout ||= @project.timeout || ENV["VANAGON_TIMEOUT"] || 7200 end |