Skip to content

Commit

Permalink
Extracted proxy commands to a module
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-alexandrov committed Nov 21, 2024
1 parent 4d8241e commit 006fa0d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
14 changes: 6 additions & 8 deletions lib/kamal/commands/accessory.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Kamal::Commands::Accessory < Kamal::Commands::Base
include Kamal::Commands::Proxy::Exec

attr_reader :accessory_config
delegate :service_name, :image, :hosts, :port, :files, :directories, :cmd,
:network_args, :publish_args, :env_args, :volume_args, :label_args, :option_args,
Expand Down Expand Up @@ -40,14 +42,6 @@ def info
docker :ps, *service_filter
end

def deploy(target:)
proxy_exec :deploy, service_name, *proxy.deploy_command_args(target: target)
end

def remove
proxy_exec :remove, service_name
end


def logs(timestamps: true, since: nil, lines: nil, grep: nil, grep_options: nil)
pipe \
Expand Down Expand Up @@ -117,6 +111,10 @@ def ensure_env_directory
end

private
def proxy_deploy_command_args(target:)
proxy.deploy_command_args(target: target)
end

def service_filter
[ "--filter", "label=service=#{service_name}" ]
end
Expand Down
10 changes: 9 additions & 1 deletion lib/kamal/commands/app.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Kamal::Commands::App < Kamal::Commands::Base
include Assets, Containers, Execution, Images, Logging, Proxy
include Assets, Containers, Execution, Images, Logging, Kamal::Commands::Proxy::Exec

ACTIVE_DOCKER_STATUSES = [ :running, :restarting ]

Expand Down Expand Up @@ -76,6 +76,14 @@ def ensure_env_directory
end

private
def service_name
role.container_prefix
end

def proxy_deploy_command_args(target:)
role.proxy.deploy_command_args(target: target)
end

def latest_image_id
docker :image, :ls, *argumentize("--filter", "reference=#{config.latest_image}"), "--format", "'{{.ID}}'"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Kamal::Commands::App::Proxy
module Kamal::Commands::Proxy::Exec
delegate :proxy_container_name, to: :config

def deploy(target:)
proxy_exec :deploy, role.container_prefix, *role.proxy.deploy_command_args(target: target)
proxy_exec :deploy, service_name, *proxy_deploy_command_args(target: target)
end

def remove
proxy_exec :remove, role.container_prefix
proxy_exec :remove, service_name
end

private
Expand Down

0 comments on commit 006fa0d

Please sign in to comment.