Class: Bankai::Docker::Stage

Inherits:
Object
  • Object
show all
Includes:
DSL::Argument, DSL::Commands, DSL::Name
Defined in:
lib/bankai/docker/stage.rb

Overview

The multistage

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DSL::Commands

#add, #cmd, #copy, #entrypoint, #env, #expose, #package, #package_command, #run, #runtime_package, #volume, #workdir

Methods included from DSL::Argument

#argument

Constructor Details

#initialize(name, from: nil, &block) ⇒ Stage

Returns a new instance of Stage.



22
23
24
25
26
27
28
29
30
31
# File 'lib/bankai/docker/stage.rb', line 22

def initialize(name, from: nil, &block)
  @name = name
  @from = from || "ruby:#{::RUBY_VERSION}-alpine"
  @index = main? ? 999 : Stage.next_index
  @commands = []
  @arguments = {}
  @block = block
  @mutex = Mutex.new
  @executed = false
end

Class Attribute Details

.indexObject (readonly)

Returns the value of attribute index.



8
9
10
# File 'lib/bankai/docker/stage.rb', line 8

def index
  @index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



20
21
22
# File 'lib/bankai/docker/stage.rb', line 20

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



20
21
22
# File 'lib/bankai/docker/stage.rb', line 20

def name
  @name
end

Class Method Details

.next_indexObject



10
11
12
13
# File 'lib/bankai/docker/stage.rb', line 10

def next_index
  @index ||= 0
  @index += 1
end

Instance Method Details

#command(type, *arguments) ⇒ Object



49
50
51
# File 'lib/bankai/docker/stage.rb', line 49

def command(type, *arguments)
  @commands << Command.new(type, *arguments)
end

#copiesObject



64
65
66
67
68
# File 'lib/bankai/docker/stage.rb', line 64

def copies
  return unless main?

  Copy.to_s
end

#from(new_value = nil) ⇒ Object



43
44
45
46
47
# File 'lib/bankai/docker/stage.rb', line 43

def from(new_value = nil)
  return @from if new_value.nil?

  @from = new_value
end

#main?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/bankai/docker/stage.rb', line 39

def main?
  name == :main
end

#produce(source, destination = nil) ⇒ Object



60
61
62
# File 'lib/bankai/docker/stage.rb', line 60

def produce(source, destination = nil)
  Copy.add(@name, source, destination || source)
end

#tagObject



33
34
35
36
37
# File 'lib/bankai/docker/stage.rb', line 33

def tag
  return File.name if main?

  "#{File.name}:#{@name}"
end

#to_sObject



53
54
55
56
57
58
# File 'lib/bankai/docker/stage.rb', line 53

def to_s
  ensure_executed
  root = Bankai::Docker::Generators::Base.default_source_root
  template = ERB.new(::File.read("#{root}/stage.erb"), nil, '-')
  template.result(binding)
end