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, #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

#cleanup_traefikObject



58
59
60
61
62
63
64
65
# File 'lib/kamal/commands/proxy.rb', line 58

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_proxy_directoryObject



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

def ensure_proxy_directory
  make_directory config.proxy_directory
end

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



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

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

#get_boot_optionsObject



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

def get_boot_options
  combine [ :cat, config.proxy_options_file ], [ :echo, "\"#{config.proxy_options_default.join(" ")}\"" ], by: "||"
end

#infoObject



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

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

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



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

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

#remove_containerObject



50
51
52
# File 'lib/kamal/commands/proxy.rb', line 50

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

#remove_imageObject



54
55
56
# File 'lib/kamal/commands/proxy.rb', line 54

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

#remove_proxy_directoryObject



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

def remove_proxy_directory
  remove_directory config.proxy_directory
end

#reset_boot_optionsObject



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

def reset_boot_options
  remove_file config.proxy_options_file
end

#runObject



4
5
6
7
8
9
10
11
12
13
# File 'lib/kamal/commands/proxy.rb', line 4

def run
  docker :run,
    "--name", container_name,
    "--network", "kamal",
    "--detach",
    "--restart", "unless-stopped",
    "--volume", "kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy",
    "\$\(#{get_boot_options.join(" ")}\)",
    config.proxy_image
end

#startObject



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

def start
  docker :container, :start, container_name
end

#start_or_runObject



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

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

#stop(name: container_name) ⇒ Object



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

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

#versionObject



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

def version
  pipe \
    docker(:inspect, container_name, "--format '{{.Config.Image}}'"),
    [ :cut, "-d:", "-f2" ]
end