Prep for 2.5
- Reset KAMAL on alias command, rather than relying on checking "invoked_via_subcommand" - Validate the accessories roles when loading the configuration not later on when trying to access them
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
class Kamal::Cli::Alias::Command < Thor::DynamicCommand
|
class Kamal::Cli::Alias::Command < Thor::DynamicCommand
|
||||||
def run(instance, args = [])
|
def run(instance, args = [])
|
||||||
if (_alias = KAMAL.config.aliases[name])
|
if (_alias = KAMAL.config.aliases[name])
|
||||||
|
KAMAL.reset
|
||||||
Kamal::Cli::Main.start(Shellwords.split(_alias.command) + ARGV[1..-1])
|
Kamal::Cli::Main.start(Shellwords.split(_alias.command) + ARGV[1..-1])
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ module Kamal::Cli
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
initialize_commander unless config[:invoked_via_subcommand]
|
initialize_commander unless KAMAL.configured?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -4,13 +4,20 @@ require "active_support/core_ext/object/blank"
|
|||||||
|
|
||||||
class Kamal::Commander
|
class Kamal::Commander
|
||||||
attr_accessor :verbosity, :holding_lock, :connected
|
attr_accessor :verbosity, :holding_lock, :connected
|
||||||
|
attr_reader :specific_roles, :specific_hosts
|
||||||
delegate :hosts, :roles, :primary_host, :primary_role, :roles_on, :proxy_hosts, :accessory_hosts, to: :specifics
|
delegate :hosts, :roles, :primary_host, :primary_role, :roles_on, :proxy_hosts, :accessory_hosts, to: :specifics
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
reset
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset
|
||||||
self.verbosity = :info
|
self.verbosity = :info
|
||||||
self.holding_lock = false
|
self.holding_lock = false
|
||||||
self.connected = false
|
self.connected = false
|
||||||
@specifics = nil
|
@specifics = @specific_roles = @specific_hosts = nil
|
||||||
|
@config = @config_kwargs = nil
|
||||||
|
@commands = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def config
|
def config
|
||||||
@@ -28,8 +35,6 @@ class Kamal::Commander
|
|||||||
@config || @config_kwargs
|
@config || @config_kwargs
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :specific_roles, :specific_hosts
|
|
||||||
|
|
||||||
def specific_primary!
|
def specific_primary!
|
||||||
@specifics = nil
|
@specifics = nil
|
||||||
if specific_roles.present?
|
if specific_roles.present?
|
||||||
@@ -89,35 +94,35 @@ class Kamal::Commander
|
|||||||
end
|
end
|
||||||
|
|
||||||
def builder
|
def builder
|
||||||
@builder ||= Kamal::Commands::Builder.new(config)
|
@commands[:builder] ||= Kamal::Commands::Builder.new(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
def docker
|
def docker
|
||||||
@docker ||= Kamal::Commands::Docker.new(config)
|
@commands[:docker] ||= Kamal::Commands::Docker.new(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
def hook
|
def hook
|
||||||
@hook ||= Kamal::Commands::Hook.new(config)
|
@commands[:hook] ||= Kamal::Commands::Hook.new(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
def lock
|
def lock
|
||||||
@lock ||= Kamal::Commands::Lock.new(config)
|
@commands[:lock] ||= Kamal::Commands::Lock.new(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
def proxy
|
def proxy
|
||||||
@proxy ||= Kamal::Commands::Proxy.new(config)
|
@commands[:proxy] ||= Kamal::Commands::Proxy.new(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
def prune
|
def prune
|
||||||
@prune ||= Kamal::Commands::Prune.new(config)
|
@commands[:prune] ||= Kamal::Commands::Prune.new(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
def registry
|
def registry
|
||||||
@registry ||= Kamal::Commands::Registry.new(config)
|
@commands[:registry] ||= Kamal::Commands::Registry.new(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
def server
|
def server
|
||||||
@server ||= Kamal::Commands::Server.new(config)
|
@commands[:server] ||= Kamal::Commands::Server.new(config)
|
||||||
end
|
end
|
||||||
|
|
||||||
def alias(name)
|
def alias(name)
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ class Kamal::Configuration::Accessory
|
|||||||
context: "accessories/#{name}",
|
context: "accessories/#{name}",
|
||||||
with: Kamal::Configuration::Validator::Accessory
|
with: Kamal::Configuration::Validator::Accessory
|
||||||
|
|
||||||
|
ensure_valid_roles
|
||||||
|
|
||||||
@env = initialize_env
|
@env = initialize_env
|
||||||
@proxy = initialize_proxy if running_proxy?
|
@proxy = initialize_proxy if running_proxy?
|
||||||
@registry = initialize_registry if accessory_config["registry"].present?
|
@registry = initialize_registry if accessory_config["registry"].present?
|
||||||
@@ -200,17 +202,17 @@ class Kamal::Configuration::Accessory
|
|||||||
|
|
||||||
def hosts_from_roles
|
def hosts_from_roles
|
||||||
if accessory_config.key?("roles")
|
if accessory_config.key?("roles")
|
||||||
accessory_config["roles"].flat_map do |role|
|
accessory_config["roles"].flat_map { |role| config.role(role)&.hosts }
|
||||||
unless (role = config.role(role))
|
|
||||||
raise Kamal::ConfigurationError, "Unknown role in accessories config: '#{role}'" unless config.role(role)
|
|
||||||
end
|
|
||||||
|
|
||||||
role.hosts
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def network
|
def network
|
||||||
accessory_config["network"] || DEFAULT_NETWORK
|
accessory_config["network"] || DEFAULT_NETWORK
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ensure_valid_roles
|
||||||
|
if accessory_config["roles"] && (missing_roles = accessory_config["roles"] - config.roles.map(&:name)).any?
|
||||||
|
raise Kamal::ConfigurationError, "accessories/#{name}: unknown roles #{missing_roles.join(", ")}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user