Skip to content

Commit

Permalink
Group configuration methods in logical sections
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Sep 16, 2023
1 parent f648fe6 commit e9ef13d
Showing 1 changed file with 56 additions and 54 deletions.
110 changes: 56 additions & 54 deletions lib/kamal/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,8 @@ def abbreviated_version
Kamal::Utils.abbreviate_version(version)
end

def run_directory
raw_config.run_directory || ".kamal"
end

def run_directory_as_docker_volume
if Pathname.new(run_directory).absolute?
run_directory
else
File.join "$(pwd)", run_directory
end
def minimum_version
raw_config.minimum_version
end


Expand Down Expand Up @@ -98,10 +90,6 @@ def traefik_hosts
roles.select(&:running_traefik?).flat_map(&:hosts).uniq
end

def boot
Kamal::Configuration::Boot.new(config: self)
end


def repository
[ raw_config.registry["server"], image ].compact.join("/")
Expand Down Expand Up @@ -142,6 +130,18 @@ def logging_args
end


def boot
Kamal::Configuration::Boot.new(config: self)
end

def builder
Kamal::Configuration::Builder.new(config: self)
end

def traefik
raw_config.traefik || {}
end

def ssh
Kamal::Configuration::Ssh.new(config: self)
end
Expand All @@ -163,14 +163,46 @@ def readiness_delay
raw_config.readiness_delay || 7
end

def minimum_version
raw_config.minimum_version
def run_id
@run_id ||= SecureRandom.hex(16)
end


def run_directory
raw_config.run_directory || ".kamal"
end

def run_directory_as_docker_volume
if Pathname.new(run_directory).absolute?
run_directory
else
File.join "$(pwd)", run_directory
end
end

def hooks_path
raw_config.hooks_path || ".kamal/hooks"
end

def host_env_directory
"#{run_directory}/env"
end

def asset_path
raw_config.asset_path
end


def valid?
ensure_destination_if_required && ensure_required_keys_present && ensure_valid_kamal_version
end

# Will raise KeyError if any secret ENVs are missing
def ensure_env_available
roles.each(&:env_file)

true
end

def to_h
{
Expand All @@ -191,39 +223,17 @@ def to_h
}.compact
end

def traefik
raw_config.traefik || {}
end

def hooks_path
raw_config.hooks_path || ".kamal/hooks"
end

def builder
Kamal::Configuration::Builder.new(config: self)
end

# Will raise KeyError if any secret ENVs are missing
def ensure_env_available
roles.each(&:env_file)

true
end

def host_env_directory
"#{run_directory}/env"
end

def run_id
@run_id ||= SecureRandom.hex(16)
end

def asset_path
raw_config.asset_path
end

private
# Will raise ArgumentError if any required config keys are missing
def ensure_destination_if_required
if require_destination? && destination.nil?
raise ArgumentError, "You must specify a destination"
end

true
end

def ensure_required_keys_present
%i[ service image registry servers ].each do |key|
raise ArgumentError, "Missing required configuration for #{key}" unless raw_config[key].present?
Expand Down Expand Up @@ -254,14 +264,6 @@ def ensure_valid_kamal_version
true
end

def ensure_destination_if_required
if require_destination? && destination.nil?
raise ArgumentError, "You must specify a destination"
end

true
end


def role_names
raw_config.servers.is_a?(Array) ? [ "web" ] : raw_config.servers.keys.sort
Expand Down

0 comments on commit e9ef13d

Please sign in to comment.