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

Returns a new instance of Commander.



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

def initialize
  reset
end

Instance Attribute Details

#connectedObject

Returns the value of attribute connected.



8
9
10
# File 'lib/kamal/commander.rb', line 8

def connected
  @connected
end

#holding_lockObject

Returns the value of attribute holding_lock.



8
9
10
# File 'lib/kamal/commander.rb', line 8

def holding_lock
  @holding_lock
end

#lock_waitObject

Returns the value of attribute lock_wait.



8
9
10
# File 'lib/kamal/commander.rb', line 8

def lock_wait
  @lock_wait
end

#lock_wait_intervalObject

Returns the value of attribute lock_wait_interval.



8
9
10
# File 'lib/kamal/commander.rb', line 8

def lock_wait_interval
  @lock_wait_interval
end

#lock_wait_timeoutObject

Returns the value of attribute lock_wait_timeout.



8
9
10
# File 'lib/kamal/commander.rb', line 8

def lock_wait_timeout
  @lock_wait_timeout
end

#loggingObject

Returns the value of attribute logging.



8
9
10
# File 'lib/kamal/commander.rb', line 8

def logging
  @logging
end

#specific_hostsObject

Returns the value of attribute specific_hosts.



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

def specific_hosts
  @specific_hosts
end

#specific_rolesObject

Returns the value of attribute specific_roles.



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

def specific_roles
  @specific_roles
end

#verbosityObject

Returns the value of attribute verbosity.



8
9
10
# File 'lib/kamal/commander.rb', line 8

def verbosity
  @verbosity
end

Instance Method Details

#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



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

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

#alias(name) ⇒ Object



136
137
138
# File 'lib/kamal/commander.rb', line 136

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

#builderObject



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

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

#configObject



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

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

#configure(**kwargs) ⇒ Object



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

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

#configured?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/kamal/commander.rb', line 42

def configured?
  @config || @config_kwargs
end

#connected?Boolean

Returns:

  • (Boolean)


181
182
183
# File 'lib/kamal/commander.rb', line 181

def connected?
  self.connected
end

#dockerObject



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

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

#holding_lock?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/kamal/commander.rb', line 177

def holding_lock?
  self.holding_lock
end

#hookObject



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

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

#loadbalancerObject



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

def loadbalancer
  @commands[:loadbalancer] ||= Kamal::Commands::Loadbalancer.new(config, loadbalancer_config: loadbalancer_config)
end

#loadbalancer_configObject



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

def loadbalancer_config
  @loadbalancer_config ||= Kamal::Configuration::Loadbalancer.new(config: config, proxy_config: config.proxy.proxy_config, secrets: config.secrets)
end

#lockObject



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

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

#log(line) ⇒ Object



173
174
175
# File 'lib/kamal/commander.rb', line 173

def log(line)
  output_logger << "#{line}\n" if logging
end

#modify(command:, subcommand:) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
# File 'lib/kamal/commander.rb', line 161

def modify(command:, subcommand:)
  @logging = true
  if modify_started
    ActiveSupport::Notifications.instrument("modify.kamal",
      command: command, subcommand: subcommand, destination: config.destination, hosts: hosts) { yield }
  else
    yield
  end
ensure
  output_logger.close if modify_finished
end

#proxy(host) ⇒ Object



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

def proxy(host)
  Kamal::Commands::Proxy.new(config, host: host)
end

#pruneObject



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

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

#registryObject



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

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

#resetObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kamal/commander.rb', line 16

def reset
  self.verbosity = :info
  self.holding_lock = ENV["KAMAL_LOCK"] == "true"
  self.connected = false
  self.logging = false
  self.lock_wait = false
  self.lock_wait_timeout = 900
  self.lock_wait_interval = 15
  @modify_depth = 0
  @specifics = @specific_roles = @specific_hosts = nil
  @config = @config_kwargs = nil
  @output_logger = nil
  @commands = {}
end

#resolve_alias(name) ⇒ Object



140
141
142
143
144
145
146
147
# File 'lib/kamal/commander.rb', line 140

def resolve_alias(name)
  if @config
    @config.aliases[name]&.command
  else
    raw_config = Kamal::Configuration.load_raw_config(**@config_kwargs.to_h.slice(:config_file, :destination))
    raw_config[:aliases]&.dig(name)
  end
end

#serverObject



132
133
134
# File 'lib/kamal/commander.rb', line 132

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

#specific_primary!Object



46
47
48
49
50
51
52
53
# File 'lib/kamal/commander.rb', line 46

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



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

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



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/kamal/commander.rb', line 149

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