Class: Kamal::Commands::Loadbalancer
- Defined in:
- lib/kamal/commands/loadbalancer.rb
Constant Summary
Constants inherited from Base
Base::DOCKER_HEALTH_STATUS_FORMAT
Instance Attribute Summary collapse
-
#loadbalancer_config ⇒ Object
readonly
Returns the value of attribute loadbalancer_config.
Attributes inherited from Base
Instance Method Summary collapse
- #container_name ⇒ Object
- #deploy(targets: []) ⇒ Object
- #ensure_apps_config_directory ⇒ Object
- #ensure_directory ⇒ Object
- #follow_logs(host:, timestamps: true, grep: nil, grep_options: nil) ⇒ Object
- #info ⇒ Object
-
#initialize(config, loadbalancer_config: nil) ⇒ Loadbalancer
constructor
A new instance of Loadbalancer.
- #logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil) ⇒ Object
- #remove_container ⇒ Object
- #remove_directory ⇒ Object
- #remove_image ⇒ Object
- #run ⇒ Object
- #start ⇒ Object
- #start_or_run ⇒ Object
- #stop(name: container_name) ⇒ Object
- #version ⇒ Object
Methods inherited from Base
#container_id_for, #ensure_docker_installed, #make_directory, #make_directory_for, #remove_file, #run_over_ssh
Constructor Details
#initialize(config, loadbalancer_config: nil) ⇒ Loadbalancer
Returns a new instance of Loadbalancer.
6 7 8 9 |
# File 'lib/kamal/commands/loadbalancer.rb', line 6 def initialize(config, loadbalancer_config: nil) super(config) @loadbalancer_config = loadbalancer_config end |
Instance Attribute Details
#loadbalancer_config ⇒ Object (readonly)
Returns the value of attribute loadbalancer_config.
4 5 6 |
# File 'lib/kamal/commands/loadbalancer.rb', line 4 def loadbalancer_config @loadbalancer_config end |
Instance Method Details
#container_name ⇒ Object
93 94 95 |
# File 'lib/kamal/commands/loadbalancer.rb', line 93 def container_name loadbalancer_config.container_name end |
#deploy(targets: []) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kamal/commands/loadbalancer.rb', line 37 def deploy(targets: []) target_args = targets.map { |t| "#{t}:80" } hosts = loadbalancer_config.hosts = [] << "--target=#{target_args.join(',')}" << "--host=#{hosts.join(',')}" << "--tls" if loadbalancer_config.ssl? docker :exec, container_name, "kamal-proxy", "deploy", loadbalancer_config.config.service, * end |
#ensure_apps_config_directory ⇒ Object
85 86 87 |
# File 'lib/kamal/commands/loadbalancer.rb', line 85 def ensure_apps_config_directory make_directory config.proxy_boot.apps_directory end |
#ensure_directory ⇒ Object
81 82 83 |
# File 'lib/kamal/commands/loadbalancer.rb', line 81 def ensure_directory make_directory loadbalancer_config.directory end |
#follow_logs(host:, timestamps: true, grep: nil, grep_options: nil) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/kamal/commands/loadbalancer.rb', line 66 def follow_logs(host:, timestamps: true, grep: nil, grep_options: nil) run_over_ssh pipe( docker(:logs, container_name, ("--timestamps" if ), "--tail", "10", "--follow", "2>&1"), (%(grep "#{grep}"#{" #{}" if }) if grep) ).join(" "), host: host end |
#info ⇒ Object
50 51 52 |
# File 'lib/kamal/commands/loadbalancer.rb', line 50 def info docker :ps, "--filter", "'name=^#{container_name}$'" end |
#logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil) ⇒ Object
60 61 62 63 64 |
# File 'lib/kamal/commands/loadbalancer.rb', line 60 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 ), "2>&1"), ("grep '#{grep}'#{" #{}" if }" if grep) end |
#remove_container ⇒ Object
73 74 75 |
# File 'lib/kamal/commands/loadbalancer.rb', line 73 def remove_container docker :container, :prune, "--force", "--filter", "label=org.opencontainers.image.title=kamal-loadbalancer" end |
#remove_directory ⇒ Object
89 90 91 |
# File 'lib/kamal/commands/loadbalancer.rb', line 89 def remove_directory super(loadbalancer_config.directory) end |
#remove_image ⇒ Object
77 78 79 |
# File 'lib/kamal/commands/loadbalancer.rb', line 77 def remove_image docker :image, :prune, "--all", "--force", "--filter", "label=org.opencontainers.image.title=kamal-loadbalancer" end |
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/kamal/commands/loadbalancer.rb', line 11 def run pipe \ [ :echo, proxy_image ], xargs(docker(:run, "--name", container_name, "--network", "kamal", "--detach", "--restart", "unless-stopped", "--publish", "80:80", "--publish", "443:443", "--label", label, *volume_mounts)) end |
#start ⇒ Object
25 26 27 |
# File 'lib/kamal/commands/loadbalancer.rb', line 25 def start docker :container, :start, container_name end |
#start_or_run ⇒ Object
33 34 35 |
# File 'lib/kamal/commands/loadbalancer.rb', line 33 def start_or_run combine start, run, by: "||" end |
#stop(name: container_name) ⇒ Object
29 30 31 |
# File 'lib/kamal/commands/loadbalancer.rb', line 29 def stop(name: container_name) docker :container, :stop, name end |
#version ⇒ Object
54 55 56 57 58 |
# File 'lib/kamal/commands/loadbalancer.rb', line 54 def version pipe \ docker(:inspect, container_name, "--format '{{.Config.Image}}'"), [ :cut, "-d:", "-f2" ] end |