go build can't find package sources

Yaron Idan picture Yaron Idan · Nov 16, 2018 · Viewed 7.9k times · Source

I'm trying to build the teamcity prometheus exporter I found in this repo.
In the readme it instructs me to execute the following command which should build the project - docker run --rm -v "$PWD":/go/src/github.com/guidewire/teamcity_exporter -w /go/src/github.com/guidewire/teamcity_exporter -e GOOS=linux -e GOARCH=amd64 golang:1.8 go build -o bin/teamcity_exporter -v

But it fails with the following error -

teamcity_exporter.go:15:2: cannot find package "github.com/guidewire/teamcity-go-bindings" in any of:
    /go/src/github.com/guidewire/teamcity_exporter/vendor/github.com/guidewire/teamcity-go-bindings (vendor tree)
    /usr/local/go/src/github.com/guidewire/teamcity-go-bindings (from $GOROOT)
    /go/src/github.com/guidewire/teamcity-go-bindings (from $GOPATH)
teamcity_exporter.go:16:2: cannot find package "github.com/orcaman/concurrent-map" in any of:
    /go/src/github.com/guidewire/teamcity_exporter/vendor/github.com/orcaman/concurrent-map (vendor tree)
    /usr/local/go/src/github.com/orcaman/concurrent-map (from $GOROOT)
    /go/src/github.com/orcaman/concurrent-map (from $GOPATH)
collector.go:6:2: cannot find package "github.com/prometheus/client_golang/prometheus" in any of:
    /go/src/github.com/guidewire/teamcity_exporter/vendor/github.com/prometheus/client_golang/prometheus (vendor tree)
    /usr/local/go/src/github.com/prometheus/client_golang/prometheus (from $GOROOT)
    /go/src/github.com/prometheus/client_golang/prometheus (from $GOPATH)
teamcity_exporter.go:18:2: cannot find package "github.com/prometheus/common/log" in any of:
    /go/src/github.com/guidewire/teamcity_exporter/vendor/github.com/prometheus/common/log (vendor tree)
    /usr/local/go/src/github.com/prometheus/common/log (from $GOROOT)
    /go/src/github.com/prometheus/common/log (from $GOPATH)
teamcity_exporter.go:19:2: cannot find package "github.com/prometheus/common/version" in any of:
    /go/src/github.com/guidewire/teamcity_exporter/vendor/github.com/prometheus/common/version (vendor tree)
    /usr/local/go/src/github.com/prometheus/common/version (from $GOROOT)
    /go/src/github.com/prometheus/common/version (from $GOPATH)
config.go:8:2: cannot find package "gopkg.in/yaml.v2" in any of:
    /go/src/github.com/guidewire/teamcity_exporter/vendor/gopkg.in/yaml.v2 (vendor tree)
    /usr/local/go/src/gopkg.in/yaml.v2 (from $GOROOT)
    /go/src/gopkg.in/yaml.v2 (from $GOPATH)

I've tried looking around for go package managers and using them to preinstall the packages (went over dep and govendor but both didn't seem fit to my use case) .

Also opened an issue in the github repo but there are a few other issues that didn't get any response so I'm not getting my hopes up.

I'm not that familiar with go, so I was hoping someone here might have a clue as to what I'm missing.
Thanks!

Answer

poy picture poy · Nov 16, 2018

I would recommend changing go build to go get. That should fetch all the dependencies and will also build the binary and drop it into $GOPATH/bin. go build expects everything to already be in place.