Skip to content

Add DefaultDockerClientConfig.Builder#isDockerHostSetExplicitly - #1692

Merged
bsideup merged 9 commits into
docker-java:masterfrom
kiview:docker-host-modified-getter
Aug 23, 2021
Merged

bsideup merged 9 commits into
docker-java:masterfrom
kiview:docker-host-modified-getter

Conversation

@kiview

@kiview kiview commented Aug 23, 2021

Copy link
Copy Markdown
Contributor

The current implementation specifies that hasDefaultDockerHost() returns false, if dockerHost has a value different from the default DOCKER_HOST value.

This means, this implementation will also return true if dockerHost is set through ENV or properties to the default value.

This PR would increase the robustness of testcontainers/testcontainers-java#4387.

/**
* Considered default if dockerHost is set to the default value.
*/
public final boolean hasDefaultDockerHost() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let's change it to isDockerHostSetExplicitly(), to detect user's intention to override it (even if set to the default value)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alright, will invert the logic (changed it to usesImplicitDockerHost() before).
As you can see, the checks are all over the place in DefaultDockerClientConfig now, I lack the idea of a clean way to capture all places atm.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Have you considered removing docker.host from DEFAULT_PROPERTIES, using dockerHost != null to detect explicit value, and then passing dockerHost != null ? dockerHost : DEFAULT_DOCKER_HOST to DefaultDockerClientConfig from build()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

would work nicely if dockerHost could be null in Builder 😐
But I will check further in this in this direction.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why can't it be? :)

@kiview kiview Aug 23, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It can now. However, it changes the contract of Builder.withDockerHost(), meaning it will only do parsing of host URI on build().

I would consider this an acceptable tradeoff for the dramatically simplified changeset.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can keep the validation, and call it from withProperties only if the value is not null

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, works nicely.

@kiview kiview changed the title Add getter for checking if dockerHost in DefaultDockerClientConfig.Builder has default value Add getter for checking if dockerHost is DefaultDockerClientConfig.Builder set by user Aug 23, 2021
return this;
}

public final boolean isDockerHostSetExplicit() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rnorth I need your help with naming 😅 shouldn't it be "explicitly"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

uff, it probably should :D

@bsideup bsideup changed the title Add getter for checking if dockerHost is DefaultDockerClientConfig.Builder set by user Add DefaultDockerClientConfig.Builder#isDockerHostSetExplicitly Aug 23, 2021
@bsideup
bsideup merged commit e6f4ade into docker-java:master Aug 23, 2021
@bsideup bsideup added this to the next milestone Sep 9, 2021
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.

2 participants