Class: Kamal::Commands::Proxy

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

Constant Summary

Constants inherited from Base

Base::DOCKER_HEALTH_STATUS_FORMAT

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#container_id_for, #ensure_docker_installed, #initialize, #make_directory, #make_directory_for, #remove_directory, #remove_file, #run_over_ssh

Constructor Details

This class inherits a constructor from Kamal::Commands::Base

Instance Method Details

#boot_configObject



72
73
74
# File 'lib/kamal/commands/proxy.rb', line 72

def boot_config
  [ :echo, "#{substitute(read_boot_options)} #{substitute(read_image)}:#{substitute(read_image_version)} #{substitute(read_run_command)}" ]
end

#cleanup_traefikObject



51
52
53
54
55
56
57
58
# File 'lib/kamal/commands/proxy.rb', line 51

def cleanup_traefik
  chain \
    docker(:container, :stop, "traefik"),
    combine(
      docker(:container, :prune, "--force", "--filter", "label=org.opencontainers.image.title=Traefik"),
      docker(:image, :prune, "--all", "--force", "--filter", "label=org.opencontainers.image.title=Traefik")
    )
end

#ensure_apps_config_directoryObject



68
69
70
# File 'lib/kamal/commands/proxy.rb', line 68

def ensure_apps_config_directory
  make_directory config.proxy_boot.apps_directory
end

#ensure_proxy_directoryObject



60
61
62
# File 'lib/kamal/commands/proxy.rb', line 60

def ensure_proxy_directory
  make_directory config.proxy_boot.host_directory
end

#follow_logs(host:, timestamps: true, grep: nil, grep_options: nil) ⇒ Object



36
37
38
39
40
41
# File 'lib/kamal/commands/proxy.rb', line 36

def follow_logs(host:, timestamps: true, grep: nil, grep_options: nil)
  run_over_ssh pipe(
    docker(:logs, container_name, ("--timestamps" if timestamps), "--tail", "10", "--follow", "2>&1"),
    (%(grep "#{grep}"#{" #{grep_options}" if grep_options}) if grep)
  ).join(" "), host: host
end

#infoObject



20
21
22
# File 'lib/kamal/commands/proxy.rb', line 20

def info
  docker :ps, "--filter", "name=^#{container_name}$"
end

#logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil) ⇒ Object



30
31
32
33
34
# File 'lib/kamal/commands/proxy.rb', line 30

def logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil)
  pipe \
    docker(:logs, container_name, ("--since #{since}" if since), ("--tail #{lines}" if lines), ("--timestamps" if timestamps), "2>&1"),
    ("grep '#{grep}'#{" #{grep_options}" if grep_options}" if grep)
end

#read_boot_optionsObject



76
77
78
# File 'lib/kamal/commands/proxy.rb', line 76

def read_boot_options
  read_file(config.proxy_boot.options_file, default: config.proxy_boot.default_boot_options.join(" "))
end

#read_imageObject



80
81
82
# File 'lib/kamal/commands/proxy.rb', line 80

def read_image
  read_file(config.proxy_boot.image_file, default: config.proxy_boot.image_default)
end

#read_image_versionObject



84
85
86
# File 'lib/kamal/commands/proxy.rb', line 84

def read_image_version
  read_file(config.proxy_boot.image_version_file, default: Kamal::Configuration::Proxy::Boot::MINIMUM_VERSION)
end

#read_run_commandObject



88
89
90
# File 'lib/kamal/commands/proxy.rb', line 88

def read_run_command
  read_file(config.proxy_boot.run_command_file)
end

#remove_containerObject



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

def remove_container
  docker :container, :prune, "--force", "--filter", "label=org.opencontainers.image.title=kamal-proxy"
end

#remove_imageObject



47
48
49
# File 'lib/kamal/commands/proxy.rb', line 47

def remove_image
  docker :image, :prune, "--all", "--force", "--filter", "label=org.opencontainers.image.title=kamal-proxy"
end

#remove_proxy_directoryObject



64
65
66
# File 'lib/kamal/commands/proxy.rb', line 64

def remove_proxy_directory
  remove_directory config.proxy_boot.host_directory
end

#reset_boot_optionsObject



92
93
94
# File 'lib/kamal/commands/proxy.rb', line 92

def reset_boot_options
  remove_file config.proxy_boot.options_file
end

#reset_imageObject



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

def reset_image
  remove_file config.proxy_boot.image_file
end

#reset_image_versionObject



100
101
102
# File 'lib/kamal/commands/proxy.rb', line 100

def reset_image_version
  remove_file config.proxy_boot.image_version_file
end

#reset_run_commandObject



104
105
106
# File 'lib/kamal/commands/proxy.rb', line 104

def reset_run_command
  remove_file config.proxy_boot.run_command_file
end

#runObject



4
5
6
# File 'lib/kamal/commands/proxy.rb', line 4

def run
  pipe boot_config, xargs(docker_run)
end

#startObject



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

def start
  docker :container, :start, container_name
end

#start_or_runObject



16
17
18
# File 'lib/kamal/commands/proxy.rb', line 16

def start_or_run
  combine start, run, by: "||"
end

#stop(name: container_name) ⇒ Object



12
13
14
# File 'lib/kamal/commands/proxy.rb', line 12

def stop(name: container_name)
  docker :container, :stop, name
end

#versionObject



24
25
26
27
28
# File 'lib/kamal/commands/proxy.rb', line 24

def version
  pipe \
    docker(:inspect, container_name, "--format '{{.Config.Image}}'"),
    [ :awk, "-F:", "'{print \$NF}'" ]
end