Class: Kamal::Configuration::Proxy

Inherits:
Object
  • Object
show all
Includes:
Validation
Defined in:
lib/kamal/configuration/proxy.rb

Constant Summary collapse

DEFAULT_LOG_REQUEST_HEADERS =
[ "Cache-Control", "Last-Modified", "User-Agent" ]
CONTAINER_NAME =
"kamal-proxy"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validation

#validate!, #validation_yml

Constructor Details

#initialize(config:, proxy_config:, context: "proxy") ⇒ Proxy

Returns a new instance of Proxy.



11
12
13
14
15
# File 'lib/kamal/configuration/proxy.rb', line 11

def initialize(config:, proxy_config:, context: "proxy")
  @config = config
  @proxy_config = proxy_config
  validate! @proxy_config, with: Kamal::Configuration::Validator::Proxy, context: context
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/kamal/configuration/proxy.rb', line 9

def config
  @config
end

#proxy_configObject (readonly)

Returns the value of attribute proxy_config.



9
10
11
# File 'lib/kamal/configuration/proxy.rb', line 9

def proxy_config
  @proxy_config
end

Instance Method Details

#app_portObject



17
18
19
# File 'lib/kamal/configuration/proxy.rb', line 17

def app_port
  proxy_config.fetch("app_port", 80)
end

#deploy_command_args(target:) ⇒ Object



51
52
53
# File 'lib/kamal/configuration/proxy.rb', line 51

def deploy_command_args(target:)
  optionize ({ target: "#{target}:#{app_port}" }).merge(deploy_options), with: "="
end

#deploy_optionsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kamal/configuration/proxy.rb', line 29

def deploy_options
  {
    host: hosts,
    tls: proxy_config["ssl"].presence,
    "tls-on-demand-url": proxy_config["tls_on_demand_url"],
    "deploy-timeout": seconds_duration(config.deploy_timeout),
    "drain-timeout": seconds_duration(config.drain_timeout),
    "health-check-interval": seconds_duration(proxy_config.dig("healthcheck", "interval")),
    "health-check-timeout": seconds_duration(proxy_config.dig("healthcheck", "timeout")),
    "health-check-path": proxy_config.dig("healthcheck", "path"),
    "target-timeout": seconds_duration(proxy_config["response_timeout"]),
    "buffer-requests": proxy_config.fetch("buffering", { "requests": true }).fetch("requests", true),
    "buffer-responses": proxy_config.fetch("buffering", { "responses": true }).fetch("responses", true),
    "buffer-memory": proxy_config.dig("buffering", "memory"),
    "max-request-body": proxy_config.dig("buffering", "max_request_body"),
    "max-response-body": proxy_config.dig("buffering", "max_response_body"),
    "forward-headers": proxy_config.dig("forward_headers"),
    "log-request-header": proxy_config.dig("logging", "request_headers") || DEFAULT_LOG_REQUEST_HEADERS,
    "log-response-header": proxy_config.dig("logging", "response_headers")
  }.compact
end

#hostsObject



25
26
27
# File 'lib/kamal/configuration/proxy.rb', line 25

def hosts
  proxy_config["hosts"] || proxy_config["host"]&.split(",") || []
end

#merge(other) ⇒ Object



55
56
57
# File 'lib/kamal/configuration/proxy.rb', line 55

def merge(other)
  self.class.new config: config, proxy_config: proxy_config.deep_merge(other.proxy_config)
end

#ssl?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/kamal/configuration/proxy.rb', line 21

def ssl?
  proxy_config.fetch("ssl", false)
end