Class: LabSystem::DockerShell

Inherits:
DevSystem::Shell show all
Defined in:
lib/lab_system/shells/docker_shell.rb

Direct Known Subclasses

KrokiDockerShell

Class Method Summary collapse

Methods inherited from DevSystem::Shell

cruby?, engine, jruby?, linux?, mac?, os, ruby_version, unix?, windows?

Methods inherited from Liza::Controller

color, inherited, on_connected

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Class Method Details

.hello_alpineObject



13
14
15
16
17
# File 'lib/lab_system/shells/docker_shell.rb', line 13

def self.hello_alpine
  KernelShell.call_backticks "docker run alpine echo 'hello world'"

  true
end

.hello_worldObject



5
6
7
8
9
# File 'lib/lab_system/shells/docker_shell.rb', line 5

def self.hello_world
  KernelShell.call_backticks "docker run hello-world"

  true
end

.parse_version(output) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lab_system/shells/docker_shell.rb', line 26

def self.parse_version output
  h = {}
  current_section = current_sub = nil
  
  output.each_line do |line|
    line = line.strip
    next if line.empty?

    if line.start_with?("Client:")

      name = line.split(":", 2).last.strip
      current_section = h["Client"] = {"Name" => name}
      current_sub = current_section

    elsif line.start_with?("Server:")
      name = line.split(":", 2).last.strip
      current_section = h["Server"] = {"Name" => name}

    elsif current_section

      if line.end_with?(":")
        key = line.chomp(":")
        current_sub = current_section[key] = {}
      elsif line.include?(":")
        key, value = line.split(":", 2).map(&:strip)
        current_sub[key] = value
      end

    end
  end

  h
end

.versionObject



21
22
23
24
# File 'lib/lab_system/shells/docker_shell.rb', line 21

def self.version
  output = KernelShell.call_backticks "docker version"
  parse_version output
end