#Is WithMountedCache persisted across Dagger runs?

1 messages · Page 1 of 1 (latest)

jovial canyon
#

Hey All,

I have a small pipeline where I build something with Bazel inside a container:

    runner := client.Container(dagger.ContainerOpts{Platform: "linux/arm64"}).
        From("ubuntu:22.04").
        WithExec([]string{"apt-get", "update", "-yq"}).
        WithExec([]string{"apt-get", "install", "-yq", "ca-certificates", "git", "gcc"}).
        WithExec([]string{
            "mkdir", "-p", "/root/.cache",
        })

    _, err = runner.
        WithDirectory("/workspace", client.Host().Directory("."),
            dagger.ContainerWithDirectoryOpts{
                Exclude: []string{"bazel-*"},
            }).
        WithWorkdir("/workspace").
        WithMountedCache("/root/.cache/", client.CacheVolume("cache")).
        WithExec([]string{
            "du", "-d", "2", "-h", "/root/.cache/",
        }).
        WithExec([]string{
            "./bazel.sh",
            "build",
            "--repository_cache=/root/.cache/bazel/repository",
            "--disk_cache=/root/.cache/bazel/disk",
            "//cmd/myapp",
        }).
        Sync(ctx)

I'm using WithMountedCache to cache artifacts that Bazel produces in cache volume but on subsequent runs /root/.cache is always empty. Is that expected? If not, what could be the reason?

crisp pollen
#

can you double check in your engine logs that it's not being garbage collected for some reason? If you see a message like "removed snapshopt" in the logs, that could be the case

jovial canyon
#

@crisp pollen thanks for the tip! Oh yeah I see it

time="2023-12-13T07:48:59Z" level=debug msg="removed snapshot" key=buildkit/46/ju6zst28qka58ovs0ojme0wpg snapshotter=overlayfs
time="2023-12-13T07:48:59Z" level=debug msg="removed snapshot" key=buildkit/61/opgzmjwpx0bz9g5wlzlkq4g3f snapshotter=overlayfs
time="2023-12-13T07:48:59Z" level=debug msg="removed snapshot" key=buildkit/38/s068i1jl2juxcgshs59zl59x9 snapshotter=overlayfs
time="2023-12-13T07:48:59Z" level=debug msg="removed snapshot" key=buildkit/40/mm5b4il3wr8wbnrlmi3b1ceko snapshotter=overlayfs
time="2023-12-13T07:48:59Z" level=debug msg="removed snapshot" key=buildkit/43/w0d5knxu1s2te2p4wy051k9lc snapshotter=overlayfs
time="2023-12-13T07:48:59Z" level=debug msg="removed snapshot" key=buildkit/52/psme6uortvcagbubtehvleuh8-view snapshotter=overlayfs
time="2023-12-13T07:48:59Z" level=debug msg="removed snapshot" key=buildkit/58/8vlxsonrpa9heqirgcxf0pm7t snapshotter=overlayfs
time="2023-12-13T07:48:59Z" level=debug msg="removed snapshot" key=buildkit/60/hzxx3u24zpubtafi6p2t67p88 snapshotter=overlayfs
time="2023-12-13T07:48:59Z" level=debug msg="removed content" digest="sha256:19fbd6d36af4c083ad7b2e3aa67757834a3c3bf8aa1f4fa39de312101170d524"
time="2023-12-13T07:48:59Z" level=debug msg="content garbage collected" d=6.61975ms
time="2023-12-13T07:48:59Z" level=debug msg="snapshot garbage collected" d=467.179417ms snapshotter=overlayfs
time="2023-12-13T07:48:59Z" level=debug msg="gc cleaned up 2935452216 bytes"
#

it's supposed to be pretty large snapshot...

crisp pollen
#

generally this happens when the engine enters in a disk pressure state and has to free some space. You can remove your engine and start from a clean state to validate this

jovial canyon
#

I see, thanks. I'll try to recycle the engine docker container

crisp pollen
#

cc @shell socket since your'e also playing with Dagger and Bazel

jovial canyon
#

hm still cleans up snapshots

#

do you know what's the threshold at which it starts doing that?

crisp pollen
jovial canyon
#

roger, thanks!

jovial canyon
#

Disabling gc totally fixed btw - I was low on space

shell socket
crisp pollen
#

oh yes! I got confused with @pine berry ! sorry for that! 😓