Skip to content

Commit dbd7d6c

Browse files
diegomarquezpML-Marco
authored andcommitted
feat: add default base image for Java 25 (GoogleContainerTools#4436)
* feat: add default base image for Java 25 * chore: change deprecated test manifest reference
1 parent 7418cbb commit dbd7d6c

File tree

8 files changed

+50
-26
lines changed

8 files changed

+50
-26
lines changed

docs/google-cloud-build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Any Java container can be used for building, not only the `gcr.io/cloud-builders
1313

1414
```yaml
1515
steps:
16-
- name: 'docker.io/library/eclipse-temurin:21'
16+
- name: 'docker.io/library/eclipse-temurin:25'
1717
entrypoint: './gradlew'
1818
args: ['--console=plain', '--no-daemon', ':server:jib', '-Djib.to.image=gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA']
1919
```

jib-cli/src/main/java/com/google/cloud/tools/jib/cli/jar/JarFiles.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ private static String getDefaultBaseImage(ArtifactProcessor processor) {
9292
if (processor.getJavaVersion() <= 17) {
9393
return "eclipse-temurin:17-jre";
9494
}
95-
return "eclipse-temurin:21-jre";
95+
if (processor.getJavaVersion() <= 21) {
96+
return "eclipse-temurin:21-jre";
97+
}
98+
return "eclipse-temurin:25-jre";
9699
}
97100
}

jib-cli/src/test/java/com/google/cloud/tools/jib/cli/jar/JarFilesTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public class JarFilesTest {
7373
"13, eclipse-temurin:17-jre",
7474
"17, eclipse-temurin:17-jre",
7575
"21, eclipse-temurin:21-jre",
76+
"25, eclipse-temurin:25-jre",
7677
})
7778
public void testToJibContainer_defaultBaseImage(int javaVersion, String expectedBaseImage)
7879
throws IOException, InvalidImageReferenceException {

jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/ContainerizerIntegrationTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,10 @@ public void testSteps_forBuildToDockerRegistry_skipExistingDigest()
278278
public void testBuildToDockerRegistry_dockerHubBaseImage()
279279
throws InvalidImageReferenceException, IOException, InterruptedException, ExecutionException,
280280
RegistryException, CacheDirectoryCreationException {
281+
// We use eclipse-temurin instead of openjdk due to its deprecation
282+
// see https://hub.docker.com/_/openjdk#deprecation-notice
281283
buildImage(
282-
ImageReference.parse("openjdk:8-jre-slim"),
284+
ImageReference.parse("eclipse-temurin:8-jre-alpine"),
283285
Containerizer.to(RegistryImage.named(dockerHost + ":5000/testimage:testtag")),
284286
Collections.emptyList());
285287

jib-gradle-plugin/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ Field | Type | Default | Description
210210

211211
<a name="from-closure"></a>`from` is a closure with the following properties:
212212

213-
Property | Type | Default | Description
214-
--- | --- | --- | ---
215-
`image` | `String` | `eclipse-temurin:{8,11,17,21}-jre` (or `jetty` for WAR) | The image reference for the base image. The source type can be specified using a [special type prefix](#setting-the-base-image).
216-
`auth` | [`auth`](#auth-closure) | *None* | Specifies credentials directly (alternative to `credHelper`).
217-
`credHelper` | `String` | *None* | Specifies a credential helper that can authenticate pulling the base image. This parameter can either be configured as an absolute path to the credential helper executable or as a credential helper suffix (following `docker-credential-`).
218-
`platforms` | [`platforms`](#platforms-closure) | See [`platforms`](#platforms-closure) | Configures platforms of base images to select from a manifest list.
213+
Property | Type | Default | Description
214+
--- | --- |------------------------------------------------------------| ---
215+
`image` | `String` | `eclipse-temurin:{8,11,17,21,25}-jre` (or `jetty` for WAR) | The image reference for the base image. The source type can be specified using a [special type prefix](#setting-the-base-image).
216+
`auth` | [`auth`](#auth-closure) | *None* | Specifies credentials directly (alternative to `credHelper`).
217+
`credHelper` | `String` | *None* | Specifies a credential helper that can authenticate pulling the base image. This parameter can either be configured as an absolute path to the credential helper executable or as a credential helper suffix (following `docker-credential-`).
218+
`platforms` | [`platforms`](#platforms-closure) | See [`platforms`](#platforms-closure) | Configures platforms of base images to select from a manifest list.
219219

220220
<a name="to-closure"></a>`to` is a closure with the following properties:
221221

jib-maven-plugin/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,12 @@ Field | Type | Default | Description
259259

260260
<a name="from-object"></a>`from` is an object with the following properties:
261261

262-
Property | Type | Default | Description
263-
--- | --- | --- | ---
264-
`image` | string | `eclipse-temurin:{8,11,17,21}-jre` (or `jetty` for WAR) | The image reference for the base image. The source type can be specified using a [special type prefix](#setting-the-base-image).
265-
`auth` | [`auth`](#auth-object) | *None* | Specifies credentials directly (alternative to `credHelper`).
266-
`credHelper` | string | *None* | Specifies a credential helper that can authenticate pulling the base image. This parameter can either be configured as an absolute path to the credential helper executable or as a credential helper suffix (following `docker-credential-`).
267-
`platforms` | list | See [`platform`](#platform-object) | Configures platforms of base images to select from a manifest list.
262+
Property | Type | Default | Description
263+
--- | --- |-----------------------------------------------------------| ---
264+
`image` | string | `eclipse-temurin:{8,11,17,21,25}-jre` (or `jetty` for WAR) | The image reference for the base image. The source type can be specified using a [special type prefix](#setting-the-base-image).
265+
`auth` | [`auth`](#auth-object) | *None* | Specifies credentials directly (alternative to `credHelper`).
266+
`credHelper` | string | *None* | Specifies a credential helper that can authenticate pulling the base image. This parameter can either be configured as an absolute path to the credential helper executable or as a credential helper suffix (following `docker-credential-`).
267+
`platforms` | list | See [`platform`](#platform-object) | Configures platforms of base images to select from a manifest list.
268268

269269
<a name="to-object"></a>`to` is an object with the following properties:
270270

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ static JavaContainerBuilder getJavaContainerBuilderWithBaseImage(
533533
if (isKnownJava21Image(prefixRemoved) && javaVersion > 21) {
534534
throw new IncompatibleBaseImageJavaVersionException(21, javaVersion);
535535
}
536+
if (isKnownJava25Image(prefixRemoved) && javaVersion > 25) {
537+
throw new IncompatibleBaseImageJavaVersionException(25, javaVersion);
538+
}
536539

537540
ImageReference baseImageReference = ImageReference.parse(prefixRemoved);
538541
if (baseImageConfig.startsWith(Jib.DOCKER_DAEMON_IMAGE_PREFIX)) {
@@ -778,8 +781,10 @@ static String getDefaultBaseImage(ProjectProperties projectProperties)
778781
return "eclipse-temurin:17-jre";
779782
} else if (javaVersion <= 21) {
780783
return "eclipse-temurin:21-jre";
784+
} else if (javaVersion <= 25) {
785+
return "eclipse-temurin:25-jre";
781786
}
782-
throw new IncompatibleBaseImageJavaVersionException(21, javaVersion);
787+
throw new IncompatibleBaseImageJavaVersionException(25, javaVersion);
783788
}
784789

785790
/**
@@ -1113,4 +1118,14 @@ private static boolean isKnownJava17Image(String imageReference) {
11131118
private static boolean isKnownJava21Image(String imageReference) {
11141119
return imageReference.startsWith("eclipse-temurin:21");
11151120
}
1121+
1122+
/**
1123+
* Checks if the given image is a known Java 25 image. May return false negative.
1124+
*
1125+
* @param imageReference the image reference
1126+
* @return {@code true} if the image is a known Java 25 image
1127+
*/
1128+
private static boolean isKnownJava25Image(String imageReference) {
1129+
return imageReference.startsWith("eclipse-temurin:25");
1130+
}
11161131
}

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,8 @@ public void testGetDefaultBaseImage_warProject()
904904
"11, eclipse-temurin:11-jre",
905905
"13, eclipse-temurin:17-jre",
906906
"17, eclipse-temurin:17-jre",
907-
"21, eclipse-temurin:21-jre"
907+
"21, eclipse-temurin:21-jre",
908+
"25, eclipse-temurin:25-jre"
908909
})
909910
public void testGetDefaultBaseImage_defaultJavaBaseImage(
910911
int javaVersion, String expectedBaseImage) throws IncompatibleBaseImageJavaVersionException {
@@ -914,16 +915,16 @@ public void testGetDefaultBaseImage_defaultJavaBaseImage(
914915
}
915916

916917
@Test
917-
public void testGetDefaultBaseImage_projectHigherThanJava21() {
918-
when(projectProperties.getMajorJavaVersion()).thenReturn(22);
918+
public void testGetDefaultBaseImage_projectHigherThanJava25() {
919+
when(projectProperties.getMajorJavaVersion()).thenReturn(26);
919920

920921
IncompatibleBaseImageJavaVersionException exception =
921922
assertThrows(
922923
IncompatibleBaseImageJavaVersionException.class,
923924
() -> PluginConfigurationProcessor.getDefaultBaseImage(projectProperties));
924925

925-
assertThat(exception.getBaseImageMajorJavaVersion()).isEqualTo(21);
926-
assertThat(exception.getProjectMajorJavaVersion()).isEqualTo(22);
926+
assertThat(exception.getBaseImageMajorJavaVersion()).isEqualTo(25);
927+
assertThat(exception.getProjectMajorJavaVersion()).isEqualTo(26);
927928
}
928929

929930
@Test
@@ -983,7 +984,9 @@ public void testGetJavaContainerBuilderWithBaseImage_registryWithPrefix()
983984
"eclipse-temurin:17, 17, 19",
984985
"eclipse-temurin:17-jre, 17, 19",
985986
"eclipse-temurin:21, 21, 22",
986-
"eclipse-temurin:21-jre, 21, 22"
987+
"eclipse-temurin:21-jre, 21, 22",
988+
"eclipse-temurin:25, 25, 26",
989+
"eclipse-temurin:25-jre, 25, 26"
987990
})
988991
public void testGetJavaContainerBuilderWithBaseImage_incompatibleJavaBaseImage(
989992
String baseImage, int baseImageJavaVersion, int appJavaVersion) {
@@ -1013,17 +1016,17 @@ public void testGetJavaContainerBuilderWithBaseImage_java12BaseImage()
10131016
}
10141017

10151018
@Test
1016-
public void testGetJavaContainerBuilderWithBaseImage_java22NoBaseImage() {
1017-
when(projectProperties.getMajorJavaVersion()).thenReturn(22);
1019+
public void testGetJavaContainerBuilderWithBaseImage_java26NoBaseImage() {
1020+
when(projectProperties.getMajorJavaVersion()).thenReturn(26);
10181021
when(rawConfiguration.getFromImage()).thenReturn(Optional.empty());
10191022
IncompatibleBaseImageJavaVersionException exception =
10201023
assertThrows(
10211024
IncompatibleBaseImageJavaVersionException.class,
10221025
() ->
10231026
PluginConfigurationProcessor.getJavaContainerBuilderWithBaseImage(
10241027
rawConfiguration, projectProperties, inferredAuthProvider));
1025-
assertThat(exception.getBaseImageMajorJavaVersion()).isEqualTo(21);
1026-
assertThat(exception.getProjectMajorJavaVersion()).isEqualTo(22);
1028+
assertThat(exception.getBaseImageMajorJavaVersion()).isEqualTo(25);
1029+
assertThat(exception.getProjectMajorJavaVersion()).isEqualTo(26);
10271030
}
10281031

10291032
@Test

0 commit comments

Comments
 (0)