Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make config.primary_role a Role instead of a string #590

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/kamal/cli/healthcheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Kamal::Cli::Healthcheck < Kamal::Cli::Base

desc "perform", "Health check current app version"
def perform
raise "The primary host is not configured to run Traefik" unless KAMAL.config.role(KAMAL.config.primary_role).running_traefik?
raise "The primary host is not configured to run Traefik" unless KAMAL.config.primary_role.running_traefik?
on(KAMAL.primary_host) do
begin
execute *KAMAL.healthcheck.run
Expand Down
2 changes: 1 addition & 1 deletion lib/kamal/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def deploy
say "Ensure Traefik is running...", :magenta
invoke "kamal:cli:traefik:boot", [], invoke_options

if KAMAL.config.role(KAMAL.config.primary_role).running_traefik?
if KAMAL.config.primary_role.running_traefik?
say "Ensure app can pass healthcheck...", :magenta
invoke "kamal:cli:healthcheck:perform", [], invoke_options
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kamal/commands/healthcheck.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Kamal::Commands::Healthcheck < Kamal::Commands::Base

def run
primary = config.role(config.primary_role)
primary = config.primary_role

docker :run,
"--detach",
Expand Down
14 changes: 9 additions & 5 deletions lib/kamal/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def all_hosts
end

def primary_host
role(primary_role)&.primary_host
primary_role&.primary_host
end

def traefik_roles
Expand Down Expand Up @@ -209,6 +209,10 @@ def asset_path
end

def primary_role
role(primary_role_name)
end

def primary_role_name
raw_config.primary_role || "web"
end

Expand Down Expand Up @@ -264,12 +268,12 @@ def ensure_required_keys_present
raise ArgumentError, "You must specify a password for the registry in config/deploy.yml (or set the ENV variable if that's used)"
end

unless role_names.include?(primary_role)
raise ArgumentError, "The primary_role #{primary_role} isn't defined"
unless role_names.include?(primary_role_name)
raise ArgumentError, "The primary_role #{primary_role_name} isn't defined"
end

if role(primary_role).hosts.empty?
raise ArgumentError, "No servers specified for the #{primary_role} primary_role"
if primary_role.hosts.empty?
raise ArgumentError, "No servers specified for the #{primary_role_name} primary_role"
end

unless allow_empty_roles?
Expand Down
2 changes: 1 addition & 1 deletion lib/kamal/configuration/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def running_traefik?
end

def primary?
@config.primary_role == name
@config.primary_role_name == name
end


Expand Down
4 changes: 2 additions & 2 deletions test/commander_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class CommanderTest < ActiveSupport::TestCase
end

test "primary_role" do
assert_equal "web", @kamal.primary_role
assert_equal "web", @kamal.primary_role_name
@kamal.specific_roles = "workers"
assert_equal "workers", @kamal.primary_role
assert_equal "workers", @kamal.primary_role_name
end

test "roles_on" do
Expand Down
4 changes: 2 additions & 2 deletions test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ class ConfigurationTest < ActiveSupport::TestCase
end

test "primary role" do
assert_equal "web", @config.primary_role
assert_equal "web", @config.primary_role_name

config = Kamal::Configuration.new(@deploy_with_roles.deep_merge({
servers: { "alternate_web" => { "hosts" => [ "1.1.1.4", "1.1.1.5" ] } },
primary_role: "alternate_web" } ))


assert_equal "alternate_web", config.primary_role
assert_equal "alternate_web", config.primary_role_name
assert_equal "1.1.1.4", config.primary_host
assert config.role(:alternate_web).primary?
assert config.role(:alternate_web).running_traefik?
Expand Down
Loading