Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use container network if nested_docker #64

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions lib/beaker/hypervisor/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,23 @@ def get_ssh_connection_info(container)
else
# The many faces of container networking

# Host to Container
port22 = network_settings.dig('PortBindings','22/tcp')
if port22.nil? && network_settings.key?('Ports')
port22 = network_settings.dig('Ports','22/tcp')
# Container to container
if nested_docker?
ip = network_settings['IPAddress']
port = 22 if ip && !ip.empty?
end
ip = port22[0]['HostIp'] if port22
port = port22[0]['HostPort'] if port22

# Container to container
# Host to Container
unless ip && port
ip = nil
port = nil

ip = network_settings['IPAddress']
port = 22 if ip && !ip.empty?
port22 = network_settings.dig('PortBindings','22/tcp')
if port22.nil? && network_settings.key?('Ports')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if statement is unnecessary and the following line could be changed to:

port22 ||= network_settings.dig('Ports','22/tcp')

port22 = network_settings.dig('Ports','22/tcp')
end
ip = port22[0]['HostIp'] if port22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HostIp could be empty so you're going to want to fall back to IPAddress as in the removed code if necessary.

port = port22[0]['HostPort'] if port22
end

# Container through gateway
Expand Down