Allow specifying multiple hosts for kamal proxy via an array
This commit is contained in:
@@ -360,7 +360,7 @@ class Kamal::Configuration
|
|||||||
end
|
end
|
||||||
|
|
||||||
def ensure_unique_hosts_for_ssl_roles
|
def ensure_unique_hosts_for_ssl_roles
|
||||||
hosts = roles.select(&:ssl?).map { |role| role.proxy.host }
|
hosts = roles.select(&:ssl?).flat_map { |role| role.proxy.hosts }
|
||||||
duplicates = hosts.tally.filter_map { |host, count| host if count > 1 }
|
duplicates = hosts.tally.filter_map { |host, count| host if count > 1 }
|
||||||
|
|
||||||
raise Kamal::ConfigurationError, "Different roles can't share the same host for SSL: #{duplicates.join(", ")}" if duplicates.any?
|
raise Kamal::ConfigurationError, "Different roles can't share the same host for SSL: #{duplicates.join(", ")}" if duplicates.any?
|
||||||
|
|||||||
@@ -28,6 +28,17 @@ proxy:
|
|||||||
# If multiple hosts are needed, these can be specified by comma-separating the hosts.
|
# If multiple hosts are needed, these can be specified by comma-separating the hosts.
|
||||||
host: foo.example.com,bar.example.com
|
host: foo.example.com,bar.example.com
|
||||||
|
|
||||||
|
# Hosts
|
||||||
|
#
|
||||||
|
# The hosts that will be used to serve the app. The proxy will only route requests
|
||||||
|
# to this host to your app.
|
||||||
|
#
|
||||||
|
# If no hosts are set, then all requests will be forwarded, except for matching
|
||||||
|
# requests for other apps deployed on that server that do have a host set.
|
||||||
|
hosts:
|
||||||
|
- foo.example.com
|
||||||
|
- bar.example.com
|
||||||
|
|
||||||
# App port
|
# App port
|
||||||
#
|
#
|
||||||
# The port the application container is exposed on.
|
# The port the application container is exposed on.
|
||||||
|
|||||||
@@ -22,13 +22,13 @@ class Kamal::Configuration::Proxy
|
|||||||
proxy_config.fetch("ssl", false)
|
proxy_config.fetch("ssl", false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def host
|
def hosts
|
||||||
proxy_config["host"]
|
proxy_config["hosts"] || proxy_config["host"]&.split(",") || []
|
||||||
end
|
end
|
||||||
|
|
||||||
def deploy_options
|
def deploy_options
|
||||||
{
|
{
|
||||||
host: proxy_config["host"],
|
host: hosts.present? ? hosts.join(",") : nil,
|
||||||
tls: proxy_config["ssl"] ? true : nil,
|
tls: proxy_config["ssl"] ? true : nil,
|
||||||
"deploy-timeout": seconds_duration(config.deploy_timeout),
|
"deploy-timeout": seconds_duration(config.deploy_timeout),
|
||||||
"drain-timeout": seconds_duration(config.drain_timeout),
|
"drain-timeout": seconds_duration(config.drain_timeout),
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class Kamal::Configuration::Validator::Proxy < Kamal::Configuration::Validator
|
|||||||
unless config.nil?
|
unless config.nil?
|
||||||
super
|
super
|
||||||
|
|
||||||
if config["host"].blank? && config["ssl"]
|
if config["host"].blank? && config["hosts"].blank? && config["ssl"]
|
||||||
error "Must set a host to enable automatic SSL"
|
error "Must set a host to enable automatic SSL"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -119,6 +119,22 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
new_command.deploy(target: "172.1.0.2").join(" ")
|
new_command.deploy(target: "172.1.0.2").join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "deploy with SSL" do
|
||||||
|
@config[:proxy] = { "ssl" => true, "host" => "example.com" }
|
||||||
|
|
||||||
|
assert_equal \
|
||||||
|
"docker exec kamal-proxy kamal-proxy deploy app-web --target \"172.1.0.2:80\" --host \"example.com\" --tls --deploy-timeout \"30s\" --drain-timeout \"30s\" --buffer-requests --buffer-responses --log-request-header \"Cache-Control\" --log-request-header \"Last-Modified\" --log-request-header \"User-Agent\"",
|
||||||
|
new_command.deploy(target: "172.1.0.2").join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "deploy with SSL targeting multiple hosts" do
|
||||||
|
@config[:proxy] = { "ssl" => true, "hosts" => [ "example.com", "anotherexample.com" ] }
|
||||||
|
|
||||||
|
assert_equal \
|
||||||
|
"docker exec kamal-proxy kamal-proxy deploy app-web --target \"172.1.0.2:80\" --host \"example.com,anotherexample.com\" --tls --deploy-timeout \"30s\" --drain-timeout \"30s\" --buffer-requests --buffer-responses --log-request-header \"Cache-Control\" --log-request-header \"Last-Modified\" --log-request-header \"User-Agent\"",
|
||||||
|
new_command.deploy(target: "172.1.0.2").join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
test "remove" do
|
test "remove" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker exec kamal-proxy kamal-proxy remove app-web --target \"172.1.0.2:80\"",
|
"docker exec kamal-proxy kamal-proxy remove app-web --target \"172.1.0.2:80\"",
|
||||||
|
|||||||
@@ -13,6 +13,16 @@ class ConfigurationProxyTest < ActiveSupport::TestCase
|
|||||||
assert_equal true, config.proxy.ssl?
|
assert_equal true, config.proxy.ssl?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "ssl with multiple hosts passed via host" do
|
||||||
|
@deploy[:proxy] = { "ssl" => true, "host" => "example.com,anotherexample.com" }
|
||||||
|
assert_equal true, config.proxy.ssl?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "ssl with multiple hosts passed via hosts" do
|
||||||
|
@deploy[:proxy] = { "ssl" => true, "hosts" => [ "example.com", "anotherexample.com" ] }
|
||||||
|
assert_equal true, config.proxy.ssl?
|
||||||
|
end
|
||||||
|
|
||||||
test "ssl with no host" do
|
test "ssl with no host" do
|
||||||
@deploy[:proxy] = { "ssl" => true }
|
@deploy[:proxy] = { "ssl" => true }
|
||||||
assert_raises(Kamal::ConfigurationError) { config.proxy.ssl? }
|
assert_raises(Kamal::ConfigurationError) { config.proxy.ssl? }
|
||||||
|
|||||||
Reference in New Issue
Block a user