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

Inherits:
Object
  • Object
show all
Includes:
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 Helper::Trivia

class_to_lowercase, #class_to_lowercase, #delete_file, #kwargs, #to_mb

Methods included from Helper::Sha256

#hashsum, #sha256

Constructor Details

#initialize(application, next_stage) ⇒ Base

Returns a new instance of Base.



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

def initialize(application, next_stage)
  @application = application

  @next_stage = next_stage
  @next_stage.prev_stage = self
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



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

def application
  @application
end

#next_stageObject

Returns the value of attribute next_stage.



9
10
11
# File 'lib/dapp/build/stage/base.rb', line 9

def next_stage
  @next_stage
end

#prev_stageObject

Returns the value of attribute prev_stage.



9
10
11
# File 'lib/dapp/build/stage/base.rb', line 9

def prev_stage
  @prev_stage
end

Instance Method Details

#build!Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dapp/build/stage/base.rb', line 20

def build!
  return if should_be_skipped?
  prev_stage.build! if prev_stage
  begin
    if image.tagged?
      application.log_state(name, state: application.t(code: 'state.using_cache'))
    elsif application.dry_run?
      application.log_state(name, state: application.t(code: 'state.build'), styles: { status: :success })
    else
      application.log_process(name, process: application.t(code: 'status.process.building'), short: should_be_not_detailed?) do
        image_build!
      end
    end
  ensure
    log_build
  end
  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

#imageObject



52
53
54
55
56
57
58
59
# File 'lib/dapp/build/stage/base.rb', line 52

def image
  @image ||= begin
    StageImage.new(name: image_name, from: from_image).tap do |image|
      image.add_volume "#{application.build_path}:#{application.container_build_path}"
      yield image if block_given?
    end
  end
end

#save_in_cache!Object

rubocop:enable Metrics/AbcSize, Metrics/MethodLength



42
43
44
45
46
# File 'lib/dapp/build/stage/base.rb', line 42

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

#signatureObject



48
49
50
# File 'lib/dapp/build/stage/base.rb', line 48

def signature
  hashsum prev_stage.signature
end