Skip to content

Commit 2de9f46

Browse files
fix: buildkit cache prune (#238)
Signed-off-by: Shubharanshu Mahapatra <[email protected]>
1 parent dc50e93 commit 2de9f46

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

tests/builder_prune.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,19 @@ func BuilderPrune(o *option.Option) {
2424
`, localImages[defaultImage]))
2525
ginkgo.DeferCleanup(os.RemoveAll, buildContext)
2626
command.RemoveAll(o)
27+
28+
// Build the Image and remove the resource to be able to prune
29+
command.Run(o, "build", buildContext)
30+
command.RemoveAll(o)
2731
})
2832
ginkgo.AfterEach(func() {
2933
command.RemoveAll(o)
3034
})
3135
ginkgo.It("should prune the builder cache successfully", func() {
32-
command.Run(o, "build", "--output=type=docker", buildContext)
33-
// There is no interface to validate the current builder cache size.
34-
// To validate in Buildkit, run `buildctl du -v`.
35-
args := []string{"builder", "prune"}
36-
37-
// TODO(macedonv): remove after nerdctlv2 is supported across all platforms.
38-
if o.IsNerdctlV2() {
39-
// Do not prompt for user response during automated testing.
40-
args = append(args, "--force")
41-
}
42-
36+
buildCacheShouldExist()
37+
args := []string{"builder", "prune", "--force"}
4338
command.Run(o, args...)
39+
buildCacheShouldNotExist()
4440
})
4541
})
4642
}

tests/tests.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,21 @@ func buildImage(o *option.Option, imageName string) {
234234
ginkgo.DeferCleanup(os.RemoveAll, buildContext)
235235
command.Run(o, "build", "-q", "-t", imageName, buildContext)
236236
}
237+
238+
func buildCacheShouldExist() {
239+
buildctlOpts, err := option.New([]string{"buildctl"})
240+
if err != nil {
241+
ginkgo.Fail(err.Error())
242+
}
243+
cmdOut := command.Run(buildctlOpts, "du", "--format", "json")
244+
gomega.Expect(strings.TrimSpace(string(cmdOut.Out.Contents()))).ToNot(gomega.Equal("null"))
245+
}
246+
247+
func buildCacheShouldNotExist() {
248+
buildctlOpts, err := option.New([]string{"buildctl"})
249+
if err != nil {
250+
ginkgo.Fail(err.Error())
251+
}
252+
cmdOut := command.Run(buildctlOpts, "du", "--format", "json")
253+
gomega.Expect(strings.TrimSpace(string(cmdOut.Out.Contents()))).To(gomega.Equal("null"))
254+
}

0 commit comments

Comments
 (0)