Class: RakeCompilerDock::DockerCheck

Inherits:
Object
  • Object
show all
Includes:
Colors
Defined in:
lib/rake_compiler_dock/docker_check.rb

Constant Summary

Constants included from Colors

Colors::ColorMap, Colors::ESC, Colors::NND

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Colors

#colored, #disable_colors, #enable_colors

Constructor Details

#initialize(io) ⇒ DockerCheck

Returns a new instance of DockerCheck.


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rake_compiler_dock/docker_check.rb', line 9

def initialize(io)
  @io = io
  if !io.tty? || (RUBY_PLATFORM=~/mingw|mswin/ && RUBY_VERSION[/^\d+/] < '2')
    disable_colors
  else
    enable_colors
  end

  docker_version

  unless ok?
    b2d_version

    if b2d_avail?
      io.puts
      io.puts yellow("boot2docker is available, but not ready to use. Trying to start.")

      b2d_init
      if b2d_init_ok?
        b2d_start

        docker_version
      end
    end
  end
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io


7
8
9
# File 'lib/rake_compiler_dock/docker_check.rb', line 7

def io
  @io
end

Instance Method Details

#b2d_avail?Boolean

Returns:

  • (Boolean)

54
55
56
# File 'lib/rake_compiler_dock/docker_check.rb', line 54

def b2d_avail?
  @b2d_version_status == 0 && @b2d_version_text =~ /version/
end

#b2d_initObject


58
59
60
61
# File 'lib/rake_compiler_dock/docker_check.rb', line 58

def b2d_init
  system("boot2docker init") rescue SystemCallError
  @b2d_init_status = $?.exitstatus
end

#b2d_init_ok?Boolean

Returns:

  • (Boolean)

63
64
65
# File 'lib/rake_compiler_dock/docker_check.rb', line 63

def b2d_init_ok?
  @b2d_init_status == 0
end

#b2d_startObject


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rake_compiler_dock/docker_check.rb', line 67

def b2d_start
  @b2d_start_text = `boot2docker start` rescue SystemCallError
  @b2d_start_status = $?.exitstatus
  @b2d_start_envset = false

  if @b2d_start_status == 0
    io.puts @b2d_start_text
    @b2d_start_text.scan(/(unset |Remove-Item Env:\\)(.+?)$/) do |_, key|
      ENV.delete(key)
      @b2d_start_envset = true
    end
    @b2d_start_text.scan(/(export |\$Env:)(.+?)(=| = ")(.*?)(|\")$/) do |_, key, _, val, _|
      ENV[key] = val
      @b2d_start_envset = true
    end
  end

  if @b2d_start_envset
    io.puts yellow("Using above environment variables for starting rake-compiler-dock.")
  end
end

#b2d_start_has_env?Boolean

Returns:

  • (Boolean)

93
94
95
# File 'lib/rake_compiler_dock/docker_check.rb', line 93

def b2d_start_has_env?
  @b2d_start_envset
end

#b2d_start_ok?Boolean

Returns:

  • (Boolean)

89
90
91
# File 'lib/rake_compiler_dock/docker_check.rb', line 89

def b2d_start_ok?
  @b2d_start_status == 0
end

#b2d_versionObject


49
50
51
52
# File 'lib/rake_compiler_dock/docker_check.rb', line 49

def b2d_version
  @b2d_version_text = `boot2docker version 2>&1` rescue SystemCallError
  @b2d_version_status = $?.exitstatus
end

#docker_client_avail?Boolean

Returns:

  • (Boolean)

45
46
47
# File 'lib/rake_compiler_dock/docker_check.rb', line 45

def docker_client_avail?
  @docker_version_text =~ /version/
end

#docker_versionObject


36
37
38
39
# File 'lib/rake_compiler_dock/docker_check.rb', line 36

def docker_version
  @docker_version_text = `docker version 2>&1` rescue SystemCallError
  @docker_version_status = $?.exitstatus
end

#help_textObject


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/rake_compiler_dock/docker_check.rb', line 97

def help_text
  help = []
  if !ok? && docker_client_avail? && !b2d_avail?
    help << red("Docker client tools work, but connection to the local docker server failed.")
    case RUBY_PLATFORM
    when /linux/
      help << yellow("Please make sure the docker daemon is running.")
      help << ""
      help << yellow("On Ubuntu/Debian:")
      help << "   sudo service docker start"
      help << yellow("or")
      help << "   sudo service docker.io start"
      help << ""
      help << yellow("On Fedora/Centos/RHEL")
      help << "   sudo systemctl start docker"
      help << ""
      help << yellow("On SuSE")
      help << "   sudo systemctl start docker"
      help << ""
      help << yellow("Then re-check with '") + white("docker version") + yellow("'")
      help << yellow("or have a look at the FAQs: http://git.io/vtD2Z")
    else
      help << yellow("    Please check why '") + white("docker version") + yellow("' fails")
      help << yellow("    or have a look at the FAQs: http://git.io/vtD2Z")
    end
  elsif !ok? && !b2d_avail?
    case RUBY_PLATFORM
    when /mingw|mswin/
      help << red("Docker is not available.")
      help << yellow("Please download and install boot2docker:")
      help << yellow("    https://github.com/boot2docker/windows-installer/releases")
    when /linux/
      help << red("Docker is not available.")
      help << ""
      help << yellow("Install on Ubuntu/Debian:")
      help << "    sudo apt-get install docker.io"
      help << ""
      help << yellow("Install on Fedora/Centos/RHEL")
      help << "    sudo yum install docker"
      help << "    sudo systemctl start docker"
      help << ""
      help << yellow("Install on SuSE")
      help << "    sudo zypper install docker"
      help << "    sudo systemctl start docker"
    when /darwin/
      help << red("Docker is not available.")
      help << yellow("Please download and install boot2docker:")
      help << yellow("    https://github.com/boot2docker/osx-installer/releases")
    else
      help << red("Docker is not available.")
    end
  elsif !ok? && !b2d_init_ok?
    help << red("boot2docker is installed but couldn't be initialized.")
    help << ""
    help << yellow("    Please check why '") + white("boot2docker init") + yellow("' fails")
    help << yellow("    or have a look at the FAQs: http://git.io/vtDBH")
  elsif !ok? && !b2d_start_ok?
    help << red("boot2docker is installed but couldn't be started.")
    help << ""
    help << yellow("    Please check why '") + white("boot2docker start") + yellow("' fails.")
    help << yellow("    You might need to re-init with '") + white("boot2docker delete") + yellow("'")
    help << yellow("    or have a look at the FAQs: http://git.io/vtDBH")
  elsif !ok? && b2d_start_ok?
    help << red("boot2docker is installed and started, but 'docker version' failed.")
    help << ""
    if b2d_start_has_env?
      help << yellow("    Please copy and paste above environment variables to your terminal")
      help << yellow("    and check why '") + white("docker version") + yellow("' fails.")
    else
      help << yellow("    Please check why '") + white("docker version") + yellow("' fails.")
    end
    help << yellow("    You might need to re-init with '") + white("boot2docker delete") + yellow("'")
    help << yellow("    or have a look at the FAQs: http://git.io/vtDBH")
  end

  help.join("\n")
end

#ok?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/rake_compiler_dock/docker_check.rb', line 41

def ok?
  @docker_version_status == 0 && @docker_version_text =~ /version/
end

175
176
177
# File 'lib/rake_compiler_dock/docker_check.rb', line 175

def print_help_text
  io.puts(help_text)
end