newPushCommand creates a new `docker push` command
(dockerCLI command.Cli)
| 34 | |
| 35 | // newPushCommand creates a new `docker push` command |
| 36 | func newPushCommand(dockerCLI command.Cli) *cobra.Command { |
| 37 | var opts pushOptions |
| 38 | |
| 39 | cmd := &cobra.Command{ |
| 40 | Use: "push [OPTIONS] NAME[:TAG]", |
| 41 | Short: "Upload an image to a registry", |
| 42 | Args: cli.ExactArgs(1), |
| 43 | RunE: func(cmd *cobra.Command, args []string) error { |
| 44 | opts.remote = args[0] |
| 45 | return runPush(cmd.Context(), dockerCLI, opts) |
| 46 | }, |
| 47 | Annotations: map[string]string{ |
| 48 | "category-top": "6", |
| 49 | "aliases": "docker image push, docker push", |
| 50 | }, |
| 51 | ValidArgsFunction: completion.ImageNames(dockerCLI, 1), |
| 52 | DisableFlagsInUseLine: true, |
| 53 | } |
| 54 | |
| 55 | flags := cmd.Flags() |
| 56 | flags.BoolVarP(&opts.all, "all-tags", "a", false, "Push all tags of an image to the repository") |
| 57 | flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output") |
| 58 | |
| 59 | // TODO(thaJeztah): DEPRECATED: remove in v29.1 or v30 |
| 60 | flags.Bool("disable-content-trust", true, "Skip image verification (deprecated)") |
| 61 | _ = flags.MarkDeprecated("disable-content-trust", "support for docker content trust was removed") |
| 62 | |
| 63 | // Don't default to DOCKER_DEFAULT_PLATFORM env variable, always default to |
| 64 | // pushing the image as-is. This also avoids forcing the platform selection |
| 65 | // on older APIs which don't support it. |
| 66 | flags.StringVar(&opts.platform, "platform", "", |
| 67 | `Push a platform-specific manifest as a single-platform image to the registry. |
| 68 | Image index won't be pushed, meaning that other manifests, including attestations won't be preserved. |
| 69 | 'os[/arch[/variant]]': Explicit platform (eg. linux/amd64)`) |
| 70 | flags.SetAnnotation("platform", "version", []string{"1.46"}) |
| 71 | |
| 72 | _ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms()) |
| 73 | |
| 74 | return cmd |
| 75 | } |
| 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 { |
searching dependent graphs…