From e5168a4f30302f53f233ef73abd03120c2575edf Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Mon, 7 Dec 2020 13:55:50 -0800 Subject: [PATCH 1/8] Allow comma-separated list of platforms --- pkg/build/gobuild.go | 49 ++++++++++++++++++++++ pkg/build/gobuild_test.go | 78 +++++++++++++++++++++++++++++++++++ pkg/build/options.go | 13 ++++++ pkg/commands/config.go | 19 +++------ pkg/commands/options/build.go | 3 +- pkg/commands/resolver.go | 16 ++++++- 6 files changed, 162 insertions(+), 16 deletions(-) diff --git a/pkg/build/gobuild.go b/pkg/build/gobuild.go index 1da4b9c2c4..99acb7a5fa 100644 --- a/pkg/build/gobuild.go +++ b/pkg/build/gobuild.go @@ -61,6 +61,7 @@ type gobuild struct { disableOptimizations bool mod *modules buildContext buildContext + platform string } // Option is a functional option for NewGo. @@ -73,6 +74,7 @@ type gobuildOpener struct { disableOptimizations bool mod *modules buildContext buildContext + platform string } func (gbo *gobuildOpener) Open() (Interface, error) { @@ -86,6 +88,7 @@ func (gbo *gobuildOpener) Open() (Interface, error) { disableOptimizations: gbo.disableOptimizations, mod: gbo.mod, buildContext: gbo.buildContext, + platform: gbo.platform, }, nil } @@ -623,6 +626,15 @@ func (g *gobuild) buildAll(ctx context.Context, s string, base v1.ImageIndex) (v return nil, fmt.Errorf("%q has unexpected mediaType %q in base for %q", desc.Digest, desc.MediaType, s) } + matches, err := matchesPlatformSpec(desc.Platform, g.platform) + if err != nil { + return nil, err + } + + if !matches { + continue + } + base, err := base.Image(desc.Digest) if err != nil { return nil, err @@ -649,3 +661,40 @@ func (g *gobuild) buildAll(ctx context.Context, s string, base v1.ImageIndex) (v return mutate.IndexMediaType(mutate.AppendManifests(empty.Index, adds...), baseType), nil } + +func matchesPlatformSpec(base *v1.Platform, spec string) (bool, error) { + if spec == "all" { + return true, nil + } + + // Don't build anything without a platform field unless "all". Unclear what we should do here. + if base == nil { + return false, nil + } + + // This should never happen because we default to linux/amd64. + if spec == "" { + return false, fmt.Errorf("platform was unexpectedly %q", "") + } + + // TODO: Parse this once in Open() and match more efficiently. + for _, platform := range strings.Split(spec, ",") { + parts := strings.Split(platform, "/") + if len(parts) > 0 && base.OS != parts[0] { + continue + } + if len(parts) > 1 && base.Architecture != parts[1] { + continue + } + if len(parts) > 2 && base.Variant != parts[2] { + continue + } + if len(parts) > 3 { + return false, fmt.Errorf("too many slashes in platform spec: %s", platform) + } + + return true, nil + } + + return false, nil +} diff --git a/pkg/build/gobuild_test.go b/pkg/build/gobuild_test.go index 486d0db9c2..8799a5f357 100644 --- a/pkg/build/gobuild_test.go +++ b/pkg/build/gobuild_test.go @@ -458,6 +458,7 @@ func TestGoBuildIndex(t *testing.T) { context.Background(), WithCreationTime(creationTime), WithBaseImages(func(context.Context, string) (Result, error) { return base, nil }), + WithPlatforms("all"), withBuilder(writeTempFile), ) if err != nil { @@ -611,3 +612,80 @@ func TestGoarm(t *testing.T) { } } } + +func TestMatchesPlatformSpec(t *testing.T) { + for _, tc := range []struct { + platform *v1.Platform + spec string + result bool + err bool + }{{ + platform: nil, + spec: "all", + result: true, + }, { + platform: nil, + spec: "linux/amd64", + result: false, + }, { + platform: &v1.Platform{ + Architecture: "amd64", + OS: "linux", + }, + spec: "all", + result: true, + }, { + platform: &v1.Platform{ + Architecture: "amd64", + OS: "windows", + }, + spec: "linux", + result: false, + }, { + platform: &v1.Platform{ + Architecture: "arm64", + OS: "linux", + Variant: "v3", + }, + spec: "linux/amd64,linux/arm64", + result: true, + }, { + platform: &v1.Platform{ + Architecture: "arm64", + OS: "linux", + Variant: "v3", + }, + spec: "linux/amd64,linux/arm64/v4", + result: false, + }, { + platform: &v1.Platform{ + Architecture: "arm64", + OS: "linux", + Variant: "v3", + }, + spec: "linux/amd64,linux/arm64/v3/z5", + err: true, + }, { + spec: "", + platform: &v1.Platform{ + Architecture: "amd64", + OS: "linux", + }, + err: true, + }, + } { + matches, err := matchesPlatformSpec(tc.platform, tc.spec) + if tc.err { + if err == nil { + t.Errorf("matchesPlatformSpec(%v, %q) expected err", tc.platform, tc.spec) + } + continue + } + if err != nil { + t.Fatalf("matchesPlatformSpec failed for %v %q: %v", tc.platform, tc.spec, err) + } + if got, want := matches, tc.result; got != want { + t.Errorf("wrong result for %v %q: want %t got %t", tc.platform, tc.spec, want, got) + } + } +} diff --git a/pkg/build/options.go b/pkg/build/options.go index 66ddf4cad6..413bd9929a 100644 --- a/pkg/build/options.go +++ b/pkg/build/options.go @@ -45,6 +45,19 @@ func WithDisabledOptimizations() Option { } } +// WithPlatforms is a functional option for building certain platforms for +// multi-platform base images. To build everything from the base, use "all", +// otherwise use a comma-separated list of platform specs, i.e.: +// +// platform = [/[/]] +// allowed = all | platform[,platform]* +func WithPlatforms(platforms string) Option { + return func(gbo *gobuildOpener) error { + gbo.platform = platforms + return nil + } +} + // withBuilder is a functional option for overriding the way go binaries // are built. func withBuilder(b builder) Option { diff --git a/pkg/commands/config.go b/pkg/commands/config.go index e9a3b9b0f5..954acfc1ee 100644 --- a/pkg/commands/config.go +++ b/pkg/commands/config.go @@ -20,7 +20,6 @@ import ( "log" "os" "os/signal" - "path" "strconv" "strings" "syscall" @@ -41,16 +40,6 @@ var ( ) func getBaseImage(platform string) build.GetBase { - // Default to linux/amd64 unless GOOS and GOARCH are set. - if platform == "" { - platform = "linux/amd64" - - goos, goarch := os.Getenv("GOOS"), os.Getenv("GOARCH") - if goos != "" && goarch != "" { - platform = path.Join(goos, goarch) - } - } - return func(ctx context.Context, s string) (build.Result, error) { s = strings.TrimPrefix(s, build.StrictScheme) // Viper configuration file keys are case insensitive, and are @@ -71,8 +60,12 @@ func getBaseImage(platform string) build.GetBase { // Using --platform=all will use an image index for the base, // otherwise we'll resolve it to the appropriate platform. + // + // Platforms can be comma-separated if we only want a subset of the base + // image. + multiplatform := platform == "all" || strings.Contains(platform, ",") var p v1.Platform - if platform != "" && platform != "all" { + if platform != "" && !multiplatform { parts := strings.Split(platform, "/") if len(parts) > 0 { p.OS = parts[0] @@ -96,7 +89,7 @@ func getBaseImage(platform string) build.GetBase { } switch desc.MediaType { case types.OCIImageIndex, types.DockerManifestList: - if platform == "all" { + if multiplatform { return desc.ImageIndex() } return desc.Image() diff --git a/pkg/commands/options/build.go b/pkg/commands/options/build.go index b31da8b136..67a282c866 100644 --- a/pkg/commands/options/build.go +++ b/pkg/commands/options/build.go @@ -33,6 +33,5 @@ func AddBuildOptions(cmd *cobra.Command, bo *BuildOptions) { cmd.Flags().BoolVar(&bo.DisableOptimizations, "disable-optimizations", bo.DisableOptimizations, "Disable optimizations when building Go code. Useful when you want to interactively debug the created container.") cmd.Flags().StringVar(&bo.Platform, "platform", "", - "Which platform to use when pulling a multi-platform base. Format: all | [/[/]]") - + "Which platform to use when pulling a multi-platform base. Format: all | [/[/]][,platform]*") } diff --git a/pkg/commands/resolver.go b/pkg/commands/resolver.go index 79cc5cd957..393a19c90c 100644 --- a/pkg/commands/resolver.go +++ b/pkg/commands/resolver.go @@ -24,6 +24,7 @@ import ( "log" "net/http" "os" + "path" "strings" "sync" @@ -69,8 +70,21 @@ func gobuildOptions(bo *options.BuildOptions) ([]build.Option, error) { if err != nil { return nil, err } + + platform := bo.Platform + // Default to linux/amd64 unless GOOS and GOARCH are set. + if platform == "" { + platform = "linux/amd64" + + goos, goarch := os.Getenv("GOOS"), os.Getenv("GOARCH") + if goos != "" && goarch != "" { + platform = path.Join(goos, goarch) + } + } + opts := []build.Option{ - build.WithBaseImages(getBaseImage(bo.Platform)), + build.WithBaseImages(getBaseImage(platform)), + build.WithPlatforms(platform), } if creationTime != nil { opts = append(opts, build.WithCreationTime(*creationTime)) From acdf83faf2092522440907419545cd24d6bfafb2 Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Tue, 8 Dec 2020 11:10:37 -0800 Subject: [PATCH 2/8] Parse platform spec once --- pkg/build/gobuild.go | 69 +++++++++++++++++++++++++-------------- pkg/build/gobuild_test.go | 5 +-- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/pkg/build/gobuild.go b/pkg/build/gobuild.go index 99acb7a5fa..d2b9740a02 100644 --- a/pkg/build/gobuild.go +++ b/pkg/build/gobuild.go @@ -62,6 +62,7 @@ type gobuild struct { mod *modules buildContext buildContext platform string + parsedPlatform []v1.Platform } // Option is a functional option for NewGo. @@ -81,6 +82,10 @@ func (gbo *gobuildOpener) Open() (Interface, error) { if gbo.getBase == nil { return nil, errors.New("a way of providing base images must be specified, see build.WithBaseImages") } + parsed, err := parseSpec(gbo.platform) + if err != nil { + return nil, err + } return &gobuild{ getBase: gbo.getBase, creationTime: gbo.creationTime, @@ -89,6 +94,7 @@ func (gbo *gobuildOpener) Open() (Interface, error) { mod: gbo.mod, buildContext: gbo.buildContext, platform: gbo.platform, + parsedPlatform: parsed, }, nil } @@ -626,12 +632,7 @@ func (g *gobuild) buildAll(ctx context.Context, s string, base v1.ImageIndex) (v return nil, fmt.Errorf("%q has unexpected mediaType %q in base for %q", desc.Digest, desc.MediaType, s) } - matches, err := matchesPlatformSpec(desc.Platform, g.platform) - if err != nil { - return nil, err - } - - if !matches { + if !matchesPlatformSpec(desc.Platform, g.platform, g.parsedPlatform) { continue } @@ -662,39 +663,57 @@ func (g *gobuild) buildAll(ctx context.Context, s string, base v1.ImageIndex) (v return mutate.IndexMediaType(mutate.AppendManifests(empty.Index, adds...), baseType), nil } -func matchesPlatformSpec(base *v1.Platform, spec string) (bool, error) { +func parseSpec(spec string) ([]v1.Platform, error) { + // Don't bother parsing "all". + // "" should never happen because we default to linux/amd64. + platforms := []v1.Platform{} + if spec == "all" || spec == "" { + return platforms, nil + } + + for _, platform := range strings.Split(spec, ",") { + var p v1.Platform + parts := strings.Split(strings.TrimSpace(platform), "/") + if len(parts) > 0 { + p.OS = parts[0] + } + if len(parts) > 1 { + p.Architecture = parts[1] + } + if len(parts) > 2 { + p.Variant = parts[2] + } + if len(parts) > 3 { + return nil, fmt.Errorf("too many slashes in platform spec: %s", platform) + } + platforms = append(platforms, p) + } + return platforms, nil +} + +func matchesPlatformSpec(base *v1.Platform, spec string, parsed []v1.Platform) bool { if spec == "all" { - return true, nil + return true } // Don't build anything without a platform field unless "all". Unclear what we should do here. if base == nil { - return false, nil + return false } - // This should never happen because we default to linux/amd64. - if spec == "" { - return false, fmt.Errorf("platform was unexpectedly %q", "") - } - - // TODO: Parse this once in Open() and match more efficiently. - for _, platform := range strings.Split(spec, ",") { - parts := strings.Split(platform, "/") - if len(parts) > 0 && base.OS != parts[0] { + for _, p := range parsed { + if p.OS != "" && base.OS != p.OS { continue } - if len(parts) > 1 && base.Architecture != parts[1] { + if p.Architecture != "" && base.Architecture != p.Architecture { continue } - if len(parts) > 2 && base.Variant != parts[2] { + if p.Variant != "" && base.Variant != p.Variant { continue } - if len(parts) > 3 { - return false, fmt.Errorf("too many slashes in platform spec: %s", platform) - } - return true, nil + return true } - return false, nil + return false } diff --git a/pkg/build/gobuild_test.go b/pkg/build/gobuild_test.go index 8799a5f357..abc1a7229c 100644 --- a/pkg/build/gobuild_test.go +++ b/pkg/build/gobuild_test.go @@ -671,10 +671,10 @@ func TestMatchesPlatformSpec(t *testing.T) { Architecture: "amd64", OS: "linux", }, - err: true, + result: false, }, } { - matches, err := matchesPlatformSpec(tc.platform, tc.spec) + parsed, err := parseSpec(tc.spec) if tc.err { if err == nil { t.Errorf("matchesPlatformSpec(%v, %q) expected err", tc.platform, tc.spec) @@ -684,6 +684,7 @@ func TestMatchesPlatformSpec(t *testing.T) { if err != nil { t.Fatalf("matchesPlatformSpec failed for %v %q: %v", tc.platform, tc.spec, err) } + matches := matchesPlatformSpec(tc.platform, tc.spec, parsed) if got, want := matches, tc.result; got != want { t.Errorf("wrong result for %v %q: want %t got %t", tc.platform, tc.spec, want, got) } From a21c7a0aca860426ba4be512c23b2cb3703e3a75 Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Tue, 8 Dec 2020 11:10:52 -0800 Subject: [PATCH 3/8] Update --platform docs in README --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9f131194ac..760eef374d 100644 --- a/README.md +++ b/README.md @@ -454,13 +454,25 @@ a multi-architecture (aka "manifest list"), with support for each OS and architecture pair supported by the base image. -If `ko` is invoked with `--platform=/` (e.g., +If `ko` is invoked with `--platform=/` (e.g., `--platform=linux/amd64` or `--platform=linux/arm64`), then it will attempt to build an image for that OS and architecture only, assuming the base image supports it. -When `--platform` is not provided, `ko` builds an image with the OS and -architecture based on the build environment's `GOOS` and `GOARCH`. +If the base image is a manifest list with more platforms than you want to build, +invoking `ko` with comma-separated list of platforms (e.g. +`--platform=linux/amd64,linux/arm/v6`) will produce a manifest list +containing only the provided platforms. Note that if the base image does not +contain platforms that are provided by this flag, `ko` will be unable to build +a corresponding image, and this is not an error. The resulting artifact will be +a multi-platform image containing the intersection of platforms from the base +image and the `--platform` flag. This is especially relevant for projects that +use multiple base images, as you must ensure that every base image contains all +the platforms that you'd like to build. + +When `--platform` is not provided, if both `GOOS` and `GOARCH` environment +variables are set, `ko` will build an image for `${GOOS}/${GOARCH}`, otherwise +`ko` will build a `linux/amd64` image. ## Enable Autocompletion From eda26fc103653d4444f94dfbacc36b23ae013dbb Mon Sep 17 00:00:00 2001 From: jonjohnsonjr Date: Mon, 14 Dec 2020 08:26:59 -0800 Subject: [PATCH 4/8] Update pkg/build/gobuild_test.go Co-authored-by: Matt Moore --- pkg/build/gobuild_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/build/gobuild_test.go b/pkg/build/gobuild_test.go index abc1a7229c..acd6c00459 100644 --- a/pkg/build/gobuild_test.go +++ b/pkg/build/gobuild_test.go @@ -672,8 +672,7 @@ func TestMatchesPlatformSpec(t *testing.T) { OS: "linux", }, result: false, - }, - } { + }} { parsed, err := parseSpec(tc.spec) if tc.err { if err == nil { From 02c68d0d6cc656cd7666739ee2f0ebbca6c4f888 Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Mon, 21 Dec 2020 13:30:31 -0800 Subject: [PATCH 5/8] Return err for bad defaulting for --platform Also respect GOARM as variant if the goarch is arm. --- pkg/commands/resolver.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/commands/resolver.go b/pkg/commands/resolver.go index 393a19c90c..4bb7a1fb14 100644 --- a/pkg/commands/resolver.go +++ b/pkg/commands/resolver.go @@ -72,14 +72,27 @@ func gobuildOptions(bo *options.BuildOptions) ([]build.Option, error) { } platform := bo.Platform - // Default to linux/amd64 unless GOOS and GOARCH are set. if platform == "" { platform = "linux/amd64" - goos, goarch := os.Getenv("GOOS"), os.Getenv("GOARCH") + goos, goarch, goarm := os.Getenv("GOOS"), os.Getenv("GOARCH"), os.Getenv("GOARM") + + // Default to linux/amd64 unless GOOS and GOARCH are set. if goos != "" && goarch != "" { platform = path.Join(goos, goarch) } + + // Use GOARM for variant if it's set and GOARCH is arm. + if strings.Contains(goarch, "arm") && goarm != "" { + platform = path.Join(platform, "v"+goarm) + } + } else { + // Make sure these are all unset + for _, env := range []string{"GOOS", "GOARCH", "GOARM"} { + if s, ok := os.LookupEnv(env); ok { + return nil, fmt.Errorf("cannot use --platform with %s=%q", env, s) + } + } } opts := []build.Option{ From f447fd2e6f20e2277f60ee839339b1caeaa7fc42 Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Mon, 21 Dec 2020 13:48:49 -0800 Subject: [PATCH 6/8] Refactor platform matching --- pkg/build/gobuild.go | 27 +++++++++++++++------------ pkg/build/gobuild_test.go | 8 ++++---- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/pkg/build/gobuild.go b/pkg/build/gobuild.go index d2b9740a02..8028f71798 100644 --- a/pkg/build/gobuild.go +++ b/pkg/build/gobuild.go @@ -54,6 +54,11 @@ type buildContext interface { Import(path string, srcDir string, mode gb.ImportMode) (*gb.Package, error) } +type platformMatcher struct { + spec string + platforms []v1.Platform +} + type gobuild struct { getBase GetBase creationTime v1.Time @@ -61,8 +66,7 @@ type gobuild struct { disableOptimizations bool mod *modules buildContext buildContext - platform string - parsedPlatform []v1.Platform + platformMatcher *platformMatcher } // Option is a functional option for NewGo. @@ -82,7 +86,7 @@ func (gbo *gobuildOpener) Open() (Interface, error) { if gbo.getBase == nil { return nil, errors.New("a way of providing base images must be specified, see build.WithBaseImages") } - parsed, err := parseSpec(gbo.platform) + matcher, err := parseSpec(gbo.platform) if err != nil { return nil, err } @@ -93,8 +97,7 @@ func (gbo *gobuildOpener) Open() (Interface, error) { disableOptimizations: gbo.disableOptimizations, mod: gbo.mod, buildContext: gbo.buildContext, - platform: gbo.platform, - parsedPlatform: parsed, + platformMatcher: matcher, }, nil } @@ -632,7 +635,7 @@ func (g *gobuild) buildAll(ctx context.Context, s string, base v1.ImageIndex) (v return nil, fmt.Errorf("%q has unexpected mediaType %q in base for %q", desc.Digest, desc.MediaType, s) } - if !matchesPlatformSpec(desc.Platform, g.platform, g.parsedPlatform) { + if !g.platformMatcher.matches(desc.Platform) { continue } @@ -663,12 +666,12 @@ func (g *gobuild) buildAll(ctx context.Context, s string, base v1.ImageIndex) (v return mutate.IndexMediaType(mutate.AppendManifests(empty.Index, adds...), baseType), nil } -func parseSpec(spec string) ([]v1.Platform, error) { +func parseSpec(spec string) (*platformMatcher, error) { // Don't bother parsing "all". // "" should never happen because we default to linux/amd64. platforms := []v1.Platform{} if spec == "all" || spec == "" { - return platforms, nil + return &platformMatcher{spec: spec}, nil } for _, platform := range strings.Split(spec, ",") { @@ -688,11 +691,11 @@ func parseSpec(spec string) ([]v1.Platform, error) { } platforms = append(platforms, p) } - return platforms, nil + return &platformMatcher{spec: spec, platforms: platforms}, nil } -func matchesPlatformSpec(base *v1.Platform, spec string, parsed []v1.Platform) bool { - if spec == "all" { +func (pm *platformMatcher) matches(base *v1.Platform) bool { + if pm.spec == "all" { return true } @@ -701,7 +704,7 @@ func matchesPlatformSpec(base *v1.Platform, spec string, parsed []v1.Platform) b return false } - for _, p := range parsed { + for _, p := range pm.platforms { if p.OS != "" && base.OS != p.OS { continue } diff --git a/pkg/build/gobuild_test.go b/pkg/build/gobuild_test.go index acd6c00459..dadf5703ad 100644 --- a/pkg/build/gobuild_test.go +++ b/pkg/build/gobuild_test.go @@ -673,17 +673,17 @@ func TestMatchesPlatformSpec(t *testing.T) { }, result: false, }} { - parsed, err := parseSpec(tc.spec) + pm, err := parseSpec(tc.spec) if tc.err { if err == nil { - t.Errorf("matchesPlatformSpec(%v, %q) expected err", tc.platform, tc.spec) + t.Errorf("parseSpec(%v, %q) expected err", tc.platform, tc.spec) } continue } if err != nil { - t.Fatalf("matchesPlatformSpec failed for %v %q: %v", tc.platform, tc.spec, err) + t.Fatalf("parseSpec failed for %v %q: %v", tc.platform, tc.spec, err) } - matches := matchesPlatformSpec(tc.platform, tc.spec, parsed) + matches := pm.matches(tc.platform) if got, want := matches, tc.result; got != want { t.Errorf("wrong result for %v %q: want %t got %t", tc.platform, tc.spec, want, got) } From 8706b096b801b0311599d3097c37879c2e20d857 Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Mon, 21 Dec 2020 13:54:04 -0800 Subject: [PATCH 7/8] Update README.md to mention GOARM --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 760eef374d..010132c283 100644 --- a/README.md +++ b/README.md @@ -471,8 +471,11 @@ use multiple base images, as you must ensure that every base image contains all the platforms that you'd like to build. When `--platform` is not provided, if both `GOOS` and `GOARCH` environment -variables are set, `ko` will build an image for `${GOOS}/${GOARCH}`, otherwise -`ko` will build a `linux/amd64` image. +variables are set, `ko` will build an image for `${GOOS}/${GOARCH}[/v${GOARM}]`, +otherwise `ko` will build a `linux/amd64` image. + +Note that using both `--platform` and GOOS/GOARCH will return an error, as it's +unclear what platform should be used. ## Enable Autocompletion From 7999d02d88c5f25dd7260b10a6f4c41844b48734 Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Mon, 21 Dec 2020 16:02:36 -0800 Subject: [PATCH 8/8] Fix travis test --- .travis.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5fde9318d1..b723baeb6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,14 +18,9 @@ script: - go install -mod=vendor ./cmd/ko # Try with all, and GOOS/GOARCH set. - | - GOOS=${GOOS} GOARCH=${GOARCH} KO_DOCKER_REPO=ko.local ko publish --platform=all -B ./cmd/ko/test - OUTPUT=$(docker run -i ko.local/test -wait=false 2>&1) - if [[ ! "${OUTPUT}" =~ "$(cat ./cmd/ko/test/kodata/kenobi)" ]]; then - echo Mismatched output: ${OUTPUT}, wanted: $(cat ./cmd/ko/test/kodata/kenobi) - exit 1 - fi - if [[ ! "${OUTPUT}" =~ "$(cat ./cmd/ko/test/kodata/HEAD)" ]]; then - echo Mismatched output: ${OUTPUT}, wanted: $(cat ./cmd/ko/test/kodata/HEAD) + OUTPUT=$(GOOS=${GOOS} GOARCH=${GOARCH} KO_DOCKER_REPO=ko.local ko publish --platform=all -B ./cmd/ko/test 2>&1) + if [[ ! "${OUTPUT}" =~ "cannot use --platform with GOOS=\"${GOOS}\"" ]]; then + echo Mismatched output: ${OUTPUT}, wanted: "cannot use --platform with GOOS=\"${GOOS}\"" exit 1 fi