Class: Dapp::Build::Stage::Base
Overview
Direct Known Subclasses
ArtifactBase, BeforeInstall, BeforeSetup, BuildArtifact, DockerInstructions, From, GABase, GADependenciesBase, InstallGroup::Install, SetupGroup::ChefCookbooks, SetupGroup::Setup
Instance Attribute Summary collapse
Instance Method Summary
collapse
#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?
class_to_lowercase, #class_to_lowercase, #delete_file, #kwargs, #search_file_upward
#hashsum, #paths_content_hashsum, #sha256
Constructor Details
#initialize(dimg, 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(dimg, next_stage)
@dimg = dimg
@next_stage = next_stage
@next_stage.prev_stage = self
end
|
Instance Attribute Details
#dimg ⇒ Object
Returns the value of attribute dimg.
11
12
13
|
# File 'lib/dapp/build/stage/base.rb', line 11
def dimg
@dimg
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
#artifact? ⇒ Boolean
144
145
146
|
# File 'lib/dapp/build/stage/base.rb', line 144
def artifact?
false
end
|
#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
dimg.introspect_image!(image: 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 dimg.project.dry_run?
try_lock = proc do
next yield unless should_be_tagged?
no_lock = false
dimg.project.lock("#{dimg.project.name}.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
|
#builder_checksum ⇒ Object
137
138
|
# File 'lib/dapp/build/stage/base.rb', line 137
def builder_checksum
end
|
#dependencies ⇒ Object
140
141
142
|
# File 'lib/dapp/build/stage/base.rb', line 140
def dependencies
[]
end
|
#dependencies_empty? ⇒ Boolean
119
120
121
|
# File 'lib/dapp/build/stage/base.rb', line 119
def dependencies_empty?
dependencies.flatten.compact.delete_if { |val| val.respond_to?(:empty?) && val.empty? }.empty?
end
|
#empty? ⇒ Boolean
115
116
117
|
# File 'lib/dapp/build/stage/base.rb', line 115
def empty?
dependencies_empty?
end
|
#image ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/dapp/build/stage/base.rb', line 65
def image
@image ||= begin
if empty?
prev_stage.image
else
Image::Stage.new(name: image_name, from: from_image, project: dimg.project)
end
end
end
|
#image_add_build_volumes ⇒ Object
98
99
100
|
# File 'lib/dapp/build/stage/base.rb', line 98
def image_add_build_volumes
image_add_default_volumes(:build_dir)
end
|
#image_add_default_volumes(type) ⇒ Object
102
103
104
105
106
107
108
109
|
# File 'lib/dapp/build/stage/base.rb', line 102
def image_add_default_volumes(type)
(dimg.config.public_send("_#{type}_mount").map(&:_to) +
from_image.labels.select { |l, _| l == "dapp-#{type}-dir" }.map { |_, value| value.split(';') }.flatten).each do |path|
absolute_path = File.expand_path(File.join('/', path))
tmp_path = dimg.send(type, 'mount', absolute_path[1..-1]).tap(&:mkpath)
image.add_volume "#{tmp_path}:#{absolute_path}"
end
end
|
#image_add_tmp_volumes ⇒ Object
94
95
96
|
# File 'lib/dapp/build/stage/base.rb', line 94
def image_add_tmp_volumes
image_add_default_volumes(:tmp_dir)
end
|
#image_add_volumes ⇒ Object
89
90
91
92
|
# File 'lib/dapp/build/stage/base.rb', line 89
def image_add_volumes
image_add_tmp_volumes
image_add_build_volumes
end
|
#image_should_be_build? ⇒ Boolean
111
112
113
|
# File 'lib/dapp/build/stage/base.rb', line 111
def image_should_be_build?
!empty? || dimg.project.log_verbose?
end
|
#prepare_image ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/dapp/build/stage/base.rb', line 75
def prepare_image
return if dimg.project.dry_run?
image.add_volumes_from dimg.project.base_container
image_add_volumes
image.add_service_change_label dapp: dimg.stage_dapp_label
image.add_service_change_label 'dapp-cache-version'.to_sym => Dapp::BUILD_CACHE_VERSION
image.add_service_change_label 'dapp-dev-mode'.to_sym => true if dimg.dev_mode?
if dimg.project.ssh_auth_sock
image.add_volume "#{dimg.project.ssh_auth_sock}:/tmp/dapp-ssh-agent"
image.add_env 'SSH_AUTH_SOCK', '/tmp/dapp-ssh-agent'
end
end
|
#save_in_cache! ⇒ Object
60
61
62
63
|
# File 'lib/dapp/build/stage/base.rb', line 60
def save_in_cache!
prev_stage.save_in_cache! if prev_stage
image.save_in_cache! if should_be_tagged? && !dimg.project.dry_run?
end
|
#signature ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/dapp/build/stage/base.rb', line 123
def signature
if empty?
prev_stage.signature
else
args = []
args << prev_stage.signature unless prev_stage.nil?
args << dimg.build_cache_version
args << builder_checksum
args.concat(dependencies.flatten)
hashsum args
end
end
|