We have a pipeline that mounts a dag.CacheVolume and tries to install artifacts using the cache.
base := dag.Container().
From("rust:1.81.0").
WithEnvVariable("CARGO_TARGET_DIR", "/rust/target").
WithMountedCache("/rust/target", dag.CacheVolume("cargo-targets")).
WithExec([]string{"cargo", "install", "cargo-chef@0.1.55"})
When using this locally (on my laptop), all works fine, but when running this in our remote environment (SelfHosted GitHub runners, shared dagger engine in the same node than the runners), the next scenario is seen:
Workflow ouptut:
Caused by:
Permission denied (os error 13)
error: failed to compile `cargo-chef v0.1.55`, intermediate artifacts can be found at `/rust/target`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
In order to debug it further, we just created a simple function that mounts a CacheVolume, and we found permissions are different from remote to local executions.
func (m *Forge) CacheVolume(ctx context.Context) (string, error) {
return dag.Container().
From("rust:1.81.0").
WithEnvVariable("CARGO_TARGET_DIR", "/rust/target").
WithMountedCache("/rust/target", dag.CacheVolume("test-volume"), dagger.ContainerWithMountedCacheOpts{Owner: "root"}).
WithExec([]string{"ls", "-la", "/rust/target/"}).Stdout(ctx)
}
Locally, the volume mounted is owned by root:root
$> dagger call cache-volume
✔ connect 0.2s
✔ loading module 2.0s
✔ parsing command line arguments 0.0s
✔ forge: Forge! 0.0s
✔ Forge.cacheVolume: String! 0.9s
total 16
drwxr-xr-x 3 root root 4096 Nov 21 22:02 .
drwxr-xr-x 3 root root 4096 Dec 12 13:25 ..
While on the runner dagger-engine:
17 : Container.withExec DONE [7.0s]
17 : [6.9s] | total 16
17 : [6.9s] | drwxr-xr-x 3 root 1001 4096 Nov 21 14:11 .
17 : [6.9s] | drwxr-xr-x 3 root 1001 4096 Dec 12 13:36 ..