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

docker run failed #897

Closed
DarthPestilane opened this issue Dec 25, 2019 · 10 comments
Closed

docker run failed #897

DarthPestilane opened this issue Dec 25, 2019 · 10 comments
Labels
area: docker bug Something isn't working feedback required Requires additional feedback

Comments

@DarthPestilane
Copy link

run this

docker run --rm -v $(pwd):/app -w /app  golangci/golangci-lint:v1.21.0 golangci-lint run

as readme.md said.

and error happend:

level=error msg="Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler"

tested on macOS

@tpounds tpounds added bug Something isn't working area: docker labels Dec 30, 2019
@tpounds
Copy link
Contributor

tpounds commented Dec 30, 2019

@DarthPestilane Does this only happen on macOS with Docker? Do you get the same error with the binary release?

@tpounds tpounds added the feedback required Requires additional feedback label Dec 30, 2019
@ernado
Copy link
Member

ernado commented Jan 3, 2020

Seems like same as #884

@Luzifer
Copy link

Luzifer commented Jan 6, 2020

  • Docker: 19.03.5-ce
  • OS: Archlinux
# tags=(latest latest-alpine v1.21-alpine v1.22-alpine v1.22.2-alpine)
# for tag in "${tags[@]}"; do echo "==== $tag"; docker run --rm -ti -v $(pwd):$(pwd) -w $(pwd) golangci/golangci-lint:$tag golangci-lint run; done
==== latest
ERRO Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler 
==== latest-alpine
ERRO Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler 
==== v1.21-alpine
ERRO Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler 
==== v1.22-alpine
ERRO Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler 
==== v1.22.2-alpine
ERRO Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler 
# docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.22.2 golangci-lint run -v
level=info msg="[config_reader] Config search paths: [./ /app /]"
level=info msg="[config_reader] Used config file .golangci.yml"
level=info msg="[lintersdb] Active 30 linters: [bodyclose deadcode depguard dogsled funlen gocognit goconst gocritic gocyclo godox gofmt goimports golint gomnd gosec gosimple govet ineffassign misspell nakedret prealloc scopelint staticcheck structcheck stylecheck typecheck unconvert unused varcheck wsl]"
level=info msg="[lintersdb] Active 30 linters: [bodyclose deadcode depguard dogsled funlen gocognit goconst gocritic gocyclo godox gofmt goimports golint gomnd gosec gosimple govet ineffassign misspell nakedret prealloc scopelint staticcheck structcheck stylecheck typecheck unconvert unused varcheck wsl]"
level=info msg="[loader] Go packages loading at mode 575 (imports|name|types_sizes|compiled_files|deps|exports_file|files) took 2.365517004s"
level=error msg="Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler"
level=info msg="Memory: 25 samples, avg is 68.9MB, max is 68.9MB"
level=info msg="Execution took 2.375639296s"

# docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.22.2 golangci-lint run -v
level=info msg="[config_reader] Config search paths: [./ /app /]"
level=info msg="[lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
level=info msg="[lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
level=info msg="[loader] Go packages loading at mode 575 (name|types_sizes|exports_file|deps|files|imports|compiled_files) took 2.42721109s"
level=error msg="Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler"
level=info msg="Memory: 26 samples, avg is 68.7MB, max is 68.7MB"
level=info msg="Execution took 2.43755305s"

Not experiencing the same issue when running golangci-lint run locally with version built from master on 2020-01-02.

@Luzifer
Copy link

Luzifer commented Jan 8, 2020

Follow-up on my last comment:

When executing the same commands with golangci/golangci-lint:v1.22.2-alpine and enabled --modules-download-mode=vendor the error does not occur.

@ClaudiaJ
Copy link

ClaudiaJ commented Jan 8, 2020

We found in reviewdog/action-golangci-lint#21 this error occurs with projects importing private module dependencies.

I've tested further by downloading modules to host, mounting the host's ${GOPATH}/pkg/mod into the container, and passing --modules-download-mode=readonly:

go mod download
docker run --rm \
        -v ${GOPATH}/pkg/mod:/go/pkg/mod \
        -v $(pwd):/app \
        -w /app \
        golangci/golangci-lint:v1.22.2-alpine \
        golangci-lint run -v --modules-download-mode=readonly

This successfully ran, bypassing the error. It's not ideal though, as I'm not yet sure how (if possible) to mount a volume from host w/in GitHub Actions to solve my own needs.

@Dominik-K
Copy link
Contributor

