#Is it possible to set global default paths?

1 messages · Page 1 of 1 (latest)

fast granite
#

Looking at the default paths documentation: https://docs.dagger.io/api/default-paths/

There seems to be no no way to set a global default path. Is this somehow possible instead of having to add a comment to every function signature?

It is possible to assign a default path for a Directory or File argument in a Dagger Function. Dagger will automatically use this default path when no value is specified for the argument. The Directory or File loaded in this manner is not merely a string, but the actual filesystem state of the directory or file.

dreamy hamlet
#

something like this should work

#
type HelloDagger struct {
    Source *dagger.Directory
}

func New(
    // +optional
    // +defaultPath="."
    source *dagger.Directory,
) *HelloDagger {
    return &HelloDagger{
        Source: source,
    }
}

// Publish the application container after building and testing it on-the-fly
func (m *HelloDagger) Publish(ctx context.Context) (string, error) {
    s := m.Source
    _, err := m.Test(ctx, s)
    if err != nil {
        return "", err
    }
    return m.Build(s).
        Publish(ctx, fmt.Sprintf("ttl.sh/hello-dagger-%.0f", math.Floor(rand.Float64()*10000000))) //#nosec
}
#

and then dagger call publish should use . as the default value for source

#

you can override if needed with dagger call --source=/my/path publish