我在一个使用GoLang和Docker 的项目中工作,并使用 go.mod 来维护依赖关系。当我在没有 docker 的情况下构建时,该项目工作正常,但是当我尝试构建 docker 图像时,出现此错误:
internal/server/server.go:8:2: cannot find package "github.com/gorilla/mux" in any of:
/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
/go/src/github.com/gorilla/mux (from $GOPATH)
cmd/root.go:7:2: cannot find package "github.com/spf13/cobra" in any of:
/usr/local/go/src/github.com/spf13/cobra (from $GOROOT)
/go/src/github.com/spf13/cobra (from $GOPATH)
make: *** [Makefile:30: build] Error 1
文件
# Build Stage
FROM lacion/alpine-golang-buildimage:1.9.7 AS build-stage
LABEL app="build-status-hub"
LABEL REPO="https://github.com/MSLacerda/status-hub"
ENV PROJPATH=/go/src/github.com/MSLacerda/status-hub
# Because of https://github.com/docker/docker/issues/14914
ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin
ADD . /go/src/github.com/MSLacerda/status-hub
WORKDIR /go/src/github.com/MSLacerda/status-hub
RUN make build
Dockerfile其实有更多的指令,但我只把控制台显示错误的部分放在这里。
生成文件
build:
@echo "building ${BIN_NAME} ${VERSION}"
@echo "GOPATH=${GOPATH}"
go build -ldflags "-X github.com/MSLacerda/status-hub/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X github.com/MSLacerda/status-hub/version.BuildDate=${BUILD_DATE}" -o bin/${BIN_NAME}
go.mod
module github.com/MSLacerda/status-hub
require (
github.com/Sirupsen/logrus v1.0.6
github.com/gorilla/mux v1.7.0
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.2.0
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2 // indirect
)
萧十郎
相关分类