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

fix: collect bridge IP address correctly #626

Merged
merged 4 commits into from May 12, 2024
Merged

Conversation

dlen
Copy link
Contributor

@dlen dlen commented May 9, 2024

I bumped into this issue while using https://github.com/testcontainers/testcontainers-rs-modules-community/tree/main/src/mysql
and the latest version of testcontainers-rs.

get_bridge_ip_address was not returning the correct IP address value. When running a container on GNU/Linux systems
NetworkSettings.bridge might be an empty string therefore it is not useful as a default value.

This PR tries to provide a default value for such scenarios where:

  • No --bridge flag has been explicitly provided when starting the container
  • NetworkSettings.bridge is an empty string
  • Container has not been launched with a specific network and therefore defaults to whatever is configured on the docker daemon

Thanks for all the efforts in this project!

Copy link
Collaborator

@DDtKey DDtKey left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution! 🙏

The changes makes sense to me, I've left a couple of minor comments

testcontainers/src/core/containers/async_container.rs Outdated Show resolved Hide resolved
testcontainers/src/core/containers/async_container.rs Outdated Show resolved Hide resolved
@DDtKey DDtKey changed the title Collect correctly bridge IP address fix: collect bridge IP address correctly May 9, 2024
@dlen
Copy link
Contributor Author

dlen commented May 9, 2024

Wow @DDtKey thanks a lot for the prompt response!! I have pushed your suggestions

@DDtKey
Copy link
Collaborator

DDtKey commented May 9, 2024

Could you take a look at falling tests?

@dlen
Copy link
Contributor Author

dlen commented May 9, 2024

Yes, np

@dlen
Copy link
Contributor Author

dlen commented May 9, 2024

Found some issues with the old approach so I had to switch to determine the network attached to the container by using HostConfig.NetworkMode. Even though it is named NetworkMode it contains the name of the network attached and not its mode. So, when we have the network name it a matter of inspect that network and find its driver to finally conclude if it is a bridged network in order to obtain the bridge ip. I think the test should pass on the CI now.

@DDtKey DDtKey changed the title fix: collect bridge IP address correctly fix!: collect bridge IP address correctly May 9, 2024
@DDtKey
Copy link
Collaborator

DDtKey commented May 9, 2024

I think we should consider this change as breaking one.

Thus, I'm going to include this into 0.17.0.
JFYI: I want to include couple of changes in the next major release, so it will probably will take some time before releasing (not too long)

@DDtKey DDtKey added this to the 0.17.0 milestone May 9, 2024
@dlen
Copy link
Contributor Author

dlen commented May 9, 2024 via email

Comment on lines +387 to +388
#[tokio::test]
async fn async_should_rely_on_network_mode_when_network_is_provided_and_settings_bridge_empty()
Copy link
Collaborator

@DDtKey DDtKey May 10, 2024

Choose a reason for hiding this comment

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

Hi @dlen!
I was about to merge the PR, but wanted to double-check the test coverage and current behavior in main.
And understood that these tests are passing against it.

I'm just wondering if this could be covered better, because if we change this back - we don't see any failures.
Sorry for the late notice

@dlen
Copy link
Contributor Author

dlen commented May 10, 2024 via email

@DDtKey
Copy link
Collaborator

DDtKey commented May 11, 2024

Nothing specific at the moment, but I'll think of it a bit later.

The main goal is to make a test which fails against main, but passes with new changes. That would be ideal option, as we consider this a fix

But in fact, I don't rush you. We even can proceed with this and add tests separately

@DDtKey DDtKey changed the title fix!: collect bridge IP address correctly fix: collect bridge IP address correctly May 12, 2024
@DDtKey DDtKey enabled auto-merge (squash) May 12, 2024 15:04
@DDtKey DDtKey merged commit 52483f8 into testcontainers:main May 12, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants