diff --git a/lib/kamal/cli/accessory.rb b/lib/kamal/cli/accessory.rb index e6dc78cc2..dd56231e5 100644 --- a/lib/kamal/cli/accessory.rb +++ b/lib/kamal/cli/accessory.rb @@ -224,18 +224,14 @@ def remove_service_directory(name) def upgrade(name) confirming "This will restart all accessories" do with_lock do - if options[:rolling] - KAMAL.accessory_hosts.each do |host| - say "Upgrading accessories on #{host}...", :magenta - KAMAL.with_specific_hosts(host) do - reboot name - end - say "Upgraded accessories on #{host}...", :magenta + host_groups = options[:rolling] ? KAMAL.accessory_hosts : [ KAMAL.accessory_hosts ] + host_groups.each do |hosts| + host_list = Array(hosts).join(",") + KAMAL.with_specific_hosts(hosts) do + say "Upgrading #{name} accessories on #{host_list}...", :magenta + reboot name + say "Upgraded #{name} accessories on #{host_list}...", :magenta end - else - say "Upgrading accessories on all hosts...", :magenta - reboot name - say "Upgraded accessories on all hosts", :magenta end end end diff --git a/lib/kamal/cli/proxy.rb b/lib/kamal/cli/proxy.rb index 0e6a74aeb..545cee2a4 100644 --- a/lib/kamal/cli/proxy.rb +++ b/lib/kamal/cli/proxy.rb @@ -72,7 +72,7 @@ def upgrade host_groups = options[:rolling] ? KAMAL.hosts : [ KAMAL.hosts ] host_groups.each do |hosts| host_list = Array(hosts).join(",") - say "Upgrading proxy on #{host_list}..." + say "Upgrading proxy on #{host_list}...", :magenta run_hook "pre-proxy-reboot", hosts: host_list on(hosts) do |host| execute *KAMAL.auditor.record("Rebooted proxy"), verbosity: :debug @@ -97,7 +97,7 @@ def upgrade end run_hook "post-proxy-reboot", hosts: host_list - say "Upgraded proxy on #{host_list}" + say "Upgraded proxy on #{host_list}", :magenta end end end diff --git a/lib/kamal/commander/specifics.rb b/lib/kamal/commander/specifics.rb index 288fd9b55..190d2b69a 100644 --- a/lib/kamal/commander/specifics.rb +++ b/lib/kamal/commander/specifics.rb @@ -23,7 +23,7 @@ def proxy_hosts end def accessory_hosts - specific_hosts || config.accessories.flat_map(&:hosts) + config.accessories.flat_map(&:hosts) & specified_hosts end private diff --git a/test/cli/accessory_test.rb b/test/cli/accessory_test.rb index 072962e17..b8da2a7ab 100644 --- a/test/cli/accessory_test.rb +++ b/test/cli/accessory_test.rb @@ -222,21 +222,21 @@ class CliAccessoryTest < CliTestCase test "upgrade" do run_command("upgrade", "-y", "all").tap do |output| - assert_match "Upgrading accessories on all hosts...", output + assert_match "Upgrading all accessories on 1.1.1.3,1.1.1.1,1.1.1.2...", output assert_match "docker network create kamal on 1.1.1.3", output assert_match "docker container stop app-mysql on 1.1.1.3", output assert_match "docker run --name app-mysql --detach --restart unless-stopped --network kamal --log-opt max-size=\"10m\" --publish 3306:3306 --env MYSQL_ROOT_HOST="%" --env-file .kamal/apps/app/env/accessories/mysql.env --volume $PWD/app-mysql/etc/mysql/my.cnf:/etc/mysql/my.cnf --volume $PWD/app-mysql/data:/var/lib/mysql --label service=\"app-mysql\" mysql:5.7 on 1.1.1.3", output - assert_match "Upgraded accessories on all hosts", output + assert_match "Upgraded all accessories on 1.1.1.3,1.1.1.1,1.1.1.2...", output end end test "upgrade rolling" do run_command("upgrade", "--rolling", "-y", "all").tap do |output| - assert_match "Upgrading accessories on 1.1.1.3...", output + assert_match "Upgrading all accessories on 1.1.1.3...", output assert_match "docker network create kamal on 1.1.1.3", output assert_match "docker container stop app-mysql on 1.1.1.3", output assert_match "docker run --name app-mysql --detach --restart unless-stopped --network kamal --log-opt max-size=\"10m\" --publish 3306:3306 --env MYSQL_ROOT_HOST="%" --env-file .kamal/apps/app/env/accessories/mysql.env --volume $PWD/app-mysql/etc/mysql/my.cnf:/etc/mysql/my.cnf --volume $PWD/app-mysql/data:/var/lib/mysql --label service=\"app-mysql\" mysql:5.7 on 1.1.1.3", output - assert_match "Upgraded accessories on 1.1.1.3", output + assert_match "Upgraded all accessories on 1.1.1.3", output end end diff --git a/test/cli/main_test.rb b/test/cli/main_test.rb index 60fdf5c74..4b111bad4 100644 --- a/test/cli/main_test.rb +++ b/test/cli/main_test.rb @@ -500,7 +500,7 @@ class CliMainTest < CliTestCase test "upgrade rolling" do invoke_options = { "config_file" => "test/fixtures/deploy_with_accessories.yml", "skip_hooks" => false, "confirmed" => true, "rolling" => false } Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:proxy:upgrade", [], invoke_options).times(4) - Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:upgrade", [ "all" ], invoke_options).times(4) + Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:upgrade", [ "all" ], invoke_options).times(3) run_command("upgrade", "--rolling", "-y", config_file: "deploy_with_accessories").tap do |output| assert_match "Upgrading 1.1.1.1...", output