Skip to content

Don't reuse parent go.mod by default #7527

Closed

Description

@shykes

Problem

When initializing a new dagger module with the Go SDK, by default no go.mod is created if a parent go.mod already exists. This is not the correct default behavior. It causes confusion, and in some cases can even break development altogether.

As a rule of thumb: by default, my dagger module should be an island. It should work the same regardless of what else is going on in the same repo. If I want my module's behavior to depend on another part of the repo, that should be expressed as a dagger dependency in my dagger.json.

Solution

Change the default behavior of the Go SDK, to not reuse a parent go.mod. Initializing a dagger module in Go should always result in also initializing a new go module, by default

Activity

  1. self-assigned this
    on Jul 25, 2024
  2. elee commented on Jul 30, 2024

    @elee

    👍 to this as I'm bumping up against it introducing Dagger to a Go project with a pre-existing go.{mod,sum}

  3. marcosnils commented on Jul 30, 2024

    @marcosnils
    Contributor

    👍 to this as I'm bumping up against it introducing Dagger to a Go project with a pre-existing go.{mod,sum}

    I'm currently working on this one. I'll try to squeeze it before the next release 👐

  4. elee commented on Jul 30, 2024

    @elee

    For those playing along at home, I worked around this in a primitive way: move the go mod/sum out of the way and initialize without them in the root of the repo

    $ dagger version
    dagger v0.12.3 (registry.dagger.io/engine) darwin/arm64
    $ mkdir yee ; mv go.{mod,sum} yee
    $ dagger init --sdk=go --source=./dagger -d
    <output omitted>
    $ mv yee/* . ; rm -rf yee

    This works I believe because the go mod tidy issued here just happens to catch our root go mod but not mutate it

    genSt := &generator.GeneratedState{
    Overlay: overlay,
    PostCommands: []*exec.Cmd{
    // run 'go mod tidy' after generating to fix and prune dependencies
    exec.Command("go", "mod", "tidy"),
    },
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions