-
Notifications
You must be signed in to change notification settings - Fork 90
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
Feature/look in path #175
Open
hpryce
wants to merge
10
commits into
master
Choose a base branch
from
feature/look_in_path
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/look in path #175
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
195d9af
Locate docker and docker-compose using the path variable.
ab078a6
Merge branch 'feature/use-path-to-find-executables' of https://github…
hpryce a12076d
Reintroduce support for explicitly setting docker-compose location.
hpryce 35ab870
Docker for Mac is not in the path when tests run from IDE.
hpryce 252a88e
Split out finding possible command locations from testing those locat…
hpryce 0a61921
Add jsr dep
hpryce d39fb31
Refactor to simply logic and improve test coverage by using Environme…
hpryce 19791dd
Add case for Windows path variable "Path"
hpryce a734f16
Process builder will look for command on the path
hpryce fa10060
Merge branch 'master' into feature/look_in_path
hpryce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
...rule-core/src/main/java/com/palantir/docker/compose/execution/DockerCommandLocations.java
This file was deleted.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
...e-rule-core/src/main/java/com/palantir/docker/compose/execution/DockerCommandLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2016 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.palantir.docker.compose.execution; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import javax.annotation.Nullable; | ||
import org.apache.commons.lang3.SystemUtils; | ||
import org.immutables.value.Value; | ||
|
||
@Value.Immutable | ||
public abstract class DockerCommandLocator { | ||
|
||
private static final List<String> MAC_SEARCH_LOCATIONS = ImmutableList.of("/usr/local/bin", "/usr/bin"); | ||
|
||
protected abstract String command(); | ||
|
||
@Value.Default | ||
protected boolean isWindows() { | ||
return SystemUtils.IS_OS_WINDOWS; | ||
} | ||
|
||
@Value.Default | ||
protected List<String> macSearchLocations() { | ||
return MAC_SEARCH_LOCATIONS; | ||
} | ||
|
||
@Value.Derived | ||
protected String executableName() { | ||
if (isWindows()) { | ||
return command() + ".exe"; | ||
} | ||
return command(); | ||
} | ||
|
||
@Nullable | ||
protected abstract String locationOverride(); | ||
|
||
public String getLocation() { | ||
if (locationOverride() != null) { | ||
return locationOverride(); | ||
} | ||
return macSearchLocations() | ||
.stream() | ||
.map(p -> Paths.get(p, executableName())) | ||
.filter(Files::exists) | ||
.findFirst() | ||
.map(Path::toString) | ||
.orElse(executableName()); | ||
} | ||
|
||
public static ImmutableDockerCommandLocator.Builder forCommand(String command) { | ||
return ImmutableDockerCommandLocator.builder() | ||
.command(command); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,19 +29,12 @@ | |
public abstract class DockerComposeExecutable implements Executable { | ||
private static final Logger log = LoggerFactory.getLogger(DockerComposeExecutable.class); | ||
|
||
private static final DockerCommandLocations DOCKER_COMPOSE_LOCATIONS = new DockerCommandLocations( | ||
System.getenv("DOCKER_COMPOSE_LOCATION"), | ||
"/usr/local/bin/docker-compose", | ||
"/usr/bin/docker-compose" | ||
); | ||
|
||
private static String defaultDockerComposePath() { | ||
String pathToUse = DOCKER_COMPOSE_LOCATIONS.preferredLocation() | ||
.orElseThrow(() -> new IllegalStateException( | ||
"Could not find docker-compose, looked in: " + DOCKER_COMPOSE_LOCATIONS)); | ||
|
||
DockerCommandLocator commandLocator = DockerCommandLocator.forCommand("docker-compose") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. returning a builder just to do this looks kinda meh, might as well do the entire builder from here and delete the |
||
.locationOverride(System.getenv("DOCKER_COMPOSE_LOCATION")) | ||
.build(); | ||
String pathToUse = commandLocator.getLocation(); | ||
log.debug("Using docker-compose found at " + pathToUse); | ||
|
||
return pathToUse; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 0 additions & 70 deletions
70
...ore/src/test/java/com/palantir/docker/compose/execution/DockerCommandLocationsShould.java
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
...-core/src/test/java/com/palantir/docker/compose/execution/DockerCommandLocatorShould.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2016 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.palantir.docker.compose.execution; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.core.Is.is; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
public class DockerCommandLocatorShould { | ||
private static final String command = "not-a-real-command!"; | ||
private static final String windowsCommand = command + ".exe"; | ||
|
||
@Rule public TemporaryFolder folder = new TemporaryFolder(); | ||
|
||
@Rule public ExpectedException exception = ExpectedException.none(); | ||
|
||
@Test public void | ||
returns_the_command_name_when_no_other_paths_contain_command() { | ||
DockerCommandLocator locator = DockerCommandLocator.forCommand(command) | ||
.isWindows(false) | ||
.build(); | ||
|
||
assertThat(locator.getLocation(), is(command)); | ||
} | ||
|
||
@Test public void | ||
returns_the_command_name_with_exe_on_windows_when_no_other_paths_contain_command() { | ||
DockerCommandLocator locator = DockerCommandLocator.forCommand(command) | ||
.isWindows(true) | ||
.build(); | ||
|
||
assertThat(locator.getLocation(), is(windowsCommand)); | ||
} | ||
|
||
@Test public void | ||
allow_the_path_to_be_overriden() throws IOException { | ||
Path overrideFolder = folder.newFolder("override").toPath(); | ||
String overridenCommand = Files.createFile(overrideFolder.resolve(command)).toString(); | ||
|
||
DockerCommandLocator locator = DockerCommandLocator.forCommand(command) | ||
.locationOverride(overridenCommand) | ||
.isWindows(false) | ||
.build(); | ||
|
||
assertThat(locator.getLocation(), is(overridenCommand)); | ||
} | ||
|
||
@Test public void | ||
search_in_known_mac_install_locations_for_the_command() throws IOException { | ||
Path macSearchFolder = folder.newFolder("override").toPath(); | ||
String commandLocation = Files.createFile(macSearchFolder.resolve(command)).toString(); | ||
|
||
DockerCommandLocator locator = DockerCommandLocator.forCommand(command) | ||
.macSearchLocations(singletonList(macSearchFolder.toString())) | ||
.isWindows(false) | ||
.build(); | ||
|
||
assertThat(locator.getLocation(), is(commandLocation)); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning a constant to represent a default where the constant is framed as a question is somewhat misleading (I still don't know what the default is)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is to allow it to be overriden in tests, otherwise it should behave as a constant.
Would "useWindowsExecutableNaming" have been easier to understand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isWindows
is fine, but I'm starting to think that making it a default doesn't really make any sense. Whoever creates this builder will know at the time what environment they're in, and it feels odd to be like "I'm not going to specify if I'm running on windows because defaults"Unless of course this is for backcompat and it's used in client code then nevermind.