Class: Kitchen::Driver::Docker

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

Overview

Docker driver for Kitchen.

Author:

Constant Summary collapse

MUTEX_FOR_SSH_KEYS =
Mutex.new

Instance Method Summary collapse

Instance Method Details

#create(state) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/kitchen/driver/docker.rb', line 118

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] = 'localhost'
  if remote_socket?
    state[:hostname] = socket_uri.host
  elsif config[:use_internal_docker_network]
    state[:hostname] = container_ip(state)
  end
  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



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

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



114
115
116
# File 'lib/kitchen/driver/docker.rb', line 114

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

#destroy(state) ⇒ Object



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

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

#dev_nullObject



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

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)


145
146
147
# File 'lib/kitchen/driver/docker.rb', line 145

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

#verify_dependenciesObject



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

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 https://www.docker.com/get-started'
end