Class: Kamal::Commander

Inherits:
Object
  • Object
show all
Defined in:
lib/kamal/commander.rb

Defined Under Namespace

Classes: Specifics

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommander



9
10
11
12
13
14
# File 'lib/kamal/commander.rb', line 9

def initialize
  self.verbosity = :info
  self.holding_lock = false
  self.connected = false
  @specifics = nil
end

Instance Attribute Details

#connectedObject

Returns the value of attribute connected.



6
7
8
# File 'lib/kamal/commander.rb', line 6

def connected
  @connected
end

#holding_lockObject

Returns the value of attribute holding_lock.



6
7
8
# File 'lib/kamal/commander.rb', line 6

def holding_lock
  @holding_lock
end

#specific_hostsObject

Returns the value of attribute specific_hosts.



31
32
33
# File 'lib/kamal/commander.rb', line 31

def specific_hosts
  @specific_hosts
end

#specific_rolesObject

Returns the value of attribute specific_roles.



31
32
33
# File 'lib/kamal/commander.rb', line 31

def specific_roles
  @specific_roles
end

#verbosityObject

Returns the value of attribute verbosity.



6
7
8
# File 'lib/kamal/commander.rb', line 6

def verbosity
  @verbosity
end

Instance Method Details

#accessories_on(host) ⇒ Object



79
80
81
# File 'lib/kamal/commander.rb', line 79

def accessories_on(host)
  config.accessories.select { |accessory| accessory.hosts.include?(host.to_s) }.map(&:name)
end

#accessory(name) ⇒ Object



88
89
90
# File 'lib/kamal/commander.rb', line 88

def accessory(name)
  Kamal::Commands::Accessory.new(config, name: name)
end

#accessory_namesObject



75
76
77
# File 'lib/kamal/commander.rb', line 75

def accessory_names
  config.accessories&.collect(&:name) || []
end

#alias(name) ⇒ Object



128
129
130
# File 'lib/kamal/commander.rb', line 128

def alias(name)
  config.aliases[name]
end

#app(role: nil, host: nil) ⇒ Object



84
85
86
# File 'lib/kamal/commander.rb', line 84

def app(role: nil, host: nil)
  Kamal::Commands::App.new(config, role: role, host: host)
end

#auditor(**details) ⇒ Object



92
93
94
# File 'lib/kamal/commander.rb', line 92

def auditor(**details)
  Kamal::Commands::Auditor.new(config, **details)
end

#boot_strategyObject



145
146
147
148
149
150
151
# File 'lib/kamal/commander.rb', line 145

def boot_strategy
  if config.boot.limit.present?
    { in: :groups, limit: config.boot.limit, wait: config.boot.wait }
  else
    {}
  end
end

#builderObject



96
97
98
# File 'lib/kamal/commander.rb', line 96

def builder
  @builder ||= Kamal::Commands::Builder.new(config)
end

#configObject



16
17
18
19
20
21
# File 'lib/kamal/commander.rb', line 16

def config
  @config ||= Kamal::Configuration.create_from(**@config_kwargs).tap do |config|
    @config_kwargs = nil
    configure_sshkit_with(config)
  end
end

#configure(**kwargs) ⇒ Object



23
24
25
# File 'lib/kamal/commander.rb', line 23

def configure(**kwargs)
  @config, @config_kwargs = nil, kwargs
end

#configured?Boolean



27
28
29
# File 'lib/kamal/commander.rb', line 27

def configured?
  @config || @config_kwargs
end

#connected?Boolean



157
158
159
# File 'lib/kamal/commander.rb', line 157

def connected?
  self.connected
end

#dockerObject



100
101
102
# File 'lib/kamal/commander.rb', line 100

def docker
  @docker ||= Kamal::Commands::Docker.new(config)
end

#holding_lock?Boolean



153
154
155
# File 'lib/kamal/commander.rb', line 153

def holding_lock?
  self.holding_lock
end

#hookObject



104
105
106
# File 'lib/kamal/commander.rb', line 104

def hook
  @hook ||= Kamal::Commands::Hook.new(config)
end

#lockObject



108
109
110
# File 'lib/kamal/commander.rb', line 108

def lock
  @lock ||= Kamal::Commands::Lock.new(config)
end

#proxyObject



112
113
114
# File 'lib/kamal/commander.rb', line 112

def proxy
  @proxy ||= Kamal::Commands::Proxy.new(config)
end

#pruneObject



116
117
118
# File 'lib/kamal/commander.rb', line 116

def prune
  @prune ||= Kamal::Commands::Prune.new(config)
end

#registryObject



120
121
122
# File 'lib/kamal/commander.rb', line 120

def registry
  @registry ||= Kamal::Commands::Registry.new(config)
end

#serverObject



124
125
126
# File 'lib/kamal/commander.rb', line 124

def server
  @server ||= Kamal::Commands::Server.new(config)
end

#specific_primary!Object



33
34
35
36
37
38
39
40
# File 'lib/kamal/commander.rb', line 33

def specific_primary!
  @specifics = nil
  if specific_roles.present?
    self.specific_hosts = [ specific_roles.first.primary_host ]
  else
    self.specific_hosts = [ config.primary_host ]
  end
end

#with_specific_hosts(hosts) ⇒ Object



68
69
70
71
72
73
# File 'lib/kamal/commander.rb', line 68

def with_specific_hosts(hosts)
  original_hosts, self.specific_hosts = specific_hosts, hosts
  yield
ensure
  self.specific_hosts = original_hosts
end

#with_verbosity(level) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/kamal/commander.rb', line 133

def with_verbosity(level)
  old_level = self.verbosity

  self.verbosity = level
  SSHKit.config.output_verbosity = level

  yield
ensure
  self.verbosity = old_level
  SSHKit.config.output_verbosity = old_level
end