Dominik-K commented Jan 13, 2020

@DarthPestilane @Luzifer @ClaudiaJ : What are the outputs when you add the environment variables GL_DEBUG=linters_output GOPACKAGESPRINTGOLISTERRORS=1 (source)? That gives a better insight & can reveal different root causes.

@Luzifer
Copy link

Luzifer commented Jan 13, 2020

# docker run --rm -v $(pwd):/app -w /app -e GL_DEBUG=linters_output -e GOPACKAGESPRINTGOLISTERRORS=1 golangci/golangci-lint:v1.22.2-alpine golangci-lint run -v
level=info msg="[config_reader] Config search paths: [./ /app /]"
level=info msg="[config_reader] Used config file .golangci.yml"
level=info msg="[lintersdb] Active 27 linters: [bodyclose deadcode depguard dogsled funlen gocognit goconst gocritic gocyclo godox gofmt goimports golint gosec gosimple govet ineffassign misspell nakedret scopelint staticcheck structcheck stylecheck typecheck unconvert unused varcheck]"
level=info msg="[lintersdb] Active 27 linters: [bodyclose deadcode depguard dogsled funlen gocognit goconst gocritic gocyclo godox gofmt goimports golint gosec gosimple govet ineffassign misspell nakedret scopelint staticcheck structcheck stylecheck typecheck unconvert unused varcheck]"
GOROOT=/usr/local/go GOPATH=/go GO111MODULE= PWD=/app go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=true" "-deps=true" "-find=false" "--" "./..." stderr: <<go: github.com/[[REDACTED]]@v0.0.0-20191029153130-d813d6d9dc53: git init --bare in /go/pkg/mod/cache/vcs/3ca44adb07787bed76ecd6b968fcab6d748d3e60a027ceab941754ea58cef49f: exec: "git": executable file not found in $PATH
>>
GOROOT=/usr/local/go GOPATH=/go GO111MODULE= PWD= go [list -f {{context.GOARCH}} {{context.Compiler}} -- unsafe] stderr: <<go: github.com/[[REDACTED]]@v0.0.0-20191029153130-d813d6d9dc53: git init --bare in /go/pkg/mod/cache/vcs/3ca44adb07787bed76ecd6b968fcab6d748d3e60a027ceab941754ea58cef49f: exec: "git": executable file not found in $PATH
>>
level=info msg="[loader] Go packages loading at mode 575 (compiled_files|deps|exports_file|files|imports|name|types_sizes) took 2.364244004s"
level=error msg="Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler"
level=info msg="Memory: 25 samples, avg is 68.9MB, max is 69.2MB"
level=info msg="Execution took 2.368312899s"
# docker run --rm -v $(pwd):/app -w /app -e GL_DEBUG=linters_output -e GOPACKAGESPRINTGOLISTERRORS=1 golangci/golangci-lint:v1.22.2 golangci-lint run -v
level=info msg="[config_reader] Config search paths: [./ /app /]"
level=info msg="[config_reader] Used config file .golangci.yml"
level=info msg="[lintersdb] Active 27 linters: [bodyclose deadcode depguard dogsled funlen gocognit goconst gocritic gocyclo godox gofmt goimports golint gosec gosimple govet ineffassign misspell nakedret scopelint staticcheck structcheck stylecheck typecheck unconvert unused varcheck]"
level=info msg="[lintersdb] Active 27 linters: [bodyclose deadcode depguard dogsled funlen gocognit goconst gocritic gocyclo godox gofmt goimports golint gosec gosimple govet ineffassign misspell nakedret scopelint staticcheck structcheck stylecheck typecheck unconvert unused varcheck]"
GOROOT=/usr/local/go GOPATH=/go GO111MODULE= PWD=/app go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=true" "-deps=true" "-find=false" "--" "./..." stderr: <<go: github.com/[[REDACTED]]@v0.0.0-20191029153130-d813d6d9dc53: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /go/pkg/mod/cache/vcs/3ca44adb07787bed76ecd6b968fcab6d748d3e60a027ceab941754ea58cef49f: exit status 128:
        fatal: could not read Username for 'https://github.com': terminal prompts disabled
>>
GOROOT=/usr/local/go GOPATH=/go GO111MODULE= PWD= go [list -f {{context.GOARCH}} {{context.Compiler}} -- unsafe] stderr: <<go: github.com/[[REDACTED]]@v0.0.0-20191029153130-d813d6d9dc53: invalid version: git fetch -f https://github.com/[[REDACTED]]
        fatal: could not read Username for 'https://github.com': terminal prompts disabled
