Class: Dapp::Image::Stage

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

Overview

Stage

Direct Known Subclasses

Scratch

Instance Attribute Summary

Attributes inherited from Docker

#from, #name, #project

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_volume, #add_volumes_from, #prepare_instructions

Methods inherited from Docker

cache, #cache_reset, cache_reset, #created_at, #id, image_config_option, #pull!, #push!, #size, #tagged?, #untag!

Constructor Details

#initialize(name:, project:, built_id: nil, from: nil) ⇒ Stage

Returns a new instance of Stage.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dapp/image/stage.rb', line 8

def initialize(name:, project:, built_id: nil, from: nil)
  @container_name = "#{name[/[[^:].]*/]}.#{SecureRandom.hex(4)}"
  @built_id = built_id

  @bash_commands          = []
  @options                = {}
  @change_options         = {}
  @service_change_options = {}

  super(name: name, project: project, from: from)
end

Instance Method Details

#build! ⇒ Object



24
25
26
27
28
29
# File 'lib/dapp/image/stage.rb', line 24

def build!
  run!
  @built_id = commit!
ensure
  project.shellout("docker rm #{container_name}")
end

#built? ⇒ Boolean

Returns:

  • (Boolean)


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

def built?
  !@built_id.nil?
end

#built_id ⇒ Object



20
21
22
# File 'lib/dapp/image/stage.rb', line 20

def built_id
  @built_id ||= id
end

#export!(name) ⇒ Object



35
36
37
38
39
40
# File 'lib/dapp/image/stage.rb', line 35

def export!(name)
  image = self.class.new(name: name, project: project, built_id: built_id)
  image.tag!
  image.push!
  image.untag!
end

#import!(name) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/dapp/image/stage.rb', line 42

def import!(name)
  image = self.class.new(name: name, project: project)
  image.pull!
  @built_id = image.built_id
  tag!
  image.untag!
end

#labels ⇒ Object

Raises:



56
57
58
59
# File 'lib/dapp/image/stage.rb', line 56

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

#tag! ⇒ Object



50
51
52
53
54
# File 'lib/dapp/image/stage.rb', line 50

def tag!
  project.log_warning(desc: { code: :another_image_already_tagged }) if !(existed_id = id).nil? && built_id != existed_id
  project.shellout!("docker tag #{built_id} #{name}")
  cache_reset
end