Skip to content

Commit bf22096

Browse files
committed
Issue #4506: ignore unknown "artifactType" field in manifest descriptors
1 parent 6a851b6 commit bf22096

5 files changed

Lines changed: 51 additions & 1 deletion

File tree

jib-core/src/main/java/com/google/cloud/tools/jib/image/json/OciIndexTemplate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public List<String> getDigestsForPlatform(String architecture, String os) {
125125
* href="https://github.com/opencontainers/image-spec/blob/main/image-index.md">OCI Image Index
126126
* Specification</a>
127127
*/
128+
@JsonIgnoreProperties(ignoreUnknown = true)
128129
public static class ManifestDescriptorTemplate
129130
extends BuildableManifestTemplate.ContentDescriptorTemplate {
130131

jib-core/src/main/java/com/google/cloud/tools/jib/image/json/V22ManifestListTemplate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public List<String> getDigestsForPlatform(String architecture, String os) {
114114
}
115115

116116
/** Template for inner JSON object representing a single platform specific manifest. */
117+
@JsonIgnoreProperties(ignoreUnknown = true)
117118
public static class ManifestDescriptorTemplate implements JsonTemplate {
118119

119120
@JsonIgnoreProperties(ignoreUnknown = true)

jib-core/src/test/java/com/google/cloud/tools/jib/image/json/OciIndexTemplateTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ public void testFromJson() throws IOException, URISyntaxException, DigestExcepti
7575
Assert.assertEquals(1000, manifest.getSize());
7676
}
7777

78+
@Test
79+
public void testFromJsonWithUnknownProperties()
80+
throws IOException, URISyntaxException, DigestException {
81+
// Loads a JSON index whose manifest descriptors carry an OCI 1.1 "artifactType" field, which
82+
// Jib does not model. Unknown descriptor properties must be ignored rather than fail parsing.
83+
// https://github.com/GoogleContainerTools/jib/issues/4506
84+
Path jsonFile =
85+
Paths.get(Resources.getResource("core/json/ociindex_artifacttype.json").toURI());
86+
87+
OciIndexTemplate ociIndexJson =
88+
JsonTemplateMapper.readJsonFromFile(jsonFile, OciIndexTemplate.class);
89+
90+
Assert.assertEquals(2, ociIndexJson.getManifests().size());
91+
Assert.assertEquals(
92+
"sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f",
93+
ociIndexJson.getDigestsForPlatform("amd64", "linux").get(0));
94+
Assert.assertEquals(
95+
"sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270",
96+
ociIndexJson.getDigestsForPlatform("arm64", "linux").get(0));
97+
}
98+
7899
@Test
79100
public void testToJsonWithPlatform() throws DigestException, IOException, URISyntaxException {
80101
// Loads the expected JSON string.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"schemaVersion": 2,
3+
"mediaType": "application/vnd.oci.image.index.v1+json",
4+
"manifests": [
5+
{
6+
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
7+
"size": 1395,
8+
"digest": "sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f",
9+
"platform": {
10+
"architecture": "amd64",
11+
"os": "linux"
12+
},
13+
"artifactType": "application/vnd.docker.container.image.v1+json"
14+
},
15+
{
16+
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
17+
"size": 1395,
18+
"digest": "sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270",
19+
"platform": {
20+
"architecture": "arm64",
21+
"os": "linux"
22+
},
23+
"artifactType": "application/vnd.docker.container.image.v1+json"
24+
}
25+
]
26+
}

jib-core/src/test/resources/core/json/v22manifest_list.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"platform": {
1010
"architecture": "ppc64le",
1111
"os": "linux"
12-
}
12+
},
13+
"artifactType": "application/vnd.docker.container.image.v1+json"
1314
},
1415
{
1516
"mediaType": "application/vnd.docker.image.manifest.v2+json",

0 commit comments

Comments
 (0)