Module: ComposeUtils

Defined in:
lib/docker-compose/utils/compose_utils.rb

Class Method Summary collapse

Class Method Details

.format_command(command) ⇒ Object

Transform docker command from string to an array of commands



28
29
30
# File 'lib/docker-compose/utils/compose_utils.rb', line 28

def self.format_command(command)
  command.nil? ? nil : command.split(' ')
end

.format_image(image) ⇒ Object

Format a given docker image in a complete structure (base image + tag)



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/docker-compose/utils/compose_utils.rb', line 5

def self.format_image(image)
  base_image = nil
  tag = nil

  if image.nil?
    return nil
  end

  if image.index(':').nil?
    base_image = image
    tag = 'latest'
  else
    image_split = image.split(':')
    base_image = image_split[0]
    tag = image_split[1]
  end

  "#{base_image}:#{tag}"
end

.format_port(port_entry) ⇒ Object

Read a port specification in string format and create a compose port structure



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/docker-compose/utils/compose_utils.rb', line 36

def self.format_port(port_entry)
  compose_port = nil
  container_port = nil
  host_port = nil
  host_ip = nil

  port_parts = port_entry.split(':')

  case port_parts.length
    # [container port]
    when 1
      compose_port = ComposePort.new(port_parts[0])

    # [host port]:[container port]
    when 2
      compose_port = ComposePort.new(port_parts[1], port_parts[0])

    # [host ip]:[host port]:[container port]
    when 3
      compose_port = ComposePort.new(port_parts[2], port_parts[1], port_parts[0])
  end

  compose_port
end