ko-build / ko

Build and deploy Go applications
https://ko.build
Apache License 2.0
7.63k stars 401 forks source link

0.15.3 has breaking issues error resolving image references: build: go build: exit status 2: flag provided but not defined: -platform #1317

Closed houshengbo closed 5 months ago

houshengbo commented 5 months ago

0.15.3 has breaking issues

https://github.com/knative/serving/actions/runs/9127229170/job/25097079749?pr=15219

2024/05/17 11:05:55 Building knative.dev/serving/cmd/webhook for linux/amd64
Error: error processing import paths in "config/core/999-cache.yaml": error resolving image references: build: go build: exit status 2: flag provided but not defined: -platform
usage: go build [-o output] [build flags] [packages]
Run 'go help build' for details.
imjasonh commented 5 months ago

@nmittler possibly related to some of your recent go flag changes? Can you take a look?

dprotaso commented 5 months ago

To repro use the env-var

export KO_FLAGS="--platform=linux/amd64"

dprotaso commented 5 months ago

Yeah git bisect shows

2a4c12f410f678ee72c2dcd8036ceb1b9b113c10 is the first bad commit
commit 2a4c12f410f678ee72c2dcd8036ceb1b9b113c10
Author: Nathan Mittler <nmittler@aviatrix.com>
Date:   Wed May 15 13:16:12 2024 -0700

    Add global flags and ldflags

    Fixes #1304

 docs/configuration.md                         | 25 ++++++++++++++
 pkg/build/gobuild.go                          | 50 ++++++++++++++++++---------
 pkg/build/gobuild_test.go                     | 49 ++++++++++++++++++++++++++
 pkg/build/options.go                          | 16 +++++++++
 pkg/commands/options/build.go                 | 20 ++++++++---
 pkg/commands/options/build_test.go            | 23 +++++++++---
 pkg/commands/options/testdata/config/.ko.yaml |  5 +++
 pkg/commands/resolver.go                      |  2 ++
 8 files changed, 165 insertions(+), 25 deletions(-)
bisect found first bad commit
nmittler commented 5 months ago

hmm ... possibly https://github.com/ko-build/ko/pull/1314? In pkg/commands/options/build.go I added v.GetStringSlice("flags"). Not sure if this is interacting with KO_FLAGS?

nmittler commented 5 months ago

Actually .. is KO_FLAGS even an environment variable that ko previously supported? Maybe a viper thing?

dprotaso commented 5 months ago

Yeah

On Fri, May 17, 2024 at 12:35 Nathan Mittler @.***> wrote:

Actually .. is KO_FLAGS even an environment variable that ko previously supported?

— Reply to this email directly, view it on GitHub https://github.com/ko-build/ko/issues/1317#issuecomment-2117969650, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAERARZTMI2XEFRBA3SBRDZCYWWDAVCNFSM6AAAAABH4IRAQSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJXHE3DSNRVGA . You are receiving this because you commented.Message ID: @.***>

nmittler commented 5 months ago

Unfortunately, I'm definitely not a viper expert :). I'm guessing that <EnvPrefix>_FLAGS is a default variable exposed and used by viper, but I don't see it mentioned in the docs. Any links on how this works?

dprotaso commented 5 months ago

Actually sorry I made a mistake - KO_FLAGS is not a ko thing. I guess in your commit you're now reading it for some reason.

dprotaso commented 5 months ago

I guess when you added that GetStringSlice it prepends KO in front of the envvar - https://github.com/ko-build/ko/blame/bb99eccfe235e7b583c857bb1bafbf45f72178d1/pkg/commands/options/build.go#L112

dprotaso commented 5 months ago

maybe you should rename the flag? eg. go_flags or something? Then it can be set using KO_GO_FLAGS likewise with the ldflags- since those are go build specific

nmittler commented 5 months ago

@dprotaso yeah, that's was my thought as well. Will send a PR shortly.