Skip to content

Commit

Permalink
system-reset: use CleanCacheMount to clear build cache
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
flouthoc committed Feb 3, 2023
1 parent 5ca35d6 commit 9e7f1be
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/podman/system/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/build/cache/Dockerfilecacheread
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions test/e2e/build/cache/Dockerfilecachewrite
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions test/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})

0 comments on commit 9e7f1be

Please sign in to comment.