class Kitchen::Provisioner::Dokken

@author Sean OMeara <sean@sean.io>

Public Instance Methods

call(state) click to toggle source

(see Base#call)

# File lib/kitchen/provisioner/dokken.rb, line 57
def call(state)
  create_sandbox
  write_run_command(run_command)
  instance.transport.connection(state) do |conn|
    if remote_docker_host? || running_inside_docker?
      info("Transferring files to #{instance.to_str}")
      conn.upload(sandbox_dirs, config[:root_path])
    end

    conn.execute(prepare_command)
    conn.execute_with_retry(
      "sh #{config[:root_path]}/run_command",
      config[:retry_on_exit_code],
      config[:max_retries],
      config[:wait_for_retry]
    )
  end
rescue Kitchen::Transport::TransportFailed => ex
  raise ActionFailed, ex.message
ensure
  cleanup_dokken_sandbox if config[:clean_dokken_sandbox] # rubocop: disable Lint/EnsureReturn
end
validate_config() click to toggle source
# File lib/kitchen/provisioner/dokken.rb, line 80
def validate_config
  # check if we have an space for the user provided options
  # or add it if not to avoid issues
  unless config[:chef_options].start_with? " "
    config[:chef_options].prepend(" ")
  end

  # strip spaces from all other options
  config[:chef_binary] = config[:chef_binary].strip
  config[:chef_log_level] = config[:chef_log_level].strip
  config[:chef_output_format] = config[:chef_output_format].strip

  # if the user wants to be funny and pass empty strings
  # just use the defaults
  config[:chef_log_level] = "warn" if config[:chef_log_level].empty?
  config[:chef_output_format] = "doc" if config[:chef_output_format].empty?
end

Private Instance Methods

cleanup_dokken_sandbox() click to toggle source
# File lib/kitchen/provisioner/dokken.rb, line 123
def cleanup_dokken_sandbox
  return if sandbox_path.nil?

  debug("Cleaning up local sandbox in #{sandbox_path}")
  FileUtils.rmtree(Dir.glob("#{sandbox_path}/*"))
end
run_command() click to toggle source

patching Kitchen::Provisioner::ChefZero#run_command

# File lib/kitchen/provisioner/dokken.rb, line 101
def run_command
  validate_config
  cmd = config[:chef_binary]
  cmd << config[:chef_options].to_s
  cmd << " -l #{config[:chef_log_level]}"
  cmd << " -F #{config[:chef_output_format]}"
  cmd << " -c /opt/kitchen/client.rb"
  cmd << " -j /opt/kitchen/dna.json"
  cmd << "--profile-ruby" if config[:profile_ruby]
  cmd << "--slow-report" if config[:slow_resource_report]

  chef_cmd(cmd)
end
runner_container_name() click to toggle source
# File lib/kitchen/provisioner/dokken.rb, line 119
def runner_container_name
  instance.name.to_s
end
write_run_command(command) click to toggle source
# File lib/kitchen/provisioner/dokken.rb, line 115
def write_run_command(command)
  File.write("#{dokken_kitchen_sandbox}/run_command", command, mode: "wb")
end