kubevirt / kubevirt

Kubernetes Virtualization API and runtime in order to define and manage virtual machines.
https://kubevirt.io
Apache License 2.0
5.4k stars 1.3k forks source link

make builder-build failed with go: command not found #11386

Closed Longchuanzheng closed 3 weeks ago

Longchuanzheng commented 6 months ago

What happened: When I try to bump golang version refer to this doc: https://github.com/kubevirt/kubevirt/blob/main/docs/update-go-version.md I change GIMME_GO_VERSION in hack/builder/Dockerfile and exec make builder-build. It return

=> ERROR [ 8/17] RUN set -x &&     mkdir -p /go &&     source /etc/profile.d/gimme.sh &&     go install -v golang.org/x/tools/cmd/goimports@d5fe738 &&     go install -v mvdan.cc/sh/v3/cmd/shfmt@v3.1.  0.4s
------
 > [ 8/17] RUN set -x &&     mkdir -p /go &&     source /etc/profile.d/gimme.sh &&     go install -v golang.org/x/tools/cmd/goimports@d5fe738 &&     go install -v mvdan.cc/sh/v3/cmd/shfmt@v3.1.1 &&     go install -v k8s.io/code-generator/cmd/deepcopy-gen@v0.20.2 &&     go install -v k8s.io/code-generator/cmd/defaulter-gen@v0.20.2  &&     go install -v k8s.io/kube-openapi/cmd/openapi-gen@30be4d1 &&     go install -v github.com/golang/protobuf/protoc-gen-go@1643683 &&     go install -v k8s.io/code-generator/cmd/client-gen@v0.20.2 &&     go install -v github.com/securego/gosec/v2/cmd/gosec@0ce48a5 &&     go install -v sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.0 &&     go clean -cache -modcache:
#0 0.312 + mkdir -p /go
#0 0.315 + source /etc/profile.d/gimme.sh
#0 0.315 + go install -v golang.org/x/tools/cmd/goimports@d5fe738
#0 0.316 /bin/sh: line 1: go: command not found

What you expected to happen: make builder-build run without err

How to reproduce it (as minimally and precisely as possible): Steps to reproduce the behavior.

Additional context: Add any other context about the problem here. image

Environment:

Longchuanzheng commented 6 months ago

IMO, it means golang haven't installed in base image. How can I do?

brianmcarey commented 6 months ago

@Longchuanzheng - what did you change GIMME_GO_VERSION to ?

Longchuanzheng commented 6 months ago

