#Can i write to local fs using a Directory as a function input

1 messages Β· Page 1 of 1 (latest)

flat roost
#

I have a function that does something like:

func (m *K6) Run(
    ctx context.Context,
    // Direcetory to store the results
    //+required
    outputDir *Directory,
}`*Container {
...
}
#

In the Run function i call a container with

WithMountedDirectory(outputDirMountPath, outputDir)

I verified using terminal that the files exists in the container mounted directory. However in the local FS they were not created.

#

Maybe do i need to return the Directory instead of the Container πŸ€” but i still need to write to that folder the outputs

nova hound
#

*Mounted files and Directories are not persisted in the final container if you export or publish it

flat roost
#

just tried it out but does not seem to work

nova hound
#

example:

func (m *Lala) Lala() *Container {
    testFile := dag.Directory().WithNewFile("/test", "foo").File("/test")

    return dag.Container().From("alpine:latest").
        WithMountedFile("/test", testFile)
}

you can then:

dagger call lala file --path /test export --path ./test.txt

flat roost
#

oh using export from the cli

#

i using the one from the sdk

nova hound
flat roost
#

hmm

nova hound
#

oh sorry

#

you shouldn't call export in the SDK

#

you can return the *Directory or *File type

#

that's what I meant

#

and use export in the CLI

#

exporting in the SDK doesn't really export to the host machine, but to the runtime container

flat roost
#

oh gotcha

#

to the sandbox container

#

lets say

#

gonna try the one from the cli instead then

nova hound
nova hound
flat roost
# nova hound πŸ™

is not exporting the directory still πŸ€” do you see where am i messing it up?

dagger call run ... directory --path /output export --path ~/tmp/out/
#

being /output the directory in the container with the results and ~/tmp/out/ where i want to export them to

#

nvm it works

nova hound
#

πŸ‘

#

awesome!

flat roost
#

it must be something stupid ive messed up with

#

ty very much ❀️

nova hound
#

I was just typing that it worked to me πŸ™‚

flat roost
#

so that works just fine then nice

nova hound
#

remember you can use the terminal command to check what's in the underlying container

flat roost
#

yeye

#

i was using that

nova hound
flat roost
#

this directory subcommand was new gotta say

#

to me i mean

twin vessel
#

I might have a similar use case to this. Can you somehow persist what is mounted in a cache? In my case, it is migrations applied to a database.

nova hound
#

in that case you can run a WithExec cp command after the volume is populated and copy whatever files you need into the resuling Container to be published / exported