Building specific commit


(Kevin Orr) #1

I’ve seen the line in the docs that mentions how to build from source:

If you want to install from source, you can use go get to install to $GOPATH/bin.
go get -v github.com/dgraph-io/dgraph/dgraph

But there doesn’t seem to be any way to build a specific version. I’ve also tried checking out the repo locally, switching to the desired commit, and using go build inside of the dgraph/ directory, but that doesn’t fetch dependencies automatically. What is the right way to do this?


(Francesc Campoy) #2

Hi @KevOrr,

Yes, you are right in the fact that go get does not provide a way to checkout a specific version.
The approach you took is the right one:

  • go get the repository
  • go to the repository directory under your GOPATH (I’m assuming you’re not using modules)
  • git checkout $VERSION
  • go install ./....

Let us know if you need anything else!


#3

Hi @francesc, i tried this steps but it finished with errors.

Here is what I did (everything is running in Docker - docker run -it --rm golang bash).

go get -v github.com/dgraph-io/dgraph/dgraph
cd /go/src/github.com/dgraph-io/dgraph/
git fetch --all --tags --prune
git checkout tags/v1.0.15-rc9 -b version
go install ./dgraph/

Errors:

vendor/contrib.go.opencensus.io/exporter/jaeger/internal/gen-go/jaeger/agent.go:11:2: cannot find package "github.com/apache/thrift/lib/go/thrift" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/github.com/apache/thrift/lib/go/thrift (vendor tree)
	/usr/local/go/src/github.com/apache/thrift/lib/go/thrift (from $GOROOT)
	/go/src/github.com/apache/thrift/lib/go/thrift (from $GOPATH)
edgraph/access_ee.go:24:2: cannot find package "github.com/dgrijalva/jwt-go" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/github.com/dgrijalva/jwt-go (vendor tree)
	/usr/local/go/src/github.com/dgrijalva/jwt-go (from $GOROOT)
	/go/src/github.com/dgrijalva/jwt-go (from $GOPATH)
vendor/github.com/dgraph-io/dgo/protos/api/api.pb.go:6:8: cannot find package "github.com/golang/protobuf/proto" in any of:
	/go/src/github.com/dgraph-io/dgraph/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)
dgraph/cmd/zero/raft.go:37:2: cannot find package "github.com/google/uuid" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/github.com/google/uuid (vendor tree)
	/usr/local/go/src/github.com/google/uuid (from $GOROOT)
	/go/src/github.com/google/uuid (from $GOPATH)
x/metrics.go:24:2: cannot find package "github.com/prometheus/client_golang/prometheus" in any of:
	/go/src/github.com/dgraph-io/dgraph/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)
conn/pool.go:30:2: cannot find package "go.opencensus.io/plugin/ocgrpc" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/go.opencensus.io/plugin/ocgrpc (vendor tree)
	/usr/local/go/src/go.opencensus.io/plugin/ocgrpc (from $GOROOT)
	/go/src/go.opencensus.io/plugin/ocgrpc (from $GOPATH)
vendor/contrib.go.opencensus.io/exporter/jaeger/jaeger.go:30:2: cannot find package "go.opencensus.io/trace" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/go.opencensus.io/trace (vendor tree)
	/usr/local/go/src/go.opencensus.io/trace (from $GOROOT)
	/go/src/go.opencensus.io/trace (from $GOPATH)
dgraph/cmd/alpha/run.go:49:2: cannot find package "go.opencensus.io/zpages" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/go.opencensus.io/zpages (vendor tree)
	/usr/local/go/src/go.opencensus.io/zpages (from $GOROOT)
	/go/src/go.opencensus.io/zpages (from $GOPATH)
vendor/github.com/dgraph-io/dgo/protos/api/api.pb.go:11:2: cannot find package "golang.org/x/net/context" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/golang.org/x/net/context (vendor tree)
	/usr/local/go/src/golang.org/x/net/context (from $GOROOT)
	/go/src/golang.org/x/net/context (from $GOPATH)
vendor/github.com/dgraph-io/badger/y/watermark.go:24:2: cannot find package "golang.org/x/net/trace" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/golang.org/x/net/trace (vendor tree)
	/usr/local/go/src/golang.org/x/net/trace (from $GOROOT)
	/go/src/golang.org/x/net/trace (from $GOPATH)
vendor/contrib.go.opencensus.io/exporter/jaeger/jaeger.go:31:2: cannot find package "google.golang.org/api/support/bundler" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/google.golang.org/api/support/bundler (vendor tree)
	/usr/local/go/src/google.golang.org/api/support/bundler (from $GOROOT)
	/go/src/google.golang.org/api/support/bundler (from $GOPATH)
vendor/github.com/dgraph-io/dgo/protos/api/api.pb.go:12:2: cannot find package "google.golang.org/grpc" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/google.golang.org/grpc (vendor tree)
	/usr/local/go/src/google.golang.org/grpc (from $GOROOT)
	/go/src/google.golang.org/grpc (from $GOPATH)
vendor/github.com/dgraph-io/dgo/txn.go:22:2: cannot find package "google.golang.org/grpc/codes" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/google.golang.org/grpc/codes (vendor tree)
	/usr/local/go/src/google.golang.org/grpc/codes (from $GOROOT)
	/go/src/google.golang.org/grpc/codes (from $GOPATH)
x/x.go:37:2: cannot find package "google.golang.org/grpc/credentials" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/google.golang.org/grpc/credentials (vendor tree)
	/usr/local/go/src/google.golang.org/grpc/credentials (from $GOROOT)
	/go/src/google.golang.org/grpc/credentials (from $GOPATH)
