Check that there's no traefik hooks left behind

This commit is contained in:
Donal McBreen
2024-09-12 12:59:34 +01:00
parent ccb7424197
commit a40b644145
4 changed files with 27 additions and 2 deletions

View File

@@ -70,6 +70,7 @@ class Kamal::Configuration
ensure_valid_kamal_version ensure_valid_kamal_version
ensure_retain_containers_valid ensure_retain_containers_valid
ensure_valid_service_name ensure_valid_service_name
ensure_no_traefik_reboot_hooks
end end
@@ -303,6 +304,16 @@ class Kamal::Configuration
true true
end end
def ensure_no_traefik_reboot_hooks
hooks = %w[ pre-traefik-reboot post-traefik-reboot ].select { |hook_file| File.exist?(File.join(hooks_path, hook_file)) }
if hooks.any?
raise Kamal::ConfigurationError, "Found #{hooks.join(", ")}, these should be renamed to (pre|post)-proxy-reboot"
end
true
end
def role_names def role_names
raw_config.servers.is_a?(Array) ? [ "web" ] : raw_config.servers.keys.sort raw_config.servers.is_a?(Array) ? [ "web" ] : raw_config.servers.keys.sort

View File

@@ -2,7 +2,7 @@ class Kamal::Configuration::Validator::Proxy < Kamal::Configuration::Validator
def validate! def validate!
super super
if config["host"].blank? && config["ssl"] if 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

View File

@@ -9,7 +9,7 @@ class ConfigurationEnvTest < ActiveSupport::TestCase
end end
test "ssl with host" do test "ssl with host" do
@deploy[:proxy] = { "ssl" => true, "host" => "example.com" } @deploy[:proxy] = { "ssl" => true, "hosts" => [ "example.com" ] }
assert_equal true, config.proxy.ssl? assert_equal true, config.proxy.ssl?
end end

View File

@@ -342,4 +342,18 @@ class ConfigurationTest < ActiveSupport::TestCase
assert_equal config.role(:web_tokyo).running_proxy?, true assert_equal config.role(:web_tokyo).running_proxy?, true
assert_equal config.role(:web_chicago).running_proxy?, true assert_equal config.role(:web_chicago).running_proxy?, true
end end
test "traefik hooks raise error" do
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
FileUtils.mkdir_p ".kamal/hooks"
FileUtils.touch ".kamal/hooks/post-traefik-reboot"
FileUtils.touch ".kamal/hooks/pre-traefik-reboot"
exception = assert_raises(Kamal::ConfigurationError) do
Kamal::Configuration.new(@deploy)
end
assert_equal "Found pre-traefik-reboot, post-traefik-reboot, these should be renamed to (pre|post)-proxy-reboot", exception.message
end
end
end
end end