From 3072be5cf8411885cc8803290aaa6db434dae8c2 Mon Sep 17 00:00:00 2001 From: Mridula <66699525+mpeddada1@users.noreply.github.com> Date: Tue, 26 Mar 2024 12:58:33 -0400 Subject: [PATCH] fix: modify default entrypoint for WAR containerization to be compatible with Jetty 12+ (#4216) * fix: modify default entrypoint for WAR containerization to be compatible with Jetty 12+ --- docs/faq.md | 2 +- jib-cli/CHANGELOG.md | 2 ++ jib-cli/README.md | 2 +- .../java/com/google/cloud/tools/jib/cli/war/WarFiles.java | 5 ++++- .../com/google/cloud/tools/jib/cli/war/WarFilesTest.java | 2 +- jib-gradle-plugin/CHANGELOG.md | 2 +- jib-maven-plugin/CHANGELOG.md | 1 + .../jib/plugins/common/PluginConfigurationProcessor.java | 5 +++-- .../plugins/common/PluginConfigurationProcessorTest.java | 6 +++--- 9 files changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index 85fcffea4b..273854ead9 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -901,7 +901,7 @@ The `war` command currently supports containerization of standard WARs. It uses * Resources Layer * Classes Layer -The default entrypoint when using a jetty base image will be `java -jar /usr/local/jetty/start.jar` unless you choose to specify a custom one. +The default entrypoint when using a jetty base image will be `java -jar /usr/local/jetty/start.jar --module=ee10-deploy` unless you choose to specify a custom one. You can use a different Servlet engine base image with the help of the `--from` option and customize `--app-root`, `--entrypoint` and `--program-args`. If you don't set the `entrypoint` or `program-arguments`, Jib will inherit them from the base image. However, setting the `--app-root` is **required** if you use a non-jetty base image. Here is how the `war` command may look if you're using a Tomcat image: ``` diff --git a/jib-cli/CHANGELOG.md b/jib-cli/CHANGELOG.md index 9fe7f1ef02..f151775b8b 100644 --- a/jib-cli/CHANGELOG.md +++ b/jib-cli/CHANGELOG.md @@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file. ### Changed ### Fixed +- fix: support parsing manifest JSON containing `LayerSources:` from latest Docker. ([#4171](https://github.com/GoogleContainerTools/jib/pull/4171)) +- fix: (WAR Containerization) modify default entrypoint to `java -jar /usr/local/jetty/start.jar --module=ee10-deploy` for Jetty 12+ compatibility ([#4216](https://github.com/GoogleContainerTools/jib/pull/4216)) ## 0.12.0 diff --git a/jib-cli/README.md b/jib-cli/README.md index acac5505a4..47a9ac42da 100644 --- a/jib-cli/README.md +++ b/jib-cli/README.md @@ -190,7 +190,7 @@ This command follows the following pattern: ## Quickstart -1. Have your sample WAR ready and use the `war` command to containerize your WAR. By default, the WAR command uses [`jetty`](https://hub.docker.com/_/jetty) as the base image so the entrypoint is set to `java -jar /usr/local/jetty/start.jar`: +1. Have your sample WAR ready and use the `war` command to containerize your WAR. By default, the WAR command uses [`jetty`](https://hub.docker.com/_/jetty) as the base image so the entrypoint is set to `java -jar /usr/local/jetty/start.jar --module=ee10-deploy`: ``` $ jib war --target=docker://cli-war-quickstart .war ``` diff --git a/jib-cli/src/main/java/com/google/cloud/tools/jib/cli/war/WarFiles.java b/jib-cli/src/main/java/com/google/cloud/tools/jib/cli/war/WarFiles.java index a69d26a693..ee7830dfd2 100644 --- a/jib-cli/src/main/java/com/google/cloud/tools/jib/cli/war/WarFiles.java +++ b/jib-cli/src/main/java/com/google/cloud/tools/jib/cli/war/WarFiles.java @@ -81,7 +81,10 @@ private static List computeEntrypoint( return entrypoint; } if (commonContainerConfigCliOptions.isJettyBaseimage()) { - return ImmutableList.of("java", "-jar", "/usr/local/jetty/start.jar"); + // Since we are using Jetty 12 or later as the default, the deploy module needs to be + // specified. See + // https://eclipse.dev/jetty/documentation/jetty-12/operations-guide/index.html + return ImmutableList.of("java", "-jar", "/usr/local/jetty/start.jar", "--module=ee10-deploy"); } return null; } diff --git a/jib-cli/src/test/java/com/google/cloud/tools/jib/cli/war/WarFilesTest.java b/jib-cli/src/test/java/com/google/cloud/tools/jib/cli/war/WarFilesTest.java index 513d7bc559..5ad6ae139f 100644 --- a/jib-cli/src/test/java/com/google/cloud/tools/jib/cli/war/WarFilesTest.java +++ b/jib-cli/src/test/java/com/google/cloud/tools/jib/cli/war/WarFilesTest.java @@ -74,7 +74,7 @@ public void testToJibContainerBuilder_explodedStandard_basicInfo() assertThat(buildPlan.getBaseImage()).isEqualTo("jetty"); assertThat(buildPlan.getEntrypoint()) - .containsExactly("java", "-jar", "/usr/local/jetty/start.jar") + .containsExactly("java", "-jar", "/usr/local/jetty/start.jar", "--module=ee10-deploy") .inOrder(); assertThat(buildPlan.getLayers()).hasSize(1); assertThat(buildPlan.getLayers().get(0).getName()).isEqualTo("classes"); diff --git a/jib-gradle-plugin/CHANGELOG.md b/jib-gradle-plugin/CHANGELOG.md index 4f4e323ea9..0f5cfb9371 100644 --- a/jib-gradle-plugin/CHANGELOG.md +++ b/jib-gradle-plugin/CHANGELOG.md @@ -11,7 +11,7 @@ All notable changes to this project will be documented in this file. ### Fixed - fix: image builds should become reproducible once again ([#4204](https://github.com/GoogleContainerTools/jib/pull/4204)) - +- fix: (WAR Containerization) modify default entrypoint to `java -jar /usr/local/jetty/start.jar --module=ee10-deploy` for Jetty 12+ compatibility ([#4216](https://github.com/GoogleContainerTools/jib/pull/4216)) ## 3.4.1 diff --git a/jib-maven-plugin/CHANGELOG.md b/jib-maven-plugin/CHANGELOG.md index a39c7f1414..a1f5ff8b60 100644 --- a/jib-maven-plugin/CHANGELOG.md +++ b/jib-maven-plugin/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. ### Fixed - fix: image builds should become reproducible once again ([#4204](https://github.com/GoogleContainerTools/jib/pull/4204)) +- fix: (WAR Containerization) modify default entrypoint to `java -jar /usr/local/jetty/start.jar --module=ee10-deploy` for Jetty 12+ compatibility ([#4216](https://github.com/GoogleContainerTools/jib/pull/4216)) ## 3.4.1 diff --git a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java index f5b8f1f7d1..8ac4001db5 100644 --- a/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java +++ b/jib-plugins-common/src/main/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessor.java @@ -569,7 +569,8 @@ static JavaContainerBuilder getJavaContainerBuilderWithBaseImage( *
  • null (inheriting from the base image), if the user specified value is {@code INHERIT} *
  • the user specified one, if set *
  • for a WAR project, null (inheriting) if a custom base image is specified, and {@code - * ["java", "-jar", "/usr/local/jetty/start.jar"]} otherwise (default Jetty base image) + * ["java", "-jar", "/usr/local/jetty/start.jar", "--module=ee10-deploy"]} otherwise + * (default Jetty base image) *
  • for a non-WAR project, by resolving the main class * * @@ -622,7 +623,7 @@ static List computeEntrypoint( } return rawConfiguration.getFromImage().isPresent() ? null // Inherit if a custom base image. - : Arrays.asList("java", "-jar", "/usr/local/jetty/start.jar"); + : Arrays.asList("java", "-jar", "/usr/local/jetty/start.jar", "--module=ee10-deploy"); } List classpath = new ArrayList<>(rawExtraClasspath); diff --git a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java index cfb181a85c..51404d1351 100644 --- a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java +++ b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/PluginConfigurationProcessorTest.java @@ -474,7 +474,7 @@ public void testEntrypoint_defaultWarPackaging() ContainerBuildPlan buildPlan = processCommonConfiguration(); assertThat(buildPlan.getEntrypoint()) - .containsExactly("java", "-jar", "/usr/local/jetty/start.jar") + .containsExactly("java", "-jar", "/usr/local/jetty/start.jar", "--module=ee10-deploy") .inOrder(); verifyNoInteractions(logger); } @@ -704,7 +704,7 @@ public void testEntrypoint_warningOnMainclassForWar() ContainerBuildPlan buildPlan = processCommonConfiguration(); assertThat(buildPlan.getEntrypoint()) - .containsExactly("java", "-jar", "/usr/local/jetty/start.jar") + .containsExactly("java", "-jar", "/usr/local/jetty/start.jar", "--module=ee10-deploy") .inOrder(); verify(projectProperties) .log( @@ -726,7 +726,7 @@ public void testEntrypoint_warningOnExpandClasspathDependenciesForWar() ContainerBuildPlan buildPlan = processCommonConfiguration(); assertThat(buildPlan.getEntrypoint()) - .containsExactly("java", "-jar", "/usr/local/jetty/start.jar") + .containsExactly("java", "-jar", "/usr/local/jetty/start.jar", "--module=ee10-deploy") .inOrder(); verify(projectProperties) .log(