Skip to content

Commit

Permalink
Retrieve hostname state data after container is launched
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Coe <[email protected]>
  • Loading branch information
jeffreycoe committed Jun 17, 2020
1 parent 9751a14 commit a2b0511
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
31 changes: 18 additions & 13 deletions lib/kitchen/docker/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,27 @@ def create(state)
end

state[:username] = @config[:username]
state[:hostname] = 'localhost'
end

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

def hostname(state)
hostname = 'localhost'

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

hostname
end

def upload(locals, remote)
Expand All @@ -56,15 +70,6 @@ def upload(locals, remote)

files
end

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
end
end
end
2 changes: 1 addition & 1 deletion lib/kitchen/docker/container/linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create(state)
state[:ssh_key] = @config[:private_key]
state[:image_id] = build_image(state, dockerfile) unless state[:image_id]
state[:container_id] = run_container(state, 22) unless state[:container_id]
state[:hostname] = 'localhost'
state[:hostname] = hostname(state)
state[:port] = container_ssh_port(state)
end

Expand Down
1 change: 1 addition & 0 deletions lib/kitchen/docker/container/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def create(state)
state[:username] = @config[:username]
state[:image_id] = build_image(state, dockerfile) unless state[:image_id]
state[:container_id] = run_container(state) unless state[:container_id]
state[:hostname] = hostname(state)
end

def execute(command)
Expand Down

0 comments on commit a2b0511

Please sign in to comment.