@@ -33,7 +33,9 @@ type Validator string
3333type validateDescendantsFunc func (r io.Reader ) error
3434
3535var mapValidateDescendants = map [Validator ]validateDescendantsFunc {
36- MediaTypeManifest : validateManifestDescendants ,
36+ MediaTypeImageConfig : validateConfigDescendants ,
37+ MediaTypeManifest : validateManifestDescendants ,
38+ MediaTypeManifestList : validateManifestListDescendants ,
3739}
3840
3941// ValidationError contains all the errors that happened during validation.
@@ -117,3 +119,65 @@ func validateManifestDescendants(r io.Reader) error {
117119 }
118120 return nil
119121}
122+
123+ func validateManifestListDescendants (r io.Reader ) error {
124+ header := v1.ManifestList {}
125+
126+ buf , err := ioutil .ReadAll (r )
127+ if err != nil {
128+ return errors .Wrapf (err , "error reading the io stream" )
129+ }
130+
131+ err = json .Unmarshal (buf , & header )
132+ if err != nil {
133+ return errors .Wrap (err , "manifestlist format mismatch" )
134+ }
135+
136+ for _ , manifest := range header .Manifests {
137+ checkPlatform (manifest .Platform .OS , manifest .Platform .Architecture )
138+ }
139+ return nil
140+ }
141+
142+ func validateConfigDescendants (r io.Reader ) error {
143+ header := v1.Image {}
144+
145+ buf , err := ioutil .ReadAll (r )
146+ if err != nil {
147+ return errors .Wrapf (err , "error reading the io stream" )
148+ }
149+
150+ err = json .Unmarshal (buf , & header )
151+ if err != nil {
152+ return errors .Wrap (err , "config format mismatch" )
153+ }
154+
155+ checkPlatform (header .OS , header .Architecture )
156+
157+ return nil
158+ }
159+
160+ func checkPlatform (OS string , Architecture string ) {
161+ validCombins := map [string ][]string {
162+ "android" : {"arm" },
163+ "darwin" : {"386" , "amd64" , "arm" , "arm64" },
164+ "dragonfly" : {"amd64" },
165+ "freebsd" : {"386" , "amd64" , "arm" },
166+ "linux" : {"386" , "amd64" , "arm" , "arm64" , "ppc64" , "ppc64le" , "mips64" , "mips64le" , "s390x" },
167+ "netbsd" : {"386" , "amd64" , "arm" },
168+ "openbsd" : {"386" , "amd64" , "arm" },
169+ "plan9" : {"386" , "amd64" },
170+ "solaris" : {"amd64" },
171+ "windows" : {"386" , "amd64" }}
172+ for os , archs := range validCombins {
173+ if os == OS {
174+ for _ , arch := range archs {
175+ if arch == Architecture {
176+ break
177+ }
178+ }
179+ fmt .Printf ("waring: combination of %q and %q is invalid." , OS , Architecture )
180+ }
181+ }
182+ fmt .Printf ("waring: operation system %q of the bundle is not supported yet." , OS )
183+ }
0 commit comments