Add kamal-proxy in experimental mode
The proxy can be enabled via the config:
```
proxy:
enabled: true
hosts:
- 10.0.0.1
- 10.0.0.2
```
This will enable the proxy and cause it to be run on the hosts listed
under `hosts`, after running `kamal proxy reboot`.
Enabling the proxy disables `kamal traefik` commands and replaces them
with `kamal proxy` ones. However only the marked hosts will run the
kamal-proxy container, the rest will run Traefik as before.
This commit is contained in:
committed by
Donal McBreen
parent
66d5e25834
commit
eab717e0cf
57
lib/kamal/configuration/proxy.rb
Normal file
57
lib/kamal/configuration/proxy.rb
Normal file
@@ -0,0 +1,57 @@
|
||||
class Kamal::Configuration::Proxy
|
||||
include Kamal::Configuration::Validation
|
||||
|
||||
DEFAULT_HTTP_PORT = 80
|
||||
DEFAULT_HTTPS_PORT = 443
|
||||
DEFAULT_IMAGE = "basecamp/kamal-proxy:latest"
|
||||
|
||||
delegate :argumentize, :optionize, to: Kamal::Utils
|
||||
|
||||
def initialize(config:)
|
||||
@proxy_config = config.raw_config.proxy || {}
|
||||
validate! proxy_config
|
||||
end
|
||||
|
||||
def enabled?
|
||||
!!proxy_config.fetch("enabled", false)
|
||||
end
|
||||
|
||||
def hosts
|
||||
if enabled?
|
||||
proxy_config.fetch("hosts", [])
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def image
|
||||
proxy_config.fetch("image", DEFAULT_IMAGE)
|
||||
end
|
||||
|
||||
def container_name
|
||||
"kamal-proxy"
|
||||
end
|
||||
|
||||
def publish_args
|
||||
argumentize "--publish", [ "#{DEFAULT_HTTP_PORT}:#{DEFAULT_HTTP_PORT}", "#{DEFAULT_HTTPS_PORT}:#{DEFAULT_HTTPS_PORT}" ]
|
||||
end
|
||||
|
||||
def deploy_options
|
||||
{
|
||||
host: proxy_config["host"],
|
||||
"deploy-timeout": proxy_config["deploy_timeout"],
|
||||
"drain-timeout": proxy_config["drain_timeout"],
|
||||
"health-check-interval": proxy_config.dig("health_check", "interval"),
|
||||
"health-check-timeout": proxy_config.dig("health_check", "timeout"),
|
||||
"health-check-path": proxy_config.dig("health_check", "path"),
|
||||
"target-timeout": proxy_config["response_timeout"]
|
||||
}.compact
|
||||
end
|
||||
|
||||
def deploy_command_args
|
||||
optionize deploy_options
|
||||
end
|
||||
|
||||
private
|
||||
attr_accessor :proxy_config
|
||||
end
|
||||
Reference in New Issue
Block a user