system-reset: use CleanCacheMount to clear build cache

Just like buildkit buildah must allow cleaning the buildcache and cache generated on host by --mount=type=cache just like buildkit's prune command.

See: https://github.com/moby/buildkit#cache

Signed-off-by: Aditya R <arajan@redhat.com>
This commit is contained in:
Aditya R
2023-02-02 14:26:36 +05:30
parent 5ca35d6de7
commit 9e7f1bea42
4 changed files with 30 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"os"
"strings"
"github.com/containers/buildah/pkg/parse"
"github.com/containers/common/pkg/completion"
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/cmd/podman/validate"
@ -88,6 +89,11 @@ func reset(cmd *cobra.Command, args []string) {
if err != nil {
logrus.Error(err)
}
// Clean build cache if any
err = parse.CleanCacheMount()
if err != nil {
logrus.Error(err)
}
// Shutdown all running engines, `reset` will hijack repository
registry.ContainerEngine().Shutdown(registry.Context())
registry.ImageEngine().Shutdown(registry.Context())

View File

@ -0,0 +1,4 @@
FROM alpine
RUN mkdir /test
# use option z if selinux is enabled
RUN --mount=type=cache,target=/test,z cat /test/world

View File

@ -0,0 +1,4 @@
FROM alpine
RUN mkdir /test
# use option z if selinux is enabled
RUN --mount=type=cache,target=/test,z echo hello > /test/world

View File

@ -874,4 +874,20 @@ RUN ls /dev/test1`, ALPINE)
build.WaitWithDefaultTimeout()
Expect(build).To(Exit(0))
})
It("podman system reset must clean host shared cache", func() {
SkipIfRemote("podman-remote does not have system reset -f")
podmanTest.AddImageToRWStore(ALPINE)
session := podmanTest.Podman([]string{"build", "--pull-never", "--file", "build/cache/Dockerfilecachewrite", "build/cache/"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"system", "reset", "-f"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"build", "--pull-never", "--file", "build/cache/Dockerfilecacheread", "build/cache/"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))
})
})