-
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 4 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
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* 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; | ||
|
||
@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 gradleJibLogger; | ||
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: in this codebase, we prefer to name mocks with a mock- prefix, so like |
||
@Mock JibExtension jibExtension; | ||
@Mock ImageParameters imageParameters; | ||
@Mock ContainerParameters containerParameters; | ||
@Mock GradleProjectProperties projectProperties; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
Mockito.doReturn("gcr.io/distroless/java").when(jibExtension).getBaseImage(); | ||
Mockito.doReturn(imageParameters).when(jibExtension).getFrom(); | ||
Mockito.doReturn(new AuthParameters("mock")).when(imageParameters).getAuth(); | ||
Mockito.doReturn(containerParameters).when(jibExtension).getContainer(); | ||
Mockito.doReturn(Collections.emptyList()).when(containerParameters).getEntrypoint(); | ||
|
||
Mockito.doReturn(JavaLayerConfigurations.builder().build()) | ||
.when(projectProperties) | ||
.getJavaLayerConfigurations(); | ||
Mockito.doReturn("java.lang.Object").when(projectProperties).getMainClass(jibExtension); | ||
} | ||
|
||
@Test | ||
public void testBase() throws InvalidImageReferenceException { | ||
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. Generally, we try to name the test methods with |
||
PluginConfigurationProcessor processor = | ||
PluginConfigurationProcessor.processCommonConfiguration( | ||
gradleJibLogger, jibExtension, projectProperties); | ||
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(gradleJibLogger); | ||
} | ||
|
||
@Test | ||
public void testEntrypoint() throws InvalidImageReferenceException { | ||
Mockito.doReturn(Arrays.asList("custom", "entrypoint")) | ||
.when(containerParameters) | ||
.getEntrypoint(); | ||
|
||
PluginConfigurationProcessor processor = | ||
PluginConfigurationProcessor.processCommonConfiguration( | ||
gradleJibLogger, jibExtension, projectProperties); | ||
ContainerConfiguration configuration = processor.getContainerConfigurationBuilder().build(); | ||
|
||
Assert.assertEquals(Arrays.asList("custom", "entrypoint"), configuration.getEntrypoint()); | ||
Mockito.verifyZeroInteractions(gradleJibLogger); | ||
} | ||
|
||
@Test | ||
public void testEntrypoint_warningOnJvmFlags() throws InvalidImageReferenceException { | ||
Mockito.doReturn(Arrays.asList("custom", "entrypoint")) | ||
.when(containerParameters) | ||
.getEntrypoint(); | ||
Mockito.doReturn(Arrays.asList("jvmFlag")).when(jibExtension).getJvmFlags(); | ||
|
||
PluginConfigurationProcessor processor = | ||
PluginConfigurationProcessor.processCommonConfiguration( | ||
gradleJibLogger, jibExtension, projectProperties); | ||
ContainerConfiguration configuration = processor.getContainerConfigurationBuilder().build(); | ||
|
||
Assert.assertEquals(Arrays.asList("custom", "entrypoint"), configuration.getEntrypoint()); | ||
Mockito.verify(gradleJibLogger) | ||
.warn("mainClass and jvmFlags are ignored when entrypoint is specified"); | ||
} | ||
|
||
@Test | ||
public void testEntrypoint_warningOnMainclass() throws InvalidImageReferenceException { | ||
Mockito.doReturn(Arrays.asList("custom", "entrypoint")) | ||
.when(containerParameters) | ||
.getEntrypoint(); | ||
Mockito.doReturn("java.util.Object").when(jibExtension).getMainClass(); | ||
|
||
PluginConfigurationProcessor processor = | ||
PluginConfigurationProcessor.processCommonConfiguration( | ||
gradleJibLogger, jibExtension, projectProperties); | ||
ContainerConfiguration configuration = processor.getContainerConfigurationBuilder().build(); | ||
|
||
Assert.assertEquals(Arrays.asList("custom", "entrypoint"), configuration.getEntrypoint()); | ||
Mockito.verify(gradleJibLogger) | ||
.warn("mainClass and jvmFlags are ignored when entrypoint is specified"); | ||
} | ||
} |
This file was deleted.
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.
Maybe we should add a bit more verification here, if you think it's necessary (e.g. build with docker like the other tests and inspect, although that could be too much overhead. Or maybe just check for the dockerfile and make sure it contains the correct commands)?