-
Notifications
You must be signed in to change notification settings - Fork 545
cmd: support cli environment variables in standalone mode #3087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
b3881fd
to
dfe58c4
Compare
Slightly wondering what the most correct approach would be here. Ultimately this is one of the issues we discussed at some point when the cli plugins were created (i.e., ideally, the CLI ('host') would be able to handle the connection, and plugins to be able to use that connection. The tricky bit here is that we start to (more, and more) cli-plugins to take over env-vars (and options) that are basically owned by the CLI, which also means that the CLI won't be able to change meaning for its own env-vars, without all plugins that exist to also update accordingly. Does buildx, when running standalone, have top-level flags to specify tis-config etc? i.e., would compose be able to;
|
dfe58c4
to
81555db
Compare
Signed-off-by: CrazyMax <[email protected]>
81555db
to
7b8bf9f
Compare
Thanks for your feedback, I was keeping this one in draft because I got questions related to these changes so I'm glad you came up here 😅
No, buildx does not have any top-level flags to set tls-config but I would assume that env vars like |
// would panic. | ||
nflags := pflag.NewFlagSet(cmd.DisplayName(), pflag.ContinueOnError) | ||
options := cliflags.NewClientOptions() | ||
options.InstallFlags(nflags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused what is docker-specific in this InstallFlags
call? And if there is nothing docker-specific and just needs to be called then why isn't NewClientOptions()
handling it automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just needs to be called then why isn't
NewClientOptions()
handling it automatically.
Yes it would be better if this was handled directly in docker/cli.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is the difference from calling this function in PersistentPreRunE
instead of before NewRootCmd()
?
Anyway, if this is better in cli, make a tracking issue for it there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is the difference from calling this function in
PersistentPreRunE
instead of beforeNewRootCmd()
?
No there isn't but I was hoping to be able to use options.InstallFlags(cmd.Flags())
here but it panics because we already declare a global debug
flag.
// would panic. | ||
nflags := pflag.NewFlagSet(cmd.DisplayName(), pflag.ContinueOnError) | ||
options := cliflags.NewClientOptions() | ||
options.InstallFlags(nflags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is the difference from calling this function in PersistentPreRunE
instead of before NewRootCmd()
?
Anyway, if this is better in cli, make a tracking issue for it there.
fixes #3081
In plugin mode
buildx/cmd/buildx/main.go
Lines 67 to 71 in 8efc528
plugin.RunPlugin
sets plugin root command throughcli.SetupPluginRootCommand(cmd)
: https://github.com/docker/cli/blob/58fba25b0935586eb14aa6b20b936cfc26df7a19/cli-plugins/plugin/plugin.go#L164Which calls
options.InstallFlags
: https://github.com/docker/cli/blob/58fba25b0935586eb14aa6b20b936cfc26df7a19/cli/cobra.go#L22C6-L24 afterNewClientOptions()
.We need to do the same in standalone mode so cli environment variables are supported.