@brianmcarey Hi, thanks for your attention. I just refer your pr (https://github.com/kubevirt/kubevirt/pull/10914) and change GIMME_GO_VERSION to 1.21.5

brianmcarey commented 6 months ago

I changed the following against the release-0.59 branch and make builder-build completed successfully for me.

--- a/hack/builder/Dockerfile
+++ b/hack/builder/Dockerfile
@@ -4,7 +4,7 @@ ARG SONOBUOY_ARCH
 ARG BAZEL_ARCH

 ENV BAZEL_VERSION=5.3.1
-ENV GIMME_GO_VERSION=1.19.12
+ENV GIMME_GO_VERSION=1.21.5
 ENV GRADLE_VERSION=6.6
 ENV OPERATOR_COURIER_VERSION=2.1.11
 ENV SONOBUOY_VERSION=0.56.9
Longchuanzheng commented 6 months ago

Hi, thanks for your assertion. I suspect it is a problem with the base image. I didn't find process in Dockerfile to install golang. While there dosen't have golang in the base image.

# docker run -i quay.io/centos/centos:stream9  /bin/bash
go version
/bin/bash: line 1: go: command not found

So it is reasonable to build image failed.

Can you share me which base image dose you use? just like sha256 or tag.

brianmcarey commented 6 months ago

The installation of go is handled by /etc/profile.d/gimme.sh which is from here - https://github.com/kubevirt/kubevirt/blob/b3a75fa2d670c540ad2b93f037cc3a71977a2b79/hack/builder/Dockerfile#L71C5-L71C66

Please double check you have the GIMME_GO_VERSION variable correctly set - as in no spaces etc.

Longchuanzheng commented 6 months ago

Thanks, I set GIMME_GO_VERSION like this:

diff --git a/hack/builder/Dockerfile b/hack/builder/Dockerfile
index aaf6dcdd8..af07e8226 100644
--- a/hack/builder/Dockerfile
+++ b/hack/builder/Dockerfile
@@ -4,7 +4,7 @@ ARG SONOBUOY_ARCH
 ARG BAZEL_ARCH

 ENV BAZEL_VERSION=5.3.1
-ENV GIMME_GO_VERSION=1.19.2
+ENV GIMME_GO_VERSION=1.21.5
 ENV GRADLE_VERSION=6.6
 ENV OPERATOR_COURIER_VERSION=2.1.11
 ENV SONOBUOY_VERSION=0.56.9
brianmcarey commented 6 months ago

Ok then I would check the contents of /etc/profile.d/gimme.sh during your image build. It may not have downloaded the script correctly.

Longchuanzheng commented 6 months ago

Yes, you are right. I delete left build file and build an image just use:

...

# reference to master is for an external repo and can't yet be changed
RUN mkdir -p /gimme && curl -sL \
    https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | \
    HOME=/gimme bash >> /etc/profile.d/gimme.sh

ENV GOPATH="/go" GOBIN="/usr/bin" GO111MODULE="on"

When I run this image and find /etc/profile.d/gimme.sh is 0mb.

ls -ll /etc/profile.d/gimme.sh
-rw-r--r-- 1 root root 0 Mar  1 07:24 /etc/profile.d/gimme.sh

Also I find I can't get any data from https://raw.githubusercontent.com/travis-ci/gimme/master/gimme, although if I just open the url in chrome I can get the script. show nothing here:

curl -sL  https://raw.githubusercontent.com/travis-ci/gimme/master/gimme > log
cat log
Longchuanzheng commented 5 months ago

We can just download https://raw.githubusercontent.com/travis-ci/gimme/master/gimme and save it at hack/builder. And use

COPY gimme /etc/gimme

RUN set -x && \
    bash /etc/gimme >> /etc/profile.d/gimme.sh

Instead use crul in Dockerfile.

Longchuanzheng commented 5 months ago

@brianmcarey Hi, what should I do when I generate the builder image? I follow the https://github.com/kubevirt/kubevirt/blob/main/docs/update-go-version.md. I use go rules for bazel in https://github.com/kubevirt/kubevirt/pull/8622

http_archive(
   name = "io_bazel_rules_go",
    sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
        "https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
        "https://storage.googleapis.com/builddeps/099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
    ],
)

After above, I try to make deps-update but get err. image

brianmcarey commented 5 months ago

@brianmcarey Hi, what should I do when I generate the builder image? I follow the https://github.com/kubevirt/kubevirt/blob/main/docs/update-go-version.md. I use go rules for bazel in #8622

http_archive(
   name = "io_bazel_rules_go",
    sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
        "https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
        "https://storage.googleapis.com/builddeps/099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
    ],
)

After above, I try to make deps-update but get err.

You will probably need to backport changes from the following PRs to get this working: https://github.com/kubevirt/kubevirt/pull/10879 https://github.com/kubevirt/kubevirt/pull/10914

Longchuanzheng commented 5 months ago

@brianmcarey thanks, I build image and make deps-update succeeded. While I do make generate failed. err is:

You introduced new API rule violation

image I think this err is in hack/generate.sh

if cmp ${KUBEVIRT_DIR}/api/api-rule-violations.list ${KUBEVIRT_DIR}/api/api-rule-violations-known.list; then
    echo "openapi generated"
else
    diff -u ${KUBEVIRT_DIR}/api/api-rule-violations-known.list ${KUBEVIRT_DIR}/api/api-rule-violations.list || true
    echo "You introduced new API rule violation"
    diff ${KUBEVIRT_DIR}/api/api-rule-violations.list ${KUBEVIRT_DIR}/api/api-rule-violations-known.list
    exit 2
fi

I try to

rm api/api-rule-violations-known.list
cp api/api-rule-violations.list api/api-rule-violations-known.list

and exec diff -u api/api-rule-violations-known.list api/api-rule-violations.list locally without diff. image While I still make generate failed with You introduced new API rule violation. I think this may related to https://github.com/kubevirt/kubevirt/issues/9780 @lyarwood , Hi, can you help me?

brianmcarey commented 5 months ago

@Longchuanzheng I am not sure what may be causing this. Just so you know since the release v1.2 - KubeVirt is no longer supporting v0.59. https://github.com/kubevirt/sig-release/blob/main/releases/k8s-support-matrix.md

kubevirt-bot commented 2 months ago

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

/lifecycle stale

kubevirt-bot commented 1 month ago

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

/lifecycle rotten

brianmcarey commented 3 weeks ago

/close

kubevirt-bot commented 3 weeks ago

@brianmcarey: Closing this issue.

In response to [this](https://github.com/kubevirt/kubevirt/issues/11386#issuecomment-2260746937): >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.