Eval proxy options

To ensure that the proxy options are evaluated as if they were
added verbatim to the command, we'll eval the docker run command.

Fixes: https://github.com/basecamp/kamal/issues/1448
This commit is contained in:
Donal McBreen
2025-03-10 10:04:26 +00:00
parent 0d034ec5dc
commit a6ebe3492f
5 changed files with 51 additions and 16 deletions

View File

@@ -76,6 +76,10 @@ module Kamal::Commands
[ :sh, "-c", "'#{command.flatten.join(" ").gsub("'", "'\\\\''")}'" ]
end
def eval(*args)
[ :eval, *args ]
end
def docker(*args)
args.compact.unshift :docker
end

View File

@@ -2,14 +2,21 @@ class Kamal::Commands::Proxy < Kamal::Commands::Base
delegate :argumentize, :optionize, to: Kamal::Utils
def run
docker :run,
"--name", container_name,
"--network", "kamal",
"--detach",
"--restart", "unless-stopped",
"--volume", "kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy",
"\$\(#{get_boot_options.join(" ")}\)",
config.proxy_image
shell \
chain \
boot_options,
eval(
docker(
:run,
"--name", container_name,
"--network", "kamal",
"--detach",
"--restart", "unless-stopped",
"--volume", "kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy",
"\$OPTIONS",
config.proxy_image
)
)
end
def start
@@ -72,6 +79,10 @@ class Kamal::Commands::Proxy < Kamal::Commands::Base
remove_directory config.proxy_directory
end
def boot_options
"OPTIONS=$(cat #{config.proxy_options_file} 2> /dev/null || echo \"#{config.proxy_options_default.join(" ")}\")"
end
def get_boot_options
combine [ :cat, config.proxy_options_file ], [ :echo, "\"#{config.proxy_options_default.join(" ")}\"" ], by: "||"
end