#How to mount local directory as r/w in Go?

1 messages · Page 1 of 1 (latest)

stoic veldt
#

I have the following example:

func foo() {
    ctx := context.Background()

    client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
    if err != nil {
        log.Println(err)
        return
    }
    defer client.Close()

    contents, err := client.Container().
        From("alpine:latest").
        WithMountedDirectory("/host", client.Host().Directory(".")).
        WithExec([]string{"/bin/sh", "-c", `echo foo > /host/a`}).
        Stdout(ctx)
    if err != nil {
        log.Println(err)
        return
    }
    fmt.Println(contents)
}

But I don't see a file appear in working directory. If I run the ls command in /host dir then I can see all files/directories. What could be wrong?

sturdy bronze
#

👋 data flows only one way between Dagger operations, because they are connected in a DAG. This allows for better caching and scalability.

You can explicitly write a directory back to the host filesystem with Directory.Export

stoic veldt
#

Hmm, I see. Thanks for the help! My use case by the way is we have this e2e testing framework that spawns extra Docker containers. So, if go tests are running inside of docker already then there's no way of exporting extra data to those spawned containers :/

#

I will try exporting those files through the Dagger engine tomorrow

sturdy bronze
#

This is a common use case - there are several ways to Daggerize such a pipeline, as gradually as you need

#

Roughly:

  • For maximum compatibility / minimum initial effort, you can run a docker engine as a service container inside the DAG. Literally run dockerd on dagger. Then from there, daggerize your docker run clients and point them at your daggerized docker engine
#
  • For a more efficient solution, which requires a little bit more Dagger-specific code (but can be quite simple, depending on the complexity of your existing pipelines), simply replace your ad-hoc docker run with equivalent Dagger calls. Then you can remove the dependency on docker engine entirely: your build + e2e tests all run seamless in Dagger.
#

As an even more short-term option, you can integrate with the existing (non-Daggerized) docker engine, by mounting the docker unix socket into the DAG. S