Class: Dash::Commander

Inherits:
Object
  • Object
show all
Defined in:
lib/dash/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/dash/commander.rb', line 12

def initialize
  reset
end

Instance Attribute Details

#connectedObject

Returns the value of attribute connected.



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

def connected
  @connected
end

#holding_lockObject

Returns the value of attribute holding_lock.



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

def holding_lock
  @holding_lock
end

#holding_server_lockObject

Returns the value of attribute holding_server_lock.



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

def holding_server_lock
  @holding_server_lock
end

#lock_waitObject

Returns the value of attribute lock_wait.



8
9
10
# File 'lib/dash/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/dash/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/dash/commander.rb', line 8

def lock_wait_timeout
  @lock_wait_timeout
end

#loggingObject

Returns the value of attribute logging.



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

def logging
  @logging
end

#specific_hostsObject

Returns the value of attribute specific_hosts.



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

def specific_hosts
  @specific_hosts
end

#specific_rolesObject

Returns the value of attribute specific_roles.



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

def specific_roles
  @specific_roles
end

#verbosityObject

Returns the value of attribute verbosity.



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

def verbosity
  @verbosity
end

Instance Method Details

#accessory(name) ⇒ Object



89
90
91
# File 'lib/dash/commander.rb', line 89

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

#accessory_namesObject



81
82
83
# File 'lib/dash/commander.rb', line 81

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

#alias(name) ⇒ Object



143
144
145
# File 'lib/dash/commander.rb', line 143

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

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



85
86
87
# File 'lib/dash/commander.rb', line 85

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

#auditor(**details) ⇒ Object



93
94
95
# File 'lib/dash/commander.rb', line 93

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

#builderObject



97
98
99
# File 'lib/dash/commander.rb', line 97

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

#configObject



32
33
34
35
36
37
# File 'lib/dash/commander.rb', line 32

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

#configure(**kwargs) ⇒ Object



39
40
41
# File 'lib/dash/commander.rb', line 39

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

#configured?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/dash/commander.rb', line 43

def configured?
  @config || @config_kwargs
end

#connected?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'lib/dash/commander.rb', line 192

def connected?
  self.connected
end

#dockerObject



101
102
103
# File 'lib/dash/commander.rb', line 101

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

#holding_lock?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/dash/commander.rb', line 188

def holding_lock?
  self.holding_lock
end

#holding_server_lock?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/dash/commander.rb', line 184

def holding_server_lock?
  self.holding_server_lock
end

#hookObject



105
106
107
# File 'lib/dash/commander.rb', line 105

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

#loadbalancerObject



127
128
129
# File 'lib/dash/commander.rb', line 127

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

#loadbalancer_configObject



123
124
125
# File 'lib/dash/commander.rb', line 123

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

#lockObject



109
110
111
# File 'lib/dash/commander.rb', line 109

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

#log(line) ⇒ Object



180
181
182
# File 'lib/dash/commander.rb', line 180

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

#modify(command:, subcommand:) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/dash/commander.rb', line 168

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



119
120
121
# File 'lib/dash/commander.rb', line 119

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

#pruneObject



131
132
133
# File 'lib/dash/commander.rb', line 131

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

#registryObject



135
136
137
# File 'lib/dash/commander.rb', line 135

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

#resetObject



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

def reset
  self.verbosity = :info
  self.holding_lock = env_flag("DASH_LOCK", "KAMAL_LOCK")
  self.holding_server_lock = env_flag("DASH_SERVER_LOCK", "KAMAL_SERVER_LOCK")
  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



147
148
149
150
151
152
153
154
# File 'lib/dash/commander.rb', line 147

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

#serverObject



139
140
141
# File 'lib/dash/commander.rb', line 139

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

#server_lockObject

Guards the kamal-proxy container, which a host runs once for every destination deployed onto it. Every destination contends for this one.



115
116
117
# File 'lib/dash/commander.rb', line 115

def server_lock
  @commands[:server_lock] ||= Dash::Commands::Lock.new(config, scope: :server)
end

#specific_primary!Object



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

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



74
75
76
77
78
79
# File 'lib/dash/commander.rb', line 74

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



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/dash/commander.rb', line 156

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