Skip to content

Deprecate export functions? #6321

Closed
Closed

Description

@shykes

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:

  1. They make it seem normal and easy to interact with the host system, when it isn't. This causes confusion and disappointment.
  2. 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)
  3. 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
  4. 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

https://discord.com/channels/707636530424053791/1123687185837740053/1187346095655878656

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

  1. shykes commented on Dec 22, 2023

    @shykes
    ContributorAuthor

    FYI @sipsma , this is related to #6312

  2. sipsma commented on Dec 22, 2023

    @sipsma
    Contributor

    @shykes I'm good with removing export from 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 uses Host.

    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.

    dag.Host().ExportFile("./output/file", someFile)
    // and
    dag.Host().ExportDirectory("./output/dir", someDir)
    
    • With interface support coming soon we'd also have a route to just support a Host().Export that can handle File+Directory, but same general idea either way
    • I purposely left out Container.Export because there's a (newish) asTarball: File field on Container that invalidates it (can just export the File instead now)

    So this wouldn't change anything in regard to 1. and 2. in your list of arguments. In terms of 3., this would just mean that the CLI uses Host.Export internally instead to support the -o flag.

    • Not saying this as an argument against making this change, I'm onboard, just want to make sure we're on the same page
  3. sipsma commented on Dec 23, 2023

    @sipsma
    Contributor

    As an addendum thought, I suppose I could see a route to not even putting Export on Host, but it would be a lot more involved.

    If we added a Stream type to core and updated all SDKs to know how to handle it, then we could just expose the contents of a File as a stream of bytes and let callers read it from there and write it to the filesystem how they want.

    In this case, Directory would probably need its own asTarball: File field 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.

    • Basically, buildkit's filesync already does lots of rsync-style optimizations on the import side
    • It doesn't have those same optimizations on the export side, but it's intended to support that and there's an open issue in buildkit with a fair amount of discussion. Think it's mostly just that no one has ever gotten to implementing it

    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 export to Host could be an intermediary step to at least fix some of the short term incongruities in the API.

  4. locked and limited conversation to collaborators on Mar 24, 2026
  5. converted this issue into a discussion #12465 on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions