17
17
package helpers
18
18
19
19
import (
20
- "context"
21
20
"encoding/json"
22
21
"errors"
23
22
"fmt"
@@ -27,12 +26,6 @@ import (
27
26
"testing"
28
27
29
28
"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"
36
29
)
37
30
38
31
func CreateBuildContext (t * testing.T , dockerfile string ) string {
@@ -42,47 +35,6 @@ func CreateBuildContext(t *testing.T, dockerfile string) string {
42
35
return tmpDir
43
36
}
44
37
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
-
86
38
func ExtractDockerArchive (archiveTarPath , rootfsPath string ) error {
87
39
if err := os .MkdirAll (rootfsPath , 0755 ); err != nil {
88
40
return err
0 commit comments