Class: Dapp::Dimg::Image::Stage
Instance Attribute Summary
Attributes inherited from Docker
#dapp, #from, #name
Instance Method Summary
collapse
Methods included from Argument
#add_change_cmd, #add_change_entrypoint, #add_change_env, #add_change_expose, #add_change_label, #add_change_onbuild, #add_change_user, #add_change_volume, #add_change_workdir, #add_command, #add_env, #add_service_change_label, #add_service_command, #add_volume, #add_volumes_from, #prepare_instructions
Methods inherited from Docker
cache, cache_reset, #cache_reset, #created_at, #id, image_by_name, image_config_option, image_name?, image_name_format, load!, #pull!, #push!, save!, #size, tag!, #tagged?, #untag!
Constructor Details
#initialize(name:, dapp:, built_id: nil, from: nil) ⇒ Stage
Returns a new instance of Stage.
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/dapp/dimg/image/stage.rb', line 7
def initialize(name:, dapp:, built_id: nil, from: nil)
@container_name = "#{name[/[[^:].]*/]}.#{SecureRandom.hex(4)}"
@built_id = built_id
@bash_commands = []
@service_bash_commands = []
@options = {}
@change_options = {}
@service_change_options = {}
super(name: name, dapp: dapp, from: from)
end
|
Instance Method Details
#build! ⇒ Object
24
25
26
27
28
29
|
# File 'lib/dapp/dimg/image/stage.rb', line 24
def build!
run!
@built_id = commit!
ensure
dapp.shellout("docker rm #{container_name}")
end
|
#built? ⇒ Boolean
31
32
33
|
# File 'lib/dapp/dimg/image/stage.rb', line 31
def built?
!built_id.nil?
end
|
#built_id ⇒ Object
20
21
22
|
# File 'lib/dapp/dimg/image/stage.rb', line 20
def built_id
@built_id ||= id
end
|
#export!(name) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/dapp/dimg/image/stage.rb', line 35
def export!(name)
tag!(name).tap do |image|
image.push!
image.untag!
end
end
|
#import!(name) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/dapp/dimg/image/stage.rb', line 48
def import!(name)
clone!(name).tap do |image|
image.pull!
@built_id = image.built_id
save_in_cache!
image.untag!
end
end
|
#labels ⇒ Object
62
63
64
65
|
# File 'lib/dapp/dimg/image/stage.rb', line 62
def labels
raise Error::Build, code: :image_not_exist, data: { name: name } if built_id.nil?
self.class.image_config_option(image_id: built_id, option: 'labels')
end
|
#save_in_cache! ⇒ Object
57
58
59
60
|
# File 'lib/dapp/dimg/image/stage.rb', line 57
def save_in_cache!
dapp.log_warning(desc: { code: :another_image_already_tagged }) if !(existed_id = id).nil? && built_id != existed_id
self.class.tag!(id: built_id, tag: name)
end
|
#tag!(name) ⇒ Object
42
43
44
45
46
|
# File 'lib/dapp/dimg/image/stage.rb', line 42
def tag!(name)
clone!(name).tap do |image|
self.class.tag!(id: image.built_id, tag: image.name)
end
end
|