Class: Kamal::Configuration::Boot

Inherits:
Object
  • Object
show all
Includes:
Validation
Defined in:
lib/kamal/configuration/boot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validation

#validate!, #validation_yml

Constructor Details

#initialize(config:, boot_config: nil, context: nil) ⇒ Boot

Pass boot_config/context to scope this to a single role: the role's own boot: hash, and a context that points at the role in validation errors.



8
9
10
11
# File 'lib/kamal/configuration/boot.rb', line 8

def initialize(config:, boot_config: nil, context: nil)
  @boot_config = boot_config || config.raw_config.boot || {}
  validate! @boot_config, context: context
end

Instance Attribute Details

#boot_configObject (readonly)

Returns the value of attribute boot_config.



4
5
6
# File 'lib/kamal/configuration/boot.rb', line 4

def boot_config
  @boot_config
end

Instance Method Details

#limit?Boolean

Whether a limit is configured at all. Deliberately not a reader for the raw value: a percentage means nothing without the hosts it slices, so anything that needs the group size has to go through limit_for.

Returns:

  • (Boolean)


30
31
32
# File 'lib/kamal/configuration/boot.rb', line 30

def limit?
  boot_config["limit"].present?
end

#limit_for(hosts) ⇒ Object

The group size to slice hosts by. A percentage only means something against the set it will actually be applied to, and that set is not known until run time — --roles and --hosts narrow it, and accessories are never booted at all. So callers pass the hosts they are about to group rather than Boot reaching for a host list of its own.



17
18
19
20
21
22
23
24
25
# File 'lib/kamal/configuration/boot.rb', line 17

def limit_for(hosts)
  limit = boot_config["limit"]

  if limit.to_s.end_with?("%")
    [ hosts.count * limit.to_i / 100, 1 ].max
  else
    limit
  end
end

#parallel_rolesObject



38
39
40
# File 'lib/kamal/configuration/boot.rb', line 38

def parallel_roles
  boot_config["parallel_roles"]
end

#runner_options_for(hosts) ⇒ Object

SSHKit runner options expressing this pacing over hosts. Without a limit there is nothing to pace and on keeps its default parallel runner.

wait is always explicit: SSHKit::Runner::Sequential and ::Group both fall back to a 2 second interval, where Kamal's own boot wait means "no sleep unless you asked for one". A limit of 1 goes through Sequential rather than Group, which runs one host per slice without spawning a thread to do it. Neither trails a wait past the last group — Sequential pops its final host, and Kamal patches Group to match (sshkit_with_ext.rb).



50
51
52
53
54
55
56
57
58
59
# File 'lib/kamal/configuration/boot.rb', line 50

def runner_options_for(hosts)
  limit = limit_for(hosts)
  return {} unless limit

  if limit == 1
    { in: :sequence, wait: wait.to_i }
  else
    { in: :groups, limit: limit, wait: wait.to_i }
  end
end

#waitObject



34
35
36
# File 'lib/kamal/configuration/boot.rb', line 34

def wait
  boot_config["wait"]
end