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

go module #29300

Closed
marc-hybridblock opened this issue Dec 17, 2018 · 3 comments
Closed

go module #29300

marc-hybridblock opened this issue Dec 17, 2018 · 3 comments
Labels
FrozenDueToAge modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@marc-hybridblock
Copy link

What version of Go are you using (go version)? GO 1.11.2

$ root@f590661e3876:/srv/green# go version
go version go1.11.2 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
root@f590661e3876:/srv/green# go env
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="/srv/green/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

i have a directory github.com/product/color

and im building a mono repo with go kit this is my directory

/color/green/go.mod
/dockerfile
/blue/go.mod
/dockerfile
/yellow/go.mod
/dockerfile
/docker-compose.yaml
/frontend/
/react/

my dockerfile is like this

FROM golang

RUN mkdir -p /srv/green
WORKDIR /srv/green
COPY ./green /srv/green

RUN go get github.com/canthefason/go-watcher
RUN go install github.com/canthefason/go-watcher/cmd/watcher

RUN ls -lrt
ENV GO111MODULE=on
RUN go build

ENTRYPOINT watcher -watch /srv/

basically i just mount my needed go service and run

but i can make it run using go module if im using my sub package within the service

bash: tree: command not found
root@f590661e3876:/srv/green# go build
build github.com/product/color/: cannot find module for path github.com/product/color/green/lib

What did you expect to see?

What did you see instead?

@bcmills
Copy link
Contributor

bcmills commented Dec 18, 2018

  1. Why do you have mulitple go.mod files? (Are you versioning the modules separately?) In most cases it's simpler to have a single module per repository.

  2. Please distill your example down to the actual go commands involved, without the Docker boilerplate. If you figure out the correct go commands to run, then that should be straightforward to translate that into a dockerfile, but trying to do both at once makes the example much more difficult to follow.

  3. Unless I'm mistaken, it looks like you're combining commands in GOPATH mode (go get and go install) with one in module mode (go build). The long-term plan is to replace GOPATH mode completely, so if you're planning to use module mode it's much clearer to use it consistently from the start.

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. modules Question labels Dec 18, 2018
@Zaba505
Copy link

Zaba505 commented Dec 19, 2018

@marc-hybridblock

but i can make it run using go module if im using my sub package within the service

I'm assuming this means that it builds when you run go build locally on your machine inside the green directory. If that is correct, then the build failure stems from the

COPY ./green /srv/green

This is because when go build builds it uses the import path to either locate dependencies or sub packages. By copying the green directory, which is apart of the path github.com/product/color/green, into /srv/green/ you change the import paths without changing them in the source. The build output shows this with

cannot find module for path github.com/product/color/green/lib

The above message occurs because the Dockerfile COPY changes the location of the green package from github.com/product/color/green/lib to srv/green/lib, which is obviously not the root path for the lib sub package mentioned in the build failure.

To resolve this I recommend not build locally i.e. no COPY and instead go get the sub module you want. This solution is especially nice, since go get will also build the module after retrieving it so no go build has to be run. However, if building locally is desired I'd recommend copying your sub module directory-for-directory into Docker, as to avoid any unresolvable import paths.

@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Jan 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants