Class: Dapp::Build::Stage::Base

Inherits:
Object
  • Object
show all
Includes:
Mod::Artifact, Mod::Logging, Helper::Sha256, Helper::Trivia
Defined in:
lib/dapp/build/stage/base.rb

Overview

Base of all stages

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mod::Logging

#image_info, #log_build, #log_image_commands, #log_image_info, #should_be_introspected?, #should_be_not_detailed?, #should_be_not_present?, #should_be_skipped?, #size_difference?

Methods included from Mod::Artifact

#after_artifacts, #apply_artifact, #artifact_app_options, #artifacts_signatures, #before_artifacts, #do_artifacts, #safe_cp

Methods included from Helper::Trivia

class_to_lowercase, #class_to_lowercase, #delete_file, #kwargs

Methods included from Helper::Sha256

#hashsum, #sha256

Constructor Details

#initialize(application, next_stage) ⇒ Base

Returns a new instance of Base.



14
15
16
17
18
19
# File 'lib/dapp/build/stage/base.rb', line 14

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.



12
13
14
# File 'lib/dapp/build/stage/base.rb', line 12

def application
  @application
end

#next_stage ⇒ Object

Returns the value of attribute next_stage.



11
12
13
# File 'lib/dapp/build/stage/base.rb', line 11

def next_stage
  @next_stage
end

#prev_stage ⇒ Object

Returns the value of attribute prev_stage.



11
12
13
# File 'lib/dapp/build/stage/base.rb', line 11

def prev_stage
  @prev_stage
end

Instance Method Details

#build! ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/dapp/build/stage/base.rb', line 21

def build!
  return if should_be_skipped?
  prev_stage.build! if prev_stage
  image_build
  raise Exception::IntrospectImage,
        message: application.t(code: 'introspect.stage', data: { name: name }),
        data: { built_id: image.built_id, options: image.send(:prepared_options) } if should_be_introspected?
end

#image ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dapp/build/stage/base.rb', line 40

def image
  @image ||= begin
    Image::Stage.new(name: image_name, from: from_image).tap do |image|
      image.add_volume "#{application.tmp_path}:#{application.container_tmp_path}"
      image.add_change_label dapp: application.config._basename
      before_artifacts.each { |artifact| apply_artifact(artifact, image) }
      yield image if block_given?
      after_artifacts.each { |artifact| apply_artifact(artifact, image) }
    end
  end
end

#save_in_cache! ⇒ Object



30
31
32
33
34
# File 'lib/dapp/build/stage/base.rb', line 30

def save_in_cache!
  return if image.tagged?
  prev_stage.save_in_cache!                                                          if prev_stage
  image.tag!(log_verbose: application.log_verbose?, log_time: application.log_time?) unless application.dry_run?
end

#signature ⇒ Object



36
37
38
# File 'lib/dapp/build/stage/base.rb', line 36

def signature
  hashsum [prev_stage.signature, artifacts_signatures]
end