diff --git a/image/config.go b/image/config.go index 100d99c..8d926fe 100644 --- a/image/config.go +++ b/image/config.go @@ -53,10 +53,6 @@ func findConfig(w walker, d *descriptor) (*config, error) { if err := json.Unmarshal(buf, &c); err != nil { return err } - // check if the rootfs type is 'layers' - if c.RootFS.Type != "layers" { - return fmt.Errorf("%q is an unknown rootfs type, MUST be 'layers'", c.RootFS.Type) - } return errEOW }); err { case nil: @@ -68,6 +64,44 @@ func findConfig(w walker, d *descriptor) (*config, error) { } } +func (c *config) validate() error { + + // check if the rootfs type is 'layers' + if c.RootFS.Type != "layers" { + return fmt.Errorf("%q is an unknown rootfs type, MUST be 'layers'", c.RootFS.Type) + } + + //check os and architecture + if err := c.checkPlatform(); err != nil { + return err + } + return nil +} + +func (c *config) checkPlatform() error { + validCombins := map[string][]string{ + "darwin": {"386", "amd64", "arm", "arm64"}, + "dragonfly": {"amd64"}, + "freebsd": {"386", "amd64", "arm"}, + "linux": {"386", "amd64", "arm", "arm64", "ppc64", "ppc64le", "mips64", "mips64le"}, + "netbsd": {"386", "amd64", "arm"}, + "openbsd": {"386", "amd64", "arm"}, + "plan9": {"386", "amd64"}, + "solaris": {"amd64"}, + "windows": {"386", "amd64"}} + for os, archs := range validCombins { + if os == c.OS { + for _, arch := range archs { + if arch == c.Architecture { + return nil + } + } + return fmt.Errorf("Combination of %q and %q is invalid.", c.OS, c.Architecture) + } + } + return fmt.Errorf("Operation system %q of the bundle is not supported yet.", c.OS) +} + func (c *config) runtimeSpec(rootfs string) (*specs.Spec, error) { if c.OS != "linux" { return nil, fmt.Errorf("%s: unsupported OS", c.OS) diff --git a/image/image.go b/image/image.go index 1551c1c..9fc0a6c 100644 --- a/image/image.go +++ b/image/image.go @@ -84,9 +84,19 @@ func validate(w walker, refs []string, out *log.Logger) error { return err } - if err := m.validate(w); err != nil { + if err = m.validate(w); err != nil { return err } + + c, err := findConfig(w, &m.Config) + if err != nil { + return err + } + + if err = c.validate(); err != nil { + return err + } + if out != nil { out.Printf("reference %q: OK", ref) } @@ -180,6 +190,10 @@ func createRuntimeBundle(w walker, dest, refName, rootfs string) error { return err } + if err = c.validate(); err != nil { + return err + } + err = m.unpack(w, filepath.Join(dest, rootfs)) if err != nil { return err