Skip to content

Commit

Permalink
Check the validity of the platforms
Browse files Browse the repository at this point in the history
platforms can still be added but some warning message
will be emitted if the platform cannot pass the validity
check.

Signed-off-by: Dave Chen <dave.chen@arm.com>
  • Loading branch information
chendave committed Mar 14, 2019
1 parent c354108 commit a53fa2d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/buildkitd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,19 @@ func setDefaultConfig(cfg *config.Config) {

if cfg.Workers.OCI.Platforms == nil {
cfg.Workers.OCI.Platforms = binfmt_misc.SupportedPlatforms()
} else {
supported := binfmt_misc.ValidatePlatforms(cfg.Workers.OCI.Platforms)
if !supported {
logrus.Warn("provided platforms cannot pass the validation, please check the configuration on the 'binfmt_misc'")
}
}
if cfg.Workers.Containerd.Platforms == nil {
cfg.Workers.Containerd.Platforms = binfmt_misc.SupportedPlatforms()
} else {
supported := binfmt_misc.ValidatePlatforms(cfg.Workers.Containerd.Platforms)
if !supported {
logrus.Warn("provided platforms cannot pass the validation, please check the configuration on the 'binfmt_misc'")
}
}

if system.RunningInUserNS() {
Expand Down
5 changes: 5 additions & 0 deletions cmd/buildkitd/main_containerd_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

ctd "github.com/containerd/containerd"
"github.com/moby/buildkit/cmd/buildkitd/config"
"github.com/moby/buildkit/util/binfmt_misc"
"github.com/moby/buildkit/worker"
"github.com/moby/buildkit/worker/base"
"github.com/moby/buildkit/worker/containerd"
Expand Down Expand Up @@ -142,6 +143,10 @@ func applyContainerdFlags(c *cli.Context, cfg *config.Config) error {
}

if platforms := c.GlobalStringSlice("containerd-worker-platform"); len(platforms) != 0 {
supported := binfmt_misc.ValidatePlatforms(platforms)
if !supported {
logrus.Warn("provided platforms cannot pass the validation, please check the configuration on the 'binfmt_misc'")
}
cfg.Workers.Containerd.Platforms = platforms
}

Expand Down
5 changes: 5 additions & 0 deletions cmd/buildkitd/main_oci_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/containerd/containerd/snapshots/overlay"
"github.com/moby/buildkit/cmd/buildkitd/config"
"github.com/moby/buildkit/executor/oci"
"github.com/moby/buildkit/util/binfmt_misc"
"github.com/moby/buildkit/worker"
"github.com/moby/buildkit/worker/base"
"github.com/moby/buildkit/worker/runc"
Expand Down Expand Up @@ -142,6 +143,10 @@ func applyOCIFlags(c *cli.Context, cfg *config.Config) error {
}

if platforms := c.GlobalStringSlice("oci-worker-platform"); len(platforms) != 0 {
supported := binfmt_misc.ValidatePlatforms(platforms)
if !supported {
logrus.Warn("provided platforms cannot pass the validation, please check the configuration on the 'binfmt_misc'")
}
cfg.Workers.OCI.Platforms = platforms
}

Expand Down
19 changes: 19 additions & 0 deletions util/binfmt_misc/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,22 @@ func SupportedPlatforms() []string {

return arr
}

func ValidatePlatforms(pf []string) bool {
def := platforms.DefaultString()
var supported bool = true
for _, p := range pf {
if p != def {
if p == "linux/amd64" && !amd64Supported() {
supported = false
}
if p == "linux/arm64" && !arm64Supported() {
supported = false
}
if (strings.HasPrefix(p, "linux/arm/v6") || strings.HasPrefix(p, "linux/arm/v7")) && !armSupported() {
supported = false
}
}
}
return supported
}

0 comments on commit a53fa2d

Please sign in to comment.