Class: Kamal::Commands::Base

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

Constant Summary collapse

NO_HEALTHCHECK =

Prefixed onto the docker state when the container declares no healthcheck at all, so "nothing is probing this container" stays distinguishable from "the probe passed" — both used to reach the poller as running. The state is kept after the prefix so a healthcheck-less container that died still reports why.

"no-healthcheck"
DOCKER_HEALTH_STATUS_FORMAT =
"'{{if .State.Health}}{{.State.Health.Status}}{{else}}#{NO_HEALTHCHECK}:{{.State.Status}}{{end}}'"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.



15
16
17
# File 'lib/kamal/commands/base.rb', line 15

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



13
14
15
# File 'lib/kamal/commands/base.rb', line 13

def config
  @config
end

Instance Method Details

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



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

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

#ensure_docker_installedObject



47
48
49
50
51
# File 'lib/kamal/commands/base.rb', line 47

def ensure_docker_installed
  combine \
    ensure_local_docker_installed,
    ensure_local_buildx_installed
end

#make_directory(path) ⇒ Object



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

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

#make_directory_for(remote_file) ⇒ Object



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

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

#read_file(file, default: nil) ⇒ Object



43
44
45
# File 'lib/kamal/commands/base.rb', line 43

def read_file(file, default: nil)
  combine [ :cat, file, "2>", "/dev/null" ], [ :echo, "\"#{default}\"" ], by: "||"
end

#remove_directory(path) ⇒ Object



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

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

#remove_file(path) ⇒ Object



39
40
41
# File 'lib/kamal/commands/base.rb', line 39

def remove_file(path)
  [ :rm, path ]
end

#run_over_ssh(*command, host:) ⇒ Object



19
20
21
# File 'lib/kamal/commands/base.rb', line 19

def run_over_ssh(*command, host:)
  "ssh#{ssh_config_args}#{ssh_proxy_args}#{ssh_keys_args} -t #{config.ssh.user}@#{host} -p #{config.ssh.port} '#{command.join(" ").gsub("'", "'\\\\''")}'"
end