>>
level=info msg="[loader] Go packages loading at mode 575 (exports_file|types_sizes|compiled_files|deps|files|imports|name) took 2.370997212s"
level=error msg="Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler"
level=info msg="Memory: 25 samples, avg is 69.2MB, max is 69.4MB"
level=info msg="Execution took 2.379085073s"

I assumed something like this when -mod=(readonly|vendor) fixed the issue though it should be stated more clearly…

@Dominik-K
Copy link
Contributor

Dominik-K commented Jan 13, 2020

Adding GOPRIVATE=github.com/ORG/* solved our issue. The underlying issue (shown with GL_DEBUG=linters_output GOPACKAGESPRINTGOLISTERRORS=1) was:

verifying github.com/ORG/[email protected]: github.com/ORG/[email protected]: reading https://sum.golang.org/lookup/github.com/!ORG/[email protected]: 410 Gone

That issue will occur since golangci-lint version 1.19.0 (Docker image has Go version 1.13 since then). Go 1.13 checks the https://sum.golang.org/ checksum database by default.

@ClaudiaJ
Copy link

Good call!

With the provided Docker image:

level=info msg="[config_reader] Config search paths: [./ /app /]"
level=info msg="[lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
level=info msg="[lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
GOROOT=/usr/local/go GOPATH=/go GO111MODULE= PWD=/app go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=true" "-deps=true" "-find=false" "--" "./..." stderr: <<go: github.com/Mattel/[email protected]: git init --bare in /go/pkg/mod/cache/vcs/240ef953ff0ebf6c7591b777376e1345c876e1078e29f58deffee24516d472a3: exec: "git": executable file not found in $PATH
>>
GOROOT=/usr/local/go GOPATH=/go GO111MODULE= PWD= go [list -f {{context.GOARCH}} {{context.Compiler}} -- unsafe] stderr: <<go: github.com/Mattel/[email protected]: git init --bare in /go/pkg/mod/cache/vcs/240ef953ff0ebf6c7591b777376e1345c876e1078e29f58deffee24516d472a3: exec: "git": executable file not found in $PATH
>>
level=info msg="[loader] Go packages loading at mode 575 (name|imports|types_sizes|compiled_files|deps|exports_file|files) took 677.7645ms"
level=error msg="Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler"
level=info msg="Memory: 8 samples, avg is 68.9MB, max is 68.9MB"
level=info msg="Execution took 688.6813ms"

Noting git is not installed here per the error, but is installed w/ the Dockerfile provided by https://github.com/reviewdog/action-golangci-lint, I tested adding git:

ROM golangci/golangci-lint:v1.22-alpine

RUN apk --no-cache add git
level=info msg="[config_reader] Config search paths: [./ /app /]"
level=info msg="[lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
level=info msg="[lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
GOROOT=/usr/local/go GOPATH=/go GO111MODULE= PWD= go [list -f {{context.GOARCH}} {{context.Compiler}} -- unsafe] stderr: <<go: github.com/Mattel/[email protected]: reading github.com/Mattel/test-private-repo/go.mod at revision v1.0.0: unknown revision v1.0.0
>>
GOROOT=/usr/local/go GOPATH=/go GO111MODULE= PWD=/app go "list" "-e" "-json" "-compiled=true" "-test=true" "-export=true" "-deps=true" "-find=false" "--" "./..." stderr: <<go: github.com/Mattel/[email protected]: reading github.com/Mattel/test-private-repo/go.mod at revision v1.0.0: unknown revision v1.0.0
>>
level=info msg="[loader] Go packages loading at mode 575 (compiled_files|deps|exports_file|types_sizes|files|imports|name) took 480.2949ms"
level=error msg="Running error: context loading failed: failed to load program with go/packages: could not determine GOARCH and Go compiler"
level=info msg="Memory: 6 samples, avg is 68.9MB, max is 68.9MB"
level=info msg="Execution took 494.9273ms"

Passing in a personal access token and running in the container git config --global url.'https://username:${ACCESS_TOKEN}@github.com/'.insteadOf 'https://github.com/' && golangci-lint run -v got me through the problem

@ernado
Copy link
Member

ernado commented Apr 21, 2020

Seems like there are nothing we can do more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: docker bug Something isn't working feedback required Requires additional feedback
Projects
None yet
Development

No branches or pull requests

6 participants