Skip to content

Commit

Permalink
Merge pull request containers#4421 from flouthoc/cache-user-base
Browse files Browse the repository at this point in the history
`mount=type=cache`: seperate cache parent on host for each user
  • Loading branch information
openshift-merge-robot committed Nov 18, 2022
2 parents a1d22a2 + e6eb05f commit 117e97d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/containers/storage"
"github.com/containers/storage/pkg/idtools"
"github.com/containers/storage/pkg/lockfile"
"github.com/containers/storage/pkg/unshare"
specs "github.com/opencontainers/runtime-spec/specs-go"
selinux "github.com/opencontainers/selinux/go-selinux"
)
Expand Down Expand Up @@ -330,8 +331,8 @@ func GetCacheMount(args []string, store storage.Store, imageMountLabel string, a
// create a common cache directory, which persists on hosts within temp lifecycle
// add subdirectory if specified

// cache parent directory
cacheParent := filepath.Join(internalUtil.GetTempDir(), BuildahCacheDir)
// cache parent directory: creates separate cache parent for each user.
cacheParent := filepath.Join(internalUtil.GetTempDir(), BuildahCacheDir+"-"+strconv.Itoa(unshare.GetRootlessUID()))
// create cache on host if not present
err = os.MkdirAll(cacheParent, os.FileMode(0755))
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5410,6 +5410,9 @@ _EOF
run_buildah build -t testbud $WITH_POLICY_JSON -f $contextdir/Dockerfilecachewritewithoutz
# try reading something from persistent cache in a different build
run_buildah build -t testbud2 $WITH_POLICY_JSON -f $contextdir/Dockerfilecachereadwithoutz
buildah_cache_dir="$TMPDIR/buildah-cache-$UID"
# buildah cache parent must exist for uid specific to this invocation
test -d "$buildah_cache_dir"
expect_output --substring "hello"
}

Expand Down

0 comments on commit 117e97d

Please sign in to comment.