-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Allow configuration docker executable path and additional environment variables #1214
Conversation
- added a protected DockerClient.getProcessBuilderFactory() method for test purposes - removed a no longer used defaultProcessBuilderFactory that had no enviromment variable configuration DockerClienttest: - added DockerClient tests BuilderDockerTask: - applied google code styling
removed unused methods merged dockerExecutable & dockerEnvironemnt to dockerClient
…ub.com/gintautassulskus/jib into i468-docker-client-env
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) |
ImageConfiguration imageConfiguration = dockerDaemonImage.toImageConfiguration(); | ||
|
||
Assert.assertEquals( | ||
ImageReference.parse("docker/daemon/image").toString(), | ||
imageConfiguration.getImage().toString()); | ||
Assert.assertEquals(0, imageConfiguration.getCredentialRetrievers().size()); | ||
Assert.assertEquals(Paths.get("docker", "executable"), dockerDaemonImage.getDockerExecutable()); |
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.
Removed, as this just tests the simple getter/setter and seemed not worth adding a getter for testing.
@@ -41,17 +44,22 @@ | |||
* @return a new {@link DockerClient} | |||
*/ | |||
public static DockerClient newClient() { | |||
return new DockerClient(defaultProcessBuilderFactory(DEFAULT_DOCKER_CLIENT)); | |||
return newClient(null, null); |
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.
Probably just pass DEFAULT_DOCKER_CLIENT
and Collections.emptyMap()
so the parameters don't need to be nullable?
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.
That works, but the downside is that BuildDockerTask
will have to do
if (dockerExecutable != null && dockerEnvironment != null) {
... = DockerClient.newClient(dockerExecutable, dockerEnvironment);
} else if (dockerExecutable == null && dockerEnvironment == null ) {
... = DockerClient.newClient();
} else {
... ???
}
or make internal defaults of DockerClient
public, so that
... = DockerClient.newClient(
dockerClient == null ? DockerClient.DEFAULT_DOCKER_CLIENT : dockerClient.toString(),
dockerEnvironment == null ? ... : dockerEnvironment);
or define DockerBuildTask
's own defaults, duplicating defaults in multiple places.
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.
Hmm, maybe this warrants a simple Builder
to make the construct clearer - using null
to mean default where the default is not null
feels a bit off
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.
Good idea. Let me try a builder.
jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/DockerClientParameters.java
Outdated
Show resolved
Hide resolved
@Input | ||
@Nullable | ||
@Optional | ||
public Map<String, String> getEnvironment() { |
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.
I think setEnvironment
is missing
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.
I noticed build.gradle
works without it (don't know why), but do you think the setter should actually be there?
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.
Hmm that's interesting. How does it know what the set.. @loosebazooka Is no setter a valid construct?
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.
One thing I also noticed is that, JibExtension
doesn't have a setter for useOnlyProjectCache
or allowInsecureRegistries
either. (And interestingly, the getters for them are not public but package-private.)
But perhaps il'll be just safer to add a setter. Who knows if older Gradle versions won't work if there is no setter. I'll add a setter.
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.
I might just be remembering things wrong and perhaps a setter is only necessary if we need to accept a different type than what's declared on the getter.
jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleRawConfiguration.java
Outdated
Show resolved
Hide resolved
jib-core/src/main/java/com/google/cloud/tools/jib/docker/DockerClient.java
Outdated
Show resolved
Hide resolved
@@ -79,19 +95,22 @@ public DockerClient build() { | |||
@VisibleForTesting | |||
static Function<List<String>, ProcessBuilder> defaultProcessBuilderFactory( | |||
String dockerExecutable, Map<String, String> dockerEnvironment) { | |||
Map<String, String> environmentCopy = new HashMap<>(dockerEnvironment); |
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.
What about just having this method take an ImmutableMap
? I think we should generally favor ImmutableMap
over copying a HashMap
in our non-public API since ImmutableMap.copyOf
doesn't necessarily always perform a copy.
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.
I'm not using ImmutableMap.copyOf
and I want to believe copyOf()
does the operation safely (good to know this anyway), but I'll change the argument to ImmutableMap
, as this is not part of the public API.
We should probably add a changelog entry for this. Also are we waiting until 0.10.1 before merging this so we have more time to add the maven side? |
I think we can actually get this in for |
Yeah, I think we can get this in for |
#468 for Gradle. Branched off of #1173.
Allow configuration docker executable path and additional environment variables.