Class: Kitchen::Docker::Container

Inherits:
Object
  • Object
show all
Includes:
Helpers::CliHelper, Helpers::ContainerHelper, Helpers::FileHelper, Helpers::ImageHelper
Defined in:
lib/kitchen/docker/container.rb,
lib/kitchen/docker/container/linux.rb,
lib/kitchen/docker/container/windows.rb

Direct Known Subclasses

Linux, Windows

Defined Under Namespace

Classes: Linux, Windows

Instance Method Summary collapse

Methods included from Helpers::ImageHelper

#build_image, #image_exists?, #parse_image_id, #remove_image

Methods included from Helpers::ContainerHelper

#container_env_variables, #container_exec, #container_exists?, #container_ip_address, #copy_file_to_container, #create_dir_on_container, #dockerfile_path, #dockerfile_proxy_config, #dockerfile_template, #parse_container_id, #remote_socket?, #remove_container, #replace_env_variables, #run_container, #socket_uri

Methods included from Helpers::CliHelper

#build_copy_command, #build_env_variable_args, #build_exec_command, #build_powershell_command, #build_run_command, #config_to_options, #dev_null, #docker_command, #docker_shell_opts, #run_command

Methods included from Helpers::FileHelper

#create_temp_file

Constructor Details

#initialize(config) ⇒ Container

Returns a new instance of Container.



27
28
29
# File 'lib/kitchen/docker/container.rb', line 27

def initialize(config)
  @config = config
end

Instance Method Details

#create(state) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/kitchen/docker/container.rb', line 31

def create(state)
  if container_exists?(state)
    info("Container ID #{state[:container_id]} already exists.")
  elsif !container_exists?(state) && state[:container_id]
    raise ActionFailed, "Container ID #{state[:container_id]} was found in the kitchen state data, "\
                        'but the container does not exist.'
  end

  state[:username] = @config[:username]
end

#destroy(state) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/kitchen/docker/container.rb', line 42

def destroy(state)
  info("[Docker] Destroying Docker container #{state[:container_id]}") if state[:container_id]
  remove_container(state) if container_exists?(state)

  if @config[:remove_images] && state[:image_id]
    remove_image(state) if image_exists?(state)
  end
end

#hostname(state) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/kitchen/docker/container.rb', line 51

def hostname(state)
  hostname = 'localhost'

  if remote_socket?
    hostname = socket_uri.host
  elsif @config[:use_internal_docker_network]
    hostname = container_ip_address(state)
  end

  hostname
end

#upload(locals, remote) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/kitchen/docker/container.rb', line 63

def upload(locals, remote)
  files = locals
  files = Array(locals) unless locals.is_a?(Array)

  files.each do |file|
    copy_file_to_container(@config, file, remote)
  end

  files
end