Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ko uses "go" as default GOROOT, causing build errors #218

Closed
antoineco opened this issue Oct 7, 2020 · 10 comments
Closed

ko uses "go" as default GOROOT, causing build errors #218

antoineco opened this issue Oct 7, 2020 · 10 comments

Comments

@antoineco
Copy link
Contributor

Description

ko uses "go" as GOROOT when GOROOT is not exported in the environment, instead of defaulting to $(go env GOROOT). This prevents builds from happening.

In the previous version, the error message was quite explicit: "go: cannot find GOROOT directory: go".

Now, in 0.6.0, the error is much more ambiguous: importpath "ko://knative.dev/serving/cmd/controller" is not supported.

ko version

$ ko  version
0.6.0

How to reproduce

Example, inside https://github.com/knative/serving/

$ printenv GOROOT  # empty
$ ko publish -L ./cmd/controller  # failure
2020/10/07 12:41:33 failed to publish images: importpath "ko://knative.dev/serving/cmd/controller" is not supported
$ export GOROOT="$(go env GOROOT)"
$ printenv GOROOT
/usr/local/go
$ ko publish -L ./cmd/controller  # success
2020/10/07 12:45:13 Using base gcr.io/distroless/static:nonroot for knative.dev/serving/cmd/controller
2020/10/07 12:45:15 Building knative.dev/serving/cmd/controller for linux/amd64
[...]

Temporary workaround

Add this line to your .*shrc file:

export GOROOT="${GOROOT:-$(go env GOROOT)}"
antoineco added a commit to antoineco/dotfiles that referenced this issue Oct 7, 2020
Prevents ko tool from throwing "go: cannot find GOROOT directory: go"

ko-build/ko#218
@mattmoor
Copy link
Collaborator

mattmoor commented Oct 7, 2020

I think @scothis has an open issue for this, and I think @jonjohnsonjr has the most context on this issue.

@scothis
Copy link

scothis commented Oct 7, 2020

@mattmoor #106

@antoineco
Copy link
Contributor Author

@scothis do I understand correctly that ko just needs to be rebuilt (e.g. via go get) for GOROOT to default to the expected value?

@mattmoor
Copy link
Collaborator

mattmoor commented Oct 7, 2020

Unfortunately go get ignores replace directives in go.mod, so I'd recommend go install.

@github-actions
Copy link

github-actions bot commented Jan 6, 2021

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.

@jonjohnsonjr
Copy link
Collaborator

I believe this is resolved by #303

Please let me know if that is not the case.

@xtreme-sameer-vohra
Copy link

xtreme-sameer-vohra commented Jan 30, 2021

I believe this is resolved by #303

Please let me know if that is not the case.

I believe I ran into the same issue using ko v0.7.2 after bumping go to a new 1.15.x patch using homebrew. Building ko locally with the fix solved it.

@sebgoa
Copy link

sebgoa commented Feb 24, 2021

Yes, this is still an issue in 0.7.0

@jonjohnsonjr
Copy link
Collaborator

@sebgoa as of v0.8.0, this now prints a warning, does the "right" thing, and includes instructions for making that warning go away (by setting GOROOT explicitly).

My intention is to remove the need for this warning before cutting v0.9.0, as described in #305

If you're still having issues in v0.8.0, let me know.

@sebgoa
Copy link

sebgoa commented Feb 25, 2021

I realised that I ran into this because the Installation section in the README makes you install 0.7.0 binary, hence I did not get the warning. I am not sure if it is intentional, so I will leave it to you to update the README to the latest 0.8 release...

antoineco added a commit to antoineco/dotfiles that referenced this issue Aug 26, 2021
Prevents ko tool from throwing "go: cannot find GOROOT directory: go"

ko-build/ko#218
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants