mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
util: add platformutil
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
aa421f9c9e
commit
e773d0eb2a
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/moby/buildkit/session/auth/authprovider"
|
"github.com/moby/buildkit/session/auth/authprovider"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/tonistiigi/buildx/build"
|
"github.com/tonistiigi/buildx/build"
|
||||||
|
"github.com/tonistiigi/buildx/util/platformutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ReadTargets(ctx context.Context, files, targets, overrides []string) (map[string]Target, error) {
|
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,
|
// CacheFrom: t.CacheFrom,
|
||||||
}
|
}
|
||||||
|
|
||||||
platforms, err := build.ParsePlatformSpecs(t.Platforms)
|
platforms, err := platformutil.Parse(t.Platforms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"github.com/tonistiigi/buildx/build"
|
"github.com/tonistiigi/buildx/build"
|
||||||
|
"github.com/tonistiigi/buildx/util/platformutil"
|
||||||
"github.com/tonistiigi/buildx/util/progress"
|
"github.com/tonistiigi/buildx/util/progress"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ func runBuild(dockerCli command.Cli, in buildOptions) error {
|
|||||||
NetworkMode: in.networkMode,
|
NetworkMode: in.networkMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
platforms, err := build.ParsePlatformSpecs(in.platforms)
|
platforms, err := platformutil.Parse(in.platforms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package build
|
package platformutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
@ -7,7 +7,7 @@ import (
|
|||||||
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
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 {
|
if len(platformsStr) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -15,7 +15,7 @@ func ParsePlatformSpecs(platformsStr []string) ([]specs.Platform, error) {
|
|||||||
for _, s := range platformsStr {
|
for _, s := range platformsStr {
|
||||||
parts := strings.Split(s, ",")
|
parts := strings.Split(s, ",")
|
||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
p, err := ParsePlatformSpecs(parts)
|
p, err := Parse(parts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user