Merge branch 'basecamp:main' into buildpacks
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
kamal (2.5.3)
|
kamal (2.6.0)
|
||||||
activesupport (>= 7.0)
|
activesupport (>= 7.0)
|
||||||
base64 (~> 0.2)
|
base64 (~> 0.2)
|
||||||
bcrypt_pbkdf (~> 1.0)
|
bcrypt_pbkdf (~> 1.0)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class Kamal::Configuration::Accessory
|
|||||||
end
|
end
|
||||||
|
|
||||||
def hosts
|
def hosts
|
||||||
hosts_from_host || hosts_from_hosts || hosts_from_roles
|
hosts_from_host || hosts_from_hosts || hosts_from_roles || hosts_from_tags
|
||||||
end
|
end
|
||||||
|
|
||||||
def port
|
def port
|
||||||
@@ -201,11 +201,31 @@ class Kamal::Configuration::Accessory
|
|||||||
end
|
end
|
||||||
|
|
||||||
def hosts_from_roles
|
def hosts_from_roles
|
||||||
if accessory_config.key?("roles")
|
if accessory_config.key?("role")
|
||||||
|
config.role(accessory_config["role"])&.hosts
|
||||||
|
elsif accessory_config.key?("roles")
|
||||||
accessory_config["roles"].flat_map { |role| config.role(role)&.hosts }
|
accessory_config["roles"].flat_map { |role| config.role(role)&.hosts }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def hosts_from_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) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def extract_hosts_from_config_with_tag(tag)
|
||||||
|
if (servers_with_roles = config.raw_config.servers).is_a?(Hash)
|
||||||
|
servers_with_roles.flat_map do |role, servers_in_role|
|
||||||
|
servers_in_role.filter_map do |host|
|
||||||
|
host.keys.first if host.is_a?(Hash) && host.values.first.include?(tag)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def network
|
def network
|
||||||
accessory_config["network"] || DEFAULT_NETWORK
|
accessory_config["network"] || DEFAULT_NETWORK
|
||||||
end
|
end
|
||||||
@@ -213,6 +233,8 @@ class Kamal::Configuration::Accessory
|
|||||||
def ensure_valid_roles
|
def ensure_valid_roles
|
||||||
if accessory_config["roles"] && (missing_roles = accessory_config["roles"] - config.roles.map(&:name)).any?
|
if accessory_config["roles"] && (missing_roles = accessory_config["roles"] - config.roles.map(&:name)).any?
|
||||||
raise Kamal::ConfigurationError, "accessories/#{name}: unknown roles #{missing_roles.join(", ")}"
|
raise Kamal::ConfigurationError, "accessories/#{name}: unknown roles #{missing_roles.join(", ")}"
|
||||||
|
elsif accessory_config["role"] && !config.role(accessory_config["role"])
|
||||||
|
raise Kamal::ConfigurationError, "accessories/#{name}: unknown role #{accessory_config["role"]}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -46,13 +46,18 @@ accessories:
|
|||||||
|
|
||||||
# Accessory hosts
|
# Accessory hosts
|
||||||
#
|
#
|
||||||
# Specify one of `host`, `hosts`, or `roles`:
|
# Specify one of `host`, `hosts`, `role`, `roles`, `tag` or `tags`:
|
||||||
host: mysql-db1
|
host: mysql-db1
|
||||||
hosts:
|
hosts:
|
||||||
- mysql-db1
|
- mysql-db1
|
||||||
- mysql-db2
|
- mysql-db2
|
||||||
|
role: mysql
|
||||||
roles:
|
roles:
|
||||||
- mysql
|
- mysql
|
||||||
|
tag: writer
|
||||||
|
tags:
|
||||||
|
- 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" ]).size != 1
|
if (config.keys & [ "host", "hosts", "role", "roles", "tag", "tags" ]).size != 1
|
||||||
error "specify one of `host`, `hosts` or `roles`"
|
error "specify one of `host`, `hosts`, `role`, `roles`, `tag` or `tags`"
|
||||||
end
|
end
|
||||||
|
|
||||||
validate_docker_options!(config["options"])
|
validate_docker_options!(config["options"])
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Kamal
|
module Kamal
|
||||||
VERSION = "2.5.3"
|
VERSION = "2.6.0"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
image: "dhh/app",
|
image: "dhh/app",
|
||||||
registry: { "username" => "dhh", "password" => "secret" },
|
registry: { "username" => "dhh", "password" => "secret" },
|
||||||
servers: {
|
servers: {
|
||||||
"web" => [ "1.1.1.1", "1.1.1.2" ],
|
"web" => [ { "1.1.1.1" => "writer" }, { "1.1.1.2" => "reader" } ],
|
||||||
"workers" => [ "1.1.1.3", "1.1.1.4" ]
|
"workers" => [ { "1.1.1.3" => "writer" }, "1.1.1.4" ]
|
||||||
},
|
},
|
||||||
builder: { "arch" => "amd64" },
|
builder: { "arch" => "amd64" },
|
||||||
env: { "REDIS_URL" => "redis://x/y" },
|
env: { "REDIS_URL" => "redis://x/y" },
|
||||||
@@ -55,7 +55,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
"service" => "custom-monitoring",
|
"service" => "custom-monitoring",
|
||||||
"image" => "monitoring:latest",
|
"image" => "monitoring:latest",
|
||||||
"registry" => { "server" => "other.registry", "username" => "user", "password" => "pw" },
|
"registry" => { "server" => "other.registry", "username" => "user", "password" => "pw" },
|
||||||
"roles" => [ "web" ],
|
"role" => "web",
|
||||||
"port" => "4321:4321",
|
"port" => "4321:4321",
|
||||||
"labels" => {
|
"labels" => {
|
||||||
"cache" => "true"
|
"cache" => "true"
|
||||||
@@ -70,6 +70,14 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
"proxy" => {
|
"proxy" => {
|
||||||
"host" => "monitoring.example.com"
|
"host" => "monitoring.example.com"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"proxy" => {
|
||||||
|
"image" => "proxy:latest",
|
||||||
|
"tags" => [ "writer", "reader" ]
|
||||||
|
},
|
||||||
|
"logger" => {
|
||||||
|
"image" => "logger:latest",
|
||||||
|
"tag" => "writer"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,6 +115,8 @@ 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", "1.1.1.2" ], @config.accessory(:proxy).hosts
|
||||||
|
assert_equal [ "1.1.1.1", "1.1.1.3" ], @config.accessory(:logger).hosts
|
||||||
end
|
end
|
||||||
|
|
||||||
test "missing host" do
|
test "missing host" do
|
||||||
@@ -117,14 +127,14 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "setting host, hosts and roles" do
|
test "setting host, hosts, roles and tags" do
|
||||||
@deploy[:accessories]["mysql"]["hosts"] = [ "mysql-db1" ]
|
@deploy[:accessories]["mysql"]["hosts"] = [ "mysql-db1" ]
|
||||||
@deploy[:accessories]["mysql"]["roles"] = [ "db" ]
|
@deploy[:accessories]["mysql"]["roles"] = [ "db" ]
|
||||||
|
|
||||||
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` or `roles`", exception.message
|
assert_equal "accessories/mysql: specify one of `host`, `hosts`, `role`, `roles`, `tag` or `tags`", exception.message
|
||||||
end
|
end
|
||||||
|
|
||||||
test "all hosts" do
|
test "all hosts" do
|
||||||
|
|||||||
Reference in New Issue
Block a user