Skip to content

Commit

Permalink
Change default base images from AdoptOpenJDK to Eclipse Adoptium Ecli…
Browse files Browse the repository at this point in the history
…pse Temurin (for Java 8 and 11) and use Azul Zulu (for Java 17) (GoogleContainerTools#3491)

* Change default base images to Eclipse Temurin
* Add Zulu 17 as another base image
* Update CHANGELOGs
* Add integration test
* Refactor test code
* Migrate tests to Truth
  • Loading branch information
chanseokoh authored Nov 9, 2021
1 parent 2de13f5 commit 86a3c85
Show file tree
Hide file tree
Showing 22 changed files with 291 additions and 291 deletions.
1 change: 1 addition & 0 deletions jib-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
### Changed

- Downgraded Google HTTP libraries to 1.34.0 to resolve network issues. ([#3415](https://github.com/GoogleContainerTools/jib/pull/3415), [#3058](https://github.com/GoogleContainerTools/jib/issues/3058), [#3409](https://github.com/GoogleContainerTools/jib/issues/3409))
- Changed the default base image of the Jib CLI `jar` command from the `adoptopenjdk` images to the [`eclipse-temurin`](https://hub.docker.com/_/eclipse-temurin) (for Java 8 and 11) and [`azul/zulu-openjdk`](https://hub.docker.com/r/azul/zulu-openjdk) (for Java 17) images on Docker Hub. Note that Temurin (by Adoptium) is the new name of AdoptOpenJDK. ([#3491](https://github.com/GoogleContainerTools/jib/pull/3491))

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ public static ArtifactProcessor fromJar(
CommonContainerConfigCliOptions commonContainerConfigCliOptions)
throws IOException {
Integer jarJavaVersion = determineJavaMajorVersion(jarPath);
if (jarJavaVersion > 11 && !commonContainerConfigCliOptions.getFrom().isPresent()) {
if (jarJavaVersion > 17 && !commonContainerConfigCliOptions.getFrom().isPresent()) {
throw new IllegalStateException(
"The input JAR ("
+ jarPath
+ ") is compiled with Java "
+ jarJavaVersion
+ ", but the default base image only supports versions up to Java 11. Specify a custom base image with --from.");
String.format(
"The input JAR (%s) is compiled with Java %d, but the default base image only "
+ "supports versions up to Java 17. Specify a custom base image with --from.",
jarPath, jarJavaVersion));
}
String jarType = determineJarType(jarPath);
ProcessingMode mode = jarOptions.getMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/** Class to build a container representation from the contents of a jar file. */
public class JarFiles {
Expand Down Expand Up @@ -56,22 +55,10 @@ public static JibContainerBuilder toJibContainerBuilder(
CommonContainerConfigCliOptions commonContainerConfigCliOptions,
ConsoleLogger logger)
throws IOException, InvalidImageReferenceException {

// Use AdoptOpenJDK image as the default base image.
JibContainerBuilder containerBuilder;
Optional<String> imageReference = commonContainerConfigCliOptions.getFrom();
if (imageReference.isPresent()) {
containerBuilder =
ContainerBuilders.create(
imageReference.get(), Collections.emptySet(), commonCliOptions, logger);
} else {
containerBuilder =
(processor.getJavaVersion() <= 8)
? ContainerBuilders.create(
"adoptopenjdk:8-jre", Collections.emptySet(), commonCliOptions, logger)
: ContainerBuilders.create(
"adoptopenjdk:11-jre", Collections.emptySet(), commonCliOptions, logger);
}
String imageReference =
commonContainerConfigCliOptions.getFrom().orElseGet(() -> getDefaultBaseImage(processor));
JibContainerBuilder containerBuilder =
ContainerBuilders.create(imageReference, Collections.emptySet(), commonCliOptions, logger);

List<FileEntriesLayer> layers = processor.createLayers();
List<String> customEntrypoint = commonContainerConfigCliOptions.getEntrypoint();
Expand All @@ -94,4 +81,14 @@ public static JibContainerBuilder toJibContainerBuilder(

return containerBuilder;
}

private static String getDefaultBaseImage(ArtifactProcessor processor) {
if (processor.getJavaVersion() <= 8) {
return "eclipse-temurin:8-jre";
}
if (processor.getJavaVersion() <= 11) {
return "eclipse-temurin:11-jre";
}
return "azul/zulu-openjdk:17-jre";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ArtifactProcessorsTest {
private static final String STANDARD_WITH_INVALID_CLASS = "jar/standard/jarWithInvalidClass.jar";
private static final String STANDARD_WITH_EMPTY_CLASS_FILE =
"jar/standard/standardJarWithOnlyClasses.jar";
private static final String JAVA_14_JAR = "jar/java14WithModuleInfo.jar";
private static final String JAVA_18_JAR = "jar/java18.jar";

@Mock private CacheDirectories mockCacheDirectories;
@Mock private Jar mockJarCommand;
Expand Down Expand Up @@ -125,7 +125,7 @@ public void testFromJar_springBootExploded() throws IOException, URISyntaxExcept

@Test
public void testFromJar_incompatibleDefaultBaseImage() throws URISyntaxException {
Path jarPath = Paths.get(Resources.getResource(JAVA_14_JAR).toURI());
Path jarPath = Paths.get(Resources.getResource(JAVA_18_JAR).toURI());

IllegalStateException exception =
assertThrows(
Expand All @@ -139,13 +139,13 @@ public void testFromJar_incompatibleDefaultBaseImage() throws URISyntaxException

assertThat(exception)
.hasMessageThat()
.startsWith("The input JAR (" + jarPath + ") is compiled with Java 14");
.startsWith("The input JAR (" + jarPath + ") is compiled with Java 18");
}

@Test
public void testFromJar_incompatibleDefaultBaseImage_baseImageSpecified()
throws URISyntaxException, IOException {
Path jarPath = Paths.get(Resources.getResource(JAVA_14_JAR).toURI());
Path jarPath = Paths.get(Resources.getResource(JAVA_18_JAR).toURI());
when(mockJarCommand.getMode()).thenReturn(ProcessingMode.exploded);
when(mockCommonContainerConfigCliOptions.getFrom()).thenReturn(Optional.of("base-image"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public void testWriteImageJson()
throws InvalidImageReferenceException, IOException, DigestException {
String imageId = "sha256:61bb3ec31a47cb730eb58a38bbfa813761a51dca69d10e39c24c3d00a7b2c7a9";
String digest = "sha256:3f1be7e19129edb202c071a659a4db35280ab2bb1a16f223bfd5d1948657b6fc";
when(mockJibContainer.getTargetImage()).thenReturn(ImageReference.parse("adoptopenjdk:8-jre"));
when(mockJibContainer.getTargetImage())
.thenReturn(ImageReference.parse("eclipse-temurin:8-jre"));
when(mockJibContainer.getImageId()).thenReturn(DescriptorDigest.fromDigest(imageId));
when(mockJibContainer.getDigest()).thenReturn(DescriptorDigest.fromDigest(digest));
when(mockJibContainer.getTags()).thenReturn(ImmutableSet.of("latest", "tag-2"));
Expand All @@ -138,7 +139,7 @@ public void testWriteImageJson()
String outputJson = new String(Files.readAllBytes(outputPath), StandardCharsets.UTF_8);
ImageMetadataOutput metadataOutput =
JsonTemplateMapper.readJson(outputJson, ImageMetadataOutput.class);
assertThat(metadataOutput.getImage()).isEqualTo("adoptopenjdk:8-jre");
assertThat(metadataOutput.getImage()).isEqualTo("eclipse-temurin:8-jre");
assertThat(metadataOutput.getImageId()).isEqualTo(imageId);
assertThat(metadataOutput.getImageDigest()).isEqualTo(digest);
assertThat(metadataOutput.getTags()).containsExactly("latest", "tag-2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,51 +40,42 @@
import java.time.Instant;
import java.util.Arrays;
import java.util.Optional;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

/** Tests for {@link JarFiles}. */
@RunWith(MockitoJUnitRunner.class)
@RunWith(JUnitParamsRunner.class)
public class JarFilesTest {

@Mock private StandardExplodedProcessor mockStandardExplodedProcessor;
@Rule public final MockitoRule mockitoRule = MockitoJUnit.rule().silent();

@Mock private StandardExplodedProcessor mockStandardExplodedProcessor;
@Mock private StandardPackagedProcessor mockStandardPackagedProcessor;

@Mock private SpringBootExplodedProcessor mockSpringBootExplodedProcessor;

@Mock private SpringBootPackagedProcessor mockSpringBootPackagedProcessor;

@Mock private Jar mockJarCommand;

@Mock private CommonCliOptions mockCommonCliOptions;

@Mock private CommonContainerConfigCliOptions mockCommonContainerConfigCliOptions;

@Mock private ConsoleLogger mockLogger;

@Test
public void testToJibContainer_defaultBaseImage_java8()
throws IOException, InvalidImageReferenceException {
when(mockStandardExplodedProcessor.getJavaVersion()).thenReturn(8);
JibContainerBuilder containerBuilder =
JarFiles.toJibContainerBuilder(
mockStandardExplodedProcessor,
mockJarCommand,
mockCommonCliOptions,
mockCommonContainerConfigCliOptions,
mockLogger);
ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();

assertThat(buildPlan.getBaseImage()).isEqualTo("adoptopenjdk:8-jre");
}

@Test
public void testToJibContainer_defaultBaseImage_java9()
@Parameters(
value = {
"8, eclipse-temurin:8-jre",
"9, eclipse-temurin:11-jre",
"11, eclipse-temurin:11-jre",
"13, azul/zulu-openjdk:17-jre",
"17, azul/zulu-openjdk:17-jre",
})
public void testToJibContainer_defaultBaseImage(int javaVersion, String expectedBaseImage)
throws IOException, InvalidImageReferenceException {
when(mockStandardExplodedProcessor.getJavaVersion()).thenReturn(9);
when(mockStandardExplodedProcessor.getJavaVersion()).thenReturn(javaVersion);
JibContainerBuilder containerBuilder =
JarFiles.toJibContainerBuilder(
mockStandardExplodedProcessor,
Expand All @@ -94,7 +85,7 @@ public void testToJibContainer_defaultBaseImage_java9()
mockLogger);
ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();

assertThat(buildPlan.getBaseImage()).isEqualTo("adoptopenjdk:11-jre");
assertThat(buildPlan.getBaseImage()).isEqualTo(expectedBaseImage);
}

@Test
Expand Down Expand Up @@ -123,7 +114,7 @@ public void testToJibContainerBuilder_explodedStandard_basicInfo()
mockLogger);
ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();

assertThat(buildPlan.getBaseImage()).isEqualTo("adoptopenjdk:8-jre");
assertThat(buildPlan.getBaseImage()).isEqualTo("eclipse-temurin:8-jre");
assertThat(buildPlan.getPlatforms()).isEqualTo(ImmutableSet.of(new Platform("amd64", "linux")));
assertThat(buildPlan.getCreationTime()).isEqualTo(Instant.EPOCH);
assertThat(buildPlan.getFormat()).isEqualTo(ImageFormat.Docker);
Expand Down Expand Up @@ -172,7 +163,7 @@ public void testToJibContainerBuilder_packagedStandard_basicInfo()
mockLogger);
ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();

assertThat(buildPlan.getBaseImage()).isEqualTo("adoptopenjdk:8-jre");
assertThat(buildPlan.getBaseImage()).isEqualTo("eclipse-temurin:8-jre");
assertThat(buildPlan.getPlatforms()).isEqualTo(ImmutableSet.of(new Platform("amd64", "linux")));
assertThat(buildPlan.getCreationTime()).isEqualTo(Instant.EPOCH);
assertThat(buildPlan.getFormat()).isEqualTo(ImageFormat.Docker);
Expand Down Expand Up @@ -223,7 +214,7 @@ public void testToJibContainerBuilder_explodedLayeredSpringBoot_basicInfo()
mockLogger);
ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();

assertThat(buildPlan.getBaseImage()).isEqualTo("adoptopenjdk:8-jre");
assertThat(buildPlan.getBaseImage()).isEqualTo("eclipse-temurin:8-jre");
assertThat(buildPlan.getPlatforms()).isEqualTo(ImmutableSet.of(new Platform("amd64", "linux")));
assertThat(buildPlan.getCreationTime()).isEqualTo(Instant.EPOCH);
assertThat(buildPlan.getFormat()).isEqualTo(ImageFormat.Docker);
Expand Down Expand Up @@ -272,7 +263,7 @@ public void testToJibContainerBuilder_packagedSpringBoot_basicInfo()
mockLogger);
ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();

assertThat(buildPlan.getBaseImage()).isEqualTo("adoptopenjdk:8-jre");
assertThat(buildPlan.getBaseImage()).isEqualTo("eclipse-temurin:8-jre");
assertThat(buildPlan.getPlatforms()).isEqualTo(ImmutableSet.of(new Platform("amd64", "linux")));
assertThat(buildPlan.getCreationTime()).isEqualTo(Instant.EPOCH);
assertThat(buildPlan.getFormat()).isEqualTo(ImageFormat.Docker);
Expand Down
Binary file removed jib-cli/src/test/resources/jar/java14WithModuleInfo.jar
Binary file not shown.
Binary file added jib-cli/src/test/resources/jar/java18.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ Optional<ImagesAndRegistryClient> tryMirrors(
progressDispatcher1.newChildProducer().create("trying mirror " + mirror, 2)) {
RegistryClient registryClient =
buildContext.newBaseImageRegistryClientFactory(mirror).newRegistryClient();
List<Image> images = pullPublicImages(eventHandlers, registryClient, progressDispatcher2);
List<Image> images = pullPublicImages(registryClient, progressDispatcher2);
eventHandlers.dispatch(LogEvent.info("pulled manifest from mirror " + mirror));
return Optional.of(new ImagesAndRegistryClient(images, registryClient));

Expand All @@ -249,9 +249,7 @@ Optional<ImagesAndRegistryClient> tryMirrors(
}

private List<Image> pullPublicImages(
EventHandlers eventHandlers,
RegistryClient registryClient,
ProgressEventDispatcher progressDispatcher)
RegistryClient registryClient, ProgressEventDispatcher progressDispatcher)
throws IOException, RegistryException, LayerCountMismatchException,
BadContainerConfigurationFormatException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void test_basicCase() {
.call();
Assert.assertEquals("root", image.getUser());
Assert.assertEquals(
testDescriptorDigest, image.getLayers().asList().get(0).getBlobDescriptor().getDigest());
testDescriptorDigest, image.getLayers().get(0).getBlobDescriptor().getDigest());
}

@Test
Expand Down
2 changes: 2 additions & 0 deletions jib-gradle-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file.

### Changed

- Changed the default base image from the `adoptopenjdk` images to the [`eclipse-temurin`](https://hub.docker.com/_/eclipse-temurin) (for Java 8 and 11) and [`azul/zulu-openjdk`](https://hub.docker.com/r/azul/zulu-openjdk) (for Java 17) images on Docker Hub. Note that Temurin (by Adoptium) is the new name of AdoptOpenJDK. ([#3491](https://github.com/GoogleContainerTools/jib/pull/3491))

### Fixed

- Fixed `ClassCastException` when using non-`String` value (for example, [`Provider`](https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Provider.html)) for `Main-Class` manifest attribute of the `jar` task. ([#3396](https://github.com/GoogleContainerTools/jib/issues/3396))
Expand Down
Loading

0 comments on commit 86a3c85

Please sign in to comment.