util: add platformutil

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2019-04-17 16:48:52 -07:00
parent aa421f9c9e
commit e773d0eb2a
3 changed files with 7 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/moby/buildkit/session/auth/authprovider"
"github.com/pkg/errors"
"github.com/tonistiigi/buildx/build"
"github.com/tonistiigi/buildx/util/platformutil"
)
func ReadTargets(ctx context.Context, files, targets, overrides []string) (map[string]Target, error) {
@ -254,7 +255,7 @@ func toBuildOpt(t Target) (*build.Options, error) {
// CacheFrom: t.CacheFrom,
}
platforms, err := build.ParsePlatformSpecs(t.Platforms)
platforms, err := platformutil.Parse(t.Platforms)
if err != nil {
return nil, err
}

View File

@ -14,6 +14,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/tonistiigi/buildx/build"
"github.com/tonistiigi/buildx/util/platformutil"
"github.com/tonistiigi/buildx/util/progress"
)
@ -92,7 +93,7 @@ func runBuild(dockerCli command.Cli, in buildOptions) error {
NetworkMode: in.networkMode,
}
platforms, err := build.ParsePlatformSpecs(in.platforms)
platforms, err := platformutil.Parse(in.platforms)
if err != nil {
return err
}

View File

@ -1,4 +1,4 @@
package build
package platformutil
import (
"strings"
@ -7,7 +7,7 @@ import (
specs "github.com/opencontainers/image-spec/specs-go/v1"
)
func ParsePlatformSpecs(platformsStr []string) ([]specs.Platform, error) {
func Parse(platformsStr []string) ([]specs.Platform, error) {
if len(platformsStr) == 0 {
return nil, nil
}
@ -15,7 +15,7 @@ func ParsePlatformSpecs(platformsStr []string) ([]specs.Platform, error) {
for _, s := range platformsStr {
parts := strings.Split(s, ",")
if len(parts) > 1 {
p, err := ParsePlatformSpecs(parts)
p, err := Parse(parts)
if err != nil {
return nil, err
}