From f36e905fcc353037d8685c2feae11232e37fcbe8 Mon Sep 17 00:00:00 2001 From: Chanseok Oh Date: Tue, 16 Apr 2019 12:24:01 -0400 Subject: [PATCH] Reverse manifest V21 layers when adding (#1633) --- jib-core/CHANGELOG.md | 4 ++++ .../tools/jib/image/json/JsonToImageTranslator.java | 4 +++- .../jib/image/json/JsonToImageTranslatorTest.java | 8 ++++++-- .../src/test/resources/core/json/v21manifest.json | 12 +++++++++++- jib-gradle-plugin/CHANGELOG.md | 4 ++++ jib-maven-plugin/CHANGELOG.md | 5 +++++ 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/jib-core/CHANGELOG.md b/jib-core/CHANGELOG.md index 6cf0b1c358..ad878877da 100644 --- a/jib-core/CHANGELOG.md +++ b/jib-core/CHANGELOG.md @@ -13,6 +13,8 @@ All notable changes to this project will be documented in this file. ### Fixed +- Fixed an issue where the library creates wrong images by adding base image layers in reverse order when registry uses the old V2 image manifest, schema version 1 (such as Quay) ([#1627](https://github.com/GoogleContainerTools/jib/issues/1627)) + ## 0.9.0 ### Added @@ -22,10 +24,12 @@ All notable changes to this project will be documented in this file. - Methods in `JavaContainerBuilder` for setting the destination directories for classes, resources, directories, and additional classpath files ### Changed + - Allow skipping `JavaContainerBuilder#setMainClass()` to skip setting the entrypoint - `os` and `architecture` are taken from base image ([#1564](https://github.com/GoogleContainerTools/jib/pull/1564)) ### Fixed + - `ImageReference` assumes `registry-1.docker.io` as the registry if the host part of an image reference is `docker.io` ([#1549](https://github.com/GoogleContainerTools/jib/issues/1549)) ## 0.1.2 diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslator.java b/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslator.java index ac1e8e193e..56b792d4c3 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslator.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslator.java @@ -30,6 +30,7 @@ import com.google.cloud.tools.jib.image.ReferenceNoDiffIdLayer; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; import java.time.Duration; import java.time.Instant; import java.time.format.DateTimeParseException; @@ -72,7 +73,8 @@ public static Image toImage(V21ManifestTemplate manifestTemplate) throws LayerPropertyNotFoundException { Image.Builder imageBuilder = Image.builder(V21ManifestTemplate.class); - for (DescriptorDigest digest : manifestTemplate.getLayerDigests()) { + // V21 layers are in reverse order of V22. (The first layer is the latest one.) + for (DescriptorDigest digest : Lists.reverse(manifestTemplate.getLayerDigests())) { imageBuilder.addLayer(new DigestOnlyLayer(digest)); } diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslatorTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslatorTest.java index 7eea1d466e..1cd9465d63 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslatorTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/JsonToImageTranslatorTest.java @@ -59,11 +59,15 @@ public void testToImage_v21() Image image = JsonToImageTranslator.toImage(manifestTemplate); List layers = image.getLayers(); - Assert.assertEquals(1, layers.size()); + Assert.assertEquals(2, layers.size()); Assert.assertEquals( DescriptorDigest.fromDigest( - "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"), + "sha256:5bd451067f9ab05e97cda8476c82f86d9b69c2dffb60a8ad2fe3723942544ab3"), layers.get(0).getBlobDescriptor().getDigest()); + Assert.assertEquals( + DescriptorDigest.fromDigest( + "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"), + layers.get(1).getBlobDescriptor().getDigest()); } @Test diff --git a/jib-core/src/test/resources/core/json/v21manifest.json b/jib-core/src/test/resources/core/json/v21manifest.json index 4eaa389cf8..1eef70beb3 100644 --- a/jib-core/src/test/resources/core/json/v21manifest.json +++ b/jib-core/src/test/resources/core/json/v21manifest.json @@ -1 +1,11 @@ -{"schemaVersion":1,"fsLayers":[{"blobSum":"sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"}],"history":[{"v1Compatibility":"some v1-compatible object"}]} \ No newline at end of file +{ + "schemaVersion":1, + "fsLayers": [ + {"blobSum":"sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"}, + {"blobSum":"sha256:5bd451067f9ab05e97cda8476c82f86d9b69c2dffb60a8ad2fe3723942544ab3"} + ], + "history": [ + {"v1Compatibility":"some v1-compatible object"}, + {"v1Compatibility":"another v1-compatible object"} + ] +} diff --git a/jib-gradle-plugin/CHANGELOG.md b/jib-gradle-plugin/CHANGELOG.md index 208621a401..b2f12a7484 100644 --- a/jib-gradle-plugin/CHANGELOG.md +++ b/jib-gradle-plugin/CHANGELOG.md @@ -9,12 +9,16 @@ All notable changes to this project will be documented in this file. ### Fixed +- Fixed an issue where the plugin creates wrong images by adding base image layers in reverse order when registry uses the old V2 image manifest, schema version 1 (such as Quay) ([#1627](https://github.com/GoogleContainerTools/jib/issues/1627)) + ## 1.1.0 ### Changed + - `os` and `architecture` are taken from base image ([#1564](https://github.com/GoogleContainerTools/jib/pull/1564)) ### Fixed + - Fixed an issue where pushing to Docker Hub fails when the host part of an image reference is `docker.io` ([#1549](https://github.com/GoogleContainerTools/jib/issues/1549)) ## 1.0.2 diff --git a/jib-maven-plugin/CHANGELOG.md b/jib-maven-plugin/CHANGELOG.md index a11bcfdeee..a452b378fe 100644 --- a/jib-maven-plugin/CHANGELOG.md +++ b/jib-maven-plugin/CHANGELOG.md @@ -9,15 +9,20 @@ All notable changes to this project will be documented in this file. ### Fixed +- Fixed an issue where the plugin creates wrong images by adding base image layers in reverse order when registry uses the old V2 image manifest, schema version 1 (such as Quay) ([#1627](https://github.com/GoogleContainerTools/jib/issues/1627)) + ## 1.1.0 ### Added + - Can now decrypt proxy configurations in `settings.xml`. ([#1369](https://github.com/GoogleContainerTools/jib/issues/1369)) ### Changed + - `os` and `architecture` are taken from base image ([#1564](https://github.com/GoogleContainerTools/jib/pull/1564)) ### Fixed + - Fixed an issue where pushing to Docker Hub fails when the host part of an image reference is `docker.io` ([#1549](https://github.com/GoogleContainerTools/jib/issues/1549)) ## 1.0.2