runPush performs a push against the engine based on the specified options.
(ctx context.Context, dockerCli command.Cli, opts pushOptions)
| 76 | |
| 77 | // runPush performs a push against the engine based on the specified options. |
| 78 | func 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. |
| 90 | Other components, like attestations, will not be included. |
| 91 | To 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(¬es, out))) |
searching dependent graphs…