diff --git a/lib/kamal/cli/accessory.rb b/lib/kamal/cli/accessory.rb index 14114a25..2d71e366 100644 --- a/lib/kamal/cli/accessory.rb +++ b/lib/kamal/cli/accessory.rb @@ -16,6 +16,7 @@ def boot(name, prepare: true) execute *accessory.ensure_env_directory upload! accessory.secrets_io, accessory.secrets_path, mode: "0600" execute *accessory.run + execute *accessory.deploy if accessory.running_proxy? end end end @@ -73,6 +74,7 @@ def start(name) on(hosts) do execute *KAMAL.auditor.record("Started #{name} accessory"), verbosity: :debug execute *accessory.start + execute *accessory.deploy if accessory.running_proxy? end end end @@ -85,6 +87,7 @@ def stop(name) on(hosts) do execute *KAMAL.auditor.record("Stopped #{name} accessory"), verbosity: :debug execute *accessory.stop, raise_on_non_zero_exit: false + # execute *accessory.remove if accessory.running_proxy? end end end diff --git a/lib/kamal/commands/accessory.rb b/lib/kamal/commands/accessory.rb index 0c1b9009..41c8b174 100644 --- a/lib/kamal/commands/accessory.rb +++ b/lib/kamal/commands/accessory.rb @@ -2,8 +2,10 @@ class Kamal::Commands::Accessory < Kamal::Commands::Base attr_reader :accessory_config delegate :service_name, :image, :hosts, :port, :files, :directories, :cmd, :publish_args, :env_args, :volume_args, :label_args, :option_args, - :secrets_io, :secrets_path, :env_directory, + :secrets_io, :secrets_path, :env_directory, :running_proxy?, to: :accessory_config + delegate :proxy_container_name, to: :config + def initialize(config, name:) super(config) @@ -38,6 +40,16 @@ def info docker :ps, *service_filter end + def deploy + target = container_id_for(container_name: service_name, only_running: true) + proxy_exec :deploy, service_name, *accessory_config.proxy.deploy_command_args(target: target) if target + end + + def remove + target = container_id_for(container_name: service_name, only_running: true) + proxy_exec :remove, service_name, *accessory_config.proxy.remove_command_args(target: target) if target + end + def logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil) pipe \ @@ -110,4 +122,8 @@ def ensure_env_directory def service_filter [ "--filter", "label=service=#{service_name}" ] end + + def proxy_exec(*command) + docker :exec, proxy_container_name, "kamal-proxy", *command + end end diff --git a/lib/kamal/configuration/accessory.rb b/lib/kamal/configuration/accessory.rb index 804a1502..7f78dbd6 100644 --- a/lib/kamal/configuration/accessory.rb +++ b/lib/kamal/configuration/accessory.rb @@ -3,7 +3,7 @@ class Kamal::Configuration::Accessory delegate :argumentize, :optionize, to: Kamal::Utils - attr_reader :name, :accessory_config, :env + attr_reader :name, :accessory_config, :env, :proxy def initialize(name, config:) @name, @config, @accessory_config = name.inquiry, config, config.raw_config["accessories"][name] @@ -18,6 +18,8 @@ def initialize(name, config:) config: accessory_config.fetch("env", {}), secrets: config.secrets, context: "accessories/#{name}/env" + + # initialize_proxy if running_proxy? end def service_name @@ -100,6 +102,17 @@ def cmd accessory_config["cmd"] end + def running_proxy? + @accessory_config["proxy"].present? + end + + def initialize_proxy + @proxy = Kamal::Configuration::Proxy.new \ + config: config, + proxy_config: accessory_config["proxy"], + context: "accessories/#{name}/proxy" + end + private attr_accessor :config