Class: Dash::Commander
- Inherits:
-
Object
- Object
- Dash::Commander
- Defined in:
- lib/dash/commander.rb
Defined Under Namespace
Classes: Specifics
Instance Attribute Summary collapse
-
#connected ⇒ Object
Returns the value of attribute connected.
-
#holding_lock ⇒ Object
Returns the value of attribute holding_lock.
-
#holding_server_lock ⇒ Object
Returns the value of attribute holding_server_lock.
-
#lock_wait ⇒ Object
Returns the value of attribute lock_wait.
-
#lock_wait_interval ⇒ Object
Returns the value of attribute lock_wait_interval.
-
#lock_wait_timeout ⇒ Object
Returns the value of attribute lock_wait_timeout.
-
#logging ⇒ Object
Returns the value of attribute logging.
-
#report ⇒ Object
readonly
Returns the value of attribute report.
-
#run_directory_ensured_on ⇒ Object
readonly
Hosts whose run directory this process has already swept, so the second lock acquire of a command does not re-run the migration everywhere.
-
#specific_hosts ⇒ Object
Returns the value of attribute specific_hosts.
-
#specific_roles ⇒ Object
Returns the value of attribute specific_roles.
-
#timings ⇒ Object
readonly
Returns the value of attribute timings.
-
#verbosity ⇒ Object
Returns the value of attribute verbosity.
Instance Method Summary collapse
- #accessory(name) ⇒ Object
- #accessory_names ⇒ Object
- #alias(name) ⇒ Object
- #app(role: nil, host: nil) ⇒ Object
- #auditor(**details) ⇒ Object
- #builder ⇒ Object
- #config ⇒ Object
- #configure(**kwargs) ⇒ Object
- #configured? ⇒ Boolean
- #connected? ⇒ Boolean
- #docker ⇒ Object
- #holding_lock? ⇒ Boolean
- #holding_server_lock? ⇒ Boolean
- #hook ⇒ Object
-
#initialize ⇒ Commander
constructor
A new instance of Commander.
- #loadbalancer ⇒ Object
- #loadbalancer_config ⇒ Object
- #lock ⇒ Object
- #log(line) ⇒ Object
- #modify(command:, subcommand:) ⇒ Object
- #proxy(host) ⇒ Object
- #prune ⇒ Object
- #registry ⇒ Object
- #reset ⇒ Object
- #resolve_alias(name) ⇒ Object
- #server ⇒ Object
-
#server_lock ⇒ Object
Guards the dash-proxy container, which a host runs once for every destination deployed onto it.
- #specific_primary! ⇒ Object
- #with_specific_hosts(hosts) ⇒ Object
- #with_verbosity(level) ⇒ Object
Constructor Details
#initialize ⇒ Commander
Returns a new instance of Commander.
18 19 20 |
# File 'lib/dash/commander.rb', line 18 def initialize reset end |
Instance Attribute Details
#connected ⇒ Object
Returns the value of attribute connected.
8 9 10 |
# File 'lib/dash/commander.rb', line 8 def connected @connected end |
#holding_lock ⇒ Object
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_lock ⇒ Object
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_wait ⇒ Object
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_interval ⇒ Object
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_timeout ⇒ Object
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 |
#logging ⇒ Object
Returns the value of attribute logging.
8 9 10 |
# File 'lib/dash/commander.rb', line 8 def logging @logging end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
9 10 11 |
# File 'lib/dash/commander.rb', line 9 def report @report end |
#run_directory_ensured_on ⇒ Object (readonly)
Hosts whose run directory this process has already swept, so the second lock acquire
of a command does not re-run the migration everywhere. Per host rather than a flag:
dash upgrade narrows the host set between acquires, and a host that was never in
scope has never been swept.
15 16 17 |
# File 'lib/dash/commander.rb', line 15 def run_directory_ensured_on @run_directory_ensured_on end |
#specific_hosts ⇒ Object
Returns the value of attribute specific_hosts.
9 10 11 |
# File 'lib/dash/commander.rb', line 9 def specific_hosts @specific_hosts end |
#specific_roles ⇒ Object
Returns the value of attribute specific_roles.
9 10 11 |
# File 'lib/dash/commander.rb', line 9 def specific_roles @specific_roles end |
#timings ⇒ Object (readonly)
Returns the value of attribute timings.
9 10 11 |
# File 'lib/dash/commander.rb', line 9 def timings @timings end |
#verbosity ⇒ Object
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
98 99 100 |
# File 'lib/dash/commander.rb', line 98 def accessory(name) Dash::Commands::Accessory.new(config, name: name) end |
#accessory_names ⇒ Object
90 91 92 |
# File 'lib/dash/commander.rb', line 90 def accessory_names config.accessories&.collect(&:name) || [] end |
#alias(name) ⇒ Object
152 153 154 |
# File 'lib/dash/commander.rb', line 152 def alias(name) config.aliases[name] end |
#app(role: nil, host: nil) ⇒ Object
94 95 96 |
# File 'lib/dash/commander.rb', line 94 def app(role: nil, host: nil) Dash::Commands::App.new(config, role: role, host: host) end |
#auditor(**details) ⇒ Object
102 103 104 |
# File 'lib/dash/commander.rb', line 102 def auditor(**details) Dash::Commands::Auditor.new(config, **details) end |
#builder ⇒ Object
106 107 108 |
# File 'lib/dash/commander.rb', line 106 def builder @commands[:builder] ||= Dash::Commands::Builder.new(config) end |
#config ⇒ Object
41 42 43 44 45 46 |
# File 'lib/dash/commander.rb', line 41 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
48 49 50 |
# File 'lib/dash/commander.rb', line 48 def configure(**kwargs) @config, @config_kwargs = nil, kwargs end |
#configured? ⇒ Boolean
52 53 54 |
# File 'lib/dash/commander.rb', line 52 def configured? @config || @config_kwargs end |
#connected? ⇒ Boolean
201 202 203 |
# File 'lib/dash/commander.rb', line 201 def connected? self.connected end |
#docker ⇒ Object
110 111 112 |
# File 'lib/dash/commander.rb', line 110 def docker @commands[:docker] ||= Dash::Commands::Docker.new(config) end |
#holding_lock? ⇒ Boolean
197 198 199 |
# File 'lib/dash/commander.rb', line 197 def holding_lock? self.holding_lock end |
#holding_server_lock? ⇒ Boolean
193 194 195 |
# File 'lib/dash/commander.rb', line 193 def holding_server_lock? self.holding_server_lock end |
#hook ⇒ Object
114 115 116 |
# File 'lib/dash/commander.rb', line 114 def hook @commands[:hook] ||= Dash::Commands::Hook.new(config) end |
#loadbalancer ⇒ Object
136 137 138 |
# File 'lib/dash/commander.rb', line 136 def loadbalancer @commands[:loadbalancer] ||= Dash::Commands::Loadbalancer.new(config, loadbalancer_config: loadbalancer_config) end |
#loadbalancer_config ⇒ Object
132 133 134 |
# File 'lib/dash/commander.rb', line 132 def loadbalancer_config @loadbalancer_config ||= Dash::Configuration::Loadbalancer.new(config: config, proxy_config: config.proxy.proxy_config, secrets: config.secrets) end |
#lock ⇒ Object
118 119 120 |
# File 'lib/dash/commander.rb', line 118 def lock @commands[:lock] ||= Dash::Commands::Lock.new(config) end |
#log(line) ⇒ Object
189 190 191 |
# File 'lib/dash/commander.rb', line 189 def log(line) output_logger << "#{line}\n" if logging end |
#modify(command:, subcommand:) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/dash/commander.rb', line 177 def modify(command:, subcommand:) @logging = true if modify_started ActiveSupport::Notifications.instrument("modify.kamal", command: command, subcommand: subcommand, destination: config.destination, hosts: hosts, report: report) { yield } else yield end ensure output_logger.close if modify_finished end |
#proxy(host) ⇒ Object
128 129 130 |
# File 'lib/dash/commander.rb', line 128 def proxy(host) Dash::Commands::Proxy.new(config, host: host) end |
#prune ⇒ Object
140 141 142 |
# File 'lib/dash/commander.rb', line 140 def prune @commands[:prune] ||= Dash::Commands::Prune.new(config) end |
#registry ⇒ Object
144 145 146 |
# File 'lib/dash/commander.rb', line 144 def registry @commands[:registry] ||= Dash::Commands::Registry.new(config) end |
#reset ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dash/commander.rb', line 22 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 @timings = Dash::Timings.new @report = Dash::Report.new(timings: @timings) @specifics = @specific_roles = @specific_hosts = nil @config = @config_kwargs = nil @output_logger = nil @commands = {} @run_directory_ensured_on = [] end |
#resolve_alias(name) ⇒ Object
156 157 158 159 160 161 162 163 |
# File 'lib/dash/commander.rb', line 156 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 |
#server ⇒ Object
148 149 150 |
# File 'lib/dash/commander.rb', line 148 def server @commands[:server] ||= Dash::Commands::Server.new(config) end |
#server_lock ⇒ Object
Guards the dash-proxy container, which a host runs once for every destination deployed onto it. Every destination contends for this one.
124 125 126 |
# File 'lib/dash/commander.rb', line 124 def server_lock @commands[:server_lock] ||= Dash::Commands::Lock.new(config, scope: :server) end |
#specific_primary! ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/dash/commander.rb', line 56 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
83 84 85 86 87 88 |
# File 'lib/dash/commander.rb', line 83 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
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/dash/commander.rb', line 165 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 |