Class: Kamal::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/kamal/commands/base.rb

Constant Summary collapse

DOCKER_HEALTH_STATUS_FORMAT =
"'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'"
DOCKER_HEALTH_LOG_FORMAT =
"'{{json .State.Health}}'"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.



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

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#container_id_for(container_name:, only_running: false) ⇒ Object



25
26
27
# File 'lib/kamal/commands/base.rb', line 25

def container_id_for(container_name:, only_running: false)
  docker :container, :ls, *("--all" unless only_running), "--filter", "name=^#{container_name}$", "--quiet"
end

#make_directory(path) ⇒ Object



33
34
35
# File 'lib/kamal/commands/base.rb', line 33

def make_directory(path)
  [ :mkdir, "-p", path ]
end

#make_directory_for(remote_file) ⇒ Object



29
30
31
# File 'lib/kamal/commands/base.rb', line 29

def make_directory_for(remote_file)
  make_directory Pathname.new(remote_file).dirname.to_s
end

#remove_directory(path) ⇒ Object



37
38
39
# File 'lib/kamal/commands/base.rb', line 37

def remove_directory(path)
  [ :rm, "-r", path ]
end

#run_over_ssh(*command, host:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/kamal/commands/base.rb', line 14

def run_over_ssh(*command, host:)
  "ssh".tap do |cmd|
    if config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Jump)
      cmd << " -J #{config.ssh.proxy.jump_proxies}"
    elsif config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Command)
      cmd << " -o ProxyCommand='#{config.ssh.proxy.command_line_template}'"
    end
    cmd << " -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ")}'"
  end
end