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

Restore kamal setup to accessory hosts #1035

Merged
merged 4 commits into from
Oct 3, 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
9 changes: 7 additions & 2 deletions lib/kamal/commander/specifics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def specified_roles
end

def specified_hosts
(specific_hosts || config.all_hosts) \
.select { |host| (specific_roles || config.roles).flat_map(&:hosts).include?(host) }
specified_hosts = specific_hosts || config.all_hosts

if (specific_role_hosts = specific_roles&.flat_map(&:hosts)).present?
specified_hosts.select { |host| specific_role_hosts.include?(host) }
else
specified_hosts
end
end
end
21 changes: 21 additions & 0 deletions test/commander_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,27 @@ class CommanderTest < ActiveSupport::TestCase
assert_equal [ "1.1.1.2" ], @kamal.proxy_hosts
end

test "accessory hosts without filtering" do
configure_with(:deploy_with_single_accessory)
assert_equal [ "1.1.1.5" ], @kamal.accessory_hosts

configure_with(:deploy_with_accessories_on_independent_server)
assert_equal [ "1.1.1.5", "1.1.1.1", "1.1.1.2" ], @kamal.accessory_hosts
end

test "accessory hosts with role filtering" do
configure_with(:deploy_with_single_accessory)
@kamal.specific_roles = [ "web" ]
assert_equal [], @kamal.accessory_hosts

configure_with(:deploy_with_accessories_on_independent_server)
@kamal.specific_roles = [ "web" ]
assert_equal [ "1.1.1.1", "1.1.1.2" ], @kamal.accessory_hosts

@kamal.specific_roles = [ "workers" ]
assert_equal [], @kamal.accessory_hosts
end

private
def configure_with(variant)
@kamal = Kamal::Commander.new.tap do |kamal|
Expand Down
38 changes: 38 additions & 0 deletions test/fixtures/deploy_with_accessories_on_independent_server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
service: app
image: dhh/app
servers:
web:
- "1.1.1.1"
- "1.1.1.2"
workers:
- "1.1.1.3"
- "1.1.1.4"
registry:
username: user
password: pw
builder:
arch: amd64

accessories:
mysql:
image: mysql:5.7
host: 1.1.1.5
port: 3306
env:
clear:
MYSQL_ROOT_HOST: '%'
secret:
- MYSQL_ROOT_PASSWORD
files:
- test/fixtures/files/my.cnf:/etc/mysql/my.cnf
directories:
- data:/var/lib/mysql
redis:
image: redis:latest
roles:
- web
port: 6379
directories:
- data:/data

readiness_delay: 0
29 changes: 29 additions & 0 deletions test/fixtures/deploy_with_single_accessory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
service: app
image: dhh/app
servers:
web:
- "1.1.1.1"
- "1.1.1.2"
workers:
- "1.1.1.3"
- "1.1.1.4"
registry:
username: user
password: pw
builder:
arch: amd64

accessories:
mysql:
image: mysql:5.7
host: 1.1.1.5
port: 3306
env:
clear:
MYSQL_ROOT_HOST: '%'
secret:
- MYSQL_ROOT_PASSWORD
files:
- test/fixtures/files/my.cnf:/etc/mysql/my.cnf
directories:
- data:/var/lib/mysql