Class: Dapp::Build::Stage::Base
- Inherits:
-
Object
- Object
- Dapp::Build::Stage::Base
- Includes:
- Mod::Logging, Helper::Sha256, Helper::Trivia
- Defined in:
- lib/dapp/build/stage/base.rb
Overview
Base of all stages
Direct Known Subclasses
ArtifactBase, BeforeInstall, BeforeSetup, BuildArtifact, DockerInstructions, From, GABase, GADependenciesBase, InstallGroup::Install, SetupGroup::ChefCookbooks, SetupGroup::Setup
Instance Attribute Summary collapse
-
#application ⇒ Object
readonly
Returns the value of attribute application.
-
#next_stage ⇒ Object
Returns the value of attribute next_stage.
-
#prev_stage ⇒ Object
Returns the value of attribute prev_stage.
Instance Method Summary collapse
-
#build! ⇒ Object
rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity.
-
#build_lock! ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity.
- #dependencies ⇒ Object
- #dependencies_empty? ⇒ Boolean
- #empty? ⇒ Boolean
- #image ⇒ Object
- #image_add_tmp_volumes(type) ⇒ Object
- #image_should_be_build? ⇒ Boolean
-
#initialize(application, next_stage) ⇒ Base
constructor
A new instance of Base.
- #prepare_image ⇒ Object
- #save_in_cache! ⇒ Object
- #signature ⇒ Object
Methods included from Mod::Logging
#ignore_log_commands?, #log_build, #log_image_build, #log_image_build_process, #log_image_commands, #log_image_created_at, #log_image_details, #log_image_instructions, #log_image_size, #log_name, #log_name_context, #log_state, #should_be_introspected?, #should_be_quiet?, #should_not_be_detailed?
Methods included from Helper::Trivia
class_to_lowercase, #class_to_lowercase, #delete_file, #kwargs
Methods included from Helper::Sha256
#hashsum, #paths_content_hashsum, #sha256
Constructor Details
#initialize(application, next_stage) ⇒ Base
Returns a new instance of Base.
13 14 15 16 17 18 |
# File 'lib/dapp/build/stage/base.rb', line 13 def initialize(application, next_stage) @application = application @next_stage = next_stage @next_stage.prev_stage = self end |
Instance Attribute Details
#application ⇒ Object (readonly)
Returns the value of attribute application.
11 12 13 |
# File 'lib/dapp/build/stage/base.rb', line 11 def application @application end |
#next_stage ⇒ Object
Returns the value of attribute next_stage.
10 11 12 |
# File 'lib/dapp/build/stage/base.rb', line 10 def next_stage @next_stage end |
#prev_stage ⇒ Object
Returns the value of attribute prev_stage.
10 11 12 |
# File 'lib/dapp/build/stage/base.rb', line 10 def prev_stage @prev_stage end |
Instance Method Details
#build! ⇒ Object
rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
50 51 52 53 54 55 56 57 58 |
# File 'lib/dapp/build/stage/base.rb', line 50 def build! return if should_be_skipped? prev_stage.build! if prev_stage if image_should_be_build? prepare_image unless image.tagged? log_image_build(&method(:image_build)) end raise Exception::IntrospectImage, data: { built_id: image.built_id, options: image.send(:prepared_options) } if should_be_introspected? end |
#build_lock! ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
21 22 23 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/dapp/build/stage/base.rb', line 21 def build_lock! return yield if application.project.dry_run? try_lock = proc do next yield unless should_be_tagged? no_lock = false application.project.lock("#{application.config._basename}.image.#{image.name}") do image.cache_reset if should_be_tagged? yield else no_lock = true end end yield if no_lock end if prev_stage prev_stage.build_lock! { try_lock.call } else try_lock.call end end |
#dependencies ⇒ Object
119 120 121 |
# File 'lib/dapp/build/stage/base.rb', line 119 def dependencies [] end |
#dependencies_empty? ⇒ Boolean
107 108 109 |
# File 'lib/dapp/build/stage/base.rb', line 107 def dependencies_empty? dependencies.flatten.compact.delete_if { |val| val.respond_to?(:empty?) && val.empty? }.empty? end |
#empty? ⇒ Boolean
103 104 105 |
# File 'lib/dapp/build/stage/base.rb', line 103 def empty? dependencies_empty? end |
#image ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/dapp/build/stage/base.rb', line 66 def image @image ||= begin if empty? prev_stage.image else Image::Stage.new(name: image_name, from: from_image, project: application.project) end end end |
#image_add_tmp_volumes(type) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/dapp/build/stage/base.rb', line 90 def image_add_tmp_volumes(type) (application.config.public_send("_#{type}_dir")._store + from_image.labels.select { |l, _| l == "dapp-#{type}-dir" }.map { |_, value| value.split(';') }.flatten).each do |path| absolute_path = File.(File.join('/', path)) tmp_path = application.send("#{type}_path", absolute_path[1..-1]).tap(&:mkpath) image.add_volume "#{tmp_path}:#{absolute_path}" end end |
#image_should_be_build? ⇒ Boolean
99 100 101 |
# File 'lib/dapp/build/stage/base.rb', line 99 def image_should_be_build? !empty? || application.project.log_verbose? end |
#prepare_image ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/dapp/build/stage/base.rb', line 76 def prepare_image return if application.project.dry_run? image.add_volumes_from application.project.base_container image_add_tmp_volumes(:tmp) image_add_tmp_volumes(:build) image.add_service_change_label dapp: application.stage_dapp_label image.add_service_change_label 'dapp-cache-version'.to_sym => Dapp::BUILD_CACHE_VERSION if application.project.ssh_auth_sock image.add_volume "#{application.project.ssh_auth_sock}:#{application.project.ssh_auth_sock}" image.add_env 'SSH_AUTH_SOCK', application.project.ssh_auth_sock end end |
#save_in_cache! ⇒ Object
60 61 62 63 64 |
# File 'lib/dapp/build/stage/base.rb', line 60 def save_in_cache! prev_stage.save_in_cache! if prev_stage return unless should_be_tagged? image.tag! unless application.project.dry_run? end |
#signature ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/dapp/build/stage/base.rb', line 111 def signature if empty? prev_stage.signature else hashsum [prev_stage.signature, *dependencies.flatten] end end |