2019-04-13 07:39:06 +08:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/cli/cli"
|
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
|
"github.com/moby/buildkit/util/appcontext"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type stopOptions struct {
|
2020-04-28 05:37:17 +08:00
|
|
|
builder string
|
2019-04-13 07:39:06 +08:00
|
|
|
}
|
|
|
|
|
2020-04-28 05:37:17 +08:00
|
|
|
func runStop(dockerCli command.Cli, in stopOptions) error {
|
2019-04-13 07:39:06 +08:00
|
|
|
ctx := appcontext.Context()
|
|
|
|
|
|
|
|
txn, release, err := getStore(dockerCli)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer release()
|
|
|
|
|
2020-04-28 05:37:17 +08:00
|
|
|
if in.builder != "" {
|
|
|
|
ng, err := getNodeGroup(txn, dockerCli, in.builder)
|
2019-04-13 07:39:06 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := stop(ctx, dockerCli, ng, false); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ng, err := getCurrentInstance(txn, dockerCli)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if ng != nil {
|
|
|
|
return stop(ctx, dockerCli, ng, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
return stopCurrent(ctx, dockerCli, false)
|
|
|
|
}
|
|
|
|
|
2020-04-28 05:37:17 +08:00
|
|
|
func stopCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
|
2019-04-13 07:39:06 +08:00
|
|
|
var options stopOptions
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "stop [NAME]",
|
|
|
|
Short: "Stop builder instance",
|
|
|
|
Args: cli.RequiresMaxArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2020-04-28 05:37:17 +08:00
|
|
|
options.builder = rootOpts.builder
|
|
|
|
if len(args) > 0 {
|
|
|
|
options.builder = args[0]
|
|
|
|
}
|
|
|
|
return runStop(dockerCli, options)
|
2019-04-13 07:39:06 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
flags := cmd.Flags()
|
|
|
|
|
|
|
|
// flags.StringArrayVarP(&options.outputs, "output", "o", []string{}, "Output destination (format: type=local,dest=path)")
|
|
|
|
|
|
|
|
_ = flags
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|