Class: Kamal::Cli::Proxy
Instance Method Summary collapse
- #boot ⇒ Object
- #boot_config(subcommand) ⇒ Object
- #details ⇒ Object
- #logs ⇒ Object
- #reboot ⇒ Object
- #remove ⇒ Object
- #remove_container ⇒ Object
- #remove_image ⇒ Object
- #remove_proxy_directory ⇒ Object
- #restart ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #upgrade ⇒ Object
Methods inherited from Base
dynamic_command_class, exit_on_failure?, #initialize
Constructor Details
This class inherits a constructor from Kamal::Cli::Base
Instance Method Details
#boot ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/kamal/cli/proxy.rb', line 3 def boot with_lock do on(KAMAL.hosts) do |host| execute *KAMAL.docker.create_network rescue SSHKit::Command::Failed => e raise unless e..include?("already exists") end on(KAMAL.proxy_hosts) do |host| execute *KAMAL.registry.login version = capture_with_info(*KAMAL.proxy(host).version).strip.presence if version && Kamal::Utils.older_version?(version, Kamal::Configuration::Proxy::Run::MINIMUM_VERSION) raise "kamal-proxy version #{version} is too old, run `kamal proxy reboot` in order to update to at least #{Kamal::Configuration::Proxy::Run::MINIMUM_VERSION}" end execute *KAMAL.proxy(host).ensure_apps_config_directory execute *KAMAL.proxy(host).start_or_run end end end |
#boot_config(subcommand) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/kamal/cli/proxy.rb', line 37 def boot_config(subcommand) say "The proxy boot_config command is deprecated - set the config in the deploy YAML at proxy/run instead", :yellow proxy_boot_config = KAMAL.config.proxy_boot case subcommand when "set" = [ *(proxy_boot_config.publish_args([:http_port], [:https_port], [:publish_host_ip]) if [:publish]), *(proxy_boot_config.logging_args([:log_max_size])), *("--expose=#{[:metrics_port]}" if [:metrics_port]), *[:docker_options].map { |option| "--#{option}" } ] image = [ [:registry].presence, [:repository].presence || proxy_boot_config.repository_name, proxy_boot_config.image_name ].compact.join("/") image_version = [:image_version] = { debug: [:debug] || nil, "metrics-port": [:metrics_port] }.compact run_command = "kamal-proxy run #{Kamal::Utils.optionize().join(" ")}" if .any? on(KAMAL.proxy_hosts) do |host| proxy = KAMAL.proxy(host) execute(*proxy.ensure_proxy_directory) if != proxy_boot_config. upload! StringIO.new(.join(" ")), proxy_boot_config. else execute *proxy., raise_on_non_zero_exit: false end if image != proxy_boot_config.image_default upload! StringIO.new(image), proxy_boot_config.image_file else execute *proxy.reset_image, raise_on_non_zero_exit: false end if image_version upload! StringIO.new(image_version), proxy_boot_config.image_version_file else execute *proxy.reset_image_version, raise_on_non_zero_exit: false end if run_command upload! StringIO.new(run_command), proxy_boot_config.run_command_file else execute *proxy.reset_run_command, raise_on_non_zero_exit: false end end when "get" on(KAMAL.proxy_hosts) do |host| puts "Host #{host}: #{capture_with_info(*KAMAL.proxy(host).boot_config)}" end when "reset" on(KAMAL.proxy_hosts) do |host| proxy = KAMAL.proxy(host) execute *proxy., raise_on_non_zero_exit: false execute *proxy.reset_image, raise_on_non_zero_exit: false execute *proxy.reset_image_version, raise_on_non_zero_exit: false execute *proxy.reset_run_command, raise_on_non_zero_exit: false end else raise ArgumentError, "Unknown boot_config subcommand #{subcommand}" end end |
#details ⇒ Object
204 205 206 207 |
# File 'lib/kamal/cli/proxy.rb', line 204 def details quiet = [:quiet] on(KAMAL.proxy_hosts) { |host| puts_by_host host, capture_with_info(*KAMAL.proxy(host).info), type: "Proxy", quiet: quiet } end |
#logs ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/kamal/cli/proxy.rb', line 215 def logs grep = [:grep] = ![:skip_timestamps] if [:follow] run_locally do proxy = KAMAL.proxy(KAMAL.primary_host) info "Following logs on #{KAMAL.primary_host}..." info proxy.follow_logs(host: KAMAL.primary_host, timestamps: , grep: grep) exec proxy.follow_logs(host: KAMAL.primary_host, timestamps: , grep: grep) end else since = [:since] lines = [:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set on(KAMAL.proxy_hosts) do |host| puts_by_host host, capture(*KAMAL.proxy(host).logs(timestamps: , since: since, lines: lines, grep: grep)), type: "Proxy" end end end |
#reboot ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/kamal/cli/proxy.rb', line 109 def reboot confirming "This will cause a brief outage on each host. Are you sure?" do with_lock do host_groups = [:rolling] ? KAMAL.proxy_hosts : [ KAMAL.proxy_hosts ] host_groups.each do |hosts| host_list = Array(hosts).join(",") run_hook "pre-proxy-reboot", hosts: host_list on(hosts) do |host| proxy = KAMAL.proxy(host) execute *KAMAL.auditor.record("Rebooted proxy"), verbosity: :debug execute *KAMAL.registry.login "Stopping and removing kamal-proxy on #{host}, if running..." execute *proxy.stop, raise_on_non_zero_exit: false execute *proxy.remove_container execute *proxy.ensure_apps_config_directory execute *proxy.run end run_hook "post-proxy-reboot", hosts: host_list end end end end |
#remove ⇒ Object
238 239 240 241 242 243 244 245 246 247 |
# File 'lib/kamal/cli/proxy.rb', line 238 def remove with_lock do if removal_allowed?([:force]) stop remove_container remove_image remove_proxy_directory end end end |
#remove_container ⇒ Object
250 251 252 253 254 255 256 257 |
# File 'lib/kamal/cli/proxy.rb', line 250 def remove_container with_lock do on(KAMAL.proxy_hosts) do execute *KAMAL.auditor.record("Removed proxy container"), verbosity: :debug execute *KAMAL.proxy(host).remove_container end end end |
#remove_image ⇒ Object
260 261 262 263 264 265 266 267 |
# File 'lib/kamal/cli/proxy.rb', line 260 def remove_image with_lock do on(KAMAL.proxy_hosts) do execute *KAMAL.auditor.record("Removed proxy image"), verbosity: :debug execute *KAMAL.proxy(host).remove_image end end end |
#remove_proxy_directory ⇒ Object
270 271 272 273 274 275 276 |
# File 'lib/kamal/cli/proxy.rb', line 270 def remove_proxy_directory with_lock do on(KAMAL.proxy_hosts) do execute *KAMAL.proxy(host).remove_proxy_directory, raise_on_non_zero_exit: false end end end |
#restart ⇒ Object
196 197 198 199 200 201 |
# File 'lib/kamal/cli/proxy.rb', line 196 def restart with_lock do stop start end end |
#start ⇒ Object
176 177 178 179 180 181 182 183 |
# File 'lib/kamal/cli/proxy.rb', line 176 def start with_lock do on(KAMAL.proxy_hosts) do |host| execute *KAMAL.auditor.record("Started proxy"), verbosity: :debug execute *KAMAL.proxy(host).start end end end |
#stop ⇒ Object
186 187 188 189 190 191 192 193 |
# File 'lib/kamal/cli/proxy.rb', line 186 def stop with_lock do on(KAMAL.proxy_hosts) do |host| execute *KAMAL.auditor.record("Stopped proxy"), verbosity: :debug execute *KAMAL.proxy(host).stop, raise_on_non_zero_exit: false end end end |
#upgrade ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/kamal/cli/proxy.rb', line 137 def upgrade = { "version" => KAMAL.config.latest_tag }.merge() confirming "This will cause a brief outage on each host. Are you sure?" do host_groups = [:rolling] ? KAMAL.hosts : [ KAMAL.hosts ] host_groups.each do |hosts| host_list = Array(hosts).join(",") say "Upgrading proxy on #{host_list}...", :magenta run_hook "pre-proxy-reboot", hosts: host_list on(hosts) do |host| proxy = KAMAL.proxy(host) execute *KAMAL.auditor.record("Rebooted proxy"), verbosity: :debug execute *KAMAL.registry.login "Stopping and removing Traefik on #{host}, if running..." execute *proxy.cleanup_traefik "Stopping and removing kamal-proxy on #{host}, if running..." execute *proxy.stop, raise_on_non_zero_exit: false execute *proxy.remove_container execute *proxy.remove_image end KAMAL.with_specific_hosts(hosts) do invoke "kamal:cli:proxy:boot", [], reset_invocation(Kamal::Cli::Proxy) invoke "kamal:cli:app:boot", [], reset_invocation(Kamal::Cli::App) invoke "kamal:cli:prune:all", [], reset_invocation(Kamal::Cli::Prune) end run_hook "post-proxy-reboot", hosts: host_list say "Upgraded proxy on #{host_list}", :magenta end end end |