Add pre and post app boot hooks

Add two new hooks pre-app-boot and post-app-boot. They are analagous
to the pre/post proxy reboot hooks.

If the boot strategy deploys in groups, then the hooks are called once
per group of hosts and `KAMAL_HOSTS` contains a comma delimited list of
the hosts in that group.

If all hosts are deployed to at once, then they are called once with
`KAMAL_HOSTS` containing all the hosts.

It is possible to have pauses between groups of hosts in the boot config,
where this is the case the pause happens after the post-app-boot hook is
called.
This commit is contained in:
Donal McBreen
2025-02-03 14:14:39 +00:00
parent 09d020e9bb
commit cd73cea850
17 changed files with 116 additions and 99 deletions

View File

@@ -0,0 +1,54 @@
require "test_helper"
class ConfigurationBootTest < ActiveSupport::TestCase
test "no group strategy" do
deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, builder: { "arch" => "amd64" },
servers: { "web" => [ "1.1.1.1", "1.1.1.2" ], "workers" => [ "1.1.1.3", "1.1.1.4" ] }
}
config = Kamal::Configuration.new(deploy)
assert_nil config.boot.limit
assert_nil config.boot.wait
end
test "specific limit group strategy" do
deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, builder: { "arch" => "amd64" },
servers: { "web" => [ "1.1.1.1", "1.1.1.2" ], "workers" => [ "1.1.1.3", "1.1.1.4" ] },
boot: { "limit" => 3, "wait" => 2 }
}
config = Kamal::Configuration.new(deploy)
assert_equal 3, config.boot.limit
assert_equal 2, config.boot.wait
end
test "percentage-based group strategy" do
deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, builder: { "arch" => "amd64" },
servers: { "web" => [ "1.1.1.1", "1.1.1.2" ], "workers" => [ "1.1.1.3", "1.1.1.4" ] },
boot: { "limit" => "50%", "wait" => 2 }
}
config = Kamal::Configuration.new(deploy)
assert_equal 2, config.boot.limit
assert_equal 2, config.boot.wait
end
test "percentage-based group strategy limit is at least 1" do
deploy = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, builder: { "arch" => "amd64" },
servers: { "web" => [ "1.1.1.1", "1.1.1.2" ], "workers" => [ "1.1.1.3", "1.1.1.4" ] },
boot: { "limit" => "1%", "wait" => 2 }
}
config = Kamal::Configuration.new(deploy)
assert_equal 1, config.boot.limit
assert_equal 2, config.boot.wait
end
end