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 getDockerHostIpAddress within docker container #648

Merged
merged 1 commit into from
Apr 19, 2018
Merged

fix getDockerHostIpAddress within docker container #648

merged 1 commit into from
Apr 19, 2018

Conversation

qoomon
Copy link
Contributor

@qoomon qoomon commented Apr 18, 2018

only determine default gateway within docker container if docker host differ from default, otherwise it was set manually and it should be used as it was set

@@ -17,42 +17,43 @@
// See https://github.com/docker/docker/blob/a9fa38b1edf30b23cae3eade0be48b3d4b1de14b/daemon/initlayer/setup_unix.go#L25
public static final boolean IN_A_CONTAINER = new File("/.dockerenv").exists();

@Getter(lazy = true)
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why you dropped lazily cached result? This change will make it run every time somebody queries the host ip, and I don't see how does it fix it.
Also, was it broken?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my bad you are right i will refactor it to lazy cache again.
and yes it is broken if we run it in GitLab CI directly in the build container with the DinD service it resolves to the default gateway, however it should resolve to tcp://docker:2375 or just docker

Copy link
Member

Choose a reason for hiding this comment

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

oh wow, nice finding!

))
.map(StringUtils::trimToEmpty)
.filter(StringUtils::isNotBlank);
private static final Optional<String> defaultGateway = Optional
Copy link
Member

Choose a reason for hiding this comment

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

I know that the indentation was incorrect, but could you please revert the change to the actual change? We will fix the indentation afterwards, but it will help to understand what was modified :)

Copy link
Member

Choose a reason for hiding this comment

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

I think the whole change is as simple as getDefaultGateway().orElse("localhost") in getDockerHostIpAddress

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay will fixed

@@ -18,10 +18,8 @@
public static final boolean IN_A_CONTAINER = new File("/.dockerenv").exists();

@Getter(lazy = true)
private static final Optional<String> detectedDockerHostIp = Optional
Copy link
Member

Choose a reason for hiding this comment

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

Since this getter is public, I don't think we can just change the behaviour of it :( Could you please make this change backward compatible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah I see

@qoomon
Copy link
Contributor Author

qoomon commented Apr 19, 2018

so finally it is backward compatible so getDetectedDockerHostIp() acts as before
and I marked getDetectedDockerHostIp() with @deprecated


@Deprecated
@Getter(lazy = true)
private static final Optional<String> detectedDockerHostIp = IN_A_CONTAINER ? getDefaultGateway() : Optional.empty();
Copy link
Member

Choose a reason for hiding this comment

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

could you please put this method upper where it was, so that the diff will be smaller?

} catch (Exception e) {
log.warn("Can't parse the default gateway IP", e);
return null;
}
}
))
.map(StringUtils::trimToEmpty)
Copy link
Member

Choose a reason for hiding this comment

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

TBH I would prefer to keep this chain

@qoomon
Copy link
Contributor Author

qoomon commented Apr 19, 2018

now the diff look quite neat

@bsideup bsideup merged commit 58a24f9 into testcontainers:master Apr 19, 2018
@bsideup
Copy link
Member

bsideup commented Apr 19, 2018

@qoomon merged, thanks!

@bsideup
Copy link
Member

bsideup commented Apr 19, 2018

@qoomon oh snap, I forgot the changelog :D Will add it myself, thanks for your contribution 👍

bsideup added a commit that referenced this pull request Apr 19, 2018
rnorth pushed a commit that referenced this pull request Apr 24, 2018
rnorth pushed a commit that referenced this pull request Apr 24, 2018
rnorth pushed a commit that referenced this pull request Apr 24, 2018
rnorth pushed a commit that referenced this pull request Apr 30, 2018
rnorth pushed a commit that referenced this pull request Apr 30, 2018
rnorth pushed a commit that referenced this pull request Apr 30, 2018
rnorth pushed a commit that referenced this pull request May 13, 2018
rnorth pushed a commit that referenced this pull request May 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants