Merge branch 'main' into fix/ssh-auth-methods
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class Kamal::Configuration::Accessory
|
||||
delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Kamal::Utils
|
||||
delegate :argumentize, :env_file_with_secrets, :optionize, to: Kamal::Utils
|
||||
|
||||
attr_accessor :name, :specifics
|
||||
|
||||
@@ -45,8 +45,20 @@ class Kamal::Configuration::Accessory
|
||||
specifics["env"] || {}
|
||||
end
|
||||
|
||||
def env_file
|
||||
env_file_with_secrets env
|
||||
end
|
||||
|
||||
def host_env_directory
|
||||
File.join config.host_env_directory, "accessories"
|
||||
end
|
||||
|
||||
def host_env_file_path
|
||||
File.join host_env_directory, "#{service_name}.env"
|
||||
end
|
||||
|
||||
def env_args
|
||||
argumentize_env_with_secrets env
|
||||
argumentize "--env-file", host_env_file_path
|
||||
end
|
||||
|
||||
def files
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class Kamal::Configuration::Role
|
||||
delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Kamal::Utils
|
||||
CORD_FILE = "cord"
|
||||
delegate :argumentize, :env_file_with_secrets, :optionize, to: Kamal::Utils
|
||||
|
||||
attr_accessor :name
|
||||
|
||||
@@ -31,32 +32,68 @@ class Kamal::Configuration::Role
|
||||
end
|
||||
end
|
||||
|
||||
def env_args
|
||||
argumentize_env_with_secrets env
|
||||
def env_file
|
||||
env_file_with_secrets env
|
||||
end
|
||||
|
||||
def health_check_args
|
||||
def host_env_directory
|
||||
File.join config.host_env_directory, "roles"
|
||||
end
|
||||
|
||||
def host_env_file_path
|
||||
File.join host_env_directory, "#{[config.service, name, config.destination].compact.join("-")}.env"
|
||||
end
|
||||
|
||||
def env_args
|
||||
argumentize "--env-file", host_env_file_path
|
||||
end
|
||||
|
||||
def health_check_args(cord: true)
|
||||
if health_check_cmd.present?
|
||||
optionize({ "health-cmd" => health_check_cmd, "health-interval" => health_check_interval })
|
||||
if cord && uses_cord?
|
||||
optionize({ "health-cmd" => health_check_cmd_with_cord, "health-interval" => health_check_interval })
|
||||
.concat(["--volume", "#{cord_host_directory}:#{cord_container_directory}"])
|
||||
else
|
||||
optionize({ "health-cmd" => health_check_cmd, "health-interval" => health_check_interval })
|
||||
end
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def health_check_cmd
|
||||
options = specializations["healthcheck"] || {}
|
||||
options = config.healthcheck.merge(options) if running_traefik?
|
||||
health_check_options["cmd"] || http_health_check(port: health_check_options["port"], path: health_check_options["path"])
|
||||
end
|
||||
|
||||
options["cmd"] || http_health_check(port: options["port"], path: options["path"])
|
||||
def health_check_cmd_with_cord
|
||||
"(#{health_check_cmd}) && (stat #{cord_container_file} > /dev/null || exit 1)"
|
||||
end
|
||||
|
||||
def health_check_interval
|
||||
options = specializations["healthcheck"] || {}
|
||||
options = config.healthcheck.merge(options) if running_traefik?
|
||||
|
||||
options["interval"] || "1s"
|
||||
health_check_options["interval"] || "1s"
|
||||
end
|
||||
|
||||
def uses_cord?
|
||||
running_traefik? && cord_container_directory.present? && health_check_cmd.present?
|
||||
end
|
||||
|
||||
def cord_host_directory
|
||||
File.join config.run_directory_as_docker_volume, "cords", [full_name, config.run_id].join("-")
|
||||
end
|
||||
|
||||
def cord_host_file
|
||||
File.join cord_host_directory, CORD_FILE
|
||||
end
|
||||
|
||||
def cord_container_directory
|
||||
health_check_options.fetch("cord", nil)
|
||||
end
|
||||
|
||||
def cord_container_file
|
||||
File.join cord_container_directory, CORD_FILE
|
||||
end
|
||||
|
||||
|
||||
def cmd
|
||||
specializations["cmd"]
|
||||
end
|
||||
@@ -73,6 +110,10 @@ class Kamal::Configuration::Role
|
||||
name.web? || specializations["traefik"]
|
||||
end
|
||||
|
||||
def full_name
|
||||
[ config.service, name, config.destination ].compact.join("-")
|
||||
end
|
||||
|
||||
private
|
||||
attr_accessor :config
|
||||
|
||||
@@ -152,4 +193,12 @@ class Kamal::Configuration::Role
|
||||
def http_health_check(port:, path:)
|
||||
"curl -f #{URI.join("http://localhost:#{port}", path)} || exit 1" if path.present? || port.present?
|
||||
end
|
||||
|
||||
def health_check_options
|
||||
@health_check_options ||= begin
|
||||
options = specializations["healthcheck"] || {}
|
||||
options = config.healthcheck.merge(options) if running_traefik?
|
||||
options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user