x/x.go:38:2: cannot find package "google.golang.org/grpc/encoding/gzip" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/google.golang.org/grpc/encoding/gzip (vendor tree)
	/usr/local/go/src/google.golang.org/grpc/encoding/gzip (from $GOROOT)
	/go/src/google.golang.org/grpc/encoding/gzip (from $GOPATH)
dgraph/cmd/alpha/run.go:55:2: cannot find package "google.golang.org/grpc/health" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/google.golang.org/grpc/health (vendor tree)
	/usr/local/go/src/google.golang.org/grpc/health (from $GOROOT)
	/go/src/google.golang.org/grpc/health (from $GOPATH)
dgraph/cmd/alpha/run.go:56:2: cannot find package "google.golang.org/grpc/health/grpc_health_v1" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/google.golang.org/grpc/health/grpc_health_v1 (vendor tree)
	/usr/local/go/src/google.golang.org/grpc/health/grpc_health_v1 (from $GOROOT)
	/go/src/google.golang.org/grpc/health/grpc_health_v1 (from $GOPATH)
query/query.go:30:2: cannot find package "google.golang.org/grpc/metadata" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/google.golang.org/grpc/metadata (vendor tree)
	/usr/local/go/src/google.golang.org/grpc/metadata (from $GOROOT)
	/go/src/google.golang.org/grpc/metadata (from $GOPATH)
edgraph/access_ee.go:26:2: cannot find package "google.golang.org/grpc/peer" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/google.golang.org/grpc/peer (vendor tree)
	/usr/local/go/src/google.golang.org/grpc/peer (from $GOROOT)
	/go/src/google.golang.org/grpc/peer (from $GOPATH)
vendor/github.com/dgraph-io/dgo/txn.go:23:2: cannot find package "google.golang.org/grpc/status" in any of:
	/go/src/github.com/dgraph-io/dgraph/vendor/google.golang.org/grpc/status (vendor tree)
	/usr/local/go/src/google.golang.org/grpc/status (from $GOROOT)
	/go/src/google.golang.org/grpc/status (from $GOPATH)

Any suggestion?


(Kevin Orr) #4

Thanks for your reply @francesc. Installing master this way works:

~ $ mkdir /tmp/go
~ $ export GOPATH=/tmp/go
~ $ go get github.com/dgraph-io/dgraph/dgraph
~ $ cd /tmp/go/src/github.com/dgraph-io/dgraph
/tmp/go/src/github.com/dgraph-io/dgraph $ go install ./...
# github.com/dgraph-io/dgraph/contrib/embargo
loadinternal: cannot find runtime/cgo
/tmp/go/src/github.com/dgraph-io/dgraph $ 

But when trying to checkout a commit before installing:

~ $ mkdir /tmp/go
~ $ export GOPATH=/tmp/go
~ $ go get github.com/dgraph-io/dgraph/dgraph
~ $ cd /tmp/go/src/github.com/dgraph-io/dgraph
/tmp/go/src/github.com/dgraph-io/dgraph $ git checkout v1.0.14
Note: checking out 'v1.0.14'.

...

/tmp/go/src/github.com/dgraph-io/dgraph $ go install ./...
vendor/github.com/dgraph-io/badger/pb/pb.pb.go:6:8: cannot find package "github.com/golang/protobuf/proto" in any of:
	/tmp/go/src/github.com/dgraph-io/dgraph/vendor/github.com/golang/protobuf/proto (vendor tree)
	/usr/lib/go/src/github.com/golang/protobuf/proto (from $GOROOT)
	/tmp/go/src/github.com/golang/protobuf/proto (from $GOPATH)
x/metrics.go:24:2: cannot find package "github.com/prometheus/client_golang/prometheus" in any of:
	/tmp/go/src/github.com/dgraph-io/dgraph/vendor/github.com/prometheus/client_golang/prometheus (vendor tree)
	/usr/lib/go/src/github.com/prometheus/client_golang/prometheus (from $GOROOT)
	/tmp/go/src/github.com/prometheus/client_golang/prometheus (from $GOPATH)
x/x.go:35:2: cannot find package "go.opencensus.io/trace" in any of:
	/tmp/go/src/github.com/dgraph-io/dgraph/vendor/go.opencensus.io/trace (vendor tree)
	/usr/lib/go/src/go.opencensus.io/trace (from $GOROOT)
	/tmp/go/src/go.opencensus.io/trace (from $GOPATH)

...

It appears that some dependencies have changed between v1.0.14 and master, and go get wasn’t aware of those dependencies since it saw the repo at master.

Edit: wow haha @selmeci good timing


#5

In my case, I managed to build v1.0.14 in this way.

# at first build "master"
go get -v github.com/dgraph-io/dgraph/dgraph

# fetch target source of dgraph
cd $GOPATH/src/github.com/dgraph-io/dgraph/
git checkout v1.0.14

# in my case (v1.0.14), old? opencensus source is needed.
cd $GOPATH/src/go.opencensus.io/
git checkout v0.20.x

# I did go get again. go install is not sufficient???
go get -v github.com/dgraph-io/dgraph/dgraph

In this way, output of “dgraph version” command is not correct, so I want to know how to build specific source using make command.


(Kevin Orr) #6

@dkato with a fresh system I also had to go get go.opencensus.io. Also, this line might help you figure out how to embed the version info in the binary