-
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
Add support for defining an entrypoint #873
Changes from 19 commits
2baabc1
ab71986
9f19122
a199dcc
cca176b
32b5f9e
46ceb42
294bbe4
34800cd
e668037
c9cab37
43bb712
5de242d
11b1176
9cf376b
f27a1bb
e469e5c
f11ffed
244d5df
31306f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
jib-*/bin | ||
build | ||
target | ||
out | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,8 +101,7 @@ private static void addIfNotEmpty( | |
private final ImmutableList<CopyDirective> copyDirectives; | ||
|
||
@Nullable private String baseImage; | ||
private List<String> jvmFlags = Collections.emptyList(); | ||
private String mainClass = ""; | ||
private List<String> entrypoint = Collections.emptyList(); | ||
private List<String> javaArguments = Collections.emptyList(); | ||
private List<String> exposedPorts = Collections.emptyList(); | ||
private Map<String, String> labels = Collections.emptyMap(); | ||
|
@@ -150,24 +149,13 @@ public JavaDockerContextGenerator setBaseImage(String baseImage) { | |
} | ||
|
||
/** | ||
* Sets the JVM flags used in the {@code ENTRYPOINT}. | ||
* Sets the entrypoint to be used as the {@code ENTRYPOINT}. | ||
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. Maybe just |
||
* | ||
* @param jvmFlags the jvm flags. | ||
* @param entrypoint the entrypoint. | ||
* @return this | ||
*/ | ||
public JavaDockerContextGenerator setJvmFlags(List<String> jvmFlags) { | ||
this.jvmFlags = jvmFlags; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the main class used in the {@code ENTRYPOINT}. | ||
* | ||
* @param mainClass the name of the main class. | ||
* @return this | ||
*/ | ||
public JavaDockerContextGenerator setMainClass(String mainClass) { | ||
this.mainClass = mainClass; | ||
public JavaDockerContextGenerator setEntrypoint(List<String> entrypoint) { | ||
this.entrypoint = entrypoint; | ||
return this; | ||
} | ||
|
||
|
@@ -291,9 +279,7 @@ String makeDockerfile() throws JsonProcessingException { | |
|
||
dockerfile | ||
.append("\nENTRYPOINT ") | ||
.append( | ||
objectMapper.writeValueAsString( | ||
JavaEntrypointConstructor.makeDefaultEntrypoint(jvmFlags, mainClass))) | ||
.append(objectMapper.writeValueAsString(entrypoint)) | ||
.append("\nCMD ") | ||
.append(objectMapper.writeValueAsString(javaArguments)); | ||
return dockerfile.toString(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright 2018 Google Inc. | ||
* | ||
* 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.google.cloud.tools.jib.gradle; | ||
|
||
import com.google.cloud.tools.jib.configuration.ContainerConfiguration; | ||
import com.google.cloud.tools.jib.frontend.JavaLayerConfigurations; | ||
import com.google.cloud.tools.jib.image.InvalidImageReferenceException; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
/** Tests for {@link PluginConfigurationProcessor}. */ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class PluginConfigurationProcessorTest { | ||
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. nit: short javadoc 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. tiny nit: newline after class definition |
||
|
||
@Mock GradleJibLogger mockGradleJibLogger; | ||
@Mock JibExtension mockJibExtension; | ||
@Mock ImageParameters mockImageParameters; | ||
@Mock ContainerParameters mockContainerParameters; | ||
@Mock GradleProjectProperties mockProjectProperties; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
Mockito.doReturn("gcr.io/distroless/java").when(mockJibExtension).getBaseImage(); | ||
Mockito.doReturn(mockImageParameters).when(mockJibExtension).getFrom(); | ||
Mockito.doReturn(new AuthParameters("mock")).when(mockImageParameters).getAuth(); | ||
Mockito.doReturn(mockContainerParameters).when(mockJibExtension).getContainer(); | ||
Mockito.doReturn(Collections.emptyList()).when(mockContainerParameters).getEntrypoint(); | ||
|
||
Mockito.doReturn(JavaLayerConfigurations.builder().build()) | ||
.when(mockProjectProperties) | ||
.getJavaLayerConfigurations(); | ||
Mockito.doReturn("java.lang.Object").when(mockProjectProperties).getMainClass(mockJibExtension); | ||
} | ||
|
||
/** Test with our default mocks, which try to mimic the bare Gradle configuration. */ | ||
@Test | ||
public void testPluginConfigurationProcessor_defaults() throws InvalidImageReferenceException { | ||
PluginConfigurationProcessor processor = | ||
PluginConfigurationProcessor.processCommonConfiguration( | ||
mockGradleJibLogger, mockJibExtension, mockProjectProperties); | ||
ContainerConfiguration configuration = processor.getContainerConfigurationBuilder().build(); | ||
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. We should prob add a TODO for testing the other processing results too. |
||
Assert.assertEquals( | ||
Arrays.asList( | ||
"java", "-cp", "/app/resources/:/app/classes/:/app/libs/*", "java.lang.Object"), | ||
configuration.getEntrypoint()); | ||
Mockito.verifyZeroInteractions(mockGradleJibLogger); | ||
} | ||
|
||
@Test | ||
public void testEntrypoint() throws InvalidImageReferenceException { | ||
Mockito.doReturn(Arrays.asList("custom", "entrypoint")) | ||
.when(mockContainerParameters) | ||
.getEntrypoint(); | ||
|
||
PluginConfigurationProcessor processor = | ||
PluginConfigurationProcessor.processCommonConfiguration( | ||
mockGradleJibLogger, mockJibExtension, mockProjectProperties); | ||
ContainerConfiguration configuration = processor.getContainerConfigurationBuilder().build(); | ||
|
||
Assert.assertEquals(Arrays.asList("custom", "entrypoint"), configuration.getEntrypoint()); | ||
Mockito.verifyZeroInteractions(mockGradleJibLogger); | ||
} | ||
|
||
@Test | ||
public void testEntrypoint_warningOnJvmFlags() throws InvalidImageReferenceException { | ||
Mockito.doReturn(Arrays.asList("custom", "entrypoint")) | ||
.when(mockContainerParameters) | ||
.getEntrypoint(); | ||
Mockito.doReturn(Arrays.asList("jvmFlag")).when(mockJibExtension).getJvmFlags(); | ||
|
||
PluginConfigurationProcessor processor = | ||
PluginConfigurationProcessor.processCommonConfiguration( | ||
mockGradleJibLogger, mockJibExtension, mockProjectProperties); | ||
ContainerConfiguration configuration = processor.getContainerConfigurationBuilder().build(); | ||
|
||
Assert.assertEquals(Arrays.asList("custom", "entrypoint"), configuration.getEntrypoint()); | ||
Mockito.verify(mockGradleJibLogger) | ||
.warn("mainClass and jvmFlags are ignored when entrypoint is specified"); | ||
} | ||
|
||
@Test | ||
public void testEntrypoint_warningOnMainclass() throws InvalidImageReferenceException { | ||
Mockito.doReturn(Arrays.asList("custom", "entrypoint")) | ||
.when(mockContainerParameters) | ||
.getEntrypoint(); | ||
Mockito.doReturn("java.util.Object").when(mockJibExtension).getMainClass(); | ||
|
||
PluginConfigurationProcessor processor = | ||
PluginConfigurationProcessor.processCommonConfiguration( | ||
mockGradleJibLogger, mockJibExtension, mockProjectProperties); | ||
ContainerConfiguration configuration = processor.getContainerConfigurationBuilder().build(); | ||
|
||
Assert.assertEquals(Arrays.asList("custom", "entrypoint"), configuration.getEntrypoint()); | ||
Mockito.verify(mockGradleJibLogger) | ||
.warn("mainClass and jvmFlags are ignored when entrypoint is specified"); | ||
} | ||
|
||
// TODO should test other behaviours | ||
} |
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 is this referring to?
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.
Oh I wasn't supposed to commit that. I have Eclipse set to generate to bin/, which prevents clashes when running Maven and Gradle from outside.