MCPcopy Index your code
hub / github.com/docker/cli / runUpgrade

Function runUpgrade

cli/command/plugin/upgrade.go:44–98  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, opts pluginOptions)

Source from the content-addressed store, hash-verified

42}
43
44func runUpgrade(ctx context.Context, dockerCLI command.Cli, opts pluginOptions) error {
45 res, err := dockerCLI.Client().PluginInspect(ctx, opts.localName, client.PluginInspectOptions{})
46 if err != nil {
47 return fmt.Errorf("error reading plugin data: %w", err)
48 }
49
50 if res.Plugin.Enabled {
51 return errors.New("the plugin must be disabled before upgrading")
52 }
53
54 opts.localName = res.Plugin.Name
55 if opts.remote == "" {
56 opts.remote = res.Plugin.PluginReference
57 }
58 remote, err := reference.ParseNormalizedNamed(opts.remote)
59 if err != nil {
60 return fmt.Errorf("error parsing remote upgrade image reference: %w", err)
61 }
62 remote = reference.TagNameOnly(remote)
63
64 old, err := reference.ParseNormalizedNamed(res.Plugin.PluginReference)
65 if err != nil {
66 return fmt.Errorf("error parsing current image reference: %w", err)
67 }
68 old = reference.TagNameOnly(old)
69
70 _, _ = fmt.Fprintf(dockerCLI.Out(), "Upgrading plugin %s from %s to %s\n", res.Plugin.Name, reference.FamiliarString(old), reference.FamiliarString(remote))
71 if !opts.skipRemoteCheck && remote.String() != old.String() {
72 r, err := prompt.Confirm(ctx, dockerCLI.In(), dockerCLI.Out(), "Plugin images do not match, are you sure?")
73 if err != nil {
74 return err
75 }
76 if !r {
77 return cancelledErr{errors.New("plugin upgrade has been cancelled")}
78 }
79 }
80
81 options, err := buildPullConfig(dockerCLI, opts)
82 if err != nil {
83 return err
84 }
85
86 responseBody, err := dockerCLI.Client().PluginUpgrade(ctx, opts.localName, client.PluginUpgradeOptions(options))
87 if err != nil {
88 return err
89 }
90 defer func() {
91 _ = responseBody.Close()
92 }()
93 if err := jsonstream.Display(ctx, responseBody, dockerCLI.Out()); err != nil {
94 return err
95 }
96 _, _ = fmt.Fprintf(dockerCLI.Out(), "Upgraded plugin %s to %s\n", opts.localName, opts.remote) // todo: return proper values from the API for this result
97 return nil
98}
99
100type cancelledErr struct{ error }
101

Callers 1

newUpgradeCommandFunction · 0.85

Calls 8

buildPullConfigFunction · 0.85
PluginInspectMethod · 0.80
PluginUpgradeMethod · 0.80
ClientMethod · 0.65
OutMethod · 0.65
StringMethod · 0.65
InMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…