File: remote_ssh_helpers.rb

package info (click to toggle)
capistrano 3.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 820 kB
  • sloc: ruby: 5,351; makefile: 5
file content (33 lines) | stat: -rw-r--r-- 749 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require "open3"
require "socket"
require_relative "docker_gateway"

module RemoteSSHHelpers
  extend self

  class RemoteSSHCommandError < RuntimeError; end

  def start_ssh_server
    docker_gateway.start
  end

  def wait_for_ssh_server(retries=3)
    Socket.tcp("localhost", 2022, connect_timeout: 1).close
  rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT
    retries -= 1
    sleep(2) && retry if retries.positive?
    raise
  end

  def run_remote_ssh_command(command)
    stdout, stderr, status = docker_gateway.run_shell_command(command)
    return [stdout, stderr] if status.success?
    raise RemoteSSHCommandError, status
  end

  def docker_gateway
    @docker_gateway ||= DockerGateway.new(method(:log))
  end
end

World(RemoteSSHHelpers)