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}}'"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.



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

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

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



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

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



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

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

#make_directory_for(remote_file) ⇒ Object



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

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

#remove_directory(path) ⇒ Object



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

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

#run_over_ssh(*command, host:) ⇒ Object



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

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(" ").gsub("'", "'\\\\''")}'"
  end
end