From 77593f54951b93b47006d2916515cb85960feeff Mon Sep 17 00:00:00 2001 From: "songji.zeng" Date: Thu, 7 Nov 2024 18:47:13 +0800 Subject: [PATCH] support custom proxy image - Allow users to specify custom proxy image repository instead of using default basecamp/kamal-proxy - Help users in regions where Docker Hub access is restricted (e.g. China) to pull proxy image from cloud vendor repositories - Move proxy related configurations from configuration to proxy --- lib/kamal/cli/proxy.rb | 20 ++++++------ lib/kamal/commands/app/proxy.rb | 4 +-- lib/kamal/commands/proxy.rb | 13 ++++---- lib/kamal/configuration.rb | 42 ------------------------- lib/kamal/configuration/docs/proxy.yml | 1 - lib/kamal/configuration/proxy.rb | 31 ++++++++++++++++++- test/cli/proxy_test.rb | 43 ++++++++++++++++---------- test/commands/proxy_test.rb | 6 ++-- test/integration/main_test.rb | 2 +- 9 files changed, 78 insertions(+), 84 deletions(-) diff --git a/lib/kamal/cli/proxy.rb b/lib/kamal/cli/proxy.rb index d0e9ba2bf..534e46ddd 100644 --- a/lib/kamal/cli/proxy.rb +++ b/lib/kamal/cli/proxy.rb @@ -13,8 +13,8 @@ def boot version = capture_with_info(*KAMAL.proxy.version).strip.presence - if version && Kamal::Utils.older_version?(version, Kamal::Configuration::PROXY_MINIMUM_VERSION) - raise "kamal-proxy version #{version} is too old, run `kamal proxy reboot` in order to update to at least #{Kamal::Configuration::PROXY_MINIMUM_VERSION}" + if version && Kamal::Utils.older_version?(version, Kamal::Configuration::Proxy::MINIMUM_VERSION) + raise "kamal-proxy version #{version} is too old, run `kamal proxy reboot` in order to update to at least #{Kamal::Configuration::Proxy::MINIMUM_VERSION}" end execute *KAMAL.proxy.start_or_run end @@ -22,23 +22,25 @@ def boot end desc "boot_config ", "Manage kamal-proxy boot configuration" + option :image, type: :string, default: Kamal::Configuration::Proxy::DEFAULT_IMAGE, desc: "Name of the image" option :publish, type: :boolean, default: true, desc: "Publish the proxy ports on the host" - 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 :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 :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 when "set" boot_options = [ - *(KAMAL.config.proxy_publish_args(options[:http_port], options[:https_port]) if options[:publish]), - *(KAMAL.config.proxy_logging_args(options[:log_max_size])), - *options[:docker_options].map { |option| "--#{option}" } + *(KAMAL.config.proxy.publish_args(options[:http_port], options[:https_port]) if options[:publish]), + *(KAMAL.config.proxy.logging_args(options[:log_max_size])), + *options[:docker_options].map { |option| "--#{option}" }, + options[:image] ] on(KAMAL.proxy_hosts) do |host| execute(*KAMAL.proxy.ensure_proxy_directory) - upload! StringIO.new(boot_options.join(" ")), KAMAL.config.proxy_options_file + upload! StringIO.new(boot_options.join(" ")), KAMAL.config.proxy.options_file end when "get" on(KAMAL.proxy_hosts) do |host| diff --git a/lib/kamal/commands/app/proxy.rb b/lib/kamal/commands/app/proxy.rb index 777a4aaf5..2caead41a 100644 --- a/lib/kamal/commands/app/proxy.rb +++ b/lib/kamal/commands/app/proxy.rb @@ -1,6 +1,4 @@ module Kamal::Commands::App::Proxy - delegate :proxy_container_name, to: :config - def deploy(target:) proxy_exec :deploy, role.container_prefix, *role.proxy.deploy_command_args(target: target) end @@ -11,6 +9,6 @@ def remove private def proxy_exec(*command) - docker :exec, proxy_container_name, "kamal-proxy", *command + docker :exec, config.proxy.container_name, "kamal-proxy", *command end end diff --git a/lib/kamal/commands/proxy.rb b/lib/kamal/commands/proxy.rb index acff3dbd6..419cba695 100644 --- a/lib/kamal/commands/proxy.rb +++ b/lib/kamal/commands/proxy.rb @@ -8,8 +8,7 @@ def run "--detach", "--restart", "unless-stopped", "--volume", "kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy", - "\$\(#{get_boot_options.join(" ")}\)", - config.proxy_image + "\$\(#{get_boot_options.join(" ")}\)" end def start @@ -65,23 +64,23 @@ def cleanup_traefik end def ensure_proxy_directory - make_directory config.proxy_directory + make_directory config.proxy.directory end def remove_proxy_directory - remove_directory config.proxy_directory + remove_directory config.proxy.directory end def get_boot_options - combine [ :cat, config.proxy_options_file ], [ :echo, "\"#{config.proxy_options_default.join(" ")}\"" ], by: "||" + combine [ :cat, config.proxy.options_file ], [ :echo, "\"#{config.proxy.options_default.join(" ")}\"" ], by: "||" end def reset_boot_options - remove_file config.proxy_options_file + remove_file config.proxy.options_file end private def container_name - config.proxy_container_name + config.proxy.container_name end end diff --git a/lib/kamal/configuration.rb b/lib/kamal/configuration.rb index 92d850e2c..8bd8ac8e9 100644 --- a/lib/kamal/configuration.rb +++ b/lib/kamal/configuration.rb @@ -14,11 +14,6 @@ class Kamal::Configuration include Validation - PROXY_MINIMUM_VERSION = "v0.8.4" - PROXY_HTTP_PORT = 80 - PROXY_HTTPS_PORT = 443 - PROXY_LOG_MAX_SIZE = "10m" - class << self def create_from(config_file:, destination: nil, version: nil) ENV["KAMAL_DESTINATION"] = destination @@ -82,7 +77,6 @@ def initialize(raw_config, destination: nil, version: nil, validate: true) ensure_unique_hosts_for_ssl_roles end - def version=(version) @declared_version = version end @@ -106,7 +100,6 @@ def minimum_version raw_config.minimum_version end - def roles servers.roles end @@ -119,7 +112,6 @@ def accessory(name) accessories.detect { |a| a.name == name.to_s } end - def all_hosts (roles + accessories).flat_map(&:hosts).uniq end @@ -180,7 +172,6 @@ def retain_containers raw_config.retain_containers || 5 end - def volume_args if raw_config.volumes.present? argumentize "--volume", raw_config.volumes @@ -193,7 +184,6 @@ def logging_args logging.args end - def readiness_delay raw_config.readiness_delay || 7 end @@ -206,7 +196,6 @@ def drain_timeout raw_config.drain_timeout || 30 end - def run_directory ".kamal" end @@ -227,7 +216,6 @@ def assets_directory File.join app_directory, "assets" end - def hooks_path raw_config.hooks_path || ".kamal/hooks" end @@ -236,7 +224,6 @@ def asset_path raw_config.asset_path end - def env_tags @env_tags ||= if (tags = raw_config.env["tags"]) tags.collect { |name, config| Env::Tag.new(name, config: config, secrets: secrets) } @@ -249,35 +236,6 @@ def env_tag(name) env_tags.detect { |t| t.name == name.to_s } end - def proxy_publish_args(http_port, https_port) - argumentize "--publish", [ "#{http_port}:#{PROXY_HTTP_PORT}", "#{https_port}:#{PROXY_HTTPS_PORT}" ] - end - - def proxy_logging_args(max_size) - argumentize "--log-opt", "max-size=#{max_size}" if max_size.present? - end - - def proxy_options_default - [ *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}" - end - - def proxy_container_name - "kamal-proxy" - end - - def proxy_directory - File.join run_directory, "proxy" - end - - def proxy_options_file - File.join proxy_directory, "options" - end - - def to_h { roles: role_names, diff --git a/lib/kamal/configuration/docs/proxy.yml b/lib/kamal/configuration/docs/proxy.yml index 76ec3e41d..d5f6176d6 100644 --- a/lib/kamal/configuration/docs/proxy.yml +++ b/lib/kamal/configuration/docs/proxy.yml @@ -16,7 +16,6 @@ # It is disabled by default on all other roles but can be enabled by setting # `proxy: true` or providing a proxy configuration. proxy: - # Hosts # # The hosts that will be used to serve the app. The proxy will only route requests diff --git a/lib/kamal/configuration/proxy.rb b/lib/kamal/configuration/proxy.rb index 6232c3e03..12561871c 100644 --- a/lib/kamal/configuration/proxy.rb +++ b/lib/kamal/configuration/proxy.rb @@ -1,8 +1,13 @@ class Kamal::Configuration::Proxy include Kamal::Configuration::Validation + HTTP_PORT = 80 + HTTPS_PORT = 443 + LOG_MAX_SIZE = "10m" + MINIMUM_VERSION = "v0.8.4" DEFAULT_LOG_REQUEST_HEADERS = [ "Cache-Control", "Last-Modified", "User-Agent" ] - CONTAINER_NAME = "kamal-proxy" + DEFAULT_CONTAINER_NAME = "kamal-proxy" + DEFAULT_IMAGE = "basecamp/kamal-proxy:#{MINIMUM_VERSION}" delegate :argumentize, :optionize, to: Kamal::Utils @@ -14,6 +19,10 @@ def initialize(config:, proxy_config:, context: "proxy") validate! @proxy_config, with: Kamal::Configuration::Validator::Proxy, context: context end + def container_name + DEFAULT_CONTAINER_NAME + end + def app_port proxy_config.fetch("app_port", 80) end @@ -47,6 +56,26 @@ def deploy_options }.compact end + def directory + File.join config.run_directory, "proxy" + end + + def options_file + File.join directory, "options" + end + + def publish_args(http_port, https_port) + argumentize "--publish", [ "#{http_port}:#{HTTP_PORT}", "#{https_port}:#{HTTPS_PORT}" ] + end + + def logging_args(max_size) + argumentize "--log-opt", "max-size=#{max_size}" if max_size.present? + end + + def options_default + [ *publish_args(HTTP_PORT, HTTPS_PORT), *logging_args(LOG_MAX_SIZE), DEFAULT_IMAGE ] + end + def deploy_command_args(target:) optionize ({ target: "#{target}:#{app_port}" }).merge(deploy_options), with: "=" end diff --git a/test/cli/proxy_test.rb b/test/cli/proxy_test.rb index 0a890451b..e17671584 100644 --- a/test/cli/proxy_test.rb +++ b/test/cli/proxy_test.rb @@ -4,7 +4,7 @@ class CliProxyTest < CliTestCase test "boot" do run_command("boot").tap do |output| assert_match "docker login", output - assert_match "docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m\") #{KAMAL.config.proxy_image}", output + assert_match "docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\")", output end end @@ -18,11 +18,11 @@ class CliProxyTest < CliTestCase exception = assert_raises do run_command("boot").tap do |output| assert_match "docker login", output - assert_match "docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m\") #{KAMAL.config.proxy_image}", output + assert_match "docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\")", output end end - assert_includes exception.message, "kamal-proxy version v0.0.1 is too old, run `kamal proxy reboot` in order to update to at least #{Kamal::Configuration::PROXY_MINIMUM_VERSION}" + assert_includes exception.message, "kamal-proxy version v0.0.1 is too old, run `kamal proxy reboot` in order to update to at least #{Kamal::Configuration::Proxy::MINIMUM_VERSION}" ensure Thread.report_on_exception = false end @@ -31,12 +31,12 @@ class CliProxyTest < CliTestCase Thread.report_on_exception = false SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) .with(:docker, :inspect, "kamal-proxy", "--format '{{.Config.Image}}'", "|", :cut, "-d:", "-f2") - .returns(Kamal::Configuration::PROXY_MINIMUM_VERSION) + .returns(Kamal::Configuration::Proxy::MINIMUM_VERSION) .at_least_once run_command("boot").tap do |output| assert_match "docker login", output - assert_match "docker container start kamal-proxy || docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m\") #{KAMAL.config.proxy_image}", output + assert_match "docker container start kamal-proxy || docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\")", output end ensure Thread.report_on_exception = false @@ -57,13 +57,13 @@ class CliProxyTest < CliTestCase assert_match "docker container stop kamal-proxy on 1.1.1.1", output assert_match "Running docker container stop traefik ; docker container prune --force --filter label=org.opencontainers.image.title=Traefik && docker image prune --all --force --filter label=org.opencontainers.image.title=Traefik on 1.1.1.1", output assert_match "docker container prune --force --filter label=org.opencontainers.image.title=kamal-proxy on 1.1.1.1", output - assert_match "docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m\") #{KAMAL.config.proxy_image} on 1.1.1.1", output + assert_match "docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\") on 1.1.1.1", output assert_match "docker exec kamal-proxy kamal-proxy deploy app-web --target=\"abcdefabcdef:80\" --deploy-timeout=\"6s\" --drain-timeout=\"30s\" --buffer-requests --buffer-responses --log-request-header=\"Cache-Control\" --log-request-header=\"Last-Modified\" --log-request-header=\"User-Agent\" on 1.1.1.1", output assert_match "docker container stop kamal-proxy on 1.1.1.2", output assert_match "Running docker container stop traefik ; docker container prune --force --filter label=org.opencontainers.image.title=Traefik && docker image prune --all --force --filter label=org.opencontainers.image.title=Traefik on 1.1.1.2", output assert_match "docker container prune --force --filter label=org.opencontainers.image.title=kamal-proxy on 1.1.1.2", output - assert_match "docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m\") #{KAMAL.config.proxy_image} on 1.1.1.2", output + assert_match "docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\") on 1.1.1.2", output assert_match "docker exec kamal-proxy kamal-proxy deploy app-web --target=\"abcdefabcdef:80\" --deploy-timeout=\"6s\" --drain-timeout=\"30s\" --buffer-requests --buffer-responses --log-request-header=\"Cache-Control\" --log-request-header=\"Last-Modified\" --log-request-header=\"User-Agent\" on 1.1.1.2", output end end @@ -182,7 +182,7 @@ class CliProxyTest < CliTestCase SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) .with(:docker, :inspect, "kamal-proxy", "--format '{{.Config.Image}}'", "|", :cut, "-d:", "-f2") - .returns(Kamal::Configuration::PROXY_MINIMUM_VERSION) + .returns(Kamal::Configuration::Proxy::MINIMUM_VERSION) SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) .with(:docker, :container, :ls, "--all", "--filter", "name=^app-workers-latest$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'") @@ -198,7 +198,7 @@ class CliProxyTest < CliTestCase assert_match "/usr/bin/env mkdir -p .kamal", output assert_match "docker network create kamal", output assert_match "docker login -u [REDACTED] -p [REDACTED]", output - assert_match "docker container start kamal-proxy || docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m\") basecamp/kamal-proxy:#{Kamal::Configuration::PROXY_MINIMUM_VERSION}", output + assert_match "docker container start kamal-proxy || docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\")", output assert_match "/usr/bin/env mkdir -p .kamal", output assert_match %r{docker rename app-web-latest app-web-latest_replaced_.*}, output assert_match "/usr/bin/env mkdir -p .kamal/apps/app/env/roles", output @@ -221,7 +221,7 @@ class CliProxyTest < CliTestCase SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) .with(:docker, :inspect, "kamal-proxy", "--format '{{.Config.Image}}'", "|", :cut, "-d:", "-f2") - .returns(Kamal::Configuration::PROXY_MINIMUM_VERSION) + .returns(Kamal::Configuration::Proxy::MINIMUM_VERSION) SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) .with(:docker, :container, :ls, "--all", "--filter", "name=^app-workers-latest$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'") @@ -240,7 +240,7 @@ class CliProxyTest < CliTestCase run_command("boot_config", "set").tap do |output| %w[ 1.1.1.1 1.1.1.2 ].each do |host| assert_match "Running /usr/bin/env mkdir -p .kamal/proxy on #{host}", output - assert_match "Uploading \"--publish 80:80 --publish 443:443 --log-opt max-size=10m\" to .kamal/proxy/options on #{host}", output + assert_match "Uploading \"--publish 80:80 --publish 443:443 --log-opt max-size=10m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\" to .kamal/proxy/options on #{host}", output end end end @@ -249,7 +249,7 @@ class CliProxyTest < CliTestCase run_command("boot_config", "set", "--publish", "false").tap do |output| %w[ 1.1.1.1 1.1.1.2 ].each do |host| assert_match "Running /usr/bin/env mkdir -p .kamal/proxy on #{host}", output - assert_match "Uploading \"--log-opt max-size=10m\" to .kamal/proxy/options on #{host}", output + assert_match "Uploading \"--log-opt max-size=10m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\" to .kamal/proxy/options on #{host}", output end end end @@ -258,7 +258,7 @@ class CliProxyTest < CliTestCase run_command("boot_config", "set", "--log-max-size", "100m").tap do |output| %w[ 1.1.1.1 1.1.1.2 ].each do |host| assert_match "Running /usr/bin/env mkdir -p .kamal/proxy on #{host}", output - assert_match "Uploading \"--publish 80:80 --publish 443:443 --log-opt max-size=100m\" to .kamal/proxy/options on #{host}", output + assert_match "Uploading \"--publish 80:80 --publish 443:443 --log-opt max-size=100m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\" to .kamal/proxy/options on #{host}", output end end end @@ -267,7 +267,7 @@ class CliProxyTest < CliTestCase run_command("boot_config", "set", "--log-max-size=").tap do |output| %w[ 1.1.1.1 1.1.1.2 ].each do |host| assert_match "Running /usr/bin/env mkdir -p .kamal/proxy on #{host}", output - assert_match "Uploading \"--publish 80:80 --publish 443:443\" to .kamal/proxy/options on #{host}", output + assert_match "Uploading \"--publish 80:80 --publish 443:443 #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\" to .kamal/proxy/options on #{host}", output end end end @@ -276,7 +276,7 @@ class CliProxyTest < CliTestCase run_command("boot_config", "set", "--http-port", "8080", "--https-port", "8443").tap do |output| %w[ 1.1.1.1 1.1.1.2 ].each do |host| assert_match "Running /usr/bin/env mkdir -p .kamal/proxy on #{host}", output - assert_match "Uploading \"--publish 8080:80 --publish 8443:443 --log-opt max-size=10m\" to .kamal/proxy/options on #{host}", output + assert_match "Uploading \"--publish 8080:80 --publish 8443:443 --log-opt max-size=10m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\" to .kamal/proxy/options on #{host}", output end end end @@ -285,14 +285,23 @@ class CliProxyTest < CliTestCase run_command("boot_config", "set", "--docker_options", "label=foo=bar", "add_host=thishost:thathost").tap do |output| %w[ 1.1.1.1 1.1.1.2 ].each do |host| assert_match "Running /usr/bin/env mkdir -p .kamal/proxy on #{host}", output - assert_match "Uploading \"--publish 80:80 --publish 443:443 --log-opt max-size=10m --label=foo=bar --add_host=thishost:thathost\" to .kamal/proxy/options on #{host}", output + assert_match "Uploading \"--publish 80:80 --publish 443:443 --log-opt max-size=10m --label=foo=bar --add_host=thishost:thathost #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\" to .kamal/proxy/options on #{host}", output + end + end + end + + test "boot_config set image" do + run_command("boot_config", "set", "--image", "registry.example.com/namespace/kamal-proxy").tap do |output| + %w[ 1.1.1.1 1.1.1.2 ].each do |host| + assert_match "Running /usr/bin/env mkdir -p .kamal/proxy on #{host}", output + assert_match "Uploading \"--publish 80:80 --publish 443:443 --log-opt max-size=10m registry.example.com/namespace/kamal-proxy\" to .kamal/proxy/options on #{host}", output end end end test "boot_config get" do SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) - .with(:cat, ".kamal/proxy/options", "||", :echo, "\"--publish 80:80 --publish 443:443 --log-opt max-size=10m\"") + .with(:cat, ".kamal/proxy/options", "||", :echo, "\"--publish 80:80 --publish 443:443 --log-opt max-size=10m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\"") .returns("--publish 80:80 --publish 8443:443 --label=foo=bar") .twice diff --git a/test/commands/proxy_test.rb b/test/commands/proxy_test.rb index b7cc9f3dc..18aacb80f 100644 --- a/test/commands/proxy_test.rb +++ b/test/commands/proxy_test.rb @@ -15,7 +15,7 @@ class CommandsProxyTest < ActiveSupport::TestCase test "run" do assert_equal \ - "docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m\") basecamp/kamal-proxy:#{Kamal::Configuration::PROXY_MINIMUM_VERSION}", + "docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\")", new_command.run.join(" ") end @@ -23,7 +23,7 @@ class CommandsProxyTest < ActiveSupport::TestCase @config.delete(:proxy) assert_equal \ - "docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m\") basecamp/kamal-proxy:#{Kamal::Configuration::PROXY_MINIMUM_VERSION}", + "docker run --name kamal-proxy --network kamal --detach --restart unless-stopped --volume kamal-proxy-config:/home/kamal-proxy/.config/kamal-proxy $(cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\")", new_command.run.join(" ") end @@ -113,7 +113,7 @@ class CommandsProxyTest < ActiveSupport::TestCase test "get_boot_options" do assert_equal \ - "cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m\"", + "cat .kamal/proxy/options || echo \"--publish 80:80 --publish 443:443 --log-opt max-size=10m #{Kamal::Configuration::Proxy::DEFAULT_IMAGE}\"", new_command.get_boot_options.join(" ") end diff --git a/test/integration/main_test.rb b/test/integration/main_test.rb index ce32e6404..4a8de2be3 100644 --- a/test/integration/main_test.rb +++ b/test/integration/main_test.rb @@ -28,7 +28,7 @@ class MainTest < IntegrationTest assert_match /Proxy Host: vm2/, details assert_match /App Host: vm1/, details assert_match /App Host: vm2/, details - assert_match /basecamp\/kamal-proxy:#{Kamal::Configuration::PROXY_MINIMUM_VERSION}/, details + assert_match /basecamp\/kamal-proxy:#{Kamal::Configuration::Proxy::MINIMUM_VERSION}/, details assert_match /registry:4443\/app:#{first_version}/, details audit = kamal :audit, capture: true