#Hardcoded directories in functions

1 messages · Page 1 of 1 (latest)

warm scaffold
#

I'm trying to daggerize my current setup for a simple application. It uses Rust with HTMX and Tailwindcss for styling. In my tailwind.config.js, it uses content: ["./{src,assets}/**/*.{js,rs}"], to build the correct styles.css. I am now looking to create a function, sort of similar to my docker multistage build. Using the Dagger functions, I can see that almost all examples use *Directory , like:

func (m *App) BuildTailwind(
    // Assets directory containing tailwind.css
    assets *Directory,
    // Rust src directory
    src *Directory,
    // Tailwind.config.js file path
    tailwindConfigFile *File,
...

Since *Directory is also a requirement for WithMountedDirectory(path, *Directory, I am not really sure how I could hardcode or provide a default value - as default values only can be Go primitive types AFAIK. Is it possible to provide a default value either in the function itself or using parameter defaults?

storm notch
#

Hey @warm scaffold, sorry for the late answer.
You should be able to simply set a default path in the function like this:

if src == nil {
  src = dag.Directory().Directory("/my/default/path")
}
gentle wagon
warm scaffold
#

@gentle wagon, yes exactly. I see where you're going with dagger functions, and I like it. However, for a single project, I'd like to be able to just hardcode the necessary files and directories. That makes it easy for my co-developer who is not familiar with dagger to do something like dagger call build-tailwind and not have to worry about anything else.

I am also part of a platform team where we try to streamline setups - though we're not using Dagger just yet. Here, it would be beneficial as well to be able to expect certain directories or files to exist, sort of what this does in the internal files (dagger.gen.go in my case)

// DirectoryAsModuleOpts contains options for Directory.AsModule
type DirectoryAsModuleOpts struct {
    // An optional subpath of the directory which contains the module's configuration file.
    //
    // This is needed when the module code is in a subdirectory but requires parent directories to be loaded in order to execute. For example, the module source code may need a go.mod, project.toml, package.json, etc. file from a parent directory.
    //
    // If not set, the module source code is loaded from the root of the directory.
    SourceRootPath string
}
warm scaffold
south oak
#

Makes sense @warm scaffold - as Helder mentioned this is not possible today, the specific reason why is described here: https://docs.dagger.io/manuals/developer/overview/942201/execution-environment#host-resources

We do aim to improve this, please add any additional feedback you may have to this issue: https://github.com/dagger/dagger/issues/6723

GitHub

Somewhat related to #6112 but a bit more general Passing a large number of flags and args when using dagger call can become way too tedious to type out by hand. One example would be support for fil...

gentle wagon