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.



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

def initialize
  reset
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.



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

def specific_hosts
  @specific_hosts
end

#specific_rolesObject

Returns the value of attribute specific_roles.



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

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

#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



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

#builderObject



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

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

#configObject



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

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

#configure(**kwargs) ⇒ Object



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

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

#configured?Boolean

Returns:

  • (Boolean)


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

def configured?
  @config || @config_kwargs
end

#connected?Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/kamal/commander.rb', line 148

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)


144
145
146
# File 'lib/kamal/commander.rb', line 144

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

#lockObject



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

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

#proxyObject



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

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

#pruneObject



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

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

#registryObject



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

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

#resetObject



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

def reset
  self.verbosity = :info
  self.holding_lock = false
  self.connected = false
  @specifics = @specific_roles = @specific_hosts = nil
  @config = @config_kwargs = nil
  @commands = {}
end

#serverObject



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

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

#specific_primary!Object



38
39
40
41
42
43
44
45
# File 'lib/kamal/commander.rb', line 38

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



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

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