class Kitchen::Transport::Dokken

A Transport which uses Docker tricks to execute commands and transfer files.

@author Sean OMeara <sean@sean.io>

Public Instance Methods

connection(state, &block) click to toggle source

(see Base#connection)

# File lib/kitchen/transport/dokken.rb, line 58
def connection(state, &block)
  options = connection_options(config.to_hash.merge(state))

  if @connection && @connection_options == options
    reuse_connection(&block)
  else
    create_new_connection(options, &block)
  end
end
docker_for_mac_or_win?() click to toggle source

Detect whether or not we are running in Docker for Mac or Windows

@return [TrueClass,FalseClass]

# File lib/kitchen/transport/dokken.rb, line 220
def docker_for_mac_or_win?
  ::Docker.info(::Docker::Connection.new(config[:docker_host_url], {}))["Name"] == "docker-desktop"
rescue
  false
end

Private Instance Methods

connection_options(data) click to toggle source

Builds the hash of options needed by the Connection object on construction.

@param data [Hash] merged configuration and mutable state data @return [Hash] hash of connection options @api private

# File lib/kitchen/transport/dokken.rb, line 234
def connection_options(data)
  opts = {}
  opts[:logger] = logger
  opts[:host_ip_override] = config[:host_ip_override]
  opts[:docker_host_url] = config[:docker_host_url]
  opts[:docker_host_options] = ::Docker.options
  opts[:data_container] = data[:data_container]
  opts[:instance_name] = data[:instance_name]
  opts[:timeout] = data[:write_timeout]
  opts[:login_command] = data[:login_command]
  opts
end
create_new_connection(options, &block) click to toggle source

Creates a new Dokken Connection instance and save it for potential future reuse.

@param options [Hash] conneciton options @return [Ssh::Connection] an SSH Connection instance @api private

# File lib/kitchen/transport/dokken.rb, line 253
def create_new_connection(options, &block)
  if @connection
    logger.debug("[Dokken] shutting previous connection #{@connection}")
    @connection.close
  end

  @connection = Kitchen::Transport::Dokken::Connection.new(options, &block)
end
reuse_connection() { |connection| ... } click to toggle source

Return the last saved Dokken connection instance.

@return [Dokken::Connection] an Dokken Connection instance @api private

# File lib/kitchen/transport/dokken.rb, line 266
def reuse_connection
  logger.debug("[Dokken] reusing existing connection #{@connection}")
  yield @connection if block_given?
  @connection
end