Skip to content

Commit 6569f2f

Browse files
authored
Fix WAR entrypoint when custom base image (#3185)
1 parent f20cfcd commit 6569f2f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@ static JavaContainerBuilder getJavaContainerBuilderWithBaseImage(
543543
* <ol>
544544
* <li>null (inheriting from the base image), if the user specified value is {@code INHERIT}
545545
* <li>the user specified one, if set
546-
* <li>for a WAR project, {@code ["java", "-jar", "/usr/local/jetty/start.jar"]}
546+
* <li>for a WAR project, null (inheriting) if a custom base image is specified, and {@code
547+
* ["java", "-jar", "/usr/local/jetty/start.jar"]} otherwise (default Jetty base image)
547548
* <li>for a non-WAR project, by resolving the main class
548549
* </ol>
549550
*
@@ -589,7 +590,9 @@ static List<String> computeEntrypoint(
589590
"mainClass, extraClasspath, jvmFlags, and expandClasspathDependencies "
590591
+ "are ignored for WAR projects"));
591592
}
592-
return Arrays.asList("java", "-jar", "/usr/local/jetty/start.jar");
593+
return rawConfiguration.getFromImage().isPresent()
594+
? null
595+
: Arrays.asList("java", "-jar", "/usr/local/jetty/start.jar");
593596
}
594597

595598
List<String> classpath = new ArrayList<>(rawExtraClasspath);

jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,22 @@ public void testEntrypointClasspath_nonDefaultAppRoot()
568568
.inOrder();
569569
}
570570

571+
@Test
572+
public void testWebAppEntrypoint_inheritedFromCustomBaseImage()
573+
throws InvalidImageReferenceException, IOException, CacheDirectoryCreationException,
574+
MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException,
575+
InvalidPlatformException, InvalidContainerVolumeException,
576+
IncompatibleBaseImageJavaVersionException, NumberFormatException,
577+
InvalidContainerizingModeException, InvalidFilesModificationTimeException,
578+
InvalidCreationTimeException {
579+
when(projectProperties.isWarProject()).thenReturn(true);
580+
when(rawConfiguration.getFromImage()).thenReturn(Optional.of("custom-base-image"));
581+
582+
BuildContext buildContext = getBuildContext(processCommonConfiguration());
583+
584+
assertThat(buildContext.getContainerConfiguration().getEntrypoint()).isNull();
585+
}
586+
571587
@Test
572588
public void testGetAppRootChecked() throws InvalidAppRootException {
573589
when(rawConfiguration.getAppRoot()).thenReturn("/some/root");

0 commit comments

Comments
 (0)