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.
-
#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.
12 13 14 |
# File 'lib/dash/commander.rb', line 12 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 |
#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
90 91 92 |
# File 'lib/dash/commander.rb', line 90 def accessory(name) Dash::Commands::Accessory.new(config, name: name) end |
#accessory_names ⇒ Object
82 83 84 |
# File 'lib/dash/commander.rb', line 82 def accessory_names config.accessories&.collect(&:name) || [] end |
#alias(name) ⇒ Object
144 145 146 |
# File 'lib/dash/commander.rb', line 144 def alias(name) config.aliases[name] end |
#app(role: nil, host: nil) ⇒ Object
86 87 88 |
# File 'lib/dash/commander.rb', line 86 def app(role: nil, host: nil) Dash::Commands::App.new(config, role: role, host: host) end |
#auditor(**details) ⇒ Object
94 95 96 |
# File 'lib/dash/commander.rb', line 94 def auditor(**details) Dash::Commands::Auditor.new(config, **details) end |
#builder ⇒ Object
98 99 100 |
# File 'lib/dash/commander.rb', line 98 def builder @commands[:builder] ||= Dash::Commands::Builder.new(config) end |
#config ⇒ Object
33 34 35 36 37 38 |
# File 'lib/dash/commander.rb', line 33 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
40 41 42 |
# File 'lib/dash/commander.rb', line 40 def configure(**kwargs) @config, @config_kwargs = nil, kwargs end |
#configured? ⇒ Boolean
44 45 46 |
# File 'lib/dash/commander.rb', line 44 def configured? @config || @config_kwargs end |
#connected? ⇒ Boolean
193 194 195 |
# File 'lib/dash/commander.rb', line 193 def connected? self.connected end |
#docker ⇒ Object
102 103 104 |
# File 'lib/dash/commander.rb', line 102 def docker @commands[:docker] ||= Dash::Commands::Docker.new(config) end |
#holding_lock? ⇒ Boolean
189 190 191 |
# File 'lib/dash/commander.rb', line 189 def holding_lock? self.holding_lock end |
#holding_server_lock? ⇒ Boolean
185 186 187 |
# File 'lib/dash/commander.rb', line 185 def holding_server_lock? self.holding_server_lock end |
#hook ⇒ Object
106 107 108 |
# File 'lib/dash/commander.rb', line 106 def hook @commands[:hook] ||= Dash::Commands::Hook.new(config) end |
#loadbalancer ⇒ Object
128 129 130 |
# File 'lib/dash/commander.rb', line 128 def loadbalancer @commands[:loadbalancer] ||= Dash::Commands::Loadbalancer.new(config, loadbalancer_config: loadbalancer_config) end |
#loadbalancer_config ⇒ Object
124 125 126 |
# File 'lib/dash/commander.rb', line 124 def loadbalancer_config @loadbalancer_config ||= Dash::Configuration::Loadbalancer.new(config: config, proxy_config: config.proxy.proxy_config, secrets: config.secrets) end |
#lock ⇒ Object
110 111 112 |
# File 'lib/dash/commander.rb', line 110 def lock @commands[:lock] ||= Dash::Commands::Lock.new(config) end |
#log(line) ⇒ Object
181 182 183 |
# File 'lib/dash/commander.rb', line 181 def log(line) output_logger << "#{line}\n" if logging end |
#modify(command:, subcommand:) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/dash/commander.rb', line 169 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
120 121 122 |
# File 'lib/dash/commander.rb', line 120 def proxy(host) Dash::Commands::Proxy.new(config, host: host) end |
#prune ⇒ Object
132 133 134 |
# File 'lib/dash/commander.rb', line 132 def prune @commands[:prune] ||= Dash::Commands::Prune.new(config) end |
#registry ⇒ Object
136 137 138 |
# File 'lib/dash/commander.rb', line 136 def registry @commands[:registry] ||= Dash::Commands::Registry.new(config) end |
#reset ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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 @timings = Dash::Timings.new @specifics = @specific_roles = @specific_hosts = nil @config = @config_kwargs = nil @output_logger = nil @commands = {} end |
#resolve_alias(name) ⇒ Object
148 149 150 151 152 153 154 155 |
# File 'lib/dash/commander.rb', line 148 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
140 141 142 |
# File 'lib/dash/commander.rb', line 140 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.
116 117 118 |
# File 'lib/dash/commander.rb', line 116 def server_lock @commands[:server_lock] ||= Dash::Commands::Lock.new(config, scope: :server) end |
#specific_primary! ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/dash/commander.rb', line 48 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
75 76 77 78 79 80 |
# File 'lib/dash/commander.rb', line 75 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
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/dash/commander.rb', line 157 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 |