Skip to content

Add env variable option for experimental - #1138

Merged
thaJeztah merged 1 commit into
docker:masterfrom
seemethere:env_experimental
Jun 25, 2018
Merged

thaJeztah merged 1 commit into
docker:masterfrom
seemethere:env_experimental

Conversation

@seemethere

@seemethere seemethere commented Jun 21, 2018 •

Copy link
Copy Markdown
Contributor

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

Comment thread cli/command/cli.go Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

@seemethere seemethere Jun 22, 2018 •

Copy link
Copy Markdown
Contributor Author

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":

@silvin-lubecki silvin-lubecki left a comment •

Copy link
Copy Markdown
Contributor

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 ?

Comment thread cli/command/cli.go Outdated

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

Copy link
Copy Markdown
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

seemethere commented Jun 24, 2018 •

Copy link
Copy Markdown
Contributor Author

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.

@silvin-lubecki silvin-lubecki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @seemethere , LGTM !

@vdemeester vdemeester left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 🐸

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

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