Class: Longshoreman

Inherits:
Object
  • Object
show all
Defined in:
lib/longshoreman.rb

Defined Under Namespace

Classes: Container, Image

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image = nil, name = nil, extra_args = {}) ⇒ Longshoreman

Returns a new instance of Longshoreman.



5
6
7
8
9
10
11
12
# File 'lib/longshoreman.rb', line 5

def initialize(image = nil, name = nil, extra_args = {})
  Docker.options = { :write_timeout => 300, :read_timeout => 300 }
  Docker.validate_version!

  @ip = get_host_ip
  @container = Longshoreman::Container.new(image, name, extra_args)
  @image = Longshoreman::Image.new
end

Instance Attribute Details

#containerObject

Returns the value of attribute container.



38
39
40
# File 'lib/longshoreman.rb', line 38

def container
  @container
end

#imageObject

Returns the value of attribute image.



39
40
41
# File 'lib/longshoreman.rb', line 39

def image
  @image
end

#ipObject (readonly)

Returns the value of attribute ip.



37
38
39
# File 'lib/longshoreman.rb', line 37

def ip
  @ip
end

Instance Method Details

#cleanupObject



32
33
34
35
# File 'lib/longshoreman.rb', line 32

def cleanup
  @container.cleanup
  @image.cleanup
end

#get_host_ipObject

Figure out which IP address the Docker host is at



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/longshoreman.rb', line 15

def get_host_ip
  # Let the crazy one-liner definition begin:
  # Docker.url.split(':')[1][2..-1]
  # Docker.url = tcp://192.168.123.205:2375
  #   split(':') = ["tcp", "//192.168.123.205", "2375"]
  #   [1] = "//192.168.123.205"
  #   [2..-1] = "192.168.123.205"
  # This last bit prunes the leading //
  url = Docker.url
  case url.split(':')[0]
  when 'unix'
    "127.0.0.1"
  when 'tcp'
    url.split(':')[1][2..-1]
  end
end