Custom proxy image registry, repo and version
Use the --registry, --repository and --image_version options of `kamal proxy boot_config set` to change the kamal-proxy image used. We'll still insist that the image version is at least as high as the minimum.
This commit is contained in:
@@ -27,6 +27,9 @@ class Kamal::Cli::Proxy < Kamal::Cli::Base
|
||||
option :http_port, type: :numeric, default: Kamal::Configuration::PROXY_HTTP_PORT, desc: "HTTP port to publish on the host"
|
||||
option :https_port, type: :numeric, default: Kamal::Configuration::PROXY_HTTPS_PORT, desc: "HTTPS port to publish on the host"
|
||||
option :log_max_size, type: :string, default: Kamal::Configuration::PROXY_LOG_MAX_SIZE, desc: "Max size of proxy logs"
|
||||
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 :docker_options, type: :array, default: [], desc: "Docker options to pass to the proxy container", banner: "option=value option2=value2"
|
||||
def boot_config(subcommand)
|
||||
case subcommand
|
||||
@@ -37,17 +40,43 @@ class Kamal::Cli::Proxy < Kamal::Cli::Base
|
||||
*options[:docker_options].map { |option| "--#{option}" }
|
||||
]
|
||||
|
||||
default_boot_options = [
|
||||
*(KAMAL.config.proxy_publish_args(Kamal::Configuration::PROXY_HTTP_PORT, Kamal::Configuration::PROXY_HTTPS_PORT, nil)),
|
||||
*(KAMAL.config.proxy_logging_args(Kamal::Configuration::PROXY_LOG_MAX_SIZE)),
|
||||
]
|
||||
|
||||
image = [ options[:registry].presence, options[:repository] || KAMAL.config.proxy_repository_name, KAMAL.config.proxy_image_name ].compact.join("/")
|
||||
image_version = options[:image_version]
|
||||
|
||||
on(KAMAL.proxy_hosts) do |host|
|
||||
execute(*KAMAL.proxy.ensure_proxy_directory)
|
||||
upload! StringIO.new(boot_options.join(" ")), KAMAL.config.proxy_options_file
|
||||
if boot_options != default_boot_options
|
||||
upload! StringIO.new(boot_options.join(" ")), KAMAL.config.proxy_options_file
|
||||
else
|
||||
execute *KAMAL.proxy.reset_boot_options, raise_on_non_zero_exit: false
|
||||
end
|
||||
|
||||
if image != KAMAL.config.proxy_image_default
|
||||
upload! StringIO.new(image), KAMAL.config.proxy_image_file
|
||||
else
|
||||
execute *KAMAL.proxy.reset_image, raise_on_non_zero_exit: false
|
||||
end
|
||||
|
||||
if image_version
|
||||
upload! StringIO.new(image_version), KAMAL.config.proxy_image_version_file
|
||||
else
|
||||
execute *KAMAL.proxy.reset_image_version, raise_on_non_zero_exit: false
|
||||
end
|
||||
end
|
||||
when "get"
|
||||
on(KAMAL.proxy_hosts) do |host|
|
||||
puts "Host #{host}: #{capture_with_info(*KAMAL.proxy.get_boot_options)}"
|
||||
puts "Host #{host}: #{capture_with_info(*KAMAL.proxy.boot_config)}"
|
||||
end
|
||||
when "reset"
|
||||
on(KAMAL.proxy_hosts) do |host|
|
||||
execute *KAMAL.proxy.reset_boot_options
|
||||
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
|
||||
end
|
||||
else
|
||||
raise ArgumentError, "Unknown boot_config subcommand #{subcommand}"
|
||||
|
||||
@@ -68,6 +68,10 @@ module Kamal::Commands
|
||||
combine *commands, by: "||"
|
||||
end
|
||||
|
||||
def substitute(*commands)
|
||||
"\$\(#{commands.join(" ")}\)"
|
||||
end
|
||||
|
||||
def xargs(command)
|
||||
[ :xargs, command ].flatten
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ class Kamal::Commands::Proxy < Kamal::Commands::Base
|
||||
delegate :argumentize, :optionize, to: Kamal::Utils
|
||||
|
||||
def run
|
||||
pipe echo_boot_config, xargs(docker_run)
|
||||
pipe boot_config, xargs(docker_run)
|
||||
end
|
||||
|
||||
def start
|
||||
@@ -24,7 +24,7 @@ class Kamal::Commands::Proxy < Kamal::Commands::Base
|
||||
def version
|
||||
pipe \
|
||||
docker(:inspect, container_name, "--format '{{.Config.Image}}'"),
|
||||
[ :cut, "-d:", "-f2" ]
|
||||
[ :awk, "-F:", "'{print \$NF}'" ]
|
||||
end
|
||||
|
||||
def logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil)
|
||||
@@ -65,21 +65,41 @@ class Kamal::Commands::Proxy < Kamal::Commands::Base
|
||||
remove_directory config.proxy_directory
|
||||
end
|
||||
|
||||
def get_boot_options
|
||||
combine [ :cat, config.proxy_options_file, "2>", "/dev/null" ], [ :echo, "\"#{config.proxy_options_default.join(" ")}\"" ], by: "||"
|
||||
def boot_config
|
||||
[ :echo, "#{substitute(read_boot_options)} #{substitute(read_image)}:#{substitute(read_image_version)}" ]
|
||||
end
|
||||
|
||||
def read_boot_options
|
||||
read_file(config.proxy_options_file, default: config.proxy_options_default.join(" "))
|
||||
end
|
||||
|
||||
def read_image
|
||||
read_file(config.proxy_image_file, default: config.proxy_image_default)
|
||||
end
|
||||
|
||||
def read_image_version
|
||||
read_file(config.proxy_image_version_file, default: Kamal::Configuration::PROXY_MINIMUM_VERSION)
|
||||
end
|
||||
|
||||
def reset_boot_options
|
||||
remove_file config.proxy_options_file
|
||||
end
|
||||
|
||||
def reset_image
|
||||
remove_file config.proxy_image_file
|
||||
end
|
||||
|
||||
def reset_image_version
|
||||
remove_file config.proxy_image_version_file
|
||||
end
|
||||
|
||||
private
|
||||
def container_name
|
||||
config.proxy_container_name
|
||||
end
|
||||
|
||||
def echo_boot_config
|
||||
[ :echo, "\$\(#{get_boot_options.join(" ")}\) #{config.proxy_image}" ]
|
||||
def read_file(file, default: nil)
|
||||
combine [ :cat, file, "2>", "/dev/null" ], [ :echo, "\"#{default}\"" ], by: "||"
|
||||
end
|
||||
|
||||
def docker_run
|
||||
|
||||
@@ -261,8 +261,16 @@ class Kamal::Configuration
|
||||
[ *proxy_publish_args(PROXY_HTTP_PORT, PROXY_HTTPS_PORT), *proxy_logging_args(PROXY_LOG_MAX_SIZE) ]
|
||||
end
|
||||
|
||||
def proxy_image
|
||||
"basecamp/kamal-proxy:#{PROXY_MINIMUM_VERSION}"
|
||||
def proxy_repository_name
|
||||
"basecamp"
|
||||
end
|
||||
|
||||
def proxy_image_name
|
||||
"kamal-proxy"
|
||||
end
|
||||
|
||||
def proxy_image_default
|
||||
"#{proxy_repository_name}/#{proxy_image_name}"
|
||||
end
|
||||
|
||||
def proxy_container_name
|
||||
@@ -277,6 +285,14 @@ class Kamal::Configuration
|
||||
File.join proxy_directory, "options"
|
||||
end
|
||||
|
||||
def proxy_image_file
|
||||
File.join proxy_directory, "image"
|
||||
end
|
||||
|
||||
def proxy_image_version_file
|
||||
File.join proxy_directory, "image_version"
|
||||
end
|
||||
|
||||
def to_h
|
||||
{
|
||||
roles: role_names,
|
||||
|
||||
Reference in New Issue
Block a user