Module: Henk::Commands

Included in:
Instance
Defined in:
lib/henk/commands.rb

Instance Method Summary collapse

Instance Method Details

#commit(container) ⇒ Object



32
33
34
# File 'lib/henk/commands.rb', line 32

def commit(container)
  execute_for_word('docker', 'commit', container)
end

#kill(*containers) ⇒ Object



47
48
49
# File 'lib/henk/commands.rb', line 47

def kill(*containers)
  execute('docker', 'kill', *containers)
end

#logs(container) ⇒ Object



36
37
38
# File 'lib/henk/commands.rb', line 36

def logs(container)
  execute('docker', 'logs', container)
end

#pull(name) ⇒ Object



3
4
5
# File 'lib/henk/commands.rb', line 3

def pull(name)
  execute('docker', 'pull', name)
end

#resolve_image_name(name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/henk/commands.rb', line 7

def resolve_image_name(name)
  return resolve_untagged_image_name(name) unless name.include?(':')

  # this is a kludge.
  lines = execute_for_lines('docker', 'images')
  lines = lines.map { |line| line.split(/ +/) }

  raise "'docker images' output not as expected" unless
    lines.first[0..1] == %w(REPOSITORY TAG)

  line = lines.find { |l| l[0..1].join(':') == name}
  line && line[2]
end

#resolve_untagged_image_name(name) ⇒ Object



21
22
23
24
25
# File 'lib/henk/commands.rb', line 21

def resolve_untagged_image_name(name)
  result = execute_for_word('docker', 'images', '-q', name)
  raise "image name #{name} is ambiguous" if result.include?("\n")
  result unless result.empty?
end

#tag(image, repository, tag = nil, options = {}) ⇒ Object



40
41
42
43
44
45
# File 'lib/henk/commands.rb', line 40

def tag(image, repository, tag = nil, options = {})
  command_options = []
  command_options << '-f' if options[:force]

  execute 'docker', 'tag', *command_options, image, repository, *tag
end

#wait(container) ⇒ Object



27
28
29
30
# File 'lib/henk/commands.rb', line 27

def wait(container)
  result = execute_for_word('docker', 'wait', container)
  result &&= Integer(result)
end