Class: Dash::Commands::Proxy::State

Inherits:
Object
  • Object
show all
Defined in:
lib/dash/commands/proxy/state.rb

Overview

What one docker inspect of a proxy container tells a boot: whether it exists, which image tag it runs, and the config digest it was booted with. Three questions that used to cost three round trips each (container_id, version, config_digest).

Produced by Dash::Commands::Proxy#inspect_state and its loadbalancer twin, both of which are captured with raise_on_non_zero_exit: false - a host with no container inspects to empty output, which parses to a state that simply does not exist.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, image: nil, digest: nil) ⇒ State

Returns a new instance of State.



16
17
18
19
20
# File 'lib/dash/commands/proxy/state.rb', line 16

def initialize(id: nil, image: nil, digest: nil)
  @id = id.presence
  @image = image.presence
  @digest = digest.presence
end

Instance Attribute Details

#digest ⇒ Object (readonly)

Returns the value of attribute digest.



9
10
11
# File 'lib/dash/commands/proxy/state.rb', line 9

def digest
  @digest
end

#id ⇒ Object (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/dash/commands/proxy/state.rb', line 9

def id
  @id
end

#image ⇒ Object (readonly)

Returns the value of attribute image.



9
10
11
# File 'lib/dash/commands/proxy/state.rb', line 9

def image
  @image
end

Class Method Details

.parse(output) ⇒ Object



11
12
13
14
# File 'lib/dash/commands/proxy/state.rb', line 11

def self.parse(output)
  id, image, digest = output.to_s.strip.split(" ", 3)
  new(id: id, image: image, digest: digest)
end

Instance Method Details

#exists? ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/dash/commands/proxy/state.rb', line 22

def exists?
  id.present?
end

#version ⇒ Object

The tag, read the way Dash::Commands::Proxy#version reads it - everything past the LAST colon, so a registry host carrying a port does not get mistaken for the version.



28
29
30
# File 'lib/dash/commands/proxy/state.rb', line 28

def version
  image&.split(":")&.last
end