#Save file content to filesystem

1 messages · Page 1 of 1 (latest)

steep trench
#

Is there a way to build a file content dynamically ( in golang in this case) and save it to a file on the container's file system ? the File struct seems to only provide ways of reading the content not writing it.

frosty fox
#

Hello, you should be able to do it using:

dag.Directory().WithNewFile("/file/path", "contents")

#

to give a slightly more complete example:

    output, err := dag.Container().
        From("alpine:latest").
        WithDirectory("/foo", dag.Directory()).
        WithNewFile("/foo/test.txt", "some content").
        WithExec([]string{"sh", "-c", "cat /foo/test.txt"}).
        Stdout(ctx)
    if err != nil {
        return "", err
    }

    return output, err
}```
steep trench
#

thank you so much @frosty fox i totally missed that method facepalm

frosty fox
#

np, happy to help.

boreal crater
#

note, we should have dag.file() to mirror dag.directory() no?

frosty fox
#

i dont think we currently have that. we should probably add that

boreal crater
#

Yes that's what I mean - for sure we don't have it, but we should add it 🙂