#trouble with module usage

1 messages · Page 1 of 1 (latest)

pliant pecan
#

i'm trying to evaluate dagger and having trouble using modules.
i can't seem to get the generation working so i keep getting
! failed to serve module: input: module.withSource.initialize failed to initialize module: failed to call module "dagger" to get functions: call constructor: process "go build -ldflags -s -w -o /runtime ." did not complete successfully: exit code: 1
ide says
could not import dagger/node/internal/dagger (no required module provides package "dagger/node/internal/dagger")compilerBrokenImport
i did the module install so my dagger.json says

{
  "name": "dagger",
  "engineVersion": "v0.15.1",
  "sdk": "go",
  "dependencies": [
    {
      "name": "node",
      "source": "github.com/Dudesons/daggerverse/node@node/v0.4.0",
      "pin": "506142af431e8acef646176d58cda16968e463c3"
    }
  ],
  "source": "dagger"
}

and this is all i'm trying to do rn

package main

import (
    "context"
    "dagger/node/internal/dagger"
)

type Demo struct{}

func (m *Demo) build(ctx context.Context) error {
    dag.Node().
        WithAutoSetup("demo", dagger.Host().Directory("angular/demo")).
        Pipeline(
            ctx,
            dagger.NodePipelineOpts{
                IsOci:  true,
                TTL:    "60s",
                DryRun: true,
            },
        )
    return nil
}

running dagger develop didn't change anything.
any ideas?

pliant pecan
#

trouble with module usage

hushed vine
#

dagger develop didn't change anything
did it plop down the generated files?

/dagger.gen.go
/internal/dagger
/internal/querybuilder
/internal/telemetry

#

fwiw those should only fix the IDE errors anyways, the engine should build things correctly regardless of their presence

#

what are you running to hit ! failed to serve module: input: module.withSource.initialize failed to initialize module: failed to call module "dagger" to get functions: call constructor: process "go build -ldflags -s -w -o /runtime ." did not complete successfully: exit code: 1 ? is there any other error output there (might wanna try adding a -vvv to the call)

pliant pecan
#

hmm i can see it referring to the module, but not sure what else i'm looking for

hushed vine
#

oh wait, your build method is private, it's gotta be Build

#

not sure that'll fix it though, i'd expect a more specific error message if that was the only problem, but that's definitely a problem

pliant pecan
#

didn't change anything

steep grail
#

@pliant pecan the code in your pipeline doesn't seem to be ok

#

dagger.Host() doesn't exist

#

I've changed your snippet to this:

func (m *Demo) Build(ctx context.Context, src *dagger.Directory) error {
    dag.Node().
        WithAutoSetup("demo", src).
        Pipeline(
            ctx,
            dagger.NodePipelineOpts{
                IsOci:  true,
                TTL:    "60s",
                DryRun: true,
            },
        )
    return nil
} // Returns a container that echoes whatever string argument is provided
#

you can notice that I changed the dagger.Host() with a src argument in the module function. The way to pass artifacts from the host to your module function while using Dagger modules is via arguments as described in our docs here: https://docs.dagger.io/api/arguments/

Dagger Functions, just like regular functions, can accept arguments. In addition to basic types (string, boolean, integer, arrays...), Dagger also defines powerful core types which Dagger Functions can use for their arguments, such as Directory, Container, Service, Secret, and many more.

steep grail
#

your IDE should have shown that the dagger.Host method was undefined

pliant pecan
#

it has in the past. not sure why it doesn't rn.
anyway here are the steps i'm following with
dagger v0.15.1 (registry.dagger.io/engine:v0.15.1) darwin/arm64
rm -rf dagger.json dagger
dagger init --sdk=go --source=./dagger
dagger install github.com/Dudesons/daggerverse/node@v0.4.0
writing out to main.go (attached)
and then try to call, with new failure
hunter.morgan@INV-04069 dagger % dagger call build --src=angular -vvv

#

reattached output with error snipped

│ │ │ │ ○ Directory.withNewFile(contents: ETOOBIG:sha256:c49ba4191f2975bc9b1a0e4f070c771f0ea56c3fe6ef92f9674157390b0b594a, path: "dagger.json", permissions: 420): Directory! 0.0s
│ │ ✘ .initialize: Module! 0.2s
│ │ ! failed to initialize module: failed to call module "dagger" to get functions: call constructor: process "go build -ldflags -s -w -o /runtime ." did not complete successfully: exit code: 1
steep grail
#

@pliant pecan the issue seems to be the dagger/node/internal/dagger import

#

let me help you out really quick

#

I'll rename my module to the same as yours

pliant pecan
#

is dagger/{module}/internal/dagger not how it gets the generated code?

#

sorry if i'm being dense, and ty for the assistance, regardless

steep grail
#

np, you're not being dense at all

#

there's something I don't quite undertsand

#

your module is called dagger as per the dagger.json file

#

however, in the snipper you shared above, the method receiver type is *Demo

#

that doesn't seem correct

pliant pecan
#

join the club lol
yes let me try changing

steep grail
#

as the receiver type should be *Dagger

#

the method receiver types of CLI callable functions should have the same type as the module

#

your module should have a type Dagger struct which is the default struct that gets created based on the module name

#

and going back to the internal import, it should be dagger/dagger/internal/dagger

#

not dagger/node/internal/dagger

pliant pecan
#

is it always dagger/dagger? i think i've seen other things in repos i've been looking at to understand but i thought you were supposed to import something based on a consumed dagger moduel

#

it worked!

steep grail
pliant pecan
#

oh where dagger is the name of the module you're writing, not consuming

steep grail
#

in your case $module is dagger because you named your core module dagger lol

pliant pecan
#

ok ty

steep grail
#

sure, np