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 image golangci/golangci-lint:v1.55.2 errors when project go.mod requires go v1.21.4 #4239

Closed
5 tasks done
scacner opened this issue Dec 5, 2023 · 6 comments · Fixed by #4532
Closed
5 tasks done
Labels
area: docker bug Something isn't working

Comments

@scacner
Copy link

scacner commented Dec 5, 2023

Welcome

Description of the problem

I've seen when using docker image golangci/golangci-lint:v1.55.2 (like in CI/CD or standalone in docker) on a Go project that has a go.mod file require go version 1.21.4 an error getting thrown:

level=error msg="Running error: context loading failed: failed to load packages: failed to load with go/packages: err: exit status 1: stderr: go: go.mod requires go >= 1.21.4 (running go 1.21.3; GOTOOLCHAIN=local)\n"

Version of golangci-lint

$ docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.55.2 golangci-lint version                              
golangci-lint has version v1.55.2 built with go1.21.3 from e3c2265f on 2023-11-03T13:27:54Z

Configuration

No custom configuration file is used.

Go environment

$ docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.55.2 go version           
go version go1.21.3 linux/arm64
$ docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.55.2 go env    
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/app/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1679194962=/tmp/go-build -gno-record-gcc-switches'

Verbose output of running

$ docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.55.2 golangci-lint run -v                               
level=info msg="[config_reader] Config search paths: [./ /app / /root]"
level=info msg="[lintersdb] Active 6 linters: [errcheck gosimple govet ineffassign staticcheck unused]"
level=info msg="[loader] Go packages loading at mode 575 (types_sizes|deps|name|imports|compiled_files|exports_file|files) took 15.058319ms"
level=error msg="Running error: context loading failed: failed to load packages: failed to load with go/packages: err: exit status 1: stderr: go: go.mod requires go >= 1.21.4 (running go 1.21.3; GOTOOLCHAIN=local)\n"
level=info msg="Memory: 2 samples, avg is 22.1MB, max is 22.1MB"
level=info msg="Execution took 18.943095ms"

A minimal reproducible example or link to a public repository

From repo scacner/go-hello-world

package main

import "fmt"

func main() {
	fmt.Println("Hello, world")
}

Validation

  • Yes, I've included all the information above (version, config, etc.).
@scacner scacner added the bug Something isn't working label Dec 5, 2023
Copy link

boring-cyborg bot commented Dec 5, 2023

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez
Copy link
Member

ldez commented Dec 5, 2023

Hello,

the problem is not with golangci-lint itself but with the Docker image or your CI: the image contains go1.21.3.

$ docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.55.2 go version           
go version go1.21.3 linux/amd64
$ docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.55.2 go build  
go: go.mod requires go >= 1.21.4 (running go 1.21.3; GOTOOLCHAIN=local)
$ docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.55.2 golangci-lint run    
level=error msg="Running error: context loading failed: failed to load packages: failed to load with go/packages: err: exit status 1: stderr: go: go.mod requires go >= 1.21.4 (running go 1.21.3; GOTOOLCHAIN=local)\n"

The Go version inside the Docker image is defined during the build of the image, golangci-lint has the same behavior as Go, so this behavior is expected.

@scacner
Copy link
Author

scacner commented Dec 5, 2023

Is updating the image something I have to do to get support for go version 1.21.4?

@ldez
Copy link
Member

ldez commented Dec 5, 2023

$ docker run --rm -it -v $(pwd):/app -w /app golangci/golangci-lint:v1.55.2 sh
# go version
go version go1.21.3 linux/amd64
# go build         
go: go.mod requires go >= 1.21.4 (running go 1.21.3; GOTOOLCHAIN=local)
# golangci-lint run
ERRO Running error: context loading failed: failed to load packages: failed to load with go/packages: err: exit status 1: stderr: go: go.mod requires go >= 1.21.4 (running go 1.21.3; GOTOOLCHAIN=local) 
# curl -L https://go.dev/dl/go1.21.5.linux-amd64.tar.gz --output go1.21.5.linux-amd64.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    75  100    75    0     0    383      0 --:--:-- --:--:-- --:--:--   384
100 63.5M  100 63.5M    0     0  57.4M      0  0:00:01  0:00:01 --:--:-- 74.4M
# rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz
# go version
go version go1.21.5 linux/amd64
# go build
# golangci-lint run
# 

golangci-lint is compiled with go1.21 but it requires running some Go commands, so the installed version of Go has an impact.

The strong Go version requirement is something new, it comes with go1.21.
For now, we don't have a plan to handle that inside the Docker images.

@scacner
Copy link
Author

scacner commented Dec 6, 2023

Okay. Thanks for the explanation and work around!

@davidkuridza
Copy link

A possible solution seems to be setting Go Toolchain, for example:

$ golangci-lint run -v
...
ERRO Running error: context loading failed: failed to load packages: failed to load with go/packages: err: exit status 1: stderr: go: go.mod requires go >= 1.22.1 (running go 1.22.0; GOTOOLCHAIN=local)

$ GOTOOLCHAIN=go1.22.1 golangci-lint run -v
...
INFO Execution took 776.326069ms

The tool chain can also be set in go.mod with toolchain <version>. Alternatively, golangci-lint can be invoked with something like this:

$ GOTOOLCHAIN=$(awk '/^go / {gsub(/ /, "", $0); print}' go.mod) golangci-lint run

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants