🐞 Changes in cache volume does not reflect as expected
What is the issue?
Hi Team,
I am running into an issue when trying to understand the current behavior of CacheVolume. I have the following simple module:
import (
"context"
"dagger/foo/internal/dagger"
"fmt"
)
type Foo struct{}
func (f *Foo) TestCacheVolumePersistence(ctx context.Context, input string) (string, error) {
_, err := f.PopulateCache(ctx, input)
if err != nil {
return "", err
}
output, err := f.ListCache(ctx)
if err != nil {
return "", err
}
return output, nil
}
func (f *Foo) PopulateCache(ctx context.Context, input string) (*dagger.Container, error) {
return dag.Container().From("alpine:latest").
WithMountedCache("/foo-cache", dag.CacheVolume("foo-cache")).
WithExec([]string{"sh", "-c", fmt.Sprintf("echo '%s' > /foo-cache/bar.txt", input)}).
Sync(ctx)
}
func (f *Foo) ListCache(ctx context.Context) (string, error) {
return dag.
Container().
From("alpine:latest").
WithMountedCache("/foo-cache", dag.CacheVolume("foo-cache")).
WithExec([]string{"sh", "-c", "cat /foo-cache/bar.txt"}).
Stdout(ctx)
}
Rundagger call test-cache-volume-persistence --input "first call", it returns first call as expected.
Now run dagger call test-cache-volume-persistence --input "second call", it still returns first call when I was expecting it to return second call
I verified using .Terminal(), that the content of actual file is indeed updated, but the output returned in old cached output.
Could you please help me understand if I am missing anything here?
Many thanks
Dagger version
dagger v0.13.3 (registry.dagger.io/engine:v0.13.3) darwin/arm64
Steps to reproduce
- git clone [email protected]:rajatjindal/dagger-cache-volume-issue.git
- Run:
dagger call test-cache-volume-persistence --input "first call", notice the output "first call" (https://dagger.cloud/rajatjindal/traces/c3493503468f53037c1aece000f38759) - Run:
dagger call test-cache-volume-persistence --input "second call", notice the output "first call" while I was expecting output to be "second call" (https://dagger.cloud/rajatjindal/traces/73bc5d22f126c683385a6e0d2158ec14)
Log output
No response
not sure if this is related, but in same module (cloned from provided repo), I noticed if I try to create a file using "WithNewFile" inside the mounted cached directory, it errors out: /foo-cache/: cannot retrieve path from cache. (I am suspecting its looking for /foo-cache in the cache itself, while I am expecting /foo-cache to be the mounted dir)
dagger call with-new-file
✔ connect 0.2s
✔ initialize 0.3s
✔ prepare 0.0s
✔ foo: Foo! 0.0s
✘ Foo.withNewFile: Container! 1.0s
! call function "WithNewFile": process "/runtime" did not complete successfully: exit code: 2
┃ invoke: input: container.from.withMountedCache.withNewFile resolve: /foo-cache/: cannot retrieve path from cache
✔ Container.from(address: "alpine:latest"): Container! 0.9s
✘ Container.withNewFile(contents: "contents of somefile", path: "/foo-cache/somefile.txt"): Container! 0.0s
! /foo-cache/: cannot retrieve path from cache
Full trace at https://dagger.cloud/rajatjindal/traces/32fbaa99e5dab7fa3afb901cd7b87957
Error: response from query: input: foo.withNewFile resolve: call function "WithNewFile": process "/runtime" did not complete successfully: exit code: 2
Stdout:
invoke: input: container.from.withMountedCache.withNewFile resolve: /foo-cache/: cannot retrieve path from cache
Run 'dagger call with-new-file --help' for usage.