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

Attach user's Docker config folder to compose containers for proper authentication. #537

Closed
wants to merge 8 commits into from

Conversation

yurybubnov
Copy link

@yurybubnov yurybubnov commented Jan 9, 2018

Attach user's Docker config folder to compose containers for proper authentication.

Fixes #536

@@ -429,6 +433,11 @@ public ContainerisedDockerCompose(List<File> composeFiles, String identifier) {
addEnv("DOCKER_HOST", "unix:///docker.sock");
setStartupCheckStrategy(new IndefiniteWaitOneShotStartupCheckStrategy());
setWorkingDirectory(containerPwd);
Path dockerConfig = Paths.get(System.getProperty("user.home"), ".docker");
Copy link
Member

Choose a reason for hiding this comment

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

I checked my ~/.docker/ folder, it seems to be also used for things like Docker Machine and even some 3rd parties.
I would mount .docker/config.json instead of .docker/ to avoid mounting something really big :)

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 mention your change in CHANGELOG.md as well? :)

Copy link
Member

@kiview kiview left a comment

Choose a reason for hiding this comment

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

I suggested some improvements for code structure.

String dockerConfigProperty = System.getProperty(DOCKER_CONFIG_PROPERTY);
Path dockerConfig = Paths.get(System.getProperty("user.home"), ".docker", "config.json");

if (dockerConfigEnv != null && !dockerConfigEnv.trim().isEmpty() && Files.exists(Paths.get(dockerConfigEnv))) {
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 encapsulate this boolean expressions into private methods with a speaking name? Like dockerConfigEnvExists, dockerConfigPropertyExists, etc.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like this is the last thing still to do on this PR - is that correct? I can do this quickly tomorrow if you're stuck for time @yurybubnov. It'd be no problem.
Thanks for this PR!

Copy link
Author

Choose a reason for hiding this comment

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

CHANGELOG.md Outdated
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.

### Fixed
- Fixed retrieval of Docker host IP when running inside Docker. ([\#479](https://github.com/testcontainers/testcontainers-java/issues/479))
- Compose is now can pull images from private repositories.
Copy link
Member

Choose a reason for hiding this comment

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

Compose is now able to pull images from private repositories.

} else if (dockerConfigProperty != null && !dockerConfigProperty.trim().isEmpty() && Files.exists(Paths.get(dockerConfigProperty))) {
addFileSystemBind(dockerConfigProperty, DOCKER_CONFIG_FILE, READ_ONLY);
} else if (Files.exists(dockerConfig)) {
addFileSystemBind(dockerConfig.toString(), DOCKER_CONFIG_FILE, READ_ONLY);
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 block should go into a private method mountDockerConfig().

In addition I think this method could be structured a bit more concise, like maybe

String dockerConfigPath = determineDockerConfigPath();
addFileSystemBind(dockerConfigPath , DOCKER_CONFIG_FILE, READ_ONLY);

@yurybubnov
Copy link
Author

Made the suggested changes. Thanks for proofreading CHANGELOG. I also added documentation about the changes.

@rnorth
Copy link
Member

rnorth commented Jan 28, 2018

Rebased and merged manually after resolving conflicts

@rnorth rnorth closed this Jan 28, 2018
@rnorth
Copy link
Member

rnorth commented Jan 28, 2018

Thank you for the contribution @yurybubnov !

@bsideup bsideup added this to the 1.6.0 milestone Jan 28, 2018
@bsideup bsideup changed the title fix for https://github.com/testcontainers/testcontainers-java/issues/536 Attach user's Docker config folder to compose containers for proper authentication. Jan 28, 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

4 participants