Merge pull request #1504 from basecamp/proxy-metrics-port

Allow kamal-proxy run command options to be set
This commit is contained in:
Donal McBreen
2025-05-06 13:15:47 +01:00
committed by GitHub
6 changed files with 76 additions and 13 deletions

View File

@@ -31,6 +31,8 @@ class Kamal::Cli::Proxy < Kamal::Cli::Base
option :registry, type: :string, default: nil, desc: "Registry to use for the proxy image"
option :repository, type: :string, default: nil, desc: "Repository for the proxy image"
option :image_version, type: :string, default: nil, desc: "Version of the proxy to run"
option :metrics_port, type: :numeric, default: nil, desc: "Port to report prometheus metrics on"
option :debug, type: :boolean, default: false, desc: "Whether to run the proxy in debug mode"
option :docker_options, type: :array, default: [], desc: "Docker options to pass to the proxy container", banner: "option=value option2=value2"
def boot_config(subcommand)
proxy_boot_config = KAMAL.config.proxy_boot
@@ -40,6 +42,7 @@ class Kamal::Cli::Proxy < Kamal::Cli::Base
boot_options = [
*(proxy_boot_config.publish_args(options[:http_port], options[:https_port], options[:publish_host_ip]) if options[:publish]),
*(proxy_boot_config.logging_args(options[:log_max_size])),
*("--expose=#{options[:metrics_port]}" if options[:metrics_port]),
*options[:docker_options].map { |option| "--#{option}" }
]
@@ -51,6 +54,9 @@ class Kamal::Cli::Proxy < Kamal::Cli::Base
image_version = options[:image_version]
run_command_options = { debug: options[:debug] || nil, "metrics-port": options[:metrics_port] }.compact
run_command = "kamal-proxy run #{Kamal::Utils.optionize(run_command_options).join(" ")}" if run_command_options.any?
on(KAMAL.proxy_hosts) do |host|
execute(*KAMAL.proxy.ensure_proxy_directory)
if boot_options != proxy_boot_config.default_boot_options
@@ -70,6 +76,12 @@ class Kamal::Cli::Proxy < Kamal::Cli::Base
else
execute *KAMAL.proxy.reset_image_version, raise_on_non_zero_exit: false
end
if run_command
upload! StringIO.new(run_command), proxy_boot_config.run_command_file
else
execute *KAMAL.proxy.reset_run_command, raise_on_non_zero_exit: false
end
end
when "get"
@@ -81,6 +93,7 @@ class Kamal::Cli::Proxy < Kamal::Cli::Base
execute *KAMAL.proxy.reset_boot_options, raise_on_non_zero_exit: false
execute *KAMAL.proxy.reset_image, raise_on_non_zero_exit: false
execute *KAMAL.proxy.reset_image_version, raise_on_non_zero_exit: false
execute *KAMAL.proxy.reset_run_command, raise_on_non_zero_exit: false
end
else
raise ArgumentError, "Unknown boot_config subcommand #{subcommand}"

View File

@@ -70,7 +70,7 @@ class Kamal::Commands::Proxy < Kamal::Commands::Base
end
def boot_config
[ :echo, "#{substitute(read_boot_options)} #{substitute(read_image)}:#{substitute(read_image_version)}" ]
[ :echo, "#{substitute(read_boot_options)} #{substitute(read_image)}:#{substitute(read_image_version)} #{substitute(read_run_command)}" ]
end
def read_boot_options
@@ -85,6 +85,10 @@ class Kamal::Commands::Proxy < Kamal::Commands::Base
read_file(config.proxy_boot.image_version_file, default: Kamal::Configuration::Proxy::Boot::MINIMUM_VERSION)
end
def read_run_command
read_file(config.proxy_boot.run_command_file)
end
def reset_boot_options
remove_file config.proxy_boot.options_file
end
@@ -97,6 +101,10 @@ class Kamal::Commands::Proxy < Kamal::Commands::Base
remove_file config.proxy_boot.image_version_file
end
def reset_run_command
remove_file config.proxy_boot.run_command_file
end
private
def container_name
config.proxy_boot.container_name

View File

@@ -66,6 +66,10 @@ class Kamal::Configuration::Proxy::Boot
File.join host_directory, "image_version"
end
def run_command_file
File.join host_directory, "run_command"
end
def apps_directory
File.join host_directory, "apps-config"
end