Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consul registry broken: mismatch in type due to import being expected from "github.com/hashicorp/consul/vendor" #502

Closed
desertjinn opened this issue Jun 7, 2019 · 20 comments

Comments

@desertjinn
Copy link

My Go version is 1.12.5.

I'm building my package binary using the golang1.12.5-alpine3.9 Docker image as a package builder and I'm running the following commands in my Dockerfile to install all the necessary dependencies -

# install source dependencies
RUN go get -d -v ./...
RUN go install -v ./...

the go get command works as expected but the go install command crashes with an exit code: 2 and the following message -

# github.com/micro/go-micro/registry/consul
/go/src/github.com/micro/go-micro/registry/consul/watcher.go:48:33: cannot use cr.Client (type *"github.com/hashicorp/consul/api".Client) as type *"github.com/hashicorp/consul/vendor/github.com/hashicorp/consul/api".Client in argument to wp.RunWithClientAndLogger
/go/src/github.com/micro/go-micro/registry/consul/watcher.go:213:37: cannot use cw.r.Client (type *"github.com/hashicorp/consul/api".Client) as type *"github.com/hashicorp/consul/vendor/github.com/hashicorp/consul/api".Client in argument to wp.RunWithClientAndLogger

Just FYI, I was able to generate the Docker based package builder successfully up till 3 days ago.

@SteveZhangF
Copy link

same here, got

../github.com/micro/go-micro/registry/consul/watcher.go:48:33: cannot use cr.Client (type *"github.com/hashicorp/consul/api".Client) as type *"github.com/hashicorp/consul/vendor/github.com/hashicorp/consul/api".Client in argument to wp.RunWithClientAndLogger ../github.com/micro/go-micro/registry/consul/watcher.go:213:37: cannot use cw.r.Client (type *"github.com/hashicorp/consul/api".Client) as type *"github.com/hashicorp/consul/vendor/github.com/hashicorp/consul/api".Client in a

@asim
Copy link
Member

asim commented Jun 7, 2019

go get -u?

@desertjinn
Copy link
Author

desertjinn commented Jun 7, 2019

Using go get -u
instead of

go get -d -v ./...
go install -v ./...

Response:

directory "/go/src/<path/to/package directory>" is not using a known version control system

Also tried - go get -u ... with the same result

@asim - just out of curiosity, hashicorp/consul appears to be in the process of enabling go module support(see here).
is that what's causing this?

@vtolstov
Copy link
Contributor

vtolstov commented Jun 7, 2019

please, provide go env output

@desertjinn
Copy link
Author

@vtolstov -

Docker image: golang:1.12.5-alpine3.9

go env output:

GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build607154663=/tmp/go-build -gno-record-gcc-switches"

@vtolstov
Copy link
Contributor

vtolstov commented Jun 7, 2019

as i see you don't use go modules, so you have deps that conflict with each other.
try setting export GO111MODULE=on

@vtolstov
Copy link
Contributor

vtolstov commented Jun 7, 2019

i don't understand why it work before..
also do you have all deps in vendor folder or download it in docker based package builder?

@SteveZhangF
Copy link

I have the same issue with @desertjinn, using same docker image, it was work well yesterday, suddenly not working this morning.

@vtolstov tried export GO111MODULE=on still not working.

@vtolstov
Copy link
Contributor

vtolstov commented Jun 7, 2019

if you try to add go mod vendor step before build and use go build -mod vendor ?

@vtolstov
Copy link
Contributor

vtolstov commented Jun 7, 2019

i think that hashicorp/consul dep changed in our module file..

@desertjinn
Copy link
Author

@vtolstov - I do not have a vendor folder as I'm not using go modules to manage dependencies in my package(cause from what I understand the vendor folder is used by go modules)

And yeah, "hashicorp/consul" seem to be enabling go module support(see here) which might have caused this.

@vtolstov
Copy link
Contributor

vtolstov commented Jun 7, 2019

if you don't have vendor dir, go with enabled modules download all deps when build package, if vendor exists - it gets it from here.
i think if you use go modules by default when get and build package it may work.
if you provide some easy reproducible steps i can try myself

@desertjinn
Copy link
Author

desertjinn commented Jun 7, 2019

@vtolstov - tried with export GO111MODULE=on and it's not working for me either.
Also, I'm attempting to build packages from a private repository. So sharing my build steps might not be useful.
Anyways, here's a sample of my Dockerfile
(the missing bits are for enabling access to my private repository)

# **************************************************
# start from golang 1.12.5 image based on ***
# alpine-3.9 **************************************
# **************************************************
FROM golang:1.12.5-alpine3.9

# **************************************************
# Add arguments to retrieve values from the ********
# CLI --build-args flag to the builder *************
# **************************************************
ARG ...
.....
.....

RUN apk add --no-cache ca-certificates git 

# **************************************************
# Configure container to use private repository ****
# instead of Go's default access pattern for *******
# the proper working of Go's dep package ***********
# (this ensures all the dependencies defined in ****
# the package files are available during ***********
# the build) ***************************************
# **************************************************
RUN ...
.....
.....
.....

# **************************************************
# Copy source files and build the Go binary **
# **************************************************
# create the necessary folders under Go's src
RUN mkdir -p /go/src/<private-repo>/<pacakge>
# switch to newly created folder for building the binary
WORKDIR /go/src/<private-repo>/<pacakge>
# copy source files
COPY . .
## install source dependencies
RUN go get -d -v ./...
RUN go install -v ./...

WORKDIR /go

Note that no build steps are available in the file as this is used only to generate the base Docker image that will be used further as a package builder.

@subzerobo
Copy link

subzerobo commented Jun 8, 2019

@asim

my version is 1.12.5 same with 1.11.6 too

It seems that this issue shows up when executing go get -u github.com/micro/go-micro even after I've cleaned up whole micro folder + hashicorp from github.com folder inside $GOPATH/src/github.com

../../../micro/go-micro/registry/consul/watcher.go:48:33: cannot use cr.Client (type *"github.com/hashicorp/consul/api".Client) as type *"github.com/hashicorp/consul/vendor/github.com/hashicorp/consul/api".Client in argument to wp.RunWithClientAndLogger
../../../micro/go-micro/registry/consul/watcher.go:213:37: cannot use cw.r.Client (type *"github.com/hashicorp/consul/api".Client) as type *"github.com/hashicorp/consul/vendor/github.com/hashicorp/consul/api".Client in argument to wp.RunWithClientAndLogger

@asim
Copy link
Member

asim commented Jun 8, 2019

We're not really responsible for consuls use of censoring and the mismatch in types. We're now using go modules to manage any dependencies and I can imagine hashicorp is doing this vendoring in related to their new sub package versioning.

Our builds show that this builds perfectly fine with go modules. If you otherwise have a fix please feel free to PR.

@subzerobo
Copy link

@asim
I know that, but consider someone is going to start with your project right now, for example, you said that in go.mod you will use github.com/hashicorp/consul/api v1.1.0, even in a clean $GOHOME/src/ when we run the go get -u github.com/micro/micro we get the error ?

https://travis-ci.org/micro/go-micro/jobs/541640654

@c-warren
Copy link

c-warren commented Jun 8, 2019

I also saw this problem:
$ make build protoc -I. --go_out=plugins=micro:. \ proto/course/course.proto GOOS=linux GOARCH=amd64 go build

github.com/micro/go-micro/registry/consul
../../../micro/go-micro/registry/consul/watcher.go:48:33: cannot use cr.Client (type *"github.com/hashicorp/consul/api".Client) as type *"github.com/hashicorp/consul/vendor/github.com/hashicorp/consul/api".Client in argument to wp.RunWithClientAndLogger
../../../micro/go-micro/registry/consul/watcher.go:213:37: cannot use cw.r.Client (type *"github.com/hashicorp/consul/api".Client) as type *"github.com/hashicorp/consul/vendor/github.com/hashicorp/consul/api".Client in argument to wp.RunWithClientAndLogger
Makefile:2: recipe for target 'build' failed
make: *** [build] Error 2

I ended up doing:
$ go clean -modcache
$ export GO111MODULE=on
$ go get -u
And now I have my builds working.

@asim
Copy link
Member

asim commented Jun 8, 2019

Hashicorp have included a vendor directory as of yesterday which causes this break. Using go modules seems to be the only solution for now. We need to file an issue with them or find a way to resolve this vendoring issue.

@desertjinn
Copy link
Author

Switched to using go modules for managing packages and it works as expected now

@asim
Copy link
Member

asim commented Jun 9, 2019

Closing the issue

@asim asim closed this as completed Jun 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants