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
@github-actions github-actions bot mentioned this pull request May 26, 2024
DDtKey pushed a commit that referenced this pull request May 26, 2024
## 🤖 New release
* `testcontainers`: 0.16.7 -> 0.17.0

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.17.0] - 2024-05-26

### Details
#### Bug Fixes
- Collect bridge IP address correctly
([#626](#626))
- Replace missed panics with `Result`
([#638](#638))

#### Features
- Impl `Error` for `WaitError`
([#629](#629))
- [❗] Extend `exec` interface to return logs and exec code
([#631](#631))
- Ability to access container logs
([#633](#633))
- [❗] Switch to fallible API
([#636](#636))
- Make container and exec logs `Send`able
([#637](#637))
- Map container not found error to `eof` for container log streams
([#639](#639))
- Expose follow flag for `stdout` and `stderr`
([#640](#640))
- Add ability to read container logs into `Vec`
([#641](#641))
- [❗] Add container startup timeout with default of 1 minute
([#643](#643))

#### Miscellaneous Tasks
- Fix clippy warning without features enabled
([#632](#632))

#### Refactor
- [❗] Drop re-export of `CgroupnsMode` accessible through `core`
([#630](#630))
- [❗] Drop previously deprecated `get_host_ip_address`
([#628](#628))
- [❗] Return `PortNotExposed` error from `ContainerState::host_port_*`
([#644](#644))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants