Module: CIDE::Docker

Included in:
Builder, CLI, Runner
Defined in:
lib/cide/docker.rb

Overview

Simple docker client helper

Defined Under Namespace

Classes: Error, VersionError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.id(str) ⇒ Object

Generates a valid id for docker from any string



7
8
9
# File 'lib/cide/docker.rb', line 7

def self.id(str)
  "#{str}".downcase.gsub(/[^a-z0-9\-_.]/, '_')
end

Instance Method Details

#docker(*args, verbose: false, capture: false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cide/docker.rb', line 22

def docker(*args, verbose: false, capture: false)
  cmd = (['docker'] + args).map(&:to_s)
  p cmd if verbose

  if capture
    r, w = IO.pipe
    pid = Process.spawn(*cmd, out: w)
    w.close
    return r.read
  else
    pid = Process.spawn(*cmd)

    return 0
  end
ensure
  Process.wait(pid)
  exitstatus = $?.exitstatus
  fail Error, exitstatus if exitstatus > 0
end