More natural api when you are just applying accessory to a single tag
This commit is contained in:
@@ -207,7 +207,9 @@ class Kamal::Configuration::Accessory
|
|||||||
end
|
end
|
||||||
|
|
||||||
def hosts_from_tags
|
def hosts_from_tags
|
||||||
if accessory_config.key?("tags")
|
if accessory_config.key?("tag")
|
||||||
|
extract_hosts_from_config_with_tag(accessory_config["tag"])
|
||||||
|
elsif accessory_config.key?("tags")
|
||||||
accessory_config["tags"].flat_map { |tag| extract_hosts_from_config_with_tag(tag) }
|
accessory_config["tags"].flat_map { |tag| extract_hosts_from_config_with_tag(tag) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -53,8 +53,10 @@ accessories:
|
|||||||
- mysql-db2
|
- mysql-db2
|
||||||
roles:
|
roles:
|
||||||
- mysql
|
- mysql
|
||||||
|
tag: writer
|
||||||
tags:
|
tags:
|
||||||
- writer
|
- writer
|
||||||
|
- reader
|
||||||
|
|
||||||
# Custom command
|
# Custom command
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ class Kamal::Configuration::Validator::Accessory < Kamal::Configuration::Validat
|
|||||||
def validate!
|
def validate!
|
||||||
super
|
super
|
||||||
|
|
||||||
if (config.keys & [ "host", "hosts", "roles", "tags" ]).size != 1
|
if (config.keys & [ "host", "hosts", "roles", "tag", "tags" ]).size != 1
|
||||||
error "specify one of `host`, `hosts`, `roles` or `tags`"
|
error "specify one of `host`, `hosts`, `roles`, `tag` or `tags`"
|
||||||
end
|
end
|
||||||
|
|
||||||
validate_docker_options!(config["options"])
|
validate_docker_options!(config["options"])
|
||||||
|
|||||||
@@ -73,7 +73,11 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
},
|
},
|
||||||
"proxy" => {
|
"proxy" => {
|
||||||
"image" => "proxy:latest",
|
"image" => "proxy:latest",
|
||||||
"tags" => [ "writer" ]
|
"tags" => [ "writer", "reader" ]
|
||||||
|
},
|
||||||
|
"logger" => {
|
||||||
|
"image" => "logger:latest",
|
||||||
|
"tag" => "writer"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,7 +115,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
assert_equal [ "1.1.1.5" ], @config.accessory(:mysql).hosts
|
assert_equal [ "1.1.1.5" ], @config.accessory(:mysql).hosts
|
||||||
assert_equal [ "1.1.1.6", "1.1.1.7" ], @config.accessory(:redis).hosts
|
assert_equal [ "1.1.1.6", "1.1.1.7" ], @config.accessory(:redis).hosts
|
||||||
assert_equal [ "1.1.1.1", "1.1.1.2" ], @config.accessory(:monitoring).hosts
|
assert_equal [ "1.1.1.1", "1.1.1.2" ], @config.accessory(:monitoring).hosts
|
||||||
assert_equal [ "1.1.1.1", "1.1.1.3" ], @config.accessory(:proxy).hosts
|
assert_equal [ "1.1.1.1", "1.1.1.3", "1.1.1.2" ], @config.accessory(:proxy).hosts
|
||||||
end
|
end
|
||||||
|
|
||||||
test "missing host" do
|
test "missing host" do
|
||||||
@@ -129,7 +133,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
exception = assert_raises(Kamal::ConfigurationError) do
|
exception = assert_raises(Kamal::ConfigurationError) do
|
||||||
Kamal::Configuration.new(@deploy)
|
Kamal::Configuration.new(@deploy)
|
||||||
end
|
end
|
||||||
assert_equal "accessories/mysql: specify one of `host`, `hosts`, `roles` or `tags`", exception.message
|
assert_equal "accessories/mysql: specify one of `host`, `hosts`, `roles`, `tag` or `tags`", exception.message
|
||||||
end
|
end
|
||||||
|
|
||||||
test "all hosts" do
|
test "all hosts" do
|
||||||
|
|||||||
Reference in New Issue
Block a user