#delete file? mutate repository?

1 messages · Page 1 of 1 (latest)

thin blade
#

Lets say I want to do something that should potentially mutate files on the host go fmt or delete files on the host go mod tidy && go mod vendor, but inside of a dagger function. How could I go about that? Is it even idiomatic?

I've tried to test this with this function:

func (m *Testing) Test(ctx context.Context, testdir *Directory) (bool, error) {
    return testdir.WithoutFile("./test.txt").
        Export(ctx, ".", DirectoryExportOpts{Wipe: true})
}

but the test.txt file still remains.

midnight hound
# thin blade Lets say I want to do something that should potentially mutate files on the host...

you can mutate files within Dagger functions but those changes won't be reflected in your host since any directories or files that you pass to your functions is a copy of what you have in the host.

Your approach is mostly correct, the only difference is that you need to change your function so it returns a *Directory instead of (bool, error) so you can use the Artifacts Exports (https://docs.dagger.io/manuals/user/273920/export/) via the CLI

Just-in-time artifacts such as containers, directories and files expose an Export() function, enabling them to be exported to the host filesystem from the Dagger Function that produced them. The destination path on the host is passed to the function using the --path argument.

#

the export that you're calling in your fuction currently exports the files to the "Go runtime container" which is not your local machine