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

Function runPush

cli/command/image/push.go:78–142  ·  view source on GitHub ↗

runPush performs a push against the engine based on the specified options.

(ctx context.Context, dockerCli command.Cli, opts pushOptions)

Source from the content-addressed store, hash-verified

76
77// runPush performs a push against the engine based on the specified options.
78func runPush(ctx context.Context, dockerCli command.Cli, opts pushOptions) error {
79 var platform *ocispec.Platform
80 out := tui.NewOutput(dockerCli.Out())
81 if opts.platform != "" {
82 p, err := platforms.Parse(opts.platform)
83 if err != nil {
84 _, _ = fmt.Fprintf(dockerCli.Err(), "Invalid platform %s", opts.platform)
85 return err
86 }
87 platform = &p
88
89 out.PrintNote(`Using --platform pushes only the specified platform manifest of a multi-platform image index.
90Other components, like attestations, will not be included.
91To push the complete multi-platform image, remove the --platform flag.
92`)
93 }
94
95 ref, err := reference.ParseNormalizedNamed(opts.remote)
96 if err != nil {
97 return err
98 }
99
100 switch {
101 case opts.all && !reference.IsNameOnly(ref):
102 return errors.New("tag can't be used with --all-tags/-a")
103 case !opts.all && reference.IsNameOnly(ref):
104 ref = reference.TagNameOnly(ref)
105 if tagged, ok := ref.(reference.Tagged); ok && !opts.quiet {
106 _, _ = fmt.Fprintln(dockerCli.Out(), "Using default tag:", tagged.Tag())
107 }
108 }
109
110 // Resolve the Auth config relevant for this server
111 encodedAuth, err := command.RetrieveAuthTokenFromImage(dockerCli.ConfigFile(), ref.String())
112 if err != nil {
113 return err
114 }
115
116 responseBody, err := dockerCli.Client().ImagePush(ctx, reference.FamiliarString(ref), client.ImagePushOptions{
117 All: opts.all,
118 RegistryAuth: encodedAuth,
119 PrivilegeFunc: nil,
120 Platform: platform,
121 })
122 if err != nil {
123 return err
124 }
125
126 var notes []string
127 defer func() {
128 _ = responseBody.Close()
129 for _, note := range notes {
130 out.PrintNote(note)
131 }
132 }()
133
134 if opts.quiet {
135 err = jsonstream.Display(ctx, responseBody, streams.NewOut(io.Discard), jsonstream.WithAuxCallback(handleAux(&notes, out)))

Callers 2

newPushCommandFunction · 0.70

Calls 10

PrintNoteMethod · 0.95
handleAuxFunction · 0.85
OutMethod · 0.65
ErrMethod · 0.65
ConfigFileMethod · 0.65
StringMethod · 0.65
ClientMethod · 0.65
TagMethod · 0.45
ImagePushMethod · 0.45
CloseMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…