From a40b644145b7fe484b00bd2314b148df9abc7f3c Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Thu, 12 Sep 2024 12:59:34 +0100 Subject: [PATCH] Check that there's no traefik hooks left behind --- lib/kamal/configuration.rb | 11 +++++++++++ lib/kamal/configuration/validator/proxy.rb | 2 +- test/configuration/proxy_test.rb | 2 +- test/configuration_test.rb | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/kamal/configuration.rb b/lib/kamal/configuration.rb index 38dc2190..96784e64 100644 --- a/lib/kamal/configuration.rb +++ b/lib/kamal/configuration.rb @@ -70,6 +70,7 @@ class Kamal::Configuration ensure_valid_kamal_version ensure_retain_containers_valid ensure_valid_service_name + ensure_no_traefik_reboot_hooks end @@ -303,6 +304,16 @@ class Kamal::Configuration true 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 raw_config.servers.is_a?(Array) ? [ "web" ] : raw_config.servers.keys.sort diff --git a/lib/kamal/configuration/validator/proxy.rb b/lib/kamal/configuration/validator/proxy.rb index a4ee19bf..2b055570 100644 --- a/lib/kamal/configuration/validator/proxy.rb +++ b/lib/kamal/configuration/validator/proxy.rb @@ -2,7 +2,7 @@ class Kamal::Configuration::Validator::Proxy < Kamal::Configuration::Validator def validate! super - if config["host"].blank? && config["ssl"] + if config["hosts"].blank? && config["ssl"] error "Must set a host to enable automatic SSL" end end diff --git a/test/configuration/proxy_test.rb b/test/configuration/proxy_test.rb index 3aa3f85e..6dac27ff 100644 --- a/test/configuration/proxy_test.rb +++ b/test/configuration/proxy_test.rb @@ -9,7 +9,7 @@ class ConfigurationEnvTest < ActiveSupport::TestCase end 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? end diff --git a/test/configuration_test.rb b/test/configuration_test.rb index c64070eb..c10b8508 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -342,4 +342,18 @@ class ConfigurationTest < ActiveSupport::TestCase assert_equal config.role(:web_tokyo).running_proxy?, true assert_equal config.role(:web_chicago).running_proxy?, true 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