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

Allow configuration docker executable path and additional environment variables #1214

Merged
merged 20 commits into from
Nov 7, 2018

Conversation

chanseokoh
Copy link
Member

#468 for Gradle. Branched off of #1173.

Allow configuration docker executable path and additional environment variables.

jibDockerBuild.dockerClient.executable = '/usr/bin/docker'
jibDockerBuild.dockerClient.environment = [KEY: 'value', DOCKER_HOST: '...']

jibDockerBuild {
  dockerClient {
    executable = ...
    environment = ...
  }
}

gintautassulskus and others added 13 commits October 21, 2018 01:23
- 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
@googlebot
Copy link

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 cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@googlebot
Copy link

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());
Copy link
Member Author

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);
Copy link
Contributor

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?

Copy link
Member Author

@chanseokoh chanseokoh Nov 2, 2018

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.

Copy link
Contributor

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

Copy link
Member Author

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.

@Input
@Nullable
@Optional
public Map<String, String> getEnvironment() {
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

@googlebot googlebot added cla: no and removed cla: yes labels Nov 2, 2018
@googlebot googlebot added cla: no and removed cla: yes labels Nov 5, 2018
@@ -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);
Copy link
Contributor

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.

Copy link
Member Author

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.

@TadCordle
Copy link
Contributor

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?

@coollog
Copy link
Contributor

coollog commented Nov 7, 2018

I think we can actually get this in for 0.10.0.

@chanseokoh
Copy link
Member Author

Yeah, I think we can get this in for 0.10.0. We can do the Maven part later. I will update CHANGELOG in another PR very soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants