Skip to content

Commit

Permalink
Make an effort to match the primary_role from a list of specific roles.
Browse files Browse the repository at this point in the history
This is less surprising than picking the first role and first host.
  • Loading branch information
mdkent committed Nov 25, 2023
1 parent b1dc188 commit 79baa59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/kamal/commander.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def specific_hosts=(hosts)
end

def primary_host
specific_hosts&.first || specific_roles&.first&.primary_host || config.primary_host
# Given a list of specific roles, make an effort to match up with the primary_role
specific_hosts&.first || specific_roles&.detect { |role| role.name == config.primary_role }&.primary_host || specific_roles&.first&.primary_host || config.primary_host
end

def primary_role
Expand Down
9 changes: 9 additions & 0 deletions test/commander_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ class CommanderTest < ActiveSupport::TestCase
assert_equal({ in: :groups, limit: 1, wait: 2 }, @kamal.boot_strategy)
end

test "try to match the primary role from a list of specific roles" do
configure_with(:deploy_primary_web_role_override)

@kamal.specific_roles = [ "web_*" ]
assert_equal [ "web_chicago", "web_tokyo" ], @kamal.roles.map(&:name)
assert_equal "web_tokyo", @kamal.primary_role
assert_equal "1.1.1.3", @kamal.primary_host
end

private
def configure_with(variant)
@kamal = Kamal::Commander.new.tap do |kamal|
Expand Down

0 comments on commit 79baa59

Please sign in to comment.