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 docker-compose executable check for Win10 (#460) #461

Merged
merged 7 commits into from
Sep 29, 2017

Conversation

bsnisar
Copy link
Contributor

@bsnisar bsnisar commented Sep 21, 2017

This is fix for issue: #460

@kiview
Copy link
Member

kiview commented Sep 21, 2017

Do we run tests for local compose on Windows? I have to check at home on my Windows box.

I also wonder how https://github.com/bsnisar/testcontainers-java/blob/61d9b0e1972a8be0530d22368ee9ff200172ca6d/core/src/main/java/org/testcontainers/containers/DockerComposeContainer.java#L512 works, if we have to append .exe on Windows.

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 think I would prefer to make the value of COMPOSE_EXECUTABLE OS dependent, if that's what we also need when calling the docker-compose executable.

@@ -530,6 +531,17 @@ public void invoke() {
}
}

// #460 : docker-compose are not resolvable on Win10 machines because there is docker-compose.exe binary,
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 we can omit this comment (or change it to correct Javadoc comment syntax, but I prefer omitting it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree

@@ -530,6 +531,17 @@ public void invoke() {
}
}

// #460 : docker-compose are not resolvable on Win10 machines because there is docker-compose.exe binary,
// but not docker-compose
private boolean isDockerComposeExists() {
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer renaming the method to something like dockerComposeExecutableExists.

@bsnisar
Copy link
Contributor Author

bsnisar commented Sep 21, 2017

Hi @kiview , in my case for Win10 docker-compose is accessible locally on my cmd:
win10-cmd

But during the check inside CommandLine(executable = "docker-compose"):

    for (String pathString : getSystemPath()) {
        Path path = Paths.get(pathString);
        if (Files.exists(path.resolve(executable)) && Files.isExecutable(path.resolve(executable))) {
            return true;
        }
    }

this loop will find (among other locations) somthing like C:\Program Files\Docker\Docker\Resources\bin where no docker-compose file:

C:\Program Files\Docker\Docker\resources\bin>dir
Volume in drive C is Windows
Volume Serial Number is 8408-CF1E

Directory of C:\Program Files\Docker\Docker\resources\bin

09/10/2017 12:51 PM

.
09/10/2017 12:51 PM ..
09/10/2017 12:51 PM 6,380,236 docker-compose.exe
09/10/2017 12:51 PM 2,436,096 docker-credential-wincred.exe
09/10/2017 12:51 PM 26,885,120 docker-machine.exe
09/10/2017 12:51 PM 19,135,488 docker.exe
09/10/2017 12:51 PM 8,162,816 notary.exe

As a result even if the command is executable, run will be failed by

    if (!CommandLine.executableExists(COMPOSE_EXECUTABLE)) {
        throw new ContainerLaunchException("Local Docker Compose not found. Is " + COMPOSE_EXECUTABLE + " on the PATH?");
    }

So, for me simple fix for executable check looks good enough to satisfy this case.

@@ -530,6 +531,17 @@ public void invoke() {
}
}

// #460 : docker-compose are not resolvable on Win10 machines because there is docker-compose.exe binary,
// but not docker-compose
private boolean isDockerComposeExists() {
Copy link
Member

Choose a reason for hiding this comment

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

What if we change this method to:

        if (SystemUtils.IS_OS_WINDOWS) {
            return CommandLine.executableExists(COMPOSE_EXECUTABLE + ".exe");
        } else {
           return CommandLine.executableExists(COMPOSE_EXECUTABLE);
        }

Copy link
Contributor Author

@bsnisar bsnisar Sep 21, 2017

Choose a reason for hiding this comment

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

This variant more readable and looks better, but narrows all possible options to *.exe variant on Win machines.
How docker-compose executable looks on other Win platforms (not Win10) ?

Copy link
Member

Choose a reason for hiding this comment

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

Since we currently only support Docker for Windows on Windows 10 (see Windows support), I would be fine with this.

Copy link
Contributor Author

@bsnisar bsnisar Sep 22, 2017

Choose a reason for hiding this comment

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

In this case I will rewrite it.

Also, what about this variant:

    return SystemUtils.IS_OS_WINDOWS 
            ? CommandLine.executableExists(COMPOSE_EXECUTABLE + ".exe")
            : CommandLine.executableExists(COMPOSE_EXECUTABLE);

@kiview kiview requested a review from rnorth September 21, 2017 12:31
@@ -530,6 +531,17 @@ public void invoke() {
}
}

// #460 : docker-compose are not resolvable on Win10 machines because there is docker-compose.exe binary,
// but not docker-compose
private boolean isDockerComposeExists() {
Copy link
Member

Choose a reason for hiding this comment

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

Since we currently only support Docker for Windows on Windows 10 (see Windows support), I would be fine with this.

@kiview kiview requested a review from bsideup September 26, 2017 13:54
@kiview
Copy link
Member

kiview commented Sep 26, 2017

@bsnisar Can you please also update the CHANGELOG.md file, by referencing #460 in the line about the docker-compose fix? I'll merge afterwards.

@bsnisar
Copy link
Contributor Author

bsnisar commented Sep 27, 2017

@kiview I have updated it.
Also, as I can see there is a fix for similar problem that was merged. Is it reasonable to merge this PR after that?

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

## UNRELEASED
### Fixed
- Fixed local Docker Compose executable name resolution on Windows (#416)
Copy link
Member

Choose a reason for hiding this comment

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

What I meant, was referencing both issues here ;)

@bsnisar
Copy link
Contributor Author

bsnisar commented Sep 28, 2017

@kiview Ouh, its my misstate. I have just fixed it.

@kiview kiview merged commit 540f567 into testcontainers:master Sep 29, 2017
@ahrytsiuk
Copy link

ahrytsiuk commented Oct 6, 2017

@bsnisar @kiview Seems the issue is still remains.
Because on Windows OS the .exe suffix is appended twice to COMPOSE_EXECUTABLE.
First time here:

private static final String COMPOSE_EXECUTABLE = SystemUtils.IS_OS_WINDOWS ? "docker-compose.exe" : "docker-compose";

private static final String COMPOSE_EXECUTABLE = SystemUtils.IS_OS_WINDOWS ? "docker-compose.exe" : "docker-compose";

And second time here:

return CommandLine.executableExists(COMPOSE_EXECUTABLE + ".exe");

private boolean dockerComposeExecutableExists() {
        if (SystemUtils.IS_OS_WINDOWS) {
            return CommandLine.executableExists(COMPOSE_EXECUTABLE + ".exe");
        } else {
            return CommandLine.executableExists(COMPOSE_EXECUTABLE);
        }
}

UPD:
As I understood, when you merged this PR it just broke docker-compose on Windows OS

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

4 participants