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

missing dot in first path element when building from official golang Docker image #37396

Closed
lucas-dehandschutter opened this issue Feb 24, 2020 · 4 comments

Comments

@lucas-dehandschutter
Copy link

lucas-dehandschutter commented Feb 24, 2020

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

$ go version
go version go1.13.8 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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY="git.my.company.com"
GONOSUMDB="git.my.company.com"
GOOS="linux"
GOPATH="/go"
GOPRIVATE="git.my.company.com"
GOPROXY="https://repo.my.company.com/artifactory/api/go/proxy-go"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/go/myapp/go.mod"
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-build900476856=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I have a Go module project organized as follow:

/myapp
└── /src
    └── /foo 
        └── bar.go
└── main.go 
└── go.mod           
└── Dockerfile

The main.go file looks like this:

package main

import "myapp/src/foo"

func main() {
	foo.bar()
}

go.mod:

module myapp

go 1.13

require git.my.company.com/golang/anotherdep v1.0.3

On my workstation, this project build correctly with go build main.go

Now, I want to build this project from a Dockerfile in order to integrate it in a deployment pipeline.

The Dockerfile is as follow:

FROM golang:1.13.8-buster as build
ENV GO111MODULE="on"
ENV GOPROXY="https://repo.my.company.com/artifactory/api/go/proxy-go"
ENV GOPRIVATE="git.my.company.com"

RUN mkdir myapp
COPY ./* ./myapp/
WORKDIR ./myapp/
RUN go env
RUN go build -o app -v -x main.go

When I build this project from the Dockerfile, it fails:

$ docker build --no-cache -t myapp .
...
build command-line-arguments: cannot load myapp/src/foo: malformed module path "myapp/src/foo": missing dot in first path element
go env Output from my workstation
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/me/.cache/go-build"
GOENV="/home/me/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY="git.my.company.com
GONOSUMDB="git.my.company.com"
GOOS="linux"
GOPATH="/home/me/go"
GOPRIVATE="git.my.company.com"
GOPROXY="https://repo.my.company.com/artifactory/api/go/proxy-go"
GOROOT="/snap/go/5364"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/snap/go/5364/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/me/gitrepo/myapp/go.mod"
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-build720872982=/tmp/go-build -gno-record-gcc-switches"
go env Output from the build container
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY="git.my.company.com"
GONOSUMDB="git.my.company.com"
GOOS="linux"
GOPATH="/go"
GOPRIVATE="git.my.company.com"
GOPROXY="https://repo.my.company.com/artifactory/api/go/proxy-go"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/go/myapp/go.mod"
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-build900476856=/tmp/go-build -gno-record-gcc-switches"
@lucas-dehandschutter lucas-dehandschutter changed the title missing dot in first path element when building from official golang image missing dot in first path element when building from official golang Docker image Feb 24, 2020
@bcmills
Copy link
Contributor

bcmills commented Feb 24, 2020

The error message is not wrong.

Since there is no go.mod file in your project, main.go is not within a module, and the location of package myapp/src/foo is not specified.

The error message should at least be more helpful in Go 1.14. (See #32027.)

@bcmills bcmills closed this as completed Feb 24, 2020
@bcmills
Copy link
Contributor

bcmills commented Feb 24, 2020

For more information on how to set up a project using Go modules, see the series of blog posts starting with https://blog.golang.org/using-go-modules.

@lucas-dehandschutter
Copy link
Author

There is a go.mod in my project

Here is the file

module myapp

go 1.13

require git.my.company.com/golang/anotherdep v1.0.3

@lucas-dehandschutter
Copy link
Author

I just find out that the issue came from the copy instruction in my Dockerfile.
I used

COPY ./* ./myapp/

instead of

COPY . ./myapp/

@golang golang locked and limited conversation to collaborators Feb 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants