Code Monkey home page Code Monkey logo

Comments (4)

vbehar avatar vbehar commented on June 8, 2024 1

Hi, I had a look at this issue, and found out that it only happens if you run go mod init before dagger mod init, and if you have go > 1.21.3 locally. because go mod init will create a go.mod file with your local version of go (say 1.21.5), but when running dagger mod init, it will run in a container with go 1.21.3 in local mode, so it won't be able to do anything

the "quick" fix is to avoid running go mod init, because dagger mod init will take care of creating the go.mod file anyway if it doesn't exists, and it will have the "right" go version (the one used by the dagger container)

the real fix is to ensure that the container is properly configured, with GOTOOLCHAIN=auto. by default, the official go images have GOTOOLCHAIN=local, which is ok because you want a controlled env. but in the dagger context, I believe it makes sense to be able to run the code if even it requires a newer version of go. just adding the GOTOOLCHAIN=auto env to the container will do it:

$ echo $(docker run --rm -it golang:1.21.3 go env GOTOOLCHAIN)
local
$ echo $(docker run --rm -it -e GOTOOLCHAIN=auto golang:1.21.3 go env GOTOOLCHAIN)
auto

from dagger.

sipsma avatar sipsma commented on June 8, 2024

@samalba To clarify, you are allowed to have an existing go.mod and that's handled in general (there's integ test coverage for this). The problem here is that Go in 1.21 started creating go.mod by default with directives like go 1.21.5 which result in these errors if there's a mismatch between the version of go being used by the engine the and the version of go you used to run go mod init on your host.

So you don't get this error if your host is using go 1.21.3 (what the engine is currently on).


You can easily fix this right now by just editing the go.mod created by go mod init to just say go 1.21 rather than go 1.21.5.

I'm sure there's got to be some better way of handling this in general since there's no way we actually care about the patch version of Go.

from dagger.

samalba avatar samalba commented on June 8, 2024

Thanks for the context. Maybe a good way to solve this is to detect if there is a minor version in go.mod and hint the user to remove it. If I learned this from the output, I would have done this manually to fix it.

from dagger.

sipsma avatar sipsma commented on June 8, 2024

As a note, Nipuna mentioned that he also needed to make the same adjustment to his go.work file to remove the minor version in order for this to work fully

from dagger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.