Creating 2 dagger directories like below, changing a file in source code (eg a translation) the npm install stays cached. (which is expected)
...
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"},
})
packageJson := packageFiles.File("package.json")
packageLockJson := packageFiles.File("package-lock.json")
daggerContainer = daggerContainer.
WithMountedFile("./package.json", packageFiles.File("package.json")).
WithMountedFile("./package-lock.json", packageFiles.File("package-lock.json")).
With(nodeOpts.Npm.WithNpmInstall()).
WithDirectory(".", sourceCode).
With(nodeOpts.Npm.WithNpmBuild())
...
But If I like this, any change in the source code, (not in any of the package files), invalidates the cache.
sourceCode := dag.Host().Directory("cube-apps-admin", dagger.HostDirectoryOpts{
Exclude: []string{
"**/node_modules",
},
})
packageJson := sourceCode.File("package.json")
packageLockJson := sourceCode.File("package-lock.json")
daggerContainer = daggerContainer.
WithMountedFile("./package.json", packageJson).
WithMountedFile("./package-lock.json", packageLockJson).
With(nodeOpts.Npm.WithNpmInstall()).
WithDirectory(".", sourceCode.
WithoutFile("package.json").
WithoutFile("package-lock.json"),
).
With(nodeOpts.Npm.WithNpmBuild())
my question is, is that the right way to do it? Or is there a better way?
EDIT: add the dag on each example to make clearer what is going on