#dagger init in an existing Go application fails because of a private Go module

1 messages · Page 1 of 1 (latest)

unreal gust
#

Hi,

I'm still testing Dagger, this time I tried to run init inside a Go repository that depends on private Go modules and it fails because of go mod tidy:

$ dagger init --sdk=go --source=./dagger 
✔ connect 0.9s
...
✘ ModuleSource.asModule(engineVersion: "latest"): Module! 16.5s
! failed to create module: select: failed to update codegen and runtime: failed to generate code: failed to get modified source directory for go module sdk codegen: select: process "codegen --output /src --module-context-path /src/dagger --module-name backend.ws.wesley --introspection-json-path /schema.json" did not complete successfully: exit code: 1
Error: failed to generate code: input: moduleSource.withContextDirectory.withName.withSDK.withSourceSubpath.asModule resolve: failed to create module: select: failed to update codegen and runtime: failed to generate code: failed to get modified source directory for go module sdk codegen: select: process "codegen --output /src --module-context-path /src/dagger --module-name backend.ws.wesley --introspection-json-path /schema.json" did not complete successfully: exit code: 1

Stdout:
generating go module: backend.ws.wesley
...
writing dagger/main.go
writing go.mod
writing go.sum
running post-command: go mod tidy
post-command failed: exit status 1
Stderr:
go: golang.b47ch.com/backoff@v1.7.0: reading golang.b47ch.com/backoff/go.mod at revision v1.7.0: git ls-remote -q origin in /go/pkg/mod/cache/vcs/5da62dc7a98e7d6541f9acdcc80a0879ef99d0bde4e2de21ae4a0a09cf781211: exit status 128:
    fatal: could not read Username for 'https://github.com': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
Error: exit status 1

the thing that doesn't make sense to me is why is it reading my existing go.mod ? Shouldn't dagger generates its go.mod in the dagger directory ?

red wing
#

If so: basically the Go SDK is detecting the parent go.mod, and trying to be helpful by reusing that. But as the issue explains, most people find that surprising, so we're going to change the default behavior to what you expected.

#

cc @tropic shuttle

#

In the meantime, you should be able to fix this with:

mkdir dagger
cd dagger
go mod init <PARENT_NAME>/dagger
dagger init --sdk=go --source=.
#

(or something like that, you get the idea)

unreal gust
#

Thanks @red wing that works