-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ctl.go
67 lines (57 loc) · 1.42 KB
/
ctl.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
package debug
import (
controlapi "github.com/moby/buildkit/api/services/control"
bccommon "github.com/moby/buildkit/cmd/buildctl/common"
"github.com/moby/buildkit/util/appcontext"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
var CtlCommand = cli.Command{
Name: "ctl",
Usage: "control build records",
Action: ctl,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "pin",
Usage: "Pin build so it will not be garbage collected",
},
cli.BoolFlag{
Name: "unpin",
Usage: "Unpin build so it will be garbage collected",
},
cli.BoolFlag{
Name: "delete",
Usage: "Delete build record",
},
},
}
func ctl(clicontext *cli.Context) error {
args := clicontext.Args()
if len(args) == 0 {
return errors.Errorf("build ref must be specified")
}
ref := args[0]
c, err := bccommon.ResolveClient(clicontext)
if err != nil {
return err
}
ctx := appcontext.Context()
pin := clicontext.Bool("pin")
unpin := clicontext.Bool("unpin")
del := clicontext.Bool("delete")
if !pin && !unpin && !del {
return errors.Errorf("must specify one of --pin, --unpin, --delete")
}
if pin && unpin {
return errors.Errorf("cannot specify both --pin and --unpin")
}
if del && (pin || unpin) {
return errors.Errorf("cannot specify --delete with --pin or --unpin")
}
_, err = c.ControlClient().UpdateBuildHistory(ctx, &controlapi.UpdateBuildHistoryRequest{
Ref: ref,
Pinned: pin,
Delete: del,
})
return err
}