Class: MKIt::DockerExecCommand

Inherits:
ShellClient show all
Defined in:
lib/mkit/pods/docker_exec_command.rb

Instance Method Summary collapse

Methods inherited from ShellClient

#unregister

Constructor Details

#initialize(pod, ws, options: {}) ⇒ DockerExecCommand

Returns a new instance of DockerExecCommand.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/mkit/pods/docker_exec_command.rb', line 6

def initialize(pod, ws, options: {})
  puts "DockerExecCommand: #{options}"
  @pod = pod
  @ws = ws
  command = "docker exec"
  command += " -it" unless options[:detached] == 'true'
  command += " -d" if options[:detached] == 'true'
  command += " #{@pod.name}"
  command += " #{options[:varargs].join(' ')}" if options[:varargs]
  super(command: command)
end

Instance Method Details

#closeObject



33
34
35
# File 'lib/mkit/pods/docker_exec_command.rb', line 33

def close
  @ws.close_websocket unless @ws.nil?
end

#registerObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mkit/pods/docker_exec_command.rb', line 18

def register
  super do |stdout, stdin, pid|
      @stdout_thread = Thread.new do
        stdout.each_char { |line| @ws.send(line) }
      end

      @stdin_thread = Thread.new do
        @ws.onmessage do |msg|
          stdin.putc msg
        end
      end
      @stdout_thread.join
  end
end