Class: Kitchen::Driver::Docker

Inherits:
Base
  • Object
show all
Includes:
ShellOut
Defined in:
lib/kitchen/driver/docker.rb

Overview

Docker driver for Kitchen.

Constant Summary collapse

MUTEX_FOR_SSH_KEYS =
Mutex.new

Instance Method Summary collapse

Instance Method Details

#create(state) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/kitchen/driver/docker.rb', line 116

def create(state)
  generate_keys
  state[:username] = config[:username]
  state[:ssh_key] = config[:private_key]
  state[:image_id] = build_image(state) unless state[:image_id]
  state[:container_id] = run_container(state) unless state[:container_id]
  state[:hostname] = remote_socket? ? socket_uri.host : 'localhost'
  state[:port] = container_ssh_port(state)
  if config[:wait_for_sshd]
    instance.transport.connection(state) do |conn|
      conn.wait_until_ready
    end
  end
end

#default_imageObject



104
105
106
107
108
109
110
# File 'lib/kitchen/driver/docker.rb', line 104

def default_image
  platform, release = instance.platform.name.split('-')
  if platform == 'centos' && release
    release = 'centos' + release.split('.').first
  end
  release ? [platform, release].join(':') : platform
end

#default_platformObject



112
113
114
# File 'lib/kitchen/driver/docker.rb', line 112

def default_platform
  instance.platform.name.split('-').first
end

#destroy(state) ⇒ Object



131
132
133
134
135
136
# File 'lib/kitchen/driver/docker.rb', line 131

def destroy(state)
  rm_container(state) if container_exists?(state)
  if config[:remove_images] && state[:image_id]
    rm_image(state)
  end
end

#dev_nullObject



95
96
97
98
99
100
101
102
# File 'lib/kitchen/driver/docker.rb', line 95

def dev_null
  case RbConfig::CONFIG["host_os"]
  when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
    "NUL"
  else
    "/dev/null"
  end
end

#remote_socket?Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/kitchen/driver/docker.rb', line 138

def remote_socket?
  config[:socket] ? socket_uri.scheme == 'tcp' : false
end

#verify_dependenciesObject



88
89
90
91
92
93
# File 'lib/kitchen/driver/docker.rb', line 88

def verify_dependencies
  run_command("#{config[:binary]} >> #{dev_null} 2>&1", quiet: true, use_sudo: config[:use_sudo])
  rescue
    raise UserError,
    'You must first install the Docker CLI tool http://www.docker.io/gettingstarted/'
end