#Keep mounted cache contents during container exports

1 messages · Page 1 of 1 (latest)

oak swan
#

I am trying to build a pipeline which utilizes WithMountedCache. However, I've noticed that the cache mount does not persist when exporting/publishing the resulting container image. For example, when running bundle install I would like the bundled gems to be exported with the container image so that the whole image can be published, rather than just during the dagger call:

type Ruby struct {
    Source *dagger.Directory
}

func (m *Ruby) Container() *dagger.Container {
    return dag.
        Container().
        From("ruby").
        WithMountedCache("/bundle", dag.CacheVolume("bundle")).
        WithEnvVariable("BUNDLE_PATH", "/bundle").
        WithDirectory("", m.Source, dagger.ContainerWithDirectoryOpts{
            Include: []string{"Gemfile", "Gemfile.lock"},
        }).
        WithExec([]string{"sh", "-c", "bundle check || bundle install"}).
        WithExec([]string{"bundle", "clean"})
}

I would want the /bundle directory to be exported as well with the resulting container image:

dagger call -m ruby container export --path container.tar.gz

Is this something that is possible?

outer fable
#

FWIW this works the same way as using RUN --mount type=cache in Dockerfiles