Skip to content

Commit acb019a

Browse files
authored
Merge pull request #6311 from thaJeztah/28.x_backport_deprecate_platform_flags
[28.x backport] cli/command: remove `AddTrustSigningFlags`, `AddTrustVerificationFlags`, `AddPlatformFlag` utilities
2 parents 5a80c3e + 8088471 commit acb019a

File tree

12 files changed

+42
-33
lines changed

12 files changed

+42
-33
lines changed

cli/command/container/create.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ func NewCreateCommand(dockerCli command.Cli) *cobra.Command {
8686
// with hostname
8787
flags.Bool("help", false, "Print usage")
8888

89-
command.AddPlatformFlag(flags, &options.platform)
90-
command.AddTrustVerificationFlags(flags, &options.untrusted, dockerCli.ContentTrustEnabled())
89+
// TODO(thaJeztah): consider adding platform as "image create option" on containerOptions
90+
addPlatformFlag(flags, &options.platform)
91+
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
92+
93+
flags.BoolVar(&options.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image verification")
9194
copts = addFlags(flags)
9295

9396
addCompletions(cmd, dockerCli)

cli/command/container/opts.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ type containerOptions struct {
141141
Args []string
142142
}
143143

144+
// addPlatformFlag adds "--platform" to a set of flags for API version 1.32 and
145+
// later, using the value of "DOCKER_DEFAULT_PLATFORM" (if set) as a default.
146+
//
147+
// It should not be used for new uses, which may have a different API version
148+
// requirement.
149+
func addPlatformFlag(flags *pflag.FlagSet, target *string) {
150+
flags.StringVar(target, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
151+
_ = flags.SetAnnotation("platform", "version", []string{"1.32"})
152+
}
153+
144154
// addFlags adds all command line flags that will be used by parse to the FlagSet
145155
func addFlags(flags *pflag.FlagSet) *containerOptions {
146156
copts := &containerOptions{

cli/command/container/run.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ func NewRunCommand(dockerCli command.Cli) *cobra.Command {
6666
// with hostname
6767
flags.Bool("help", false, "Print usage")
6868

69-
command.AddPlatformFlag(flags, &options.platform)
70-
command.AddTrustVerificationFlags(flags, &options.untrusted, dockerCli.ContentTrustEnabled())
69+
// TODO(thaJeztah): consider adding platform as "image create option" on containerOptions
70+
addPlatformFlag(flags, &options.platform)
71+
flags.BoolVar(&options.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image verification")
7172
copts = addFlags(flags)
7273

7374
_ = cmd.RegisterFlagCompletionFunc("detach-keys", completeDetachKeys)

cli/command/image/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func NewBuildCommand(dockerCli command.Cli) *cobra.Command {
145145
flags.SetAnnotation("target", annotation.ExternalURL, []string{"https://docs.docker.com/reference/cli/docker/buildx/build/#target"})
146146
flags.StringVar(&options.imageIDFile, "iidfile", "", "Write the image ID to the file")
147147

148-
command.AddTrustVerificationFlags(flags, &options.untrusted, dockerCli.ContentTrustEnabled())
148+
flags.BoolVar(&options.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image verification")
149149

150150
flags.StringVar(&options.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
151151
flags.SetAnnotation("platform", "version", []string{"1.38"})

cli/command/image/import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func NewImportCommand(dockerCli command.Cli) *cobra.Command {
4747
options.changes = dockeropts.NewListOpts(nil)
4848
flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image")
4949
flags.StringVarP(&options.message, "message", "m", "", "Set commit message for imported image")
50-
command.AddPlatformFlag(flags, &options.platform)
50+
addPlatformFlag(flags, &options.platform)
5151
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
5252

5353
return cmd

cli/command/image/opts.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package image
2+
3+
import (
4+
"os"
5+
6+
"github.com/spf13/pflag"
7+
)
8+
9+
// addPlatformFlag adds "--platform" to a set of flags for API version 1.32 and
10+
// later, using the value of "DOCKER_DEFAULT_PLATFORM" (if set) as a default.
11+
//
12+
// It should not be used for new uses, which may have a different API version
13+
// requirement.
14+
func addPlatformFlag(flags *pflag.FlagSet, target *string) {
15+
flags.StringVar(target, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
16+
_ = flags.SetAnnotation("platform", "version", []string{"1.32"})
17+
}

cli/command/image/pull.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func NewPullCommand(dockerCli command.Cli) *cobra.Command {
5050
flags.BoolVarP(&opts.all, "all-tags", "a", false, "Download all tagged images in the repository")
5151
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output")
5252

53-
command.AddPlatformFlag(flags, &opts.platform)
54-
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
53+
addPlatformFlag(flags, &opts.platform)
54+
flags.BoolVar(&opts.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image verification")
5555

5656
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms)
5757

cli/command/image/push.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func NewPushCommand(dockerCli command.Cli) *cobra.Command {
5757
flags := cmd.Flags()
5858
flags.BoolVarP(&opts.all, "all-tags", "a", false, "Push all tags of an image to the repository")
5959
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output")
60-
command.AddTrustSigningFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
60+
flags.BoolVar(&opts.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image signing")
6161

6262
// Don't default to DOCKER_DEFAULT_PLATFORM env variable, always default to
6363
// pushing the image as-is. This also avoids forcing the platform selection

cli/command/plugin/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type pluginOptions struct {
3131

3232
func loadPullFlags(dockerCli command.Cli, opts *pluginOptions, flags *pflag.FlagSet) {
3333
flags.BoolVar(&opts.grantPerms, "grant-all-permissions", false, "Grant all permissions necessary to run the plugin")
34-
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
34+
flags.BoolVar(&opts.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image verification")
3535
}
3636

3737
func newInstallCommand(dockerCli command.Cli) *cobra.Command {

cli/command/plugin/push.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func newPushCommand(dockerCli command.Cli) *cobra.Command {
3333

3434
flags := cmd.Flags()
3535

36-
command.AddTrustSigningFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
36+
flags.BoolVar(&opts.untrusted, "disable-content-trust", !dockerCli.ContentTrustEnabled(), "Skip image signing")
3737

3838
return cmd
3939
}

0 commit comments

Comments
 (0)