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_idObject



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

def built_id
  @built_id ||= id
end

#export!(name) ⇒ Object



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

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



38
39
40
41
42
43
44
# File 'lib/dapp/image/stage.rb', line 38

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

#labelsObject

Raises:



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

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



46
47
48
49
50
# File 'lib/dapp/image/stage.rb', line 46

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