#any way to obtain the path from dagger.Directory

1 messages · Page 1 of 1 (latest)

river pollen
#

i've been beating my head against a wall to try and figure this one out. i'm hoping someone may have had need to do this before and will be able to just throw in a snippet.

looking at this admittedly contrived example:

func (p *Project) InitProject(
    ctx context.Context,
    // +optional
    source *dagger.Directory
} *dagger.Directory {
  return source.WithNewFile("testfile.txt", "phwar")
}

So I would like to essentially scaffold source dir that is passed in, but i really don't like the ergonomics of requiring using export on the cmd line - i know that I can use the Export method on the directory, but what I need is the path that is passed in, but converted to a dagger.Directory type so that I can not make a user pass in the same path twice. anyone have any thoughts? i think it would essentially look like:

source.WithNewFile("testfile.txt", "phwar").Export(ctx, <<path of source>>, DirectoryExportOpts{})
chrome thicket
river pollen
#

I am not a dev by trade, so I'm certainly a bit out of my league looking at a lot of the internals of it, but it would almost be enough to just have a Path() method on the Directory type

chrome thicket
river pollen
#

aaaaah, got it. that makes sense

chrome thicket
#

the sandboxing is by design, it makes Functions much safer and reusable but there is a tradeoff in convenience, which is what you're encountering

river pollen
#

yeah no, it definitely makes sense in my head in terms of safety and reusability. i am also, admittedly, using in a manner other than directed. i thought it would be fun to have the project init workflow live in a dagger function (which it still can, just a little ergonomically awkward - nothing that can't be documented around in the interim). thanks for the response!

chrome thicket