Skip to content

Commit

Permalink
Show the hints when buildkit is on multi-arch mode
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 12, 2019
1 parent 2a857a3 commit d7a155d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
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("cross-platfrom build may fail, please consdier to configure 'F' flag for '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("cross-platfrom build may fail, please consdier to configure 'F' flag for '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 d7a155d

Please sign in to comment.