1717package helpers
1818
1919import (
20- "context"
2120 "encoding/json"
2221 "errors"
2322 "fmt"
@@ -27,12 +26,6 @@ import (
2726 "testing"
2827
2928 "gotest.tools/v3/assert"
30-
31- containerd "github.com/containerd/containerd/v2/client"
32- "github.com/containerd/containerd/v2/core/content"
33-
34- "github.com/containerd/nerdctl/v2/pkg/buildkitutil"
35- "github.com/containerd/nerdctl/v2/pkg/testutil"
3629)
3730
3831func CreateBuildContext (t * testing.T , dockerfile string ) string {
@@ -42,47 +35,6 @@ func CreateBuildContext(t *testing.T, dockerfile string) string {
4235 return tmpDir
4336}
4437
45- func RmiAll (base * testutil.Base ) {
46- base .T .Logf ("Pruning images" )
47- imageIDs := base .Cmd ("images" , "--no-trunc" , "-a" , "-q" ).OutLines ()
48- // remove empty output line at the end
49- imageIDs = imageIDs [:len (imageIDs )- 1 ]
50- // use `Run` on purpose (same below) because `rmi all` may fail on individual
51- // image id that has an expected running container (e.g. a registry)
52- base .Cmd (append ([]string {"rmi" , "-f" }, imageIDs ... )... ).Run ()
53-
54- base .T .Logf ("Pruning build caches" )
55- if _ , err := buildkitutil .GetBuildkitHost (testutil .Namespace ); err == nil {
56- base .Cmd ("builder" , "prune" , "--force" ).AssertOK ()
57- }
58-
59- // For BuildKit >= 0.11, pruning cache isn't enough to remove manifest blobs that are referred by build history blobs
60- // https://github.com/containerd/nerdctl/pull/1833
61- if base .Target == testutil .Nerdctl {
62- base .T .Logf ("Pruning all content blobs" )
63- addr := base .ContainerdAddress ()
64- client , err := containerd .New (addr , containerd .WithDefaultNamespace (testutil .Namespace ))
65- assert .NilError (base .T , err )
66- cs := client .ContentStore ()
67- ctx := context .TODO ()
68- wf := func (info content.Info ) error {
69- base .T .Logf ("Pruning blob %+v" , info )
70- if err := cs .Delete (ctx , info .Digest ); err != nil {
71- base .T .Log (err )
72- }
73- return nil
74- }
75- if err := cs .Walk (ctx , wf ); err != nil {
76- base .T .Log (err )
77- }
78-
79- base .T .Logf ("Pruning all images (again?)" )
80- imageIDs = base .Cmd ("images" , "--no-trunc" , "-a" , "-q" ).OutLines ()
81- base .T .Logf ("pruning following images: %+v" , imageIDs )
82- base .Cmd (append ([]string {"rmi" , "-f" }, imageIDs ... )... ).Run ()
83- }
84- }
85-
8638func ExtractDockerArchive (archiveTarPath , rootfsPath string ) error {
8739 if err := os .MkdirAll (rootfsPath , 0755 ); err != nil {
8840 return err
0 commit comments