Skip to content

Commit

Permalink
fix: modify default entrypoint for WAR containerization to be compati…
Browse files Browse the repository at this point in the history
…ble with Jetty 12+
  • Loading branch information
mpeddada1 committed Mar 22, 2024
1 parent fb34ae4 commit 1d473f4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand Down
2 changes: 1 addition & 1 deletion jib-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <your-sample>.war
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static JibContainerBuilder toJibContainerBuilder(
CommonContainerConfigCliOptions commonContainerConfigCliOptions,
ConsoleLogger logger)
throws IOException, InvalidImageReferenceException {
String baseImage = commonContainerConfigCliOptions.getFrom().orElse("jetty");
String baseImage = fetchBaseImage(commonContainerConfigCliOptions);
JibContainerBuilder containerBuilder =
ContainerBuilders.create(baseImage, Collections.emptySet(), commonCliOptions, logger);
List<String> programArguments = commonContainerConfigCliOptions.getProgramArguments();
Expand All @@ -77,12 +77,24 @@ private static List<String> computeEntrypoint(
CommonContainerConfigCliOptions commonContainerConfigCliOptions)
throws InvalidImageReferenceException {
List<String> entrypoint = commonContainerConfigCliOptions.getEntrypoint();
String baseImage = fetchBaseImage(commonContainerConfigCliOptions);
if (!entrypoint.isEmpty()) {
return entrypoint;
}
if (commonContainerConfigCliOptions.isJettyBaseimage()) {
// If using jetty 12 or later, then specify deploy module. See
// https://eclipse.dev/jetty/documentation/jetty-12/operations-guide/index.html
if (baseImage.equals("jetty")) {
return ImmutableList.of(
"java", "-jar", "/usr/local/jetty/start.jar", "--module=ee10-deploy");
}
return ImmutableList.of("java", "-jar", "/usr/local/jetty/start.jar");
}
return null;
}

private static String fetchBaseImage(
CommonContainerConfigCliOptions commonContainerConfigCliOptions) {
return commonContainerConfigCliOptions.getFrom().orElse("jetty");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,8 @@ static JavaContainerBuilder getJavaContainerBuilderWithBaseImage(
* <li>null (inheriting from the base image), if the user specified value is {@code INHERIT}
* <li>the user specified one, if set
* <li>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)
* <li>for a non-WAR project, by resolving the main class
* </ol>
*
Expand Down Expand Up @@ -619,7 +620,7 @@ static List<String> 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<String> classpath = new ArrayList<>(rawExtraClasspath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 1d473f4

Please sign in to comment.