#private go module is breaking dagger

1 messages · Page 1 of 1 (latest)

deep compass
#

Hi, I am unable to resolve this issue so hopefully reaching out to maybe get some help. Essentially my golang service uses a private module hosted on github. Having this in the root go.mod has completely broken dagger. The directory containing dagger has its on go.mod/sum file and I am using go.work. The structure is like the following:

|- dagger/
  - go.mod
  - go.sum
  - main.go
|- cmd/
  |- service1
    - main.go
|- pkg/
  |- foo/
    - foo.go
- go.mod <- contains the private module reference
- go.sum
- go.work

I've stripped out everything from dagger/main.go but getting the following: on any dagger call

Error: input: module.withSource.initialize resolve: failed to initialize module: failed to call module "services-foo" to get functions: call constructor: process "go build -o /runtime ." did not complete successfully: exit code: 1

Stderr:
internal/dagger/dagger.gen.go:17:2: github.com/foo/bar@v0.0.0-20241003134503-1005ef8b342d: invalid version: git ls-remote -q origin in /go/pkg/mod/cache/vcs/3ad0407fede9804847d8af0ca1762538df78a9d4576bacbd52dec9cdf79066f0: exit status 128:
        fatal: could not read Username for 'https://github.com': terminal prompts disabled

Im not even trying to build the application, which I would have expected as I would need to pass the container the SSH_AUTH_SOCK

Im at a loss as to resolve this - even tried vendoring.

hollow sorrel
#

@deep compass something seems odd here. Any chance you have a Dagger Cloud trace we can see?

deep compass
#

Yeah - how would you like it sent? Apologies I dont use Discord

hollow sorrel
deep compass
#

Thanks for taking a look. As soon as I remove any reference to code from the private module and run go mod tidy to remove the reference in go.mod it works as expected

deep compass
#

Other context that might be useful: I’m using defaultDir and ignore for source

hollow sorrel
#

np, checking now @deep compass . Sorry, was in a meeting before

#

@deep compass mind sharing what's in your go.work?

#

ok, think I've found the issue

#

@deep compass can you try adding this to your dagger.json?

  "exclude": [
    "go.work"
  ]
#

that should unblock you until that issue is finalized

#

the problem is that some of your local project files are incorrectly being processed by the Go module runtime and trying to download private dependencies incorrectly.

deep compass
#

@hollow sorrel - thats worked like a charm. Thank you very much. Really appreciate the response. If I may ask a follow up question as Im only just starting to play with dagger - I currently use the following:

// Test runs unit tests as denoted by testing.Short()
func (m *FooApp) Test(
    ctx context.Context,
    // The source directory containing the go.mod file
    // +optional
    // +defaultPath="."
    // +ignore=["*", "!pkg/**/*.go", "!cmd/**/*.go", "!go.mod", "!go.sum", "!vendor/**/*"]
    src *dagger.Directory,
) (*TestResult, error) {
    //
        return &TestResult{}, nil
}

Should I be making use of this exclude within the dagger.json file? Even its just to point me to some docs.

Again, thank you!

hollow sorrel
# deep compass <@336241811179962368> - thats worked like a charm. Thank you very much. Really a...

defaultPath should generally be "/" as you usually want it to target the root of your repo. You can then use the "ignore" pragma so the client doesn't send unnecessary files to the engine. More about that here: https://docs.dagger.io/manuals/developer/functions/#directories-and-files

Dagger Functions are regular code, written in a supported programming language, and running in containers. Dagger Functions let you encapsulate common operations or workflows into discrete units with clear inputs and outputs.

#

LMK if that makes sense of if it's still confusing

keen sparrow
#

I'll try this out to ensure this scenario is handled correctly in the PR for this issue