fix: allow configurations without web roles
This commit is contained in:
@@ -3,6 +3,7 @@ class Kamal::Cli::Healthcheck < Kamal::Cli::Base
|
||||
|
||||
desc "perform", "Health check current app version"
|
||||
def perform
|
||||
return unless KAMAL.primary_role.running_traefik?
|
||||
on(KAMAL.primary_host) do
|
||||
begin
|
||||
execute *KAMAL.healthcheck.run
|
||||
|
||||
@@ -24,7 +24,7 @@ class Kamal::Commander
|
||||
attr_reader :specific_roles, :specific_hosts
|
||||
|
||||
def specific_primary!
|
||||
self.specific_hosts = [ config.primary_web_host ]
|
||||
self.specific_hosts = [ config.primary_host ]
|
||||
end
|
||||
|
||||
def specific_roles=(role_names)
|
||||
@@ -36,7 +36,7 @@ class Kamal::Commander
|
||||
end
|
||||
|
||||
def primary_host
|
||||
specific_hosts&.first || specific_roles&.first&.primary_host || config.primary_web_host
|
||||
specific_hosts&.first || specific_roles&.first&.primary_host || config.primary_host
|
||||
end
|
||||
|
||||
def primary_role
|
||||
|
||||
@@ -2,6 +2,7 @@ class Kamal::Commands::Healthcheck < Kamal::Commands::Base
|
||||
|
||||
def run
|
||||
web = config.role(:web)
|
||||
return unless web.present?
|
||||
|
||||
docker :run,
|
||||
"--detach",
|
||||
|
||||
@@ -89,8 +89,12 @@ class Kamal::Configuration
|
||||
roles.flat_map(&:hosts).uniq
|
||||
end
|
||||
|
||||
def primary_web_host
|
||||
role(:web).primary_host
|
||||
def primary_host
|
||||
primary_role.primary_host
|
||||
end
|
||||
|
||||
def primary_role
|
||||
role(:web) || roles.first
|
||||
end
|
||||
|
||||
def traefik_hosts
|
||||
@@ -208,7 +212,7 @@ class Kamal::Configuration
|
||||
{
|
||||
roles: role_names,
|
||||
hosts: all_hosts,
|
||||
primary_host: primary_web_host,
|
||||
primary_host: primary_host,
|
||||
version: version,
|
||||
repository: repository,
|
||||
absolute_image: absolute_image,
|
||||
|
||||
@@ -64,9 +64,14 @@ class CliHealthcheckTest < CliTestCase
|
||||
end
|
||||
assert_match "container not ready (unhealthy)", exception.message
|
||||
end
|
||||
|
||||
test "does not perform if primary does not have traefik" do
|
||||
SSHKit::Backend::Abstract.any_instance.expects(:execute).never
|
||||
run_command("perform", config_file: "test/fixtures/deploy_workers_only.yml")
|
||||
end
|
||||
|
||||
private
|
||||
def run_command(*command)
|
||||
stdouted { Kamal::Cli::Healthcheck.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) }
|
||||
def run_command(*command, config_file: "test/fixtures/deploy_with_accessories.yml")
|
||||
stdouted { Kamal::Cli::Healthcheck.start([*command, "-c", config_file]) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -58,9 +58,9 @@ class ConfigurationTest < ActiveSupport::TestCase
|
||||
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3" ], @config_with_roles.all_hosts
|
||||
end
|
||||
|
||||
test "primary web host" do
|
||||
assert_equal "1.1.1.1", @config.primary_web_host
|
||||
assert_equal "1.1.1.1", @config_with_roles.primary_web_host
|
||||
test "primary host" do
|
||||
assert_equal "1.1.1.1", @config.primary_host
|
||||
assert_equal "1.1.1.1", @config_with_roles.primary_host
|
||||
end
|
||||
|
||||
test "traefik hosts" do
|
||||
|
||||
10
test/fixtures/deploy_workers_only.yml
vendored
Normal file
10
test/fixtures/deploy_workers_only.yml
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
service: app
|
||||
image: dhh/app
|
||||
servers:
|
||||
workers:
|
||||
hosts:
|
||||
- 1.1.1.1
|
||||
- 1.1.1.2
|
||||
registry:
|
||||
username: user
|
||||
password: pw
|
||||
Reference in New Issue
Block a user