I have a npm binary I'd like to package up in a Docker container. I have this configuration:
# Docker image for the Mongo Stitch command
FROM golang:alpine
# Do a system update
RUN apk update
RUN apk add git
# Declare base dir
WORKDIR /root
# The console binary for Mongo Stitch
RUN git clone https://github.com/10gen/stitch-cli.git
WORKDIR /root/stitch-cli
RUN go build
CMD ["/bin/sh"]
I get this error:
main.go:8:2: cannot find package "github.com/10gen/stitch-cli/commands" in any of:
/usr/local/go/src/github.com/10gen/stitch-cli/commands (from $GOROOT)
/go/src/github.com/10gen/stitch-cli/commands (from $GOPATH)
main.go:9:2: cannot find package "github.com/10gen/stitch-cli/utils" in any of:
/usr/local/go/src/github.com/10gen/stitch-cli/utils (from $GOROOT)
/go/src/github.com/10gen/stitch-cli/utils (from $GOPATH)
main.go:11:2: cannot find package "github.com/mitchellh/cli" in any of:
/usr/local/go/src/github.com/mitchellh/cli (from $GOROOT)
/go/src/github.com/mitchellh/cli (from $GOPATH)
This is unexpected, since I imagine the official Go container would have everything I need. I have these vars set:
~ # set | grep GO
GOLANG_VERSION='1.11.5'
GOPATH='/go'
The build instructions say that go build
is sufficient to get this working. I have played with go get
, with various error outputs, but I think this might be a wild goose chase, since if I had to fetch dependencies manually the instructions would have said so.
For what it's worth though, if I do issue a go get
in the container shell, I get this:
~/stitch-cli # go get
go get: no install location for directory /root/stitch-cli outside GOPATH
For more details see: 'go help gopath'
I've tried parsing the material in said help file, but I am not sure what part applies to my case.
So, I wondered if missing GOROOT
was worth fixing. I did this:
~/stitch-cli # which go
/usr/local/go/bin/go
~/stitch-cli # GOROOT=/usr/local/go
~/stitch-cli # export GOROOT
~/stitch-cli # go build
# _/root/stitch-cli
./main.go:25:3: cannot use commands.NewWhoamiCommandFactory(ui) (type "github.com/10gen/stitch-cli/vendor/github.com/mitchellh/cli".CommandFactory) as type "github.com/mitchellh/cli".CommandFactory in map value
./main.go:26:3: cannot use commands.NewLoginCommandFactory(ui) (type "github.com/10gen/stitch-cli/vendor/github.com/mitchellh/cli".CommandFactory) as type "github.com/mitchellh/cli".CommandFactory in map value
./main.go:27:3: cannot use commands.NewLogoutCommandFactory(ui) (type "github.com/10gen/stitch-cli/vendor/github.com/mitchellh/cli".CommandFactory) as type "github.com/mitchellh/cli".CommandFactory in map value
./main.go:28:3: cannot use commands.NewExportCommandFactory(ui) (type "github.com/10gen/stitch-cli/vendor/github.com/mitchellh/cli".CommandFactory) as type "github.com/mitchellh/cli".CommandFactory in map value
./main.go:29:3: cannot use commands.NewImportCommandFactory(ui) (type "github.com/10gen/stitch-cli/vendor/github.com/mitchellh/cli".CommandFactory) as type "github.com/mitchellh/cli".CommandFactory in map value
~/stitch-cli #
OK, maybe this is a bit further, but I am now firmly in "trying random things" territory. Is there something I can do to have it work out of the box?
I also tried ordinary Alpine (v3.9) with Go manually installed, and that did not even have GOPATH
set, but I got much the same "cannot find package" errors. What could I try next to get this to compile?
I have also tried switching to the full-fat version of the Golang image, rather than this lighter Alpine image, and I get the same issues, both with build
and get
.
I could also go back to installing via NPM, but I had problems with that (and that issue would probably be out of scope of a Golang question).
Possible duplicate
My question has been identified as a possible duplicate of this question. I think that question is essentially a duplicate of the secondary problem noted here, which as I mentioned earlier, was probably a red herring. If there are any dups detailing an answer to the first error, that would likely be a better signpost.