我有一个路径为/Users/me/Documents/dev/grafana/src/github.com/grafana/grafana
的项目。该项目使用了其他几个项目,例如:
/Users/me/Documents/dev/grafana/src/github.com/BurntSushi/toml
/Users/me/Documents/dev/grafana/src/github.com/Unknwon/com
我可以在我的机器上构建一切正常,但是当我尝试在Docker中构建时,我收到了一堆cannot find package
错误。
go install -v ./pkg/cmd/grafana-server
pkg/login/ldap_settings.go:7:2: cannot find package "github.com/BurntSushi/toml" in any of:
/usr/local/go/src/github.com/BurntSushi/toml (from $GOROOT)
/go/src/github.com/BurntSushi/toml (from $GOPATH)
pkg/services/notifications/codes.go:9:2: cannot find package "github.com/Unknwon/com" in any of:
/usr/local/go/src/github.com/Unknwon/com (from $GOROOT)
/go/src/github.com/Unknwon/com (from $GOPATH)
当我自己构建时,我有$GOPATH=/Users/me/Documents/dev/grafana/
- 在我的Dockerfile中我有:
FROM golang:latest AS build
RUN go version
ENV SRC_DIR=/go/src/github.com/grafana/grafana/
ENV GIT_SSL_NO_VERIFY=1
COPY . $SRC_DIR
WORKDIR $SRC_DIR
[... dependency installations ...]
# Building of Grafana
RUN npm run build
RUN go run build.go setup
RUN go run build.go build
我无法弄清楚为什么这一步(在RUN go run build.go setup
步骤中开始)会一直报告它无法访问这些包。
我已经四处查找了类似的问题,但几乎所有相关的内容都没有指定Docker中的构建(以及那些对这种情况不起作用的内容)。
答案 0 :(得分:0)
您可以尝试以下内容,看看是否有效。
步骤1:安装go dep(go get -u github.com/golang/dep/cmd/dep)
第2步:在项目中运行命令dep init
。这将创建一个Gopkg.toml和Gopkg.lock
第3步:更改泊坞窗文件
FROM golang:latest AS build
RUN go version
WORKDIR /go/src/github.com/grafana/grafana/
ENV GIT_SSL_NO_VERIFY=1
COPY . .
RUN go get -u github.com/golang/dep/cmd/dep && \
dep ensure && \
npm run build && \
RUN go run build.go setup && \
RUN go run build.go build && \
dep如何工作是当你运行命令dep ensure
时,它会提取所有依赖项并将它们放在供应商目录中,并且可以通过代码轻松访问。