Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade on accessory hosts only with correct messages #945

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions lib/kamal/cli/accessory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/kamal/cli/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/kamal/commander/specifics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/cli/accessory_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/cli/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down