Repository navigation
Description
Overview
I regularly see developers get confused (sometimes severely) by File.Export, Directory.Export, and Container.Export, to the point of failing to "get" Dagger, and sometimes even giving up entirely.
I think we should consider the possibility of deprecating these functions.
The timing matters, because we are currently discussing a new CLI experience for Zenith (dagger call etc) which might rely on these export functions. So it seems important to discuss the future of these export functions at the same time.
My arguments for deprecating export functions:
- They make it seem normal and easy to interact with the host system, when it isn't. This causes confusion and disappointment.
- They prevent the Dagger Engine API from being remote-friendly (because they rely on side-effects by the server implementation on the client system), or multi-tenant (because these side-effects are specific to the workdir of the client process)
- As of this week, we have a Zenith CLI design that doesn't require them. Instead we could have a -o flag that saves call results to the local filesystem. There is early consensus on this
- There is precedent: we used to have an API to access the host's environment, and we deprecated it
This is meant as a conversation starter 😃 And also a way to test Github/Linear sync!
Examples of confusion
I can invoke client.Host().Directory(path) with the same path multiple times ? I create first container with WithDirectory("/project", client.Host().Directory(path, dagger.HostDirectoryOpts{Exclude: []string{"ci"}})) Then I modify some local file from go code. Then I create new container with WithDirectory("/project", client.Host().Directory(path, dagger.HostDirectoryOpts{Exclude: []string{"ci"}})) But it look the old version of file. Before I modify it. It's normal ?
I use ti like this.
chartFilePath := fmt.Sprintf("%s/%s", option.PathContext, "Chart.yaml") chartFile, err := client.Host().File(chartFilePath).Sync(ctx) if err != nil { return errors.Wrap(err, "Error when force sync Chart.taml") } container = container.WithFile(chartFilePath, chartFile)
What do you mean by snapshot ? I should it update the file content on the "cache" when I invoke the Sync.
Activity
shykes commentedon Dec 22, 2023
FYI @sipsma , this is related to #6312
sipsma commentedon Dec 22, 2023
@shykes I'm good with removing
exportfrom the various core types it's on now because I agree it's sort of odd that there's a field on those types that interacts right with the caller's host, whereas the import side usesHost.But to be clear we'd need to replace it with the ability to do export to the host another way. The most obvious being putting it on
Host, so e.g.Host().Exportthat can handle File+Directory, but same general idea either wayContainer.Exportbecause there's a (newish)asTarball: Filefield onContainerthat invalidates it (can just export theFileinstead now)So this wouldn't change anything in regard to
1.and2.in your list of arguments. In terms of3., this would just mean that the CLI usesHost.Exportinternally instead to support the-oflag.sipsma commentedon Dec 23, 2023
As an addendum thought, I suppose I could see a route to not even putting
ExportonHost, but it would be a lot more involved.If we added a
Streamtype to core and updated all SDKs to know how to handle it, then we could just expose the contents of aFileas a stream of bytes and let callers read it from there and write it to the filesystem how they want.In this case,
Directorywould probably need its ownasTarball: Filefield too, so then callers stream the tarball and unpack it to their filesystem.One thing we'd be making more complicated is hypothetical future support for more efficient exports.
You still could support rsync-style optimizations, but it would get much more complicated (I'll leave it there for the moment, can continue discussing if relevant).
IMO the above is the right long-term goal, but it's not practical in the short term, so moving
exporttoHostcould be an intermediary step to at least fix some of the short term incongruities in the API.