So this my docker file for building docker image for Go which uses dep package manager.
FROM golang:1.8.5-jessie
# install dep
RUN go get github.com/golang/dep/cmd/dep
# create a working directory
WORKDIR /go/src/app
# add Gopkg.toml and Gopkg.lock
ADD Gopkg.toml Gopkg.toml
ADD Gopkg.lock Gopkg.lock
# install packages
RUN dep ensure --vendor-only
# add source code
ADD src src
# run main.go
CMD ["go", "run", "src/main.go"]
Gopkg.toml looks like this:
[[constraint]]
name = "github.com/spf13/viper"
version = "1.1.0"
[[constraint]]
name = "github.com/gin-gonic/gin"
version = "1.3.0"
[prune]
go-tests = true
unused-packages = true
Docker image builds, but then I try to run it I get these errors:
src/requestHandler/requestHandler.go:4:2: cannot find package "_/go/src/app/vendor/github.com/gin-gonic/gin" in any of:
/usr/local/go/src/_/go/src/app/vendor/github.com/gin-gonic/gin (from $GOROOT)
/go/src/_/go/src/app/vendor/github.com/gin-gonic/gin (from $GOPATH)
src/configReader/configReader.go:4:2: cannot find package "_/go/src/app/vendor/github.com/spf13/viper" in any of:
/usr/local/go/src/_/go/src/app/vendor/github.com/spf13/viper (from $GOROOT)
/go/src/_/go/src/app/vendor/github.com/spf13/viper (from $GOPATH)
It looks like import from vendor package is missing. Can anyone could give me a hint how to fix it?
Project structure as follows:
myproject
|-src
|-httpRouter
| |-httpRouter.go
|-requesthandler
|-requesthandler.go
|-main.go
|-vendor
|-Gopkg.toml
|-Gopkg.lock
httpRouter source code:
package httpRouter
import (
"github.com/gin-gonic/gin"
"../requestHandler"
)
func SetupRouter() *gin.Engine {
router := gin.Default()
v1 := router.Group("api/v1")
{
v1.POST("/submit", requestHandler.HandleSubmitEmailRequest)
}
return router
}
UPDATE changed relative paths:
Getting these errors now.
vendor/github.com/gin-gonic/gin/binding/protobuf.go:11:2: cannot find package "github.com/golang/protobuf/proto" in any of:
/go/src/notification-gateway/vendor/github.com/golang/protobuf/proto (vendor tree)
/usr/local/go/src/github.com/golang/protobuf/proto (from $GOROOT)
/go/src/github.com/golang/protobuf/proto (from $GOPATH)
vendor/github.com/gin-gonic/gin/logger.go:14:2: cannot find package "github.com/mattn/go-isatty" in any of:
/go/src/notification-gateway/vendor/github.com/mattn/go-isatty (vendor tree)
/usr/local/go/src/github.com/mattn/go-isatty (from $GOROOT)
/go/src/github.com/mattn/go-isatty (from $GOPATH)
vendor/github.com/gin-gonic/gin/binding/msgpack.go:12:2: cannot find package "github.com/ugorji/go/codec" in any of:
/go/src/notification-gateway/vendor/github.com/ugorji/go/codec (vendor tree)
/usr/local/go/src/github.com/ugorji/go/codec (from $GOROOT)
/go/src/github.com/ugorji/go/codec (from $GOPATH)
vendor/github.com/gin-gonic/gin/binding/default_validator.go:11:2: cannot find package "gopkg.in/go-playground/validator.v8" in any of:
/go/src/notification-gateway/vendor/gopkg.in/go-playground/validator.v8 (vendor tree)
/usr/local/go/src/gopkg.in/go-playground/validator.v8 (from $GOROOT)
/go/src/gopkg.in/go-playground/validator.v8 (from $GOPATH)