From d26b3f176845b761f7bf49be1d39fe575a7b5f14 Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Tue, 22 Apr 2025 15:18:54 +0100 Subject: [PATCH] Create the .kamal/proxy/apps-config directory Manually create it to avoid ownership issues when docker creates it for you. --- lib/kamal/cli/proxy.rb | 2 ++ lib/kamal/commands/proxy.rb | 4 ++++ test/cli/proxy_test.rb | 3 +++ test/commands/proxy_test.rb | 6 ++++++ 4 files changed, 15 insertions(+) diff --git a/lib/kamal/cli/proxy.rb b/lib/kamal/cli/proxy.rb index 1ed17740..4baf9419 100644 --- a/lib/kamal/cli/proxy.rb +++ b/lib/kamal/cli/proxy.rb @@ -16,6 +16,7 @@ class Kamal::Cli::Proxy < Kamal::Cli::Base if version && Kamal::Utils.older_version?(version, Kamal::Configuration::PROXY_MINIMUM_VERSION) raise "kamal-proxy version #{version} is too old, run `kamal proxy reboot` in order to update to at least #{Kamal::Configuration::PROXY_MINIMUM_VERSION}" end + execute *KAMAL.proxy.ensure_apps_config_directory execute *KAMAL.proxy.start_or_run end end @@ -101,6 +102,7 @@ class Kamal::Cli::Proxy < Kamal::Cli::Base "Stopping and removing kamal-proxy on #{host}, if running..." execute *KAMAL.proxy.stop, raise_on_non_zero_exit: false execute *KAMAL.proxy.remove_container + execute *KAMAL.proxy.ensure_apps_config_directory execute *KAMAL.proxy.run diff --git a/lib/kamal/commands/proxy.rb b/lib/kamal/commands/proxy.rb index 658252de..d3eb6c31 100644 --- a/lib/kamal/commands/proxy.rb +++ b/lib/kamal/commands/proxy.rb @@ -65,6 +65,10 @@ class Kamal::Commands::Proxy < Kamal::Commands::Base remove_directory config.proxy_directory end + def ensure_apps_config_directory + make_directory config.proxy_apps_directory + end + def boot_config [ :echo, "#{substitute(read_boot_options)} #{substitute(read_image)}:#{substitute(read_image_version)}" ] end diff --git a/test/cli/proxy_test.rb b/test/cli/proxy_test.rb index 2ec4c726..604676fe 100644 --- a/test/cli/proxy_test.rb +++ b/test/cli/proxy_test.rb @@ -4,6 +4,7 @@ class CliProxyTest < CliTestCase test "boot" do run_command("boot").tap do |output| assert_match "docker login", output + assert_match "mkdir -p .kamal/proxy/apps-config", output assert_match "echo $(cat .kamal/proxy/options 2> /dev/null || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m\") $(cat .kamal/proxy/image 2> /dev/null || echo \"basecamp/kamal-proxy\"):$(cat .kamal/proxy/image_version 2> /dev/null || echo \"#{Kamal::Configuration::PROXY_MINIMUM_VERSION}\") | xargs docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy", output end end @@ -56,11 +57,13 @@ class CliProxyTest < CliTestCase run_command("reboot", "-y").tap do |output| assert_match "docker container stop kamal-proxy on 1.1.1.1", output assert_match "docker container prune --force --filter label=org.opencontainers.image.title=kamal-proxy on 1.1.1.1", output + assert_match "mkdir -p .kamal/proxy/apps-config on 1.1.1.1", output assert_match "echo $(cat .kamal/proxy/options 2> /dev/null || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m\") $(cat .kamal/proxy/image 2> /dev/null || echo \"basecamp/kamal-proxy\"):$(cat .kamal/proxy/image_version 2> /dev/null || echo \"#{Kamal::Configuration::PROXY_MINIMUM_VERSION}\") | xargs docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy --volume $(pwd)/.kamal/proxy/apps-config:/home/kamal-proxy/.apps-config on 1.1.1.1", output assert_match "docker exec kamal-proxy kamal-proxy deploy app-web --target=\"abcdefabcdef:80\" --deploy-timeout=\"6s\" --drain-timeout=\"30s\" --buffer-requests --buffer-responses --log-request-header=\"Cache-Control\" --log-request-header=\"Last-Modified\" --log-request-header=\"User-Agent\" on 1.1.1.1", output assert_match "docker container stop kamal-proxy on 1.1.1.2", output assert_match "docker container prune --force --filter label=org.opencontainers.image.title=kamal-proxy on 1.1.1.2", output + assert_match "mkdir -p .kamal/proxy/apps-config on 1.1.1.1", output assert_match "echo $(cat .kamal/proxy/options 2> /dev/null || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m\") $(cat .kamal/proxy/image 2> /dev/null || echo \"basecamp/kamal-proxy\"):$(cat .kamal/proxy/image_version 2> /dev/null || echo \"#{Kamal::Configuration::PROXY_MINIMUM_VERSION}\") | xargs docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy --volume $(pwd)/.kamal/proxy/apps-config:/home/kamal-proxy/.apps-config on 1.1.1.2", output assert_match "docker exec kamal-proxy kamal-proxy deploy app-web --target=\"abcdefabcdef:80\" --deploy-timeout=\"6s\" --drain-timeout=\"30s\" --buffer-requests --buffer-responses --log-request-header=\"Cache-Control\" --log-request-header=\"Last-Modified\" --log-request-header=\"User-Agent\" on 1.1.1.2", output end diff --git a/test/commands/proxy_test.rb b/test/commands/proxy_test.rb index 21863fc6..94fe9c66 100644 --- a/test/commands/proxy_test.rb +++ b/test/commands/proxy_test.rb @@ -147,6 +147,12 @@ class CommandsProxyTest < ActiveSupport::TestCase new_command.reset_image_version.join(" ") end + test "ensure_apps_config_directory" do + assert_equal \ + "mkdir -p .kamal/proxy/apps-config", + new_command.ensure_apps_config_directory.join(" ") + end + private def new_command Kamal::Commands::Proxy.new(Kamal::Configuration.new(@config, version: "123"))