Class: Kamal::Configuration::Role::Healthcheck

Inherits:
Object
  • Object
show all
Defined in:
lib/kamal/configuration/role/healthcheck.rb

Constant Summary collapse

DEFAULT_PATH =
"/up"
DEFAULT_INTERVAL =
1
DOCKER_ONLY_KEYS =

Everything that only ever reaches docker as a --health-* flag. An exec probe emits none of those, so combining them would silently drop whatever the operator wrote.

%w[ cmd port path interval timeout retries start_period start_interval ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(healthcheck_config:, context: "healthcheck") ⇒ Healthcheck

Returns a new instance of Healthcheck.



12
13
14
15
16
# File 'lib/kamal/configuration/role/healthcheck.rb', line 12

def initialize(healthcheck_config:, context: "healthcheck")
  @healthcheck_config = healthcheck_config
  @context = context
  validate!
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/kamal/configuration/role/healthcheck.rb', line 9

def context
  @context
end

#healthcheck_configObject (readonly)

Returns the value of attribute healthcheck_config.



9
10
11
# File 'lib/kamal/configuration/role/healthcheck.rb', line 9

def healthcheck_config
  @healthcheck_config
end

Instance Method Details

#argsObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/kamal/configuration/role/healthcheck.rb', line 47

def args
  return [] if exec?

  optionize({
      "health-cmd" => cmd,
      "health-interval" => duration(interval),
      "health-timeout" => duration(healthcheck_config["timeout"]),
      "health-retries" => healthcheck_config["retries"],
      "health-start-period" => duration(healthcheck_config["start_period"]),
      "health-start-interval" => duration(healthcheck_config["start_interval"])
    }.compact)
end

#cmdObject

The command docker runs inside the container. Custom commands win; otherwise we build the same curl check Kamal 1 shipped.



20
21
22
# File 'lib/kamal/configuration/role/healthcheck.rb', line 20

def cmd
  healthcheck_config["cmd"] || http_health_check
end

#execObject

The probe kamal docker execs from the deploy host during a boot, for images whose HEALTHCHECK cannot be changed. Deploy-time only: docker never runs it, so docker ps shows no (healthy) and docker inspect keeps no probe history.



27
28
29
# File 'lib/kamal/configuration/role/healthcheck.rb', line 27

def exec
  healthcheck_config["exec"]
end

#exec?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/kamal/configuration/role/healthcheck.rb', line 31

def exec?
  exec.present?
end

#intervalObject



43
44
45
# File 'lib/kamal/configuration/role/healthcheck.rb', line 43

def interval
  healthcheck_config.fetch("interval", DEFAULT_INTERVAL)
end

#pathObject



39
40
41
# File 'lib/kamal/configuration/role/healthcheck.rb', line 39

def path
  healthcheck_config.fetch("path", DEFAULT_PATH)
end

#portObject



35
36
37
# File 'lib/kamal/configuration/role/healthcheck.rb', line 35

def port
  healthcheck_config["port"]
end