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
- #dependencies ⇒ Object
- #filter_out_components(only_build) ⇒ Object
-
#initialize(platform, project, options = {}) ⇒ Driver
constructor
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity.
-
#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_object(engine_type, platform, target) ⇒ Object
-
#pick_engine(options) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
-
#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, #http_request_code, #http_request_generic, #local_command, #remote_ssh_command, #retry_with_timeout, #rsync_from, #rsync_to, #ssh_command
Constructor Details
#initialize(platform, project, options = {}) ⇒ Driver
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vanagon/driver.rb', line 24 def initialize(platform, project, = {}) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity @options = @verbose = [:verbose] || false @preserve = [:preserve] || false @workdir = [:workdir] || Dir.mktmpdir @@configdir = [:configdir] || File.join(Dir.pwd, "configs") components = [:components] || [] only_build = [:only_build] @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] || false filter_out_components(only_build) if only_build loginit('vanagon_hosts.log') @remote_workdir = [:"remote-workdir"] engine = pick_engine() load_engine_object(engine, @platform, [:target]) end |
Instance Attribute Details
#platform ⇒ Object
Returns the value of attribute platform.
14 15 16 |
# File 'lib/vanagon/driver.rb', line 14 def platform @platform end |
#preserve ⇒ Object
Returns the value of attribute preserve.
14 15 16 |
# File 'lib/vanagon/driver.rb', line 14 def preserve @preserve end |
#project ⇒ Object
Returns the value of attribute project.
14 15 16 |
# File 'lib/vanagon/driver.rb', line 14 def project @project end |
#remote_workdir ⇒ Object
Returns the value of attribute remote_workdir.
14 15 16 |
# File 'lib/vanagon/driver.rb', line 14 def remote_workdir @remote_workdir end |
#target ⇒ Object
Returns the value of attribute target.
14 15 16 |
# File 'lib/vanagon/driver.rb', line 14 def target @target end |
#verbose ⇒ Object
Returns the value of attribute verbose.
14 15 16 |
# File 'lib/vanagon/driver.rb', line 14 def verbose @verbose end |
#workdir ⇒ Object
Returns the value of attribute workdir.
14 15 16 |
# File 'lib/vanagon/driver.rb', line 14 def workdir @workdir end |
Class Method Details
.configdir ⇒ Object
93 94 95 |
# File 'lib/vanagon/driver.rb', line 93 def self.configdir @@configdir end |
.logger ⇒ Object
97 98 99 |
# File 'lib/vanagon/driver.rb', line 97 def self.logger @@logger end |
Instance Method Details
#build_host_info ⇒ Object
101 102 103 |
# File 'lib/vanagon/driver.rb', line 101 def build_host_info { "name" => @engine.build_host_name, "engine" => @engine.name } end |
#camelize(string) ⇒ Object
83 84 85 86 87 |
# File 'lib/vanagon/driver.rb', line 83 def camelize(string) string.gsub(/(?:^|_)([a-z])?/) do |match| (Regexp.last_match[1] || '').capitalize end end |
#cleanup_workdir ⇒ Object
89 90 91 |
# File 'lib/vanagon/driver.rb', line 89 def cleanup_workdir FileUtils.rm_rf(workdir) end |
#dependencies ⇒ Object
185 186 187 188 189 190 191 192 193 194 |
# File 'lib/vanagon/driver.rb', line 185 def dependencies # Simple sanity check for the project if @project.version.nil? || @project.version.empty? raise Vanagon::Error, "Project requires a version set, all is lost." end VanagonLogger.info "creating dependencies list" @project.fetch_sources(workdir, retry_count, timeout) @project.cli_manifest_json(@platform) end |
#filter_out_components(only_build) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/vanagon/driver.rb', line 49 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 VanagonLogger.info "Only building:" @project.components.each { |comp| VanagonLogger.info comp.name } end end |
#install_build_dependencies ⇒ Object
rubocop:disable Metrics/AbcSize
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/vanagon/driver.rb', line 112 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.
108 109 110 |
# File 'lib/vanagon/driver.rb', line 108 def list_build_dependencies @project.components.map(&:build_requires).flatten.uniq - @project.components.map(&:name) end |
#load_engine_object(engine_type, platform, target) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/vanagon/driver.rb', line 75 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, ScriptError => e raise Vanagon::Error.wrap(e, "Could not load the desired engine '#{engine_type}'") end |
#pick_engine(options) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vanagon/driver.rb', line 59 def pick_engine() # rubocop:disable Metrics/PerceivedComplexity if [:engine] && ![:target] [:engine] elsif @platform.build_hosts 'hardware' elsif @platform.aws_ami 'ec2' elsif @platform.docker_image 'docker' elsif [:target] 'base' else 'always_be_scheduling' end end |
#render ⇒ Object
rubocop:disable Metrics/AbcSize
172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/vanagon/driver.rb', line 172 def render # rubocop:disable Metrics/AbcSize # Simple sanity check for the project if @project.version.nil? || @project.version.empty? raise Vanagon::Error, "Project requires a version set, all is lost." end VanagonLogger.info "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
20 21 22 |
# File 'lib/vanagon/driver.rb', line 20 def retry_count @retry_count ||= @project.retry_count || ENV["VANAGON_RETRY_COUNT"] || 1 end |
#run ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
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 166 167 168 169 170 |
# File 'lib/vanagon/driver.rb', line 124 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) VanagonLogger.info "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, workdir) @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 VanagonLogger.error(e) VanagonLogger.error e.backtrace.join("\n") raise e ensure if ["hardware", "ec2"].include?(@engine.name) @engine.teardown end end |
#timeout ⇒ Object
16 17 18 |
# File 'lib/vanagon/driver.rb', line 16 def timeout @timeout ||= @project.timeout || ENV["VANAGON_TIMEOUT"] || 7200 end |