如何解决Golang在Golang.org/x/tools/go中找不到包的问题



这个问题只是在构建之间随机出现的,现在甚至我们的生产回购(几个月来没有变化(在构建时也会出现这个问题。我已经被这个问题困扰了一段时间。它不会发生在我们的本地机器上,只有在使用dockerfile时才会发生。

Step 30/73 : RUN go get -d ./...
---> Running in ca969a5fc165
[91msrc/golang.org/x/text/cmd/gotext/main.go:31:2: cannot find package "golang.org/x/tools/go/buildutil" in any of:
/usr/local/go/src/golang.org/x/tools/go/buildutil (from $GOROOT)
/app/src/golang.org/x/tools/go/buildutil (from $GOPATH)
src/golang.org/x/text/message/pipeline/extract.go:23:2: cannot find package "golang.org/x/tools/go/callgraph" in any of:
/usr/local/go/src/golang.org/x/tools/go/callgraph (from $GOROOT)
/app/src/golang.org/x/tools/go/callgraph (from $GOPATH)
src/golang.org/x/text/message/pipeline/extract.go:24:2: cannot find package "golang.org/x/tools/go/callgraph/cha" in any of:
/usr/local/go/src/golang.org/x/tools/go/callgraph/cha (from $GOROOT)
/app/src/golang.org/x/tools/go/callgraph/cha (from $GOPATH)
src/golang.org/x/text/message/pipeline/extract.go:25:2: cannot find package "golang.org/x/tools/go/loader" in any of:
/usr/local/go/src/golang.org/x/tools/go/loader (from $GOROOT)
/app/src/golang.org/x/tools/go/loader (from $GOPATH)
src/golang.org/x/text/message/pipeline/extract.go:26:2: cannot find package "golang.org/x/tools/go/ssa" in any of:
/usr/local/go/src/golang.org/x/tools/go/ssa (from $GOROOT)
/app/src/golang.org/x/tools/go/ssa (from $GOPATH)
src/golang.org/x/text/message/pipeline/extract.go:27:2: cannot find package "golang.org/x/tools/go/ssa/ssautil" in any of:
/usr/local/go/src/golang.org/x/tools/go/ssa/ssautil (from $GOROOT)
/app/src/golang.org/x/tools/go/ssa/ssautil (from $GOPATH)
[0mThe command '/bin/sh -c go get -d ./...' returned a non-zero code: 1

我已经将所有这些依赖项(减去第一个(追溯到golang.org/x/text/message/pipeline/extract.go中的一个文件中。它们都作为导入列出。以下是我们的码头文件的相关部分

RUN yum update -y
RUN yum install -y git-core
RUN yum install -y wget
RUN yum install -y gcc-c++ make
RUN yum install -y libaio
RUN yum install -y openssl-devel

# Install Go
RUN wget --no-check-certificate https://dl.google.com/go/go1.12.2.linux-amd64.tar.gz
RUN tar -xzf go1.12.2.linux-amd64.tar.gz
RUN mv go /usr/local
RUN rm go1.12.2.linux-amd64.tar.gz
# Copy application files
COPY ./ /app
WORKDIR /app
# Configure paths for GOPATH and GOROOT
ENV GOROOT="/usr/local/go"
ENV GOPATH="/app"
ENV GOBIN="$GOPATH/bin"
ENV PATH="$PATH:$GOPATH/bin:$GOROOT/bin"
# Install Go dependencies
RUN go get github.com/creack/pty
RUN go get -d -v ./...
RUN go install -v ./...

文件夹或用户权限似乎会发生这种情况。这个问题似乎是断断续续的。对我有效的解决方案是在GOROOTGOPATH目录中查找这些包,然后手动删除它们,然后运行go get。这似乎为我解决了问题

因此,修复方法似乎是将"go get-d-v./…"更改为"go get">

此外,关于为什么在我们的生产构建中发生这种情况,而没有对其进行任何更改,我们没有使用任何包版本控制,并且更新了一个外部包以导致此错误。因此,经过一些研究,我们可能应该使用go模块来处理版本控制。

最新更新