-
Notifications
You must be signed in to change notification settings - Fork 288
/
docker_prune.go
74 lines (55 loc) · 1.56 KB
/
docker_prune.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package cli
import (
"context"
"os"
"time"
"github.com/spf13/cobra"
"github.com/windmilleng/tilt/pkg/logger"
"github.com/windmilleng/tilt/pkg/model"
"github.com/windmilleng/tilt/internal/docker"
"github.com/windmilleng/tilt/internal/tiltfile"
"github.com/windmilleng/tilt/internal/analytics"
"github.com/windmilleng/tilt/internal/engine/dockerprune"
)
type dockerPruneCmd struct {
fileName string
}
type dpDeps struct {
dCli docker.Client
tfl tiltfile.TiltfileLoader
}
func newDPDeps(dCli docker.Client, tfl tiltfile.TiltfileLoader) dpDeps {
return dpDeps{
dCli: dCli,
tfl: tfl,
}
}
func (c *dockerPruneCmd) register() *cobra.Command {
cmd := &cobra.Command{
Use: "docker-prune",
Short: "run docker prune as Tilt does",
}
cmd.Flags().StringVar(&c.fileName, "file", tiltfile.FileName, "Path to Tiltfile")
return cmd
}
func (c *dockerPruneCmd) run(ctx context.Context, args []string) error {
a := analytics.Get(ctx)
a.Incr("cmd.dockerPrune", nil)
defer a.Flush(time.Second)
// (Most relevant output from dockerpruner is at the `debug` level)
l := logger.NewLogger(logger.DebugLvl, os.Stdout)
ctx = logger.WithLogger(ctx, l)
deps, err := wireDockerPrune(ctx, a)
if err != nil {
return err
}
tlr := deps.tfl.Load(ctx, c.fileName, model.NewUserConfigState(args))
if tlr.Error != nil {
return tlr.Error
}
imgSelectors := model.LocalRefSelectorsForManifests(tlr.Manifests)
dp := dockerprune.NewDockerPruner(deps.dCli)
// TODO: print the commands being run
dp.Prune(ctx, tlr.DockerPruneSettings.MaxAge, imgSelectors)
return nil
}