-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean.go
58 lines (47 loc) · 1.15 KB
/
clean.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package tug
import (
"fmt"
"log"
"os"
"os/exec"
)
// RemoveBuildxImageCache deletes any images/layers in the active buildx cache.
func RemoveBuildxImageCache(debug bool) error {
cmd := exec.Command("docker")
cmd.Args = []string{"docker", "buildx", "prune", "--force"}
cmd.Env = os.Environ()
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
if debug {
log.Printf("Command: %v\n", cmd)
}
return cmd.Run()
}
// RemoveTugBuilder deletes the tug buildx builder.
func RemoveTugBuilder(debug bool) error {
cmd := exec.Command("docker")
cmd.Args = []string{"docker", "buildx", "rm", TugBuilderName}
cmd.Env = os.Environ()
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
if debug {
log.Printf("Command: %v\n", cmd)
}
return cmd.Run()
}
// Clean empties the active buildx image cache
// and removes the tug builder,
//
// Returns zero on successful operation. Otherwise, returns non-zero.
func Clean(debug bool) int {
var status = 0
if err := RemoveBuildxImageCache(debug); err != nil {
fmt.Fprintf(os.Stderr, "%v", err)
status = 1
}
if err := RemoveTugBuilder(debug); err != nil {
fmt.Fprintf(os.Stderr, "%v", err)
status = 1
}
return status
}