Skip to content
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

Add env variable option for experimental #1138

Merged
merged 1 commit into from
Jun 25, 2018

Conversation

seemethere
Copy link
Contributor

@seemethere seemethere commented Jun 21, 2018

Signed-off-by: Eli Uriegas eli.uriegas@docker.com

- What I did
Added an option to enable the experimental cli options with an environment variable

- How to verify it

Proof of work
~/go/src/github.com/docker/cli env_experimental eli@castlerock
❯ DOCKER_CLI_EXPERIMENTAL=enabled ./build/docker manifest

Usage:  docker manifest COMMAND

Manage Docker image manifests and manifest lists

Options:
      --orchestrator string   Orchestrator to use (swarm|kubernetes|all)

Commands:
  annotate    Add additional information to a local image manifest
  create      Create a local manifest list for annotating and pushing to a registry
  inspect     Display an image manifest, or manifest list
  push        Push a manifest list to a repository

Run 'docker manifest COMMAND --help' for more information on a command.

~/go/src/github.com/docker/cli env_experimental eli@castlerock
❯ DOCKER_CLI_EXPERIMENTAL=disabled ./build/docker manifest
docker manifest is only supported on a Docker cli with experimental cli features enabled

~/go/src/github.com/docker/cli env_experimental eli@castlerock
❯ ./build/docker manifest
docker manifest is only supported on a Docker cli with experimental cli features enabled

- Description for the changelog

* Added the option to enable experimental cli features through the `DOCKER_CLI_EXPERIMENTAL environment variable

- A picture of a cute animal (not mandatory but encouraged)
pirate

@@ -180,6 +180,10 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
}

func isEnabled(value string) (bool, error) {
// Environment variable always overrides configuration
if os.Getenv("DOCKER_CLI_EXPERIMENTAL") != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the documentation, and add this env-var to the list in https://github.com/docker/cli/blob/master/docs/reference/commandline/cli.md#environment-variables ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this means that DOCKER_CLI_EXPERIMENTAL=false docker manifest will be valid? Maybe we should match the configuration file values instead of just checking the existence of the environment variable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem very consistent at the moment, for instance there is

func contentTrustEnabled() bool {
	if e := os.Getenv("DOCKER_CONTENT_TRUST"); e != "" {
		if t, err := strconv.ParseBool(e); t || err != nil {
			// treat any other value as true
			return true
		}
	}
	return false
}

but

func hide(cmd *cobra.Command) *cobra.Command {
	// If the environment variable with name "DOCKER_HIDE_LEGACY_COMMANDS" is not empty,
	// these legacy commands (such as `docker ps`, `docker exec`, etc)
	// will not be shown in output console.
	if os.Getenv("DOCKER_HIDE_LEGACY_COMMANDS") == "" {
		return cmd
	}
…

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah for it to be uniform with what the value in the config is, it would need to be either enabled or disabled. Should I change it to that?

Copy link
Contributor Author

@seemethere seemethere Jun 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what the diff would look like for that:
diff --git a/cli/command/cli.go b/cli/command/cli.go
index 37e3e10e..0597341d 100644
--- a/cli/command/cli.go
+++ b/cli/command/cli.go
@@ -182,7 +182,7 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
 func isEnabled(value string) (bool, error) {
        // Environment variable always overrides configuration
        if os.Getenv("DOCKER_CLI_EXPERIMENTAL") != "" {
-               return true, nil
+               value = os.Getenv("DOCKER_CLI_EXPERIMENTAL")
        }
        switch value {
        case "enabled":

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR @seemethere ! At first we wanted the user to explicitly enable the experimental features only by adding a value in the config file. But maybe with env var it is also explicit enough? WDYT @vdemeester ?

@@ -180,6 +180,10 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
}

func isEnabled(value string) (bool, error) {
// Environment variable always overrides configuration
if os.Getenv("DOCKER_CLI_EXPERIMENTAL") != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this means that DOCKER_CLI_EXPERIMENTAL=false docker manifest will be valid? Maybe we should match the configuration file values instead of just checking the existence of the environment variable?

@seemethere seemethere force-pushed the env_experimental branch 2 times, most recently from 7326275 to 5c88f6f Compare June 24, 2018 21:03
@seemethere seemethere requested a review from vdemeester as a code owner June 24, 2018 21:03
Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
@seemethere
Copy link
Contributor Author

seemethere commented Jun 24, 2018

Updated to environment variable to only accept enabled or disabled per @silvin-lubecki's suggestion, and added a mention in the docs per @thaJeztah's suggestion.

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @seemethere , LGTM !

Copy link
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐸

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah thaJeztah merged commit 61e53fc into docker:master Jun 25, 2018
@GordonTheTurtle GordonTheTurtle added this to the 18.06.0 milestone Jun 25, 2018
@seemethere seemethere deleted the env_experimental branch July 13, 2018 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants