diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/OciIndexTemplate.java b/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/OciIndexTemplate.java index 6eeffaf4da..1ca6529143 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/OciIndexTemplate.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/OciIndexTemplate.java @@ -125,6 +125,7 @@ public List getDigestsForPlatform(String architecture, String os) { * href="https://github.com/opencontainers/image-spec/blob/main/image-index.md">OCI Image Index * Specification */ + @JsonIgnoreProperties(ignoreUnknown = true) public static class ManifestDescriptorTemplate extends BuildableManifestTemplate.ContentDescriptorTemplate { diff --git a/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/V22ManifestListTemplate.java b/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/V22ManifestListTemplate.java index 3293587f91..e8e08def02 100644 --- a/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/V22ManifestListTemplate.java +++ b/jib-core/src/main/java/com/google/cloud/tools/jib/image/json/V22ManifestListTemplate.java @@ -114,6 +114,7 @@ public List getDigestsForPlatform(String architecture, String os) { } /** Template for inner JSON object representing a single platform specific manifest. */ + @JsonIgnoreProperties(ignoreUnknown = true) public static class ManifestDescriptorTemplate implements JsonTemplate { @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/OciIndexTemplateTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/OciIndexTemplateTest.java index f95a064306..0bfacce149 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/OciIndexTemplateTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/image/json/OciIndexTemplateTest.java @@ -75,6 +75,27 @@ public void testFromJson() throws IOException, URISyntaxException, DigestExcepti Assert.assertEquals(1000, manifest.getSize()); } + @Test + public void testFromJsonWithUnknownProperties() + throws IOException, URISyntaxException, DigestException { + // Loads a JSON index whose manifest descriptors carry an OCI 1.1 "artifactType" field, which + // Jib does not model. Unknown descriptor properties must be ignored rather than fail parsing. + // https://github.com/GoogleContainerTools/jib/issues/4506 + Path jsonFile = + Paths.get(Resources.getResource("core/json/ociindex_artifacttype.json").toURI()); + + OciIndexTemplate ociIndexJson = + JsonTemplateMapper.readJsonFromFile(jsonFile, OciIndexTemplate.class); + + Assert.assertEquals(2, ociIndexJson.getManifests().size()); + Assert.assertEquals( + "sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f", + ociIndexJson.getDigestsForPlatform("amd64", "linux").get(0)); + Assert.assertEquals( + "sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270", + ociIndexJson.getDigestsForPlatform("arm64", "linux").get(0)); + } + @Test public void testToJsonWithPlatform() throws DigestException, IOException, URISyntaxException { // Loads the expected JSON string. diff --git a/jib-core/src/test/resources/core/json/ociindex_artifacttype.json b/jib-core/src/test/resources/core/json/ociindex_artifacttype.json new file mode 100644 index 0000000000..0895ce4deb --- /dev/null +++ b/jib-core/src/test/resources/core/json/ociindex_artifacttype.json @@ -0,0 +1,26 @@ +{ + "schemaVersion": 2, + "mediaType": "application/vnd.oci.image.index.v1+json", + "manifests": [ + { + "mediaType": "application/vnd.docker.distribution.manifest.v2+json", + "size": 1395, + "digest": "sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f", + "platform": { + "architecture": "amd64", + "os": "linux" + }, + "artifactType": "application/vnd.docker.container.image.v1+json" + }, + { + "mediaType": "application/vnd.docker.distribution.manifest.v2+json", + "size": 1395, + "digest": "sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270", + "platform": { + "architecture": "arm64", + "os": "linux" + }, + "artifactType": "application/vnd.docker.container.image.v1+json" + } + ] +} diff --git a/jib-core/src/test/resources/core/json/v22manifest_list.json b/jib-core/src/test/resources/core/json/v22manifest_list.json index a9df3947b0..cc6b82ff3b 100644 --- a/jib-core/src/test/resources/core/json/v22manifest_list.json +++ b/jib-core/src/test/resources/core/json/v22manifest_list.json @@ -9,7 +9,8 @@ "platform": { "architecture": "ppc64le", "os": "linux" - } + }, + "artifactType": "application/vnd.docker.container.image.v1+json" }, { "mediaType": "application/vnd.docker.image.manifest.v2+json",