@@ -87,3 +87,53 @@ def sort_manifests:
87
87
sort_by (.platform | sort_split_platform )
88
88
| sort_attestations
89
89
;
90
+
91
+ # https://github.com/opencontainers/image-spec/blob/v1.1.0/image-index.md
92
+
93
+ def validate_oci_index_media_type :
94
+ if . != "application/vnd.oci.image.index.v1+json" then
95
+ error ("unsupported index mediaType: \( . ) " )
96
+ else . end
97
+ ;
98
+
99
+ def validate_oci_index :
100
+ if .schemaVersion != 2 then
101
+ error ("unsupported index schemaVersion: \( .schemaVersion ) " )
102
+ else . end
103
+ | .mediaType |= if . then # TODO drop this conditional (BuildKit 0.14+): https://github.com/moby/buildkit/issues/4595
104
+ validate_oci_index_media_type
105
+ else . end
106
+ ;
107
+
108
+ # https://github.com/opencontainers/image-spec/blob/v1.1.0/image-layout.md#oci-layout-file
109
+ def validate_oci_layout_file :
110
+ if .imageLayoutVersion != "1.0.0" then
111
+ error ("unsupported imageLayoutVersion: \( .imageLayoutVersion ) " )
112
+ else . end
113
+ ;
114
+
115
+ # https://github.com/opencontainers/image-spec/blob/v1.1.0/image-layout.md#indexjson-file
116
+ def validate_oci_layout_index :
117
+ validate_oci_index
118
+ | .manifests |= (
119
+ if length != 1 then
120
+ error ("expected only one manifests entry, not \( length ) " )
121
+ else . end
122
+ | . [0 ] |= (
123
+ if .size < 0 then
124
+ error ("invalid descriptor size: \( .size ) " )
125
+ else . end
126
+ # TODO validate .digest somehow (`crane validate`?) - would also be good to validate all descriptors recursively
127
+ | .mediaType |= validate_oci_index_media_type
128
+ )
129
+ )
130
+ ;
131
+
132
+ # input: array of 'oci-layout' file contents followed by 'index.json' file contents (`jq -s 'validate_oci_layout' dir/oci-layout dir/index.json`)
133
+ def validate_oci_layout :
134
+ if length != 2 then
135
+ error ("unexpected input: expecting single-document 'oci-layout' and 'index.json'" )
136
+ else . end
137
+ | . [0 ] |= validate_oci_layout_file
138
+ | . [1 ] |= validate_oci_layout_index
139
+ ;
0 commit comments