Class: Train::Transports::Docker::Connection

Inherits:
BaseConnection
  • Object
show all
Defined in:
lib/train/transports/docker.rb

Defined Under Namespace

Classes: OS

Instance Method Summary collapse

Constructor Details

#initialize(conf) ⇒ Connection

Returns a new instance of Connection.



58
59
60
61
62
63
64
65
66
# File 'lib/train/transports/docker.rb', line 58

def initialize(conf)
  super(conf)
  @id = options[:host]
  @container = ::Docker::Container.get(@id) ||
               fail("Can't find Docker container #{@id}")
  @cmd_wrapper = nil
  @cmd_wrapper = CommandWrapper.load(self, @options)
  self
end

Instance Method Details

#closeObject



68
69
70
# File 'lib/train/transports/docker.rb', line 68

def close
  # nothing to do at the moment
end

#file(path) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/train/transports/docker.rb', line 76

def file(path)
  @files[path] ||=\
    if os.aix?
      Train::File::Remote::Aix.new(self, path)
    elsif os.solaris?
      Train::File::Remote::Unix.new(self, path)
    else
      Train::File::Remote::Linux.new(self, path)
    end
end

#osObject



72
73
74
# File 'lib/train/transports/docker.rb', line 72

def os
  @os ||= OS.new(self)
end

#run_command(cmd) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/train/transports/docker.rb', line 87

def run_command(cmd)
  cmd = @cmd_wrapper.run(cmd) unless @cmd_wrapper.nil?
  stdout, stderr, exit_status = @container.exec(
    [
      '/bin/sh', '-c', cmd
    ])
  CommandResult.new(stdout.join, stderr.join, exit_status)
rescue ::Docker::Error::DockerError => _
  raise
rescue => _
  # @TODO: differentiate any other error
  raise
end

#uriObject



101
102
103
104
105
106
107
# File 'lib/train/transports/docker.rb', line 101

def uri
  if @container.nil?
    "docker://#{@id}"
  else
    "docker://#{@container.id}"
  end
end