Class: Dapp::Dimg::Image::Stage

Inherits:
Docker
  • Object
show all
Includes:
Argument
Defined in:
lib/dapp/dimg/image/stage.rb

Direct Known Subclasses

Scratch

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

#config_option, #created_at, #id, image_by_name, image_config, image_config_option, image_inspect, image_inspects, image_name?, image_name_format, image_reset, images, load!, #pull!, #push!, reset_image_inspect, save!, #size, tag!, tag?, tag_format, #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("#{dapp.host_docker} rm #{container_name}")
end

#built?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/dapp/dimg/image/stage.rb', line 31

def built?
  !built_id.nil?
end

#built_idObject



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

#labelsObject



62
63
64
# File 'lib/dapp/dimg/image/stage.rb', line 62

def labels
  config_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