Class: Mrsk::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mrsk/commands/base.rb

Constant Summary collapse

DOCKER_HEALTH_STATUS_FORMAT =
"'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'"
DOCKER_HEALTH_LOG_FORMAT =
"'{{json .State.Health}}'"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.



10
11
12
# File 'lib/mrsk/commands/base.rb', line 10

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



8
9
10
# File 'lib/mrsk/commands/base.rb', line 8

def config
  @config
end

Instance Method Details

#container_id_for(container_name:, only_running: false) ⇒ Object



25
26
27
# File 'lib/mrsk/commands/base.rb', line 25

def container_id_for(container_name:, only_running: false)
  docker :container, :ls, *("--all" unless only_running), "--filter", "name=^#{container_name}$", "--quiet"
end

#run_over_ssh(*command, host:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/mrsk/commands/base.rb', line 14

def run_over_ssh(*command, host:)
  "ssh".tap do |cmd|
    if config.ssh_proxy && config.ssh_proxy.is_a?(Net::SSH::Proxy::Jump)
      cmd << " -J #{config.ssh_proxy.jump_proxies}"
    elsif config.ssh_proxy && config.ssh_proxy.is_a?(Net::SSH::Proxy::Command)
      cmd << " -o ProxyCommand='#{config.ssh_proxy.command_line_template}'"
    end
    cmd << " -t #{config.ssh_user}@#{host} '#{command.join(" ")}'"
  end
end