#Export the result of the command

1 messages · Page 1 of 1 (latest)

candid spire
#

Hi ! I'm trying to understand a bit how dagger works and I have soem trouble to get a file out of the container.

package main

import (
    "context"
)

type Potato struct{}

func (m *Potato) Scan(ctx context.Context, host string, dir *Directory) {
    return dag.Container().
    From("projectdiscovery/nuclei:latest").
        WithExec([]string{"-u", host, "-o", "out.json","-j"}).
    Directory(".").
    Export(ctx, ".").
        Stdout(ctx)
}
dagger --debug call scan --host=honey.scanme.sh --dir=./out
Stderr:
# main
./main.go:10:9: multiple-value dag.Container().From("projectdiscovery/nuclei:latest").WithExec([]string{…}).Directory(".").Export(ctx, ".") (value of type (bool, error)) in single-value context

I do not understand the issue. The answer is probably pretty clear with the error, but I can't figure it out.

real dawn
# candid spire Hi ! I'm trying to understand a bit how dagger works and I have soem trouble to ...

hey there! if you want to export a file, you can either return a Directory or File from your function and use dagger call scan --host foo.com --dir . export --path ./export with that directly. In your example that'd be:

func (m *Testmodule) Scan(ctx context.Context, host string, dir *Directory) *Directory {
   return dag.Container().
       From("projectdiscovery/nuclei:latest").
       WithExec([]string{"-u", host, "-o", "out.json", "-j"}).
       Directory(".")
}
pure holly
ebon edge
#

@real dawn, I found my way here after trying to do the same myself.. Is there any way to actually export build artifacts from within a Dagger function? 😅

My thinking when I started poking around with Dagger, was that my own Dagger module could completely orchestrate several other functions, that themselves would build different binaries. So I'd really like for the "orchestrating" function to do all the exports needed..

ebon edge
#

Hmm, oh, I see.. it's because the module itself is running within a container, with no access to the host filesystem 🤔 So I'll probably have to just "collect" all the build artifacts, and return as a Directory, then call that single BuildAllTheThings() function from the CLI, with export ..path ./bin? appended.