#Make copies of the current state of the container for concurrent use

1 messages · Page 1 of 1 (latest)

jolly rain
#

So I have so far this:

#
    nodeOpts := containers.NewNodeOpts(ctx, containers.WithWine64())
    daggerContainer := nodeOpts.NewNodeContainer(dag)

    globalNodeModulesCache := dag.CacheVolume("global-node-modules-cache")
    sourceCode := dag.Host().Directory("cube-apps-admin", dagger.HostDirectoryOpts{
        Exclude: []string{"**/node_modules",
            "package-lock.json",
            "package.json"},
    })
    packageFiles := dag.Host().Directory("cube-apps-admin", dagger.HostDirectoryOpts{
        Include: []string{"package*.json"},
    })

    daggerContainer = daggerContainer.
        WithMountedCache(nodeOpts.GetNpmCache(), globalNodeModulesCache, dagger.ContainerWithMountedCacheOpts{
            Sharing: dagger.Shared,
        }).
        WithMountedFile("/app/package.json", packageFiles.File("package.json")).
        WithMountedFile("/app/package-lock.json", packageFiles.File("package-lock.json")).
        WithWorkdir("/app").
        With(nodeOpts.WithNpmInstall()).
        WithDirectory("/app", sourceCode, dagger.ContainerWithDirectoryOpts{
            Exclude: []string{"package.json", "package-lock.json"},
        }).
        With(nodeOpts.WithNpmBuild())
#

From this stage and after, I want 3 copies of my daggerContainer that is independent of each other

#

So I can run electron packaging on each one of the copies.

#

Reason is, that I did this, and noticed that the second copy was listing both 0 and 1 files.
Meaning that they share the space

    var wg sync.WaitGroup

    init := 10
    for idx, kind := range []string{"win64", "linux"} {
        wg.Add(1)
        go func(kind string, idx int) {
            if idx == 0 {
                init = 0
            }
            daggerContainer = daggerContainer.
                WithExec([]string{"mkdir", "-p", "/app/check"}).
                WithExec([]string{"touch", fmt.Sprintf("/app/check/%d", idx)}).
                WithExec([]string{"echo", fmt.Sprintf("I Am /app/check/%d", idx)}).
                WithExec([]string{"sleep", fmt.Sprint(init)}).
                WithExec([]string{"ls", "-la", "/app/check/"})
                // With(nodeOpts.WithNpmPackage(kind))

            var o string
            o, err = daggerContainer.Stdout(ctx)
            // _, err = daggerContainer.Sync(ctx)

            if err != nil {
                log.Error().Err(err).Msg("Failed to run packaging")
            }
            log.Info().Msgf("stdout: %s", o)
            wg.Done()
        }(kind, idx)
    }

    wg.Wait()
jolly rain
#

I think I found the solution.

After npm build I do
daggerContainer.ID()

then inside the go func I create a dag.Container(id) and rn the npm package on this one

#

Is my assumption correct?

somber scroll
#

The explanation in that doc uses the underlying GraphQL API, that all SDKs use under the hood (Go, Node, Python, etc)