From 027ed685c44d05017c8f72333ec2601e81f2bf79 Mon Sep 17 00:00:00 2001 From: Dave Chen Date: Tue, 5 Mar 2019 00:21:06 -0800 Subject: [PATCH] Show the hints when buildkit is on multi-arch mode 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 --- cmd/buildkitd/main_containerd_worker.go | 5 +++++ cmd/buildkitd/main_oci_worker.go | 5 +++++ util/binfmt_misc/detect.go | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/cmd/buildkitd/main_containerd_worker.go b/cmd/buildkitd/main_containerd_worker.go index 707a0abda9456..fa8ac44a1cd4c 100644 --- a/cmd/buildkitd/main_containerd_worker.go +++ b/cmd/buildkitd/main_containerd_worker.go @@ -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" @@ -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("cross-platfrom build may fail, pls consdier to configure 'F' flag for 'binfmt_misc'.") + } cfg.Workers.Containerd.Platforms = platforms } diff --git a/cmd/buildkitd/main_oci_worker.go b/cmd/buildkitd/main_oci_worker.go index ed293f935e7c3..fb7e752d189cb 100644 --- a/cmd/buildkitd/main_oci_worker.go +++ b/cmd/buildkitd/main_oci_worker.go @@ -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" @@ -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("cross-platfrom build may fail, pls consdier to configure 'F' flag for 'binfmt_misc'.") + } cfg.Workers.OCI.Platforms = platforms } diff --git a/util/binfmt_misc/detect.go b/util/binfmt_misc/detect.go index 719fe13451543..3ffb3e7f7f59a 100644 --- a/util/binfmt_misc/detect.go +++ b/util/binfmt_misc/detect.go @@ -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 +}