Skip to content

Commit 299c741

Browse files
author
David Heinemeier Hansson
committed
More natural api when you are just applying accessory to a single tag
1 parent fb82d04 commit 299c741

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

lib/kamal/configuration/accessory.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ def hosts_from_roles
207207
end
208208

209209
def hosts_from_tags
210-
if accessory_config.key?("tags")
210+
if accessory_config.key?("tag")
211+
extract_hosts_from_config_with_tag(accessory_config["tag"])
212+
elsif accessory_config.key?("tags")
211213
accessory_config["tags"].flat_map { |tag| extract_hosts_from_config_with_tag(tag) }
212214
end
213215
end

lib/kamal/configuration/docs/accessory.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ accessories:
5353
- mysql-db2
5454
roles:
5555
- mysql
56+
tag: writer
5657
tags:
5758
- writer
59+
- reader
5860

5961
# Custom command
6062
#

lib/kamal/configuration/validator/accessory.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ class Kamal::Configuration::Validator::Accessory < Kamal::Configuration::Validat
22
def validate!
33
super
44

5-
if (config.keys & [ "host", "hosts", "roles", "tags" ]).size != 1
6-
error "specify one of `host`, `hosts`, `roles` or `tags`"
5+
if (config.keys & [ "host", "hosts", "roles", "tag", "tags" ]).size != 1
6+
error "specify one of `host`, `hosts`, `roles`, `tag` or `tags`"
77
end
88

99
validate_docker_options!(config["options"])

test/configuration/accessory_test.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
7373
},
7474
"proxy" => {
7575
"image" => "proxy:latest",
76-
"tags" => [ "writer" ]
76+
"tags" => [ "writer", "reader" ]
77+
},
78+
"logger" => {
79+
"image" => "logger:latest",
80+
"tag" => "writer"
7781
}
7882
}
7983
}
@@ -111,7 +115,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
111115
assert_equal [ "1.1.1.5" ], @config.accessory(:mysql).hosts
112116
assert_equal [ "1.1.1.6", "1.1.1.7" ], @config.accessory(:redis).hosts
113117
assert_equal [ "1.1.1.1", "1.1.1.2" ], @config.accessory(:monitoring).hosts
114-
assert_equal [ "1.1.1.1", "1.1.1.3" ], @config.accessory(:proxy).hosts
118+
assert_equal [ "1.1.1.1", "1.1.1.3", "1.1.1.2" ], @config.accessory(:proxy).hosts
115119
end
116120

117121
test "missing host" do
@@ -129,7 +133,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
129133
exception = assert_raises(Kamal::ConfigurationError) do
130134
Kamal::Configuration.new(@deploy)
131135
end
132-
assert_equal "accessories/mysql: specify one of `host`, `hosts`, `roles` or `tags`", exception.message
136+
assert_equal "accessories/mysql: specify one of `host`, `hosts`, `roles`, `tag` or `tags`", exception.message
133137
end
134138

135139
test "all hosts" do

0 commit comments

Comments
 (0)