Class: Krane::ContainerOverrides

Inherits:
Object
  • Object
show all
Defined in:
lib/krane/container_overrides.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command: nil, arguments: nil, env_vars: [], image_tag: nil) ⇒ ContainerOverrides

Returns a new instance of ContainerOverrides.



6
7
8
9
10
11
# File 'lib/krane/container_overrides.rb', line 6

def initialize(command: nil, arguments: nil, env_vars: [], image_tag: nil)
  @command = command
  @arguments = arguments
  @env_vars = env_vars
  @image_tag = image_tag
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



4
5
6
# File 'lib/krane/container_overrides.rb', line 4

def arguments
  @arguments
end

#commandObject (readonly)

Returns the value of attribute command.



4
5
6
# File 'lib/krane/container_overrides.rb', line 4

def command
  @command
end

#env_varsObject (readonly)

Returns the value of attribute env_vars.



4
5
6
# File 'lib/krane/container_overrides.rb', line 4

def env_vars
  @env_vars
end

#image_tagObject (readonly)

Returns the value of attribute image_tag.



4
5
6
# File 'lib/krane/container_overrides.rb', line 4

def image_tag
  @image_tag
end

Instance Method Details

#apply!(container) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/krane/container_overrides.rb', line 13

def apply!(container)
  container.command = command if command
  container.args = arguments if arguments

  if image_tag
    image = container.image
    base_image, _old_tag = image.split(':')
    new_image = "#{base_image}:#{image_tag}"

    container.image = new_image
  end

  env_args = env_vars.map do |env|
    key, value = env.split('=', 2)
    { name: key, value: value }
  end
  container.env ||= []
  container.env = container.env.map(&:to_h) + env_args
end