2018-03-19 18:56:51 -04:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/docker/cli/cli"
|
|
|
|
"github.com/docker/cli/cli/command"
|
2018-09-20 14:02:11 -04:00
|
|
|
clitypes "github.com/docker/cli/types"
|
2018-03-19 18:56:51 -04:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newUpdateCommand(dockerCli command.Cli) *cobra.Command {
|
|
|
|
var options extendedEngineInitOptions
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "update [OPTIONS]",
|
|
|
|
Short: "Update a local engine",
|
|
|
|
Args: cli.NoArgs,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return runUpdate(dockerCli, options)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
flags := cmd.Flags()
|
|
|
|
|
|
|
|
flags.StringVar(&options.EngineVersion, "version", "", "Specify engine version")
|
2018-09-28 17:06:28 -04:00
|
|
|
flags.StringVar(&options.EngineImage, "engine-image", "", "Specify engine image (default uses the same image as currently running)")
|
2018-09-20 14:02:11 -04:00
|
|
|
flags.StringVar(&options.RegistryPrefix, "registry-prefix", clitypes.RegistryPrefix, "Override the current location where engine images are pulled")
|
2018-03-19 18:56:51 -04:00
|
|
|
flags.StringVar(&options.sockPath, "containerd", "", "override default location of containerd endpoint")
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func runUpdate(dockerCli command.Cli, options extendedEngineInitOptions) error {
|
2018-09-14 13:53:56 -04:00
|
|
|
if !isRoot() {
|
2018-09-20 14:02:11 -04:00
|
|
|
return errors.New("this command must be run as a privileged user")
|
2018-09-13 12:32:19 -04:00
|
|
|
}
|
2018-03-19 18:56:51 -04:00
|
|
|
ctx := context.Background()
|
|
|
|
client, err := dockerCli.NewContainerizedEngineClient(options.sockPath)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "unable to access local containerd")
|
|
|
|
}
|
|
|
|
defer client.Close()
|
|
|
|
authConfig, err := getRegistryAuth(dockerCli, options.RegistryPrefix)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-10-01 18:12:09 -04:00
|
|
|
if err := client.DoUpdate(ctx, options.EngineInitOptions, dockerCli.Out(), authConfig); err != nil {
|
2018-03-19 18:56:51 -04:00
|
|
|
return err
|
|
|
|
}
|
2018-09-21 14:01:06 -04:00
|
|
|
fmt.Fprintln(dockerCli.Out(), `Successfully updated engine.
|
2018-09-20 14:02:11 -04:00
|
|
|
Restart docker with 'systemctl restart docker' to complete the update.`)
|
2018-03-19 18:56:51 -04:00
|
|
|
return nil
|
|
|
|